aboutsummaryrefslogtreecommitdiff
path: root/bullet.c
diff options
context:
space:
mode:
authorquou <quou@disroot.org>2023-05-05 13:44:23 +1000
committerquou <quou@disroot.org>2023-05-05 13:44:23 +1000
commitfb104368dd33b66e0575dcc0327cbae7046a4e1e (patch)
tree67a1a66182aa8417b8fbb431576528c28f4a5ab8 /bullet.c
parent280552fa4750b5dac9243782f9c0a7e0b7eea6f8 (diff)
Add killing enemies.
Diffstat (limited to 'bullet.c')
-rw-r--r--bullet.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/bullet.c b/bullet.c
index a2f1c66..b3182ea 100644
--- a/bullet.c
+++ b/bullet.c
@@ -3,6 +3,7 @@
#include "error.h"
#include "platform.h"
#include "sprite.h"
+#include "standard.h"
#include "world.h"
Entity new_player_bullet(
@@ -17,6 +18,7 @@ Entity new_player_bullet(
CBullet* bullet;
CPosition* pos;
CSprite* sprite;
+ CCollider* col;
Sprite_ID sprid;
e = new_entity(world);
@@ -27,11 +29,13 @@ Entity new_player_bullet(
ctype_sprite |
ctype_position |
ctype_bullet |
- ctype_player_bullet
+ ctype_player_bullet |
+ ctype_collider
);
pos = &world->positions[e];
sprite = &world->sprites[e];
bullet = &world->bullets[e];
+ col = &world->colliders[e];
pos->x = x;
pos->y = y;
@@ -39,14 +43,25 @@ Entity new_player_bullet(
bullet->vy = vy;
bullet->life = life;
+ col->x = 0;
+ col->y = 0;
+
if (vx < 0) {
sprid = sprite_player_bullet_left;
+ col->w = 9 << fbits;
+ col->h = 14 << fbits;
} else if (vx > 0) {
sprid = sprite_player_bullet_right;
+ col->w = 9 << fbits;
+ col->h = 14 << fbits;
} else if (vy < 0) {
sprid = sprite_player_bullet_up;
+ col->w = 9 << fbits;
+ col->h = 14 << fbits;
} else if (vy > 0) {
sprid = sprite_player_bullet_down;
+ col->w = 9 << fbits;
+ col->h = 14 << fbits;
}
#ifdef DEBUG
else {
@@ -71,6 +86,7 @@ int new_enemy_bullet(
CBullet* bullet;
CPosition* pos;
CSprite* sprite;
+ CCollider* col;
e = new_entity(world);
@@ -80,11 +96,13 @@ int new_enemy_bullet(
ctype_sprite |
ctype_position |
ctype_bullet |
- ctype_enemy_bullet
+ ctype_enemy_bullet |
+ ctype_collider
);
pos = &world->positions[e];
sprite = &world->sprites[e];
bullet = &world->bullets[e];
+ col = &world->colliders[e];
pos->x = x;
pos->y = y;
@@ -92,6 +110,11 @@ int new_enemy_bullet(
bullet->vy = vy;
bullet->life = 500;
+ col->x = 1 << fbits;
+ col->y = 1 << fbits;
+ col->w = 3 << fbits;
+ col->h = 3 << fbits;
+
init_csprite(sprite, sprite_enemy_bullet);
return e;