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:
global first# = 0.0
global DIM enemyLast[9] as float
global DIM enemyDirection[9]
global DIM enemySpeed[9] as float
function updateEnemies()
first# = Timer()
for i = 0 to (enemyCount - 1) step 1
if enemies[i] <> 0
if first >= (enemyLast[i] + enemyDirection[i])
enemySpeed[i] = enemySpeed[i] * -1
SetSpritePhysicsVelocity(enemies[i], enemySpeed[i] * 100, GetSpritePhysicsVelocityY(enemies[i]))
enemyLast[i] = first
enemyDirection[i] = random(1,5)
else
SetSpritePhysicsVelocity(enemies[i], enemySpeed[i] * 100, GetSpritePhysicsVelocityY(enemies[i]))
endif
endif
next i
endfunction
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