diff options
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | config.h | 3 | ||||
-rw-r--r-- | enemy.c | 24 | ||||
-rw-r--r-- | intermediate/arms.bmp | bin | 262282 -> 262282 bytes | |||
-rw-r--r-- | intermediate/smol_slash_left.anm | 7 | ||||
-rw-r--r-- | intermediate/smol_slash_right.anm | 7 | ||||
-rw-r--r-- | obj.h | 1 | ||||
-rw-r--r-- | player.c | 36 |
8 files changed, 71 insertions, 9 deletions
@@ -87,6 +87,8 @@ anim_sources = \ $(int_dir)/guy_slash_right.anm \ $(int_dir)/slash_left.anm \ $(int_dir)/slash_right.anm \ + $(int_dir)/smol_slash_left.anm \ + $(int_dir)/smol_slash_right.anm \ objects = $(sources:%.c=%.o) images = $(image_sources:$(int_dir)/%.bmp=$(data_dir)/%.img) @@ -39,10 +39,13 @@ #define player_attack_frames 10 #define player_lunge_force (f1) #define player_slash_damage 1 +#define player_health 8 #define enemy_inv_frames 8 #define enemy_demon_move_force 32 #define enemy_demon_attack_dist f1 #define enemy_demon_jump_force (5 << fbits) +#define enemy_slash_damage 1 +#define enemy_knockback (4 << fbits) #endif @@ -92,7 +92,7 @@ void update_enemy_hurt(Enemy* e, const World* w) { a.y += e->y >> fbits; for (i = 0; i < w->deathzone_count; i++) { const Deathzone* dz = &w->deathzones[i]; - if (rects_overlap(&a, &dz->r)) { + if (dz->friendly && rects_overlap(&a, &dz->r)) { e->hp -= dz->hp; e->vx -= dz->vx; e->vy -= dz->vy; @@ -110,7 +110,7 @@ int tile_at(const Map* m, int x, int y) { m->collision[x + y * map_w] == 1; } -void update_demon_move(Enemy* e, const World* w) { +void update_demon_move(Enemy* e, World* w) { int nanim = e->anim; const Player* p = &w->player; if (e->state == enemy_state_patrol) { @@ -164,6 +164,24 @@ void update_demon_move(Enemy* e, const World* w) { } } else if (e->state == enemy_state_attack) { if (e->grounded < 3) { + Asset_ID sl; + Rect dz; + int sx, sy = e->y >> fbits, vx; + if (e->face == face_left) { + sl = asset_id_smol_slash_left_anm; + sx = (e->x >> fbits) - 16; + vx = enemy_knockback; + } else { + sl = asset_id_smol_slash_right_anm; + sx = (e->x >> fbits) + 16; + vx = -enemy_knockback; + } + dz.x = sx; + dz.y = sy; + dz.w = 16; + dz.h = 12; + inst_particle(w, sx, sy, sl, asset_id_arms_img); + inst_deathzone(w, &dz, vx, 0, enemy_slash_damage, 4, 0); e->state = enemy_state_patrol; } } @@ -191,7 +209,7 @@ void update_demon_move(Enemy* e, const World* w) { } } -void update_enemy_move(Enemy* e, const World* w) { +void update_enemy_move(Enemy* e, World* w) { switch (e->t) { case enemy_demon: update_demon_move(e, w); diff --git a/intermediate/arms.bmp b/intermediate/arms.bmp Binary files differindex 0b686f3..6d9b233 100644 --- a/intermediate/arms.bmp +++ b/intermediate/arms.bmp diff --git a/intermediate/smol_slash_left.anm b/intermediate/smol_slash_left.anm new file mode 100644 index 0000000..83c9026 --- /dev/null +++ b/intermediate/smol_slash_left.anm @@ -0,0 +1,7 @@ +1 +{ 96, 34, 16, 12 } +{ 112, 34, 16, 12 } +{ 128, 34, 16, 12 } +{ 144, 34, 16, 12 } +{ 160, 34, 16, 12 } +{ 176, 34, 16, 12 } diff --git a/intermediate/smol_slash_right.anm b/intermediate/smol_slash_right.anm new file mode 100644 index 0000000..d1c529d --- /dev/null +++ b/intermediate/smol_slash_right.anm @@ -0,0 +1,7 @@ +1 +{ 0, 34, 16, 12 } +{ 16, 34, 16, 12 } +{ 32, 34, 16, 12 } +{ 48, 34, 16, 12 } +{ 64, 34, 16, 12 } +{ 80, 34, 16, 12 } @@ -19,6 +19,7 @@ typedef struct { int anim; int grounded, headbutted, on_ramp, jumping; int cooldown, slashing; + int inv, hp; Face face; Rect rect; } Player; @@ -8,6 +8,8 @@ #include "render.h" #include "world.h" +const Rect player_rect = { 5, 4, 5, 12 }; + void init_player(Player* p) { p->anim = asset_id_guy_run_right_anm; p->x = 0; @@ -22,6 +24,8 @@ void init_player(Player* p) { p->cooldown = 0; p->slashing = 0; p->face = face_right; + p->inv = 0; + p->hp = player_health; } void update_player_anim(Player* p) { @@ -30,12 +34,11 @@ void update_player_anim(Player* p) { } void update_player_phys(Player* p, const Map* map) { - const Rect r = { - 5 << fbits, - 4 << fbits, - 5 << fbits, - 12 << fbits - }; + Rect r = player_rect; + r.x <<= fbits; + r.y <<= fbits; + r.w <<= fbits; + r.h <<= fbits; update_body( map, &p->x, @@ -151,6 +154,26 @@ void update_player_move(Player* p, const App* a, World* w) { } } +void update_player_hurt(Player* p, World* w) { + int i; + Rect r = player_rect; + r.x += p->x >> fbits; + r.y += p->y >> fbits; + if (p->inv) { + p->inv--; + return; + } + for (i = 0; i < w->deathzone_count; i++) { + const Deathzone* dz = &w->deathzones[i]; + if (!dz->friendly && rects_overlap(&r, &dz->r)) { + p->hp -= dz->hp; + p->vx -= dz->vx; + p->vy -= dz->vy; + p->inv = enemy_inv_frames; + } + } +} + void update_player( Player* p, World* w, @@ -158,6 +181,7 @@ void update_player( const Map* map ) { update_player_move(p, app, w); + update_player_hurt(p, w); update_player_phys(p, map); update_player_anim(p); } |