Enemy movement problem

BlitzMax Forums/BlitzMax Beginners Area/Enemy movement problem

ScottFromCanada(Posted 2010) [#1]
Edit: Solved it! Thanks anyway.

Hi all.

I am just dipping my toes into Blitzmax and am creating a very simple game to start. Basically there will be an "enemy car" that will be moving around the screen. The "player" will use their mouse to try to avoid the enemy car.

Problem being that I want the enemy car, once it hits either edge of the screen to reverse and go the other way. I can get the car to stop once it reaches the edge but not reverse it's field. Here is my code.



And here is my main loop.



Many thanks in advance.

Scott

Last edited 2010


Czar Flavius(Posted 2010) [#2]
I'm glad you've solved it! Solutions I would use for this situation are: make the speed = -speed when you reach the edge, or have a direction field and assign an id number to left and right eg 1 and 2, and adjust the speed depending on that.

Maybe it's the way you pasted it, but you should consider indenting your code to make it more readable.

Happy new year!


ScottFromCanada(Posted 2011) [#3]
Happy New Year and thanks for the advice! I will begin indenting my code for readability purposes. The way I solved it was to make the speed =-speed. Glad to see I am on the right track!