07-31-2001, 08:43 AM
I'm having a problem with my enemies' collision detection routine. I have the whole code for each enemy in an array of timers. By changing a variable, the different action for that enemy is determined. My collision detection section is accessed by the GoSub and Return commands. This works fine with all the enemies except for Enemy(0). It always registers as touching another enemy, when it isn't!
(My code didn't look very good in the text, so I attached it. Just make sure you have WordWrap in Notepad set to off.)
The movement sections look at the EnemyTouches(index) value to determine whether the enemy is touching anything, and thus, whether or not to stop.
first off the code looks to complicated for the task.
i would declare i as an integer then
for i = 0 to (number of enemies-1 )
if enemy(i).top + enemy(i). height .....
' i dont know it this would help because i dont have the time to look deeper into it but i will later. also is this in a timer? i prefer to use a loop instead of a timer because a loop seems to be more efficient to me (just an opinion). ill see what i can come up with
07-31-2001, 08:16 PM
Yes, it is in a timer, and a loop. I tried using a function, but there were problems when multiple enemies tried to use it at the same time.
07-31-2001, 11:19 PM
I don't wish to feel like an *** or anything, but you should refrain from timers in your code. The best method is to use a loop and a timestep..
then, call your series of subs from the loop..
do while endprogram = false
LocalChar 'Just a name for the sub that takes keyevents and determines what to do with them.. further examples can be given if needed
Physics 'This sub does all your physics calculations like gravity, position, collision detection, etc... this would utilize your timestep
Draw 'this would take the info in you vars [e.g. player.x] and blt to the backbuffer, then flip it to the primary once you are done drawing everything
CheckForOtherThings 'this could be a function that checks for player.health <= 0 and such...
you just have to make sure your form_uload looks like this:
private sub Form1_Unload(cancel as integer)
endprogram = true
'any other unititialization needed
07-31-2001, 11:21 PM
ahh, *sigh* i also forgot to note the fact that you need to calculate the timestep in there..
in the loop, you would need to throw in a:
thistime = timeGetTime
timestep = thistime - lasttime
lasttime = thistime
08-01-2001, 11:22 AM
I really don't like to use the nearly endless loops like that, they seem to lock up my computer.
08-01-2001, 08:29 PM
Indeed, they do that..
add a line:
sleep 5 [or 10 possibly]
through in a DoEvents, i froze my computer many times before remembering to add it in.
08-05-2001, 02:02 PM
lol, yes, don't forget that either :)