Only draw bullets on screen.
This commit is contained in:
parent
ec72a5dd40
commit
7df9ad09e2
|
@ -24,6 +24,7 @@ static void huntTarget(Bullet *b);
|
||||||
static void checkCollisions(Bullet *b);
|
static void checkCollisions(Bullet *b);
|
||||||
|
|
||||||
static Bullet bulletDef[BT_MAX];
|
static Bullet bulletDef[BT_MAX];
|
||||||
|
static Bullet *bulletsToDraw[MAX_BULLETS_TO_DRAW];
|
||||||
|
|
||||||
void initBulletDefs(void)
|
void initBulletDefs(void)
|
||||||
{
|
{
|
||||||
|
@ -58,9 +59,12 @@ void initBulletDefs(void)
|
||||||
|
|
||||||
void doBullets(void)
|
void doBullets(void)
|
||||||
{
|
{
|
||||||
|
int i = 0;
|
||||||
Bullet *b;
|
Bullet *b;
|
||||||
Bullet *prev = &battle.bulletHead;
|
Bullet *prev = &battle.bulletHead;
|
||||||
|
|
||||||
|
memset(bulletsToDraw, 0, sizeof(Bullet*) * MAX_BULLETS_TO_DRAW);
|
||||||
|
|
||||||
for (b = battle.bulletHead.next ; b != NULL ; b = b->next)
|
for (b = battle.bulletHead.next ; b != NULL ; b = b->next)
|
||||||
{
|
{
|
||||||
b->x += b->dx;
|
b->x += b->dx;
|
||||||
|
@ -86,6 +90,18 @@ void doBullets(void)
|
||||||
free(b);
|
free(b);
|
||||||
b = prev;
|
b = prev;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (collision(b->x - b->w - battle.camera.x, b->y - b->h - battle.camera.y, b->w * 2, b->h * 2, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT))
|
||||||
|
{
|
||||||
|
bulletsToDraw[i++] = b;
|
||||||
|
if (i >= MAX_BULLETS_TO_DRAW)
|
||||||
|
{
|
||||||
|
printf("Too many bullets to draw\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
prev = b;
|
prev = b;
|
||||||
}
|
}
|
||||||
|
@ -98,7 +114,7 @@ static void checkCollisions(Bullet *b)
|
||||||
|
|
||||||
candidates = getAllEntsWithin(b->x, b->y, b->w, b->h, NULL);
|
candidates = getAllEntsWithin(b->x, b->y, b->w, b->h, NULL);
|
||||||
|
|
||||||
for (i = 0, e = candidates[i] ; e != NULL ; i++, e = candidates[i])
|
for (i = 0, e = candidates[i] ; e != NULL ; e = candidates[++i])
|
||||||
{
|
{
|
||||||
if (e->type == ET_FIGHTER)
|
if (e->type == ET_FIGHTER)
|
||||||
{
|
{
|
||||||
|
@ -141,9 +157,10 @@ static void checkCollisions(Bullet *b)
|
||||||
|
|
||||||
void drawBullets(void)
|
void drawBullets(void)
|
||||||
{
|
{
|
||||||
|
int i;
|
||||||
Bullet *b;
|
Bullet *b;
|
||||||
|
|
||||||
for (b = battle.bulletHead.next ; b != NULL ; b = b->next)
|
for (i = 0, b = bulletsToDraw[i] ; b != NULL ; b = bulletsToDraw[++i])
|
||||||
{
|
{
|
||||||
blitRotated(b->texture, b->x - battle.camera.x, b->y - battle.camera.y, b->angle);
|
blitRotated(b->texture, b->x - battle.camera.x, b->y - battle.camera.y, b->angle);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
#define TURN_SPEED 2
|
#define TURN_SPEED 2
|
||||||
#define TURN_THRESHOLD 3
|
#define TURN_THRESHOLD 3
|
||||||
|
#define MAX_BULLETS_TO_DRAW 512
|
||||||
|
|
||||||
extern SDL_Texture *getTexture(char *filename);
|
extern SDL_Texture *getTexture(char *filename);
|
||||||
extern void blitRotated(SDL_Texture *texture, int x, int y, int angle);
|
extern void blitRotated(SDL_Texture *texture, int x, int y, int angle);
|
||||||
|
|
Loading…
Reference in New Issue