Alien Ship movement(for a space invader clone)
Hello
Kinda need some advice on making a space invader type game, instead of the aliens moving in a snake formation.
So far, the background and the player turret is made all that is missing is the UFO`s code of moving around above the players turret. Jus need advice on how to go about this, since Im not sure if its AI or jus simple code to make the ship bounce to different directions when it hits the edges of the game map. anyone help?
PS: I dont want the ships to curl when they fly, making them turn instantly up down left or right can do
in space invaders, the aliens just move left or right, until they hit the edge of the screen; then they move down a bit and go in the other direction.
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])
As the UFO patterns are predefined, you can encode the movements with sequences (in fact, this is called a state machine). Something like this :
1. center of screen, on top (X=width/2, Y=1)
2. move to next line (Y=Y+1)
3. move to left until X=10
4. move to next line (Y=Y+1)
5. move to right until X=width/2
6. if (Y>50) go to state 2
7. finish
This will make a snake, you could code this with if/else/while blocks directly in the code. You could go for a more general approach and do some little scripting, a routine that would read a script like this (let's say your screen is 640x480), it's the snake described above :
S1=(SETPOS,320,1)
S2=(ADD_Y,1)
S3=(MOVE_LEFT_UNTIL,10)
S4=(ADD_Y,1)
S5=(MOVE_RIGHT_UNTIL,320)
S6=(IF_Y_GREATER_B,50,S2,S7)
S7=(FINISH)
There are probably better encoding/script for this task but you get the point. With scripts, you won't have to recompile the code each time you want to test new patterns. I know some libs are available for finite states machines, maybe it's worth a look, I haven't tested that one :
http://www.isd.mel.nist.gov/projects/omacapi/Software/FiniteStateMachine/FSMIntroPage.html
[edited by - bucheron on September 16, 2003 5:05:04 PM]
1. center of screen, on top (X=width/2, Y=1)
2. move to next line (Y=Y+1)
3. move to left until X=10
4. move to next line (Y=Y+1)
5. move to right until X=width/2
6. if (Y>50) go to state 2
7. finish
This will make a snake, you could code this with if/else/while blocks directly in the code. You could go for a more general approach and do some little scripting, a routine that would read a script like this (let's say your screen is 640x480), it's the snake described above :
S1=(SETPOS,320,1)
S2=(ADD_Y,1)
S3=(MOVE_LEFT_UNTIL,10)
S4=(ADD_Y,1)
S5=(MOVE_RIGHT_UNTIL,320)
S6=(IF_Y_GREATER_B,50,S2,S7)
S7=(FINISH)
There are probably better encoding/script for this task but you get the point. With scripts, you won't have to recompile the code each time you want to test new patterns. I know some libs are available for finite states machines, maybe it's worth a look, I haven't tested that one :
http://www.isd.mel.nist.gov/projects/omacapi/Software/FiniteStateMachine/FSMIntroPage.html
[edited by - bucheron on September 16, 2003 5:05:04 PM]
opps I guess I didnt put more detail, its gonna be like space invaders, but the alien ships will move about the playing area in a snake fashion, so far I`ve used this code:-
if(ufo[1].posx < 0)
{
changeloc = rand()%2;
if(changeloc == 0){
{
ufo[1].direction.x = ufolvlspeed;
}
}
if(changeloc == 1){
{
ufo[1].direction.x = ufolvlspeed;
ufo[1].direction.y = ufolvlspeed;
}
}
if(changeloc == 2){
{
ufo[1].direction.x = ufolvlspeed;
ufo[1].direction.y = ufolvlspeed;
}
}
basically when the ufo reaches the edge of X axis, the changeloc will make a rand number, this number decides out of 3 possible ways to move away from the edge(ufolvlspeed is jus how much it should move but that can be ignored for now), ones to move back instantly, the other two are to move away diagonally. So far it works nicly.
jus wanna know if theres another way to improve it.
I dunno if anyone here used to own an Philips G7000 console aka Oddessy. There was a game on it called "Terrahawks" or "Attack of the time lord" The alien ships on their moved in a random snake formation but they curled about and stuff making them pretty hard to shoot
if(ufo[1].posx < 0)
{
changeloc = rand()%2;
if(changeloc == 0){
{
ufo[1].direction.x = ufolvlspeed;
}
}
if(changeloc == 1){
{
ufo[1].direction.x = ufolvlspeed;
ufo[1].direction.y = ufolvlspeed;
}
}
if(changeloc == 2){
{
ufo[1].direction.x = ufolvlspeed;
ufo[1].direction.y = ufolvlspeed;
}
}
basically when the ufo reaches the edge of X axis, the changeloc will make a rand number, this number decides out of 3 possible ways to move away from the edge(ufolvlspeed is jus how much it should move but that can be ignored for now), ones to move back instantly, the other two are to move away diagonally. So far it works nicly.
jus wanna know if theres another way to improve it.
I dunno if anyone here used to own an Philips G7000 console aka Oddessy. There was a game on it called "Terrahawks" or "Attack of the time lord" The alien ships on their moved in a random snake formation but they curled about and stuff making them pretty hard to shoot
or you could make a whatsamacallit,ah i forget everything after heigh school.....mmmm the graphs that generate curves, anyway if you remember what they are called just make a few going down your screen and have the aliens following the points that plot them, you could move the curve left and right so it will make some randomness look, or change the values of the curve to sharpen or flaten it etc
Well I''m not sure if this is quite what you are looking for...but I''m currently developing a shoot ''em up style game (a little more robust than space invaders tho ), and I''m using a patharray for enemy movements.
Basically, I set up all the movement functions in excel (the scatter plot can be your best friend for planning enemy movements). When an enemy moves, it basically just changes its x and y positions based off of a predetermined difference (function, hard coded x,y values). So what I did was build path arrays for each movement of my enemies, following the format of [x diff, y diff] (excel can calculate these easily, I had to write a tool to convert the numbers from excel format to nice C++ array format).
Now during run time, each enemy can just get it''s next position from the path array.
I probably lost you, but what I am basically saying is that path arrays provide an efficient solution to having to calculate movements during runtime, and you have complete control over the enemy (say if I want an enemy to just all of a sudden go a random direction and then continue with its general flight pattern, you could do this by calculation during runtime, but it would be more of a headache than you need. Path array''s solve this headache quite nicely).
The whole ''patharray'' concept is not new, the idea of having predetermined movement paths has been implemented before. I wonder if anyone besides me has ever used excel to plan out enemy movements before...
Hope that gives ya some insight. Might be a little more than you need for space invaders clone tho.
You can check out a preview of my shmup by clicking the "Z Matrix Thread" link in my sig. It''s an extremely early version tho, much has changed since that release! (note: the link for download will be down for a few hours, I need to get the self extractor back on my webspace, should be on by this evening).
-Q
| Z Matrix Thread | | My Unfinished Page | | I need answers! | | Genaside presents: Hazard Ball | | Maddox |
Basically, I set up all the movement functions in excel (the scatter plot can be your best friend for planning enemy movements). When an enemy moves, it basically just changes its x and y positions based off of a predetermined difference (function, hard coded x,y values). So what I did was build path arrays for each movement of my enemies, following the format of [x diff, y diff] (excel can calculate these easily, I had to write a tool to convert the numbers from excel format to nice C++ array format).
Now during run time, each enemy can just get it''s next position from the path array.
I probably lost you, but what I am basically saying is that path arrays provide an efficient solution to having to calculate movements during runtime, and you have complete control over the enemy (say if I want an enemy to just all of a sudden go a random direction and then continue with its general flight pattern, you could do this by calculation during runtime, but it would be more of a headache than you need. Path array''s solve this headache quite nicely).
The whole ''patharray'' concept is not new, the idea of having predetermined movement paths has been implemented before. I wonder if anyone besides me has ever used excel to plan out enemy movements before...
Hope that gives ya some insight. Might be a little more than you need for space invaders clone tho.
You can check out a preview of my shmup by clicking the "Z Matrix Thread" link in my sig. It''s an extremely early version tho, much has changed since that release! (note: the link for download will be down for a few hours, I need to get the self extractor back on my webspace, should be on by this evening).
-Q
| Z Matrix Thread | | My Unfinished Page | | I need answers! | | Genaside presents: Hazard Ball | | Maddox |
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement