Sign in to follow this  
jbosch

How to implement a spaceshooter gameplay

Recommended Posts

jbosch    107
Hi,

I'm designing a game architecture, its a 2D space shooter (user spaceship in the bottom of the screen, looking to up, and enemy spaceships at the top of the screen, looking and moving to down).

- Wich is the best option to make appear on the screen a list of referenced enemies? (they do not have to appear all at the same time, obviously)? may be controlling the elapsed time? may be controlling the "space" the player has traveled?

Thanks!

Share this post


Link to post
Share on other sites
Chetanhl    354
I think you should try some similar games and see how they work.
Here is one such game -
http://www.gamedev.net/community/gds/viewentry.asp?projectid=301616

Share this post


Link to post
Share on other sites
jbosch    107
Quote:
Original post by Chetanhl
I think you should try some similar games and see how they work.
Here is one such game -
http://www.gamedev.net/community/gds/viewentry.asp?projectid=301616


Thanks but there are no code assets or design there, isn't it?

Share this post


Link to post
Share on other sites
Chetanhl    354
Quote:
Original post by jbosch
Quote:
Original post by Chetanhl
I think you should try some similar games and see how they work.
Here is one such game -
http://www.gamedev.net/community/gds/viewentry.asp?projectid=301616


Thanks but there are no code assets or design there, isn't it?


Yes there are no code assets or design there but you can observe enemy behaviour. That game is quite fun.

Share this post


Link to post
Share on other sites
jbosch    107
Quote:
Original post by szecs
Well, you asked for behaviour which has nothing to do with the code.


that's because my bad english, sorry :-P

But I'd like to know how to implement a kind of game like that, I already know how to do isolated things like read keyboard input and move the spaceship, make it fire, check collision detection with enemies...

but what it is more difficult for me is to architect the game to allow it to grow and have multiple levels, specially how to serialize the "level objects" into an object.

Thanks!

Share this post


Link to post
Share on other sites
szecs    2990
Don't overdo objects IMHO. Just make the game work, the more games you make, the better the architecture will be. I think it's no use to struggle with a perfect/clever design if you are a beginner, it's your first game after all.

You know all the elements, sit down, and start to code. Some planning on paper with a pen can do wonders. For levels: maybe you could look into "state machines", but that's just one way to solve things. I usually do the "level" things with a bit more complex game loop instead of game states.

Share this post


Link to post
Share on other sites
jbosch    107
Quote:
Original post by szecs
Don't overdo objects IMHO. Just make the game work, the more games you make, the better the architecture will be. I think it's no use to struggle with a perfect/clever design if you are a beginner, it's your first game after all.

You know all the elements, sit down, and start to code. Some planning on paper with a pen can do wonders. For levels: maybe you could look into "state machines", but that's just one way to solve things. I usually do the "level" things with a bit more complex game loop instead of game states.


ok, thanks for the advice, I'll follow it

Share this post


Link to post
Share on other sites
voguemaster    183
If you're talking about a 2D scrolling shooter, well, the idea is pretty simple
really.

At its base, you can prepare (ahead of time) an array of enemies (or whatever name
you might conjure for them) that are sorted by distance. When I say distance,
I mean in a logical coordinate space.
When the view scrolls, each frame it advances a certain X distance in the logical
space. At that point you can check if an enemy needs to enter the view.
One way of doing that is to check the next entity (they are sorted, remember ?)
and see if its within a certain threshold of the view's "top" position.

That's one way. Of course there are other ways. For a shooter that uses a tilemap
with attributes you might have a trigger so that when a tile is rendered (enters
the view) it activates its trigger, which can be to spawn the next enemy.

I've implemented such a game not too recently in J2ME. Works great so everything is
still fresh in my mind :)

Share this post


Link to post
Share on other sites
00chris00    144
I've made such a game, problem is I was quite new to C++ at the time, so not everything is done the right way.

Here's how I stored my enemies and weapons (= the bullets shown on screen):

list<Actor*> Enemies;
list<Weapon*> Weapons;

As for adding enemies, I wrote my own "scripting language" where the .mission files looked like this:
6
-1 RestartTimer
-1 If Kills> 3 EndMission
2000 SpawnEnemy 100
4000 SpawnEnemy 300
-1 WaitTillEnemies 0
-1 Goto 1

Of course you can make your ships appear randomly, or make an event queue:

typedef struct Event
{
long int T;
int E;
};
queue<Event *> event_q;

T is the number of milliseconds after which the event will be executed, E is the type of the event. As for executing the events, assuming the queue is sorted (you could use a priority queue for that), you only need to do this...
while(Events[NextEvent].T <= T.GetTicks())
{
//switch(Events[NextEvent].E)..
}


And this is how I add new enemies inside the code:

Enemies.push_back(new Actor(SCREEN_WIDTH-100,new_pos,Ships[1]));

Ships[1] is a pointer to a ShipType object. This way I could create different enemies. At the time, I didn't know what inheritance meant. :P

A bullet is fired like this... I pass the constructor the type of the weapon (again, inheritance was an unknown word at the time), the position and a pointer to the actor who fired the weapon.

Weapons.push_back(new Weapon(Type->MainGunWeapon,pos,this));


This is how enemies and weapons are Display()-ed:

void MoveViewEnemies()
{
list<Actor*>::iterator i;

for(i=Enemies.begin();i!=Enemies.end();i++)
{
(*i)->MoveByAI();
//If the enemy is not dead, show it on the screen
if((*i)->Move()) (*i)->Display(Screen);
//else destroy it
else
{
delete *i;
i=Enemies.erase(i);
}

if(i==Enemies.end()) break;
}
return;
}

void MoveViewWeapons()
{
list<Weapon*>::iterator i;

for(i=Weapons.begin();i!=Weapons.end();i++)
{
//Move the weapon, if it goes offscreen destroy it
if(!(*i)->Move())
{
delete *i;
//Weapons.pop_back();
i=Weapons.erase(i);
}
//Othewise show it on the screen
else (*i)->Show(Screen);

if(i==Weapons.end()) break;
}
return;
}


Collision detection is done inside the Move() functions.

If you need something else, let me know. I would have no problem giving you the full source code if it wasn't so "ugly".

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