Pages: 1
Topic closed
I created a Space Invaders game that works fine at normal speed, but misbehaves in turbo mode. The problem is that I move sprites incrementally by a fixed amount inside of loops. The loops are needed to do collision detection between sprites.
I've come up with a strategy to solve the problem by moving the sprites a variable amount based on how much time has elapsed since the last movement. A simplified version of the code is below. Does anyone have a better way to do this?
Thanks,
Corey
[blocks]
<set{ Pixels Per Second }to( 240
<set{ Last Time Moved }to( 0
<reset timer>
<repeat until><touching[ edge
<move( (( (( <timer> <-> <{ Last Time Moved }> )) <*> <{ Pixels Per Second }> )) )steps>
<set{ Last Time Moved }to( <timer>
<end>
[/blocks]
Offline
Maybe the wait until could be inside of a loop. I guess the condition in the wait until could check for the collisions and make sure enough time has passed for the sprite to move at least one pixel. Maybe this would help with performance since I wouldn't be looping for no good reason. Although, after done waiting, I would have to recheck for collisions and by then, the sprites may no longer be touching. The second check for collisions would affect performance too. I've found that sensing touching can be expensive.
This is how I would imagine using the wait until (is it what you meant?):
[block]
<forever>
<wait until> << <touching[ other sprites <or> enough time has passed to move this sprite at least one pixel >>
<if> << <touching[ a sprite <or> <touching[ a sprite >> etc.
do something
<end>
<move( x )steps>
<end>
[/block]
Offline
Topic closed
Pages: 1