PDA

View Full Version : help with tis problem



keller
October 12th, 2004, 10:53 PM
hi,i am doing a maze game. i am trying to make and enemy which will move randomly and when it touches/hits my hero it will go to another keyframe which says game over. i have tried a few times but my enemy could only move forward, can anyone help me with it??

thx. i got the fla file attached.
<!-- / message --><!-- attachments -->

keller
October 13th, 2004, 12:01 AM
hi,i am doing a maze game. i am trying to make and enemy which will move randomly and when it touches/hits my hero it will go to another keyframe which says game over. i have tried a few times but my enemy could only move forward, can anyone help me with it??

thx. i got the fla file attached.
<!-- / message --><!-- attachments -->anyone can help

keller
October 13th, 2004, 03:57 AM
anyone can help
Really need ur help

Dr Warm
October 13th, 2004, 04:42 AM
when i tried ur fla i couldn't get the enemy to move at all, also u seem to be using a tile based engine with art based buildings (did u get these ideas from tonypa or similar). the problem with ur enemy is that he can't tell if he's going to hit something.
With art based there's not really anyway to do this easily, this is because u can't check in advanced if something is going to hitTest == true with something until it happens.
The way to do this is to have four surrounding invisible squares around ur mc, have them called top, left, right and down. Then u have to go
if(_root.ball.top.hitTest(wall._x, wall._y, true){//<-- sorry i can't remember how to do hitTest, because i don't use them
//need to make new direction
number = Math.ceiling(Math.random()*3);
if(number == 1){
//heads down
_root.ball._y += 5;
}
if(number == 2){
_root.ball._x -= 5;
}
if(number == 3){
_root.ball._x += 5;
}
}

do u get what i mean, and u'd have to do something like this for all four sides, it'll get kindof messy.

What i'd recommend is going back to tonypa's tutes and just use the tile-based method, that he's already made and just 'borrow' his.


BTW please put a better title for threads i had know idea what this was about, like 'help with AI for maze' or similar.
And also many ppl don't have MX2004 so either save it in MX format or submit ur problem code and u (should) get quicker responses

keller
October 13th, 2004, 10:10 PM
when i tried ur fla i couldn't get the enemy to move at all, also u seem to be using a tile based engine with art based buildings (did u get these ideas from tonypa or similar). the problem with ur enemy is that he can't tell if he's going to hit something.
With art based there's not really anyway to do this easily, this is because u can't check in advanced if something is going to hitTest == true with something until it happens.
The way to do this is to have four surrounding invisible squares around ur mc, have them called top, left, right and down. Then u have to go
if(_root.ball.top.hitTest(wall._x, wall._y, true){//<-- sorry i can't remember how to do hitTest, because i don't use them
//need to make new direction
number = Math.ceiling(Math.random()*3);
if(number == 1){
//heads down
_root.ball._y += 5;
}
if(number == 2){
_root.ball._x -= 5;
}
if(number == 3){
_root.ball._x += 5;
}
}

do u get what i mean, and u'd have to do something like this for all four sides, it'll get kindof messy.

What i'd recommend is going back to tonypa's tutes and just use the tile-based method, that he's already made and just 'borrow' his.


BTW please put a better title for threads i had know idea what this was about, like 'help with AI for maze' or similar.
And also many ppl don't have MX2004 so either save it in MX format or submit ur problem code and u (should) get quicker responses
Ok,thank a lot.i try to use the tile-based method to do.if still can't,i will ask u ok?thanks..

keller
October 13th, 2004, 10:26 PM
Ok,thank a lot.i try to use the tile-based method to do.if still can't,i will ask u ok?thanks..
Anyone got another method to solve my problem....must tell me ok.

keller
October 13th, 2004, 11:18 PM
Anyone got another method to solve my problem....must tell me ok.
Sorry,i still can't understand the tile-based method,coz if i use tat method i wan change a lot of thing.Do u and ur have another method?

Dr Warm
October 14th, 2004, 03:57 AM
yeah for the tile based method u will have to change a few of ur things, but once u've changed them, if u want to change other things, it's easier just change a 0 to a 1 in an array etc. that's why i prefer this method

i think if u want to make AI with art based u'll have to devise your own method, because i can't think of any source that i have that will help you. But to start off with u'll need to do what i said before, with the four invisible boxes around the enemy for the hitTests.

keller
October 14th, 2004, 09:26 PM
yeah for the tile based method u will have to change a few of ur things, but once u've changed them, if u want to change other things, it's easier just change a 0 to a 1 in an array etc. that's why i prefer this method

i think if u want to make AI with art based u'll have to devise your own method, because i can't think of any source that i have that will help you. But to start off with u'll need to do what i said before, with the four invisible boxes around the enemy for the hitTests.
ok thanks.i ll try my best.but if u or ur got another idea must tell me ok.thank a lot.

Dr Warm
October 15th, 2004, 03:33 AM
i looked again at ur fla, but i don't really understand how it works, maybe there's a new function that i've not looked at thats in MX2004, but i don't understand it:drool:.

in ur _root.onEnterFrame function for the character, when u have:
if(Key.onDown(Key.RIGHT)){
CheckXY(something);
}
i can't seem to work out how the checkXY works! could u explain it to me, cos u could probably use this function for the enemy as well

keller
October 19th, 2004, 04:56 AM
i looked again at ur fla, but i don't really understand how it works, maybe there's a new function that i've not looked at thats in MX2004, but i don't understand it:drool:.

in ur _root.onEnterFrame function for the character, when u have:
if(Key.onDown(Key.RIGHT)){
CheckXY(something);
}
i can't seem to work out how the checkXY works! could u explain it to me, cos u could probably use this function for the enemy as well
em...1st i write a function call function CheckXY(x,y){},u can see in my fla file.After that,i write _root.onEnterFrame function,So we no need write
if(Key.onDown(Key.RIGHT)){
CheckXY(something);
}
in MC of red.
So if(Key.onDown(Key.RIGHT)){CheckXY(1,0)},the 1 is x-axis,and is positive value,so the object will go right when i press the right arrow key.Can u understand?And When CheckXY(0,1),that mean y-axis is positive.

Dr Warm
October 19th, 2004, 05:00 AM
no i get that bit, i just don't get how it see's what's to the left and right up and down, does it have something to do with u creating the tiles at the start, or is that only for the letters?

keller
October 19th, 2004, 10:10 PM
no i get that bit, i just don't get how it see's what's to the left and right up and down, does it have something to do with u creating the tiles at the start, or is that only for the letters?
left,right,up and down is for control my hero...So all i explain to u is only for my hero not the letter,Can get it?The purpose i write the function and the _root EnterFrame function is want use the arrow key to control my hero,so it will move around the maze when i press the up,dwon,left and rigth arrow key.Can get it?

Dr Warm
October 20th, 2004, 03:38 AM
No that's not what i mean, i'll take another look at ur fla and see for myself (it's been about a week or two can't quite remember)

keller
October 20th, 2004, 09:47 PM
No that's not what i mean, i'll take another look at ur fla and see for myself (it's been about a week or two can't quite remember)
ok....but my game will pass to my lecturer after 2week.em....u knw how to use xml?Coz i never learn tis before.

Dr Warm
October 21st, 2004, 03:54 AM
i only know the very basic.. basics, i would post on a different part of this forum for stuff on xml, there are heaps of ppl that use it alot

Dr Warm
October 21st, 2004, 05:54 AM
i tried to do a ai for u but it doesn't quite work i'm not sure why, maybe if u see what i did u'll be able to fix it (hope this is the right version!)

keller
October 21st, 2004, 09:53 PM
i tried to do a ai for u but it doesn't quite work i'm not sure why, maybe if u see what i did u'll be able to fix it (hope this is the right version!)
Thanx a lot...i try to modify,see can work?thanx...but if u hav good idea for me must tell me ok?or anyone knw how to solve my problem,please tell me.Thanx...

keller
October 21st, 2004, 10:41 PM
em...i can let the enemy work nw.but still got a little bit problem which is my enemy juz only can move randomly outer part of the maze.Can u tell me why?

Below is the fla file.

Dr Warm
October 22nd, 2004, 06:40 AM
em...i can let the enemy work nw. ok, at least that bits sorted, i'll see if i can get him to move around better, though i've not had much practice with this!

Dr Warm
October 22nd, 2004, 09:43 AM
em...i can let the enemy work nw.but still got a little bit problem which is my enemy juz only can move randomly outer part of the maze.Can u tell me why? yeah he only moves around the outer edge of the maze, because he only changes direction when something is blocking his way, and obviously if he's just moving along nothing 's blocking his way so he won't change direction.

There's two solutions to this:
1st: More simpler, just put walls in the way and force him to go there, but i don't think u want that do u?

2nd: Try to get him to scan directions while he's moving, test if he can move there and then move there, if he wants to. I've tried (and failed) to get this working, but maybe u can see what i'm trying to do in the fla file, for some reason it doesn't work, i can't figure it out.......

It should work, maybe there's an error in my logic, but more likely it's in the code

BTW when u post back, don't press reply in the bottom right corner, press "post reply" that way it doesn't just post all the things that i've said again, it makes it hard to read

keller
October 27th, 2004, 05:15 AM
i knw wat u doing,i try to modify a bit.Thanx a lot.anyone got new idea must tell me k?Thanx....

keller
October 27th, 2004, 11:09 PM
i think ur idea is good,so i use it.thanx u very much...

Dr Warm
October 28th, 2004, 04:02 AM
did u get it to work? if so can u tell me what i did wrong :P, just for peace of mind :D

also what did u want the XML for?

keller
October 28th, 2004, 09:38 PM
i juz delete the code below "startDir = downArrray[changeDir]" each direction,because i think that is good enough.

the XML i want is for connect my flash game,so i can change the language in my game,ei the word "flash" become chinese word,japanese or france.Can u understand?

Dr Warm
October 29th, 2004, 07:03 AM
oh yeah i read about that yesterday in samples for mx2004. have you looked at that one, seems simple enuf?

keller
November 2nd, 2004, 02:52 AM
i have look the file,but i dunno how to use it.u knw?i got one day only.Haiz...so sad.