Programming a movement path

Hi everyone,

First post. I'm just delving into the depths of game code properly and I've reached a stage where I have a game plan, and I have an image assigned to an enemy.

In space invaders the enemies started from a single line and then gradually moved down in a linear progression. I want to start enemies at a 0 point x axis and randomise the y start location then have them moving down in diagonal or straight lines.

So far I have an enemy structure, an image assigned to the enemy and a main application body. I just need to start on the movement routine.

I don't expect hand holding through the whole learning curve, just an idea of what to read up on or snippet routines that are similar to what I'm trying to achieve, which can be best summarised as:

start location (0,randomY)
target location (randomX, randomY)

connect start location to target location by straight path

Thanks!!
Last edited on
Linear Interpolation.

http://en.wikipedia.org/wiki/Linear_interpolation

And linear algebra in general. I hope you like maths.
Last edited on
closed account (D80DSL3A)
Do you have a timing mechanism built into your game yet? You need a means of calling functions at a chosen, regular frame rate so that object motion and other animation can be done.
Hi

I've moved on a bit from there now. I have two functions called main and timer. My main function draws all the objects in starting positions in a loop. For example pseudo-code):

main
for i=0; i < 25; i++
draw image at x,y

timer
xcord=xcord+1
ycord=ycord+1
drawimage


And what happens is one of the images moves (I am assuming it is the last one drawn, so I'm trying to figure out what I need to do to feed the movement into the image array

Thanks
I'm not too good at this stuff, but if it was on a timer and...
1
2
3
4
        xPos = 25;
        yPos = 50;
        xTarget = 5;
        yTarget = 6


Wouldn't you want to itterate towards your target?
1
2
3
4
5
6
        if( ( xPos > xTarget) && ( xPos != xTarget ) )
                xPos--;
        else if( ( xPos < xTarget ) && ( xPos != xTarget ) )
                xPos++;

        drawImage();
I'd say, rather something like
Object::SetMovement(Vector offset, int frames)

Basically, you pass a vector for the movements, and how many (logical) frames that movements should take. Actual movement would be done with an update() member function, that advances the objects state by one frame.
Topic archived. No new replies allowed.