Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Change enemy sprite directions

Author
Message
Ramtastic
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 6th Feb 2013 20:18
Hi,
I am working on my first game with AppGameKit and it is going pretty well.
I am having a hard time trying to get my enemies to change directions.

I have physics on for all sprites and enemies.
My player sprite and the enemies are dynamic sprites.

Here is my code:


What I am trying to do is have each enemy change direction at a random time.
I have an array to keep track of enemy ids, an array to keep track of their speed, an array to hold random values for them to reverse direction.

I loop over all the enemies I have, then if the entry is not 0 (meaning that enemy has been deleted), I check if the timer value is greater than the random value for that enemy plus the last value of time since they changed direction.

I think my logic is there but I am unable to see any errors.

Any help would be great.
Thanks
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 6th Feb 2013 21:07
You are assigning the Timer() return to a floating point variable (first#), which is correct.

But everywhere else you are using an integer variable (first) which is not apparently assigned a value.

Since the integer variable 'first' is zero by default, it will never trigger the if statement.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
TrezSoft
AGK Tool Maker
12
Years of Service
User Offline
Joined: 8th Nov 2012
Location: UK
Posted: 6th Feb 2013 21:08
All the "first" tests after you set first# do not have the # so they will be 0.
Ramtastic
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 6th Feb 2013 21:17 Edited at: 6th Feb 2013 21:43
Wow, I can't believe I missed that.
This moment deserves a face palm.


Thanks guys.
It works now.
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 7th Feb 2013 08:21
Ramtastic, glad you found a solution. Please don't make multiple posts on the same subject, thanks!


this.mess = abs(sin(times#))

Login to post a reply

Server time is: 2024-11-24 08:52:57
Your offset time is: 2024-11-24 08:52:57