From 59c7a9282dfc38da789a3716cbed30f588956034 Mon Sep 17 00:00:00 2001 From: Lephenixnoir Date: Mon, 30 Aug 2021 19:07:22 +0200 Subject: [PATCH] refined HUD --- CMakeLists.txt | 2 ++ assets-cg/hud_life.png | Bin 0 -> 265 bytes assets-cg/hud_life2.png | Bin 0 -> 267 bytes assets-cg/hud_wave.png | Bin 322 -> 272 bytes assets-cg/hud_wave2.png | Bin 315 -> 264 bytes src/enemies.c | 8 +++++--- src/entities.h | 2 +- src/main.c | 1 + src/render.c | 43 ++++++++++++++++++++++------------------ 9 files changed, 33 insertions(+), 23 deletions(-) create mode 100644 assets-cg/hud_life.png create mode 100644 assets-cg/hud_life2.png diff --git a/CMakeLists.txt b/CMakeLists.txt index 850673e..f819758 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,6 +38,8 @@ set(ASSETS # HUD assets-cg/hud_wave.png assets-cg/hud_wave2.png + assets-cg/hud_life.png + assets-cg/hud_life2.png assets-cg/skillicons.png # Player animations assets-cg/player/player_up.aseprite diff --git a/assets-cg/hud_life.png b/assets-cg/hud_life.png new file mode 100644 index 0000000000000000000000000000000000000000..cb5ffe9c301011d60e0e67cfbfc4cbb84008c1c6 GIT binary patch literal 265 zcmeAS@N?(olHy`uVBq!ia0vp^X+X@*!3HFMm0QdOQjEnx?oJHr&dIz4at?dCIEHw1 zCYM~j_Tzj5>xK_S#vB~oMl}_`XFWXseEs52A=B>Heq~ecd7GKY)8G77{hX1J0T6hd z(n#o?5$F)T;PCl_8-Bmyb@S(b{D1PFMUrv%cO1P?^V;O_{PXdWW$}9tT1Xi(bMU0J zNG44D^yZW%8xXYZ%<18&x2sQ0kV@FzThSn+$pZu@_bdENF-c;RP;lpBW>z_FV9?`s zrh!qmj;{@5@3}uedG*+|kAciQVR1`K`bU^#k<5W3j8PAc1zhxAbPDJl22WQ%mvv4F FO#s$gXwLuu literal 0 HcmV?d00001 diff --git a/assets-cg/hud_life2.png b/assets-cg/hud_life2.png new file mode 100644 index 0000000000000000000000000000000000000000..271cbdb499e38e1cd391042733525acba028a923 GIT binary patch literal 267 zcmV+m0rdWfP)Px##Ysd#R7i>K)=vt8Kokb>@5P{?2to$#-3ab%(*;`8zB721j^G`-ftxNNxUqGV zg&+w^Fs%&1ag(-tZ#DD%-mHfCL)*ZYP?WGt*vl2l#~ttL#XhqqX+{7bBHb7u0HBp{ zq=llr0jeJMX&(48Ni$mXGspD?V^zjJ-6P$=ZnKtj-XD}#5ZC|f_`ErVeK92(cGyCeaZ@8nGZJxAD;tDm!lnwPM&qwM`_JC}fekN7nc@)5;a2JTX*>kwp+EzVjDnasr+}E5_W#w94Uk2JxnYKNeKxFGfp4tP_mG+ zWaghy7Qgr4kLRDmr<|Di^Rx6}ko!uX*6}U4>}Gc0)~{Q&Uyo(1&S{8FWjL^Zm(5PK Sc4wfk7(8A5T-G@yGywpJ)^rX4 literal 322 zcmV-I0lof-P)Px#{7FPXR7i>Kma$62KomvK$bvzU2+KBNEd!HcAt3pIDbn}@+bdY)V=M&i^8?$Y z$PWY|V6lOGfY``_ONgux7#qe$28akSs9CJFI z@xFeesp>Aad}Kc4NsIEQ-*)E{t)ywHn)}5y5tt;)g;vt6Hru}mn=NzT`DMLx0n10` z10JoUNsCg1fp6}v7DUUKFz}7gN}8L)BhI`_X7Yk)8TW@+?X^7Dq1*QXz{BSUud63+ z<42M#7oO|ZS{|I3jWy_im^Qlum2F$ zbXEzb>PQ2tf^?Iv*~X)Gub;}Nyi~rv@8P2UiPx#^+`lQR7iHhYMg}Nw)zMJkjKFAfBT8EjIP=m|I^vIFm3qt zpFv7kf#KQnR}2iJ@`F#FkQ!}`|GTf=VDz*w{y)htnjvq~QU*^8&wR9H4_7i6rXa4+#(-0{gGrX3J$`7nO zJ~cCceq-2u^#&tyeE<3Um4T6g0a5=W*BPU2f}tl*NDa35-F@{2BLLO|N+?`Bxidentity = enemy_id; - e->HP = instantiate_stat(&data->HP, level); - e->ATK = instantiate_stat(&data->ATK, level); - e->DEF = instantiate_stat(&data->DEF, level); + e->HP_max = instantiate_stat(&data->HP, level); + e->ATK = instantiate_stat(&data->ATK, level); + e->DEF = instantiate_stat(&data->DEF, level); + + e->HP = e->HP_max; return e; } diff --git a/src/entities.h b/src/entities.h index 7baed60..9a1bef4 100644 --- a/src/entities.h +++ b/src/entities.h @@ -75,7 +75,7 @@ typedef struct { /* Enemy ID (0 for player) */ uint8_t identity; /* Combat statistics */ - uint16_t HP, ATK, DEF; + uint16_t HP, ATK, DEF, HP_max; /* Time left until nexth pathfinding run (ms) */ // uint8_t pathfind_delay; diff --git a/src/main.c b/src/main.c index 2cef8cf..9412d81 100644 --- a/src/main.c +++ b/src/main.c @@ -96,6 +96,7 @@ int main(void) game_add_entity(&game, player); game.player = player; + player->HP_max += 100; player->HP += 100; player->movement_params = &emp_player; player->identity = 0; diff --git a/src/render.c b/src/render.c index c4c0512..f32631f 100644 --- a/src/render.c +++ b/src/render.c @@ -30,7 +30,7 @@ void camera_init(camera_t *c, map_t const *m) c->y = (c->limits.y_min + c->limits.y_max) / 2; /* Slightly off-center to add space for the HUD */ - c->y -= fix(0.5); + c->y -= fix(0.375); } ipoint_t camera_map2screen(camera_t const *c, fpoint_t p) @@ -117,7 +117,7 @@ void render_map(map_t const *m, camera_t const *c) extern bopti_image_t img_tileset_decor; /* Render floor and walls */ - for(int row = -2; row < m->height + 1; row++) + for(int row = -2; row < m->height + 2; row++) for(int col = -1; col < m->width + 1; col++) { struct tile *t = map_tile(m, col, row); fpoint_t tile_pos = { fix(col), fix(row) }; @@ -131,11 +131,11 @@ void render_map(map_t const *m, camera_t const *c) /* Floor/wall layer */ dsubimage(p.x, p.y, &img_tileset_base, TILE_WIDTH * (t->base % 16), TILE_HEIGHT * (t->base / 16), - TILE_WIDTH, TILE_HEIGHT, DIMAGE_NONE); + TILE_WIDTH, TILE_HEIGHT, DIMAGE_NOCLIP); /* Decoration layer */ if(t->decor) dsubimage(p.x, p.y, &img_tileset_decor, TILE_WIDTH * (t->decor % 16), TILE_HEIGHT * (t->decor / 16), - TILE_WIDTH, TILE_HEIGHT, DIMAGE_NONE); + TILE_WIDTH, TILE_HEIGHT, DIMAGE_NOCLIP); } } @@ -230,27 +230,32 @@ void render_game(game_t const *g, bool show_hitboxes) enemies_left += (g->entities[i]->identity != 0); extern bopti_image_t img_hud_wave, img_hud_wave2; - dimage((DWIDTH-img_hud_wave.width) / 2, 17, &img_hud_wave); - dsubimage((DWIDTH-img_hud_wave2.width) / 2, 17, &img_hud_wave2, - 0, 0, (img_hud_wave2.width*enemies_left) / - g->level->waves[g->wave-1].enemy_count, img_hud_wave2.height, - DIMAGE_NONE); + dimage(DWIDTH - img_hud_wave.width, 17, &img_hud_wave); + int fill_length = (img_hud_wave2.width * enemies_left) / + g->level->waves[g->wave-1].enemy_count; + dsubimage(DWIDTH - fill_length, 17, &img_hud_wave2, + img_hud_wave2.width - fill_length, 0, fill_length, + img_hud_wave2.height, DIMAGE_NONE); if(g->wave_spawned < game_current_wave(g)->enemy_count) - dprint_opt(DWIDTH / 2, 2, C_WHITE, C_NONE, DTEXT_CENTER, DTEXT_TOP, - "Wave %d: %d enemies spawning", g->wave, + dprint_opt(DWIDTH - 4, 2, C_WHITE, C_NONE, DTEXT_RIGHT, DTEXT_TOP, + "Wave %d is preppin' up...", g->wave, game_current_wave(g)->enemy_count - g->wave_spawned); else if(enemies_left > 0) - dprint_opt(DWIDTH / 2, 2, C_WHITE, C_NONE, DTEXT_CENTER, DTEXT_TOP, - "Wave %d: %d enemies left", g->wave, enemies_left); + dprint_opt(DWIDTH - 4, 2, C_WHITE, C_NONE, DTEXT_RIGHT, DTEXT_TOP, + "Wave %d is here for you!", g->wave, enemies_left); else - dprint_opt(DWIDTH / 2, 2, C_WHITE, C_NONE, DTEXT_CENTER, DTEXT_TOP, - "Wave %d: Victory!", g->wave); + dprint_opt(DWIDTH - 4, 2, C_WHITE, C_NONE, DTEXT_RIGHT, DTEXT_TOP, + "Victory! For now...", g->wave); entity_t const *player = g->player; - dprint(2, 2, C_WHITE, "HP: %d", player->HP); - dprint_opt(DWIDTH - 2, 2, C_WHITE, C_NONE, DTEXT_RIGHT, DTEXT_TOP, - "ATK:%d DEF:%d", player->ATK, player->DEF); + dprint(2, 2, C_WHITE, "HP: %d/%d", player->HP, player->HP_max); + + extern bopti_image_t img_hud_life, img_hud_life2; + dimage(0, 17, &img_hud_life); + fill_length = (img_hud_life2.width * player->HP) / player->HP_max; + dsubimage(0, 17, &img_hud_life2, 0, 0, fill_length, img_hud_life2.height, + DIMAGE_NONE); /* Render skill icons */ extern bopti_image_t img_skillicons; @@ -265,7 +270,7 @@ void render_game(game_t const *g, bool show_hitboxes) cooldown_remaining=fix(1); } - int x=15+68*i, y=DHEIGHT-28, bg=(cooldown_remaining!=0); + int x=15+68*i, y=DHEIGHT-27, bg=(cooldown_remaining!=0); dsubimage(x, y, &img_skillicons, 23*bg, 0, 23, 23, DIMAGE_NONE); dsubimage(x, y, &img_skillicons, 23*(i+2), 0, 23, 23, DIMAGE_NONE);