How to use Vectors for a game

Ok so i'm making a frogger game, and for the enemies i would like to put them into vectors as currently the way i do it at the moment is rather clunky (code follows)

My enemies need to have:

- A X and Y Pos, the Y pos will stay the same for each 'set' of enemies, but the X pos needs to change for each one
- A X velocity

I'm just not sure how to put all this into a vector the main thing that's confusing me is the X position how i can have it change each time a new item is put into the vector.

Of course the code is put in the correct sections of my game.cpp:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

e1.setPosX(1000);
e1.setPosY(550);
e1.setVelX(-35);

enemySprite=sf::Sprite(enemyImage);
enemySprite.SetCenter(enemySprite.GetSize().x/2,enemySprite.GetSize().y/2);

win->Draw(enemySprite);

if(elapsedTime>1.0F/FRAMERATE)
{

	e1.setPosX(e1.getPosX() + elapsedTime * e1.getVelX());
	Clock.Reset();

}

	if (e1.getPosX() < -55) //wrap function for the x axis
	{
		e1.setPosX(1044);
	}
closed account (Dy7SLyTq)
define a class. then vector<your_class>
Topic archived. No new replies allowed.