Sign in to follow this  
Mava_b

Creating 'Space Harrier' Styled Games

Recommended Posts

Hi everyone, Needing some help with the making of a 'Space Harrier' type game. By this, I mean a game that has a 3D perspective using 2D graphics. I'm having trouble with finding an effective way to plotting enemies as the player progresses through the level. If I used a counter to count the frames as the player progresses then use a 'if frame==1000000 then make enemey' I begin to run into some memory trouble as the game progresses. Will also be looking to use an external file once I have a good format. If any gurus out there can point me to some sort of algorithm, or anything for that matter, that would be most appreciated. Thanks for listening! Mava

Share this post


Link to post
Share on other sites
Just for your information, this type of game is often referred to as "pseudo-3D".

It's hard to tell what exactly the problem is. You mentioned an error with regard to memory but made no mention of what pointers you use where. There are a lot of errors which could possibly fit that bill. Could you print the debug output and perhaps a portion of your code related to it on the forum?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Hi thanks for replying,

The difficulty I'm having is finding a good way to create a system which allows the game to know when to start making enemies. As the player plays the game, I want to find a way so that 20 seconds into the game an enemy appears, then another 60 seconds more enemies appear etc.

The idea mentioned above works fine until the counter stops incrementing and the game eventually crashes. Of course, the above is not an ideal solution at all, as some enemies need to be defeated before more are made.

I've made 2d platformers in the past, plotting enemies throughout the level has been quite simple.

The game basically contains an 'animated' background which enemies come from. I can make the enemies and do the collision checks without any probs.

Any help you could give as to what method(s) I could possibly look for would be great.

Thanks again.

Share this post


Link to post
Share on other sites
A 32 bit number (ie. an unsigned int[1]) gives you 2^32 possible values. At 60Hz that gives you approximatly two and a bit years before you're going to overflow and wrap around. I'd suggest that you'll get plenty of precision using this method, start looking elsewhere for the cause of your bug.

[1] Probably. Check your platform/compiler.

Share this post


Link to post
Share on other sites
Why not just create a timer?

Not something counting frames, but something counting time. A timer class would be great for this sort of thing.

if (timer->GetSeconds() >= 10)
SpawnEnemy();

or something to that effect.

Share this post


Link to post
Share on other sites
The unsigned int is working much better so far.

I've reworked my whole enemy class and the crashes seem to have died down, also prevented the int from incrementing when an enemy is onscreen so that they can be defeated before more are spawned.

The timer class has been giving me some inacurate numbers, but thanks anyway :)

Cheers for all the help.

Share this post


Link to post
Share on other sites
I agree with Rasmadrak

An events queue is a great way of handling timed events and it's quite flexible too!

You need a sorted data structure that holds events and times for the events. An example might be

Time | Event
------------
0+t | PlayStartMusic
20+t | CreateEnemyGroup
40+t | CreateEnemyGroup
60+t | CreateEnemyGroup
120+t| CreateBoss

where t is the start time of the game

At the start of the game you read the time and populate the event queue. Each iteration through your game loop you check if the time is greater or equal to the event at the top of the queue. If it is then you dive in to the queue and process all the events that should happen. e.g. at 20.003+t seconds your game loop might start again and you can see that the first CreateEnemyGroup should have happened so you do the Event listed and the remove it from the queue. Then your queue looks like this:

Time | Event
------------
40+t | CreateEnemyGroup
60+t | CreateEnemyGroup
120+t| CreateBoss

You can do handy things like if you want to make the player ship take damage every 5 seconds (say they've taken too long) you could have an entry like so:

Time | Event
------------
240+t | TooLong

Then the TooLong event adds an event to the queue at current time + 5 e.g. 245+t to call itself again.

Remember to sort your queue at the start and insert new events in the right place. e.g. if you add an event at 42+t to the original queue then your datastructure should look like this:

Time | Event
------------
0+t | PlayStartMusic
20+t | CreateEnemyGroup
40+t | CreateEnemyGroup
42+t | NewEvent
60+t | CreateEnemyGroup
120+t| CreateBoss

This way you only have to check the top most item in the list and not waste time checking a massive event queue.

Hope this helps :)

Share this post


Link to post
Share on other sites
Hi, Thanks for taking the time to reply Rasmadrak and Metorical.
You guys have helped LOADS. Your definitley a credit to GameDev.net.

I'm just in the process of writing a class which handles all of the list sorting/adding/executing and so far its going great!

I can now add easy support for file format and level editor! Yipeeeeeee!

Thanks again.
Best Regards, Mava

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this