Hum, i have a question!
How do you make/use a linked list?
========================
Game project(s):
www.fiend.cjb.net
Help with game...
dont make one...use a STL vector (or list, whatever suits you best)
oh, and allocating memory for each laser is not a worry at all - reshuffling arrays is a much more time consuming task.
if you are really bothered about memory allocation you can tell a vector to pre-allocate space for x elements...
oh, and allocating memory for each laser is not a worry at all - reshuffling arrays is a much more time consuming task.
if you are really bothered about memory allocation you can tell a vector to pre-allocate space for x elements...
dont make a linked list yourself...use a STL vector (or list, whatever suits you best)
oh, and allocating memory for each laser is not a worry at all - reshuffling arrays is a much more time consuming task.
if you are really bothered about memory allocation you can tell a vector to pre-allocate space for x elements...
oh, and allocating memory for each laser is not a worry at all - reshuffling arrays is a much more time consuming task.
if you are really bothered about memory allocation you can tell a vector to pre-allocate space for x elements...
June 21, 2000 09:34 AM
Linked lists would be cool to hold the enemy ships but don''t use linked lists for the laser bullets! Lasers shoot faster(usually) then regular bullets and missles. In my game I only had 2 or 3 lasers on screen at a time, you might have 10 if your lasers bounce or are ultra-slow but still use an array for this. For the second laser you can cheese it by saying paint(x,y) then paint(x+offset,y). But the collision is not right so I would make them two swperate lasers, so you will have and array of 6 or 10 of them. Something like this
class Laser
{
int x;
int y;
boolean is_alive = false;
int speed = 5;
Color c = Color.red;
int height = 8,width = 2;
void fire_laser()
{
x = ship.x + ship.laser1_xoffset;
y = ship.y + ship.laser2_yoffset;
is_alive = true;
}
void draw_laser()
{
if(is_alive)
{
draw_rect[however using color,height,width,x,y]
y -= speed;//if 0 is at the top
if(y < 0 // y > screen_height)
is_alive = false;
}
}
}
then in your player ship class hav an array of these lasers and an index to remember which laser your on. Just remember to cycle the index variable back to zero so you don''t go out of bounds on your array when you are firing the missles. Then every frame I just go through the lasers in a for loop and call their draw_laser method which draws them if they are alive. Good luck!
class Laser
{
int x;
int y;
boolean is_alive = false;
int speed = 5;
Color c = Color.red;
int height = 8,width = 2;
void fire_laser()
{
x = ship.x + ship.laser1_xoffset;
y = ship.y + ship.laser2_yoffset;
is_alive = true;
}
void draw_laser()
{
if(is_alive)
{
draw_rect[however using color,height,width,x,y]
y -= speed;//if 0 is at the top
if(y < 0 // y > screen_height)
is_alive = false;
}
}
}
then in your player ship class hav an array of these lasers and an index to remember which laser your on. Just remember to cycle the index variable back to zero so you don''t go out of bounds on your array when you are firing the missles. Then every frame I just go through the lasers in a for loop and call their draw_laser method which draws them if they are alive. Good luck!
quote: Original post by JonatanHedborg
Hum, i have a question!
How do you make/use a linked list?
========================
Game project(s):
www.fiend.cjb.net
Simple:
typedef struct ListElement_typ{ int value; ListElement_ptr next;}ListElement, ListElement_ptr;
You just dynamically allocate memory for the next element, i.e. element1.next = new ListElement;
etc.. You can also have a link back to the previous element of the list. At the beginning and the end of the linked list you need to put a null pointer, or you can just link the list in a circle. You process the list iteratively.
------------------------------
#pragma twice
Edited by - furby100 on June 21, 2000 1:12:48 PM
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement