diff options
Diffstat (limited to 'enemy.c')
-rw-r--r-- | enemy.c | 29 |
1 files changed, 23 insertions, 6 deletions
@@ -9,6 +9,7 @@ Entity new_skull(World* world, int x, int y) { CSprite* sprite; CPosition* pos; CEnemy* enemy; + CCollider* col; Entity e; e = new_entity(world); @@ -18,15 +19,22 @@ Entity new_skull(World* world, int x, int y) { ctype_position | ctype_sprite | ctype_enemy | - ctype_skull + ctype_skull | + ctype_collider ); pos = &world->positions[e]; sprite = &world->sprites[e]; enemy = &world->enemies[e]; + col = &world->colliders[e]; pos->x = x; pos->y = y; + col->x = 2 << fbits; + col->y = 2 << fbits; + col->w = 14 << fbits; + col->h = 14 << fbits; + init_csprite(sprite, sprite_skull_right); enemy->hp = skull_hp; @@ -44,13 +52,22 @@ void enemy_system(World* world) { Player* player; CPosition* ppos; int dpx, dpy, tpx, tpy, d; - char buf[32]; player = &world->player; ppos = &world->positions[player->entity]; for (i = 0; i < world->entity_count; i++) { bits = world->bitmask[i]; + if (bits & ctype_enemy) { + enemy = &world->enemies[i]; + if (enemy->hp <= 0) { + destroy_entity(world, i); + } + } + } + + for (i = 0; i < world->entity_count; i++) { + bits = world->bitmask[i]; if ( (bits & ctype_position) && (bits & ctype_enemy) && @@ -59,8 +76,8 @@ void enemy_system(World* world) { pos = &world->positions[i]; enemy = &world->enemies[i]; - dpx = (ppos->x - pos->x) >> 4; - dpy = (ppos->y - pos->y) >> 4; + dpx = ((ppos->x - pos->x) >> 4) + 256; + dpy = ((ppos->y - pos->y) >> 4) + 256; tpx = dpx; tpy = dpy; d = ((dpx * dpx) >> fbits) + ((dpy * dpy) >> fbits); @@ -89,8 +106,8 @@ void enemy_system(World* world) { new_enemy_bullet( world, - pos->x, - pos->y, + pos->x + 2560, + pos->y + 2560, tpx * enemy_bullet_speed, tpy * enemy_bullet_speed ); |