Moving from one position to another

Monkey Forums/Monkey Beginners/Moving from one position to another

CanisLupus(Posted April) [#1]
I am creating a platform game and I just want the enemies to move from point A to point B and then from point B to point A forever. I have tried to use a timer which failed so can someone please tell me how to do this?

therevills(Posted April) [#2]
Pseudo code:

CanisLupus(Posted April) [#3]
I got an error saying - Identifier 'RIGHT' not found.

CanisLupus(Posted April) [#4]
Nevermind, I found the way to fix it. Thank you

CanisLupus(Posted April) [#5]
Just realised I got a few questions: What is the startX for and how can I create more than one enemy without creating a new class?

CanisLupus(Posted April) [#6]
I got another major issue here, my map is tall so I added a scrolling function which means when the player moves, the map moves as well. The problem is that the enemy is also moving rather than staying in that position.

Gerry Quinn(Posted April) [#7]
The way therevells set it up, startX is where the enemy begins. It's in between startX-maxSteps and startX+maxSteps which are the two end-points. The enemy moves at speedX in the appropriate direction until it reaches one, then changes direction to head towards the other.

There are other ways you could do it - many people would store the two end points, and set the enemy to the midpoint of them when it starts. Either way is fine.

As for scrolling, the enemy only needs to know its position on the map. Where it gets drawn on screen is a combination of where it is on the map, plus where the map is on screen. If the enemy is at 100,200 on the map, and the map is being drawn (because of the player position) so that the top left of the screen is 50,40 on the map, then the enemy is drawn at 50,160 on the screen (100-50,200-40).

You can have lots of instances of any class - each instance has its own set of fields. Each enemy is created using a New statement which sets its x and y position. They will be stored as fields of your App class (in the simplest case) - maybe individual named enemies or an array of them or whatever.