Making a Zombie C++ game SDL

Making a simple 2d birds eye view zombie survival, I am woundering how to make a simple timer to use in my code in order to set a pace for the zombie spawns and also slow down movement. (I am assuming this would solve the problem, it very well might not.)

My code is pretty basic for moving as a the person its just

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
if (keys[SDLK_UP])
{
ManY -= 1;
}
if (keys[SDLK_DOWN])
{
ManY += 1;
}
if (keys[SDLK_RIGHT])
{
ManX += 1;
}
if (keys[SDLK_LEFT])
{
ManX -= 1;
}
if(keys[SDLK_SPACE])
{
shoot=true;
}


All that does is control the character.


Questions I need help with:

Q: How can I get 4 zombies to spawn in their individual corners at a set frequency (every 3 seconds)

A: ???

Q: At the moment my movement is way to fast with that code, even set at - or + 1 pixel, what can I do in order to slow down movement.

A: ???

Q: When space bar is pressed I can make a bullet spawn and move in a set direction. How can I check what direction the man is facing? Should I make four if statments like

if(shoot=true && left=true)
[
bullet draw sprite etc.
]

And in the movement when you press down an arrow key it sets left right up and down all to false and sets w.e key you pressed to true so when you press space it checks which one is true to determine the direction the bullet should go and just subtract + or - X pixels from it x or y depending on the direction they are facing, would that work as a soulution?

A: ??

Q: Lastly I have an idea of a way to get the zombies to chase the person just have them move at a set pace based on the net of their ManX-ZombieX and ManY-ZombieY.

A: ??

Thank you for reading this, sorry for all the novice questions.
Any help you guys can provide would be GREATLY appreciated
Last edited on
Ah damn. I made something to similar to this about a year ago to get to grips with a proprietary game engine we had to use: http://www.youtube.com/watch?v=Aoe64KjMYXM

Unfortunately I've lost the source code! :-(

Moving toward player/bullet direction
As I said it was I proprietary engine, so not SDL but I remember using vectors rather than Cartesian coordinates for everything. Made a Vector2D class that did everything I wanted it to. This helps for making the zombies move towards the player because you can find the play position and set a bearing to that position, having them constantly walk forward.

You could achieve this using trigonometry, but the trigonometric functions in C++ are very slow. The same goes for the bullet. You can check the players bearing and create a bullet going in that direction at a fixed speed. The bullets and zombies are remarkably similar. The only differences are that the zombies update their bearing based on the player's position at each frame whereas the bullets don't, and the zombies are way slower than the bullet.

Spawning
I had random spawns outside of the playing area. I had a zombie class, then a collection class managing them. It basically allowed a certain amount to exist and, if one didn't (it had been killed) it used that slot to spawn a new one. It was all static memory, so it kept performance steady (although the video capture software in that video doesn't show it).

Timing
I can't actually remember how this worked, but I remember implementing a timer class and making sure all of the movements were multiplied by the frametime to make sure the game ran the same on different spec machines. My spawns/speed weren't dependent on time. There was a max_speed variable for the player and all of the spawning was done based on free slots in the collection class.


Sorry, I know this isn't particularly specific help, but I thought it may give you one or two ideas.
Last edited on
I'm in a similar position to you Schadek, learning c++/SDL stuff. As far as basics go I've not found a better website than this to start out with. Very useful:
http://lazyfoo.net/SDL_tutorials/
I would reccomend following along with those tutorials in a blank program, and then by the end you'll have a programme that can do most things you might want in a basic game which you can then use as like a base for any game you want to make.
Anyway, theres a couple tutorials there about making a timer that sounds like what you want, enjoy!
Topic archived. No new replies allowed.