From ca7249e954c43a3a11566945b5a7ac3f7f7d34c6 Mon Sep 17 00:00:00 2001 From: Linus Probert Date: Thu, 21 Dec 2017 08:31:25 +0100 Subject: [PATCH] Log hits, kills and misses --- .appveyor.yml | 2 +- TODO.txt | 6 ++++-- src/player.c | 24 ++++++++++++++++++------ src/player.h | 3 +++ 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index a4a3a54..38e1dc5 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -45,7 +45,7 @@ before_build: %DEPENDS% copy SDL2_ttf-2.0.14\%ARCH%\bin\*.dll %PREFIX%\lib > nul # Lua - - ps: (new-object System.Net.WebClient).Downloadfile("https://sourceforge.net/projects/luabinaries/files/5.3.4/Windows%20Libraries/Static/lua-5.3.4_Win32_vc14_lib.zip/download", "c:\lua\lua-5.3.4_Win32_vc14_lib.zip") + - ps: (New-Object Net.WebClient).DownloadFile("https://sourceforge.net/projects/luabinaries/files/5.3.4/Windows%20Libraries/Static/lua-5.3.4_Win32_vc14_lib.zip/download", "c:\lua\lua-5.3.4_Win32_vc14_lib.zip") - |- %DEPENDS% 7z x "c:\lua\lua-5.3.4_Win32_vc14_lib.zip" -o"c:\lua" > nul %DEPENDS% copy c:\lua\include\* %PREFIX%\include > nul diff --git a/TODO.txt b/TODO.txt index 0893e04..c5127b4 100644 --- a/TODO.txt +++ b/TODO.txt @@ -8,8 +8,8 @@ x Move "clip" from texture to sprite x Hitting enemies x Nicer enemy hits (Text textures, healthbars?) - This could need some love later on. - - Add hits to stats - - Player hits + x Add hits to stats + x Player hits x Moving enemies x Stupid roaming enemies x Smart agressive enemies @@ -20,6 +20,8 @@ x Moving enemies o XP - Some xp amount logic - Level threshholds +- Statistics + - More stuff to count - gui - Items - More gui diff --git a/src/player.c b/src/player.c index f4c3d86..893f0d6 100644 --- a/src/player.c +++ b/src/player.c @@ -31,8 +31,14 @@ has_collided(Player *player, RoomMatrix *matrix) &space->monster->stats); monster_hit(space->monster, hit); + if (hit > 0) + player->hits += 1; + else + player->misses += 1; + if (space->monster->stats.hp <= 0) { // TODO(Linus): This needs some love later on. + player->kills += 1; player->xp += 10; } } @@ -148,9 +154,12 @@ player_create(class_t class, SDL_Renderer *renderer) { Player *player = malloc(sizeof(Player)); player->sprite = sprite_create(); - player->total_steps = 0; - player->steps = 0; - player->xp = 0; + player->total_steps = 0; + player->steps = 0; + player->xp = 0; + player->hits = 0; + player->kills = 0; + player->misses = 0; char asset[100]; switch (class) { @@ -216,10 +225,13 @@ player_print(Player *p) printf("\n"); printf("--------=== <[ Player Stats ]> ===--------\n"); - printf("HP: %d\n", p->stats.hp); - printf("Level: %u XP: %u\n", p->stats.lvl, p->xp); - printf("Pos: %dx%d RoomPos: %dx%d\n", pos.x, pos.y, roomPos.x, roomPos.y); + printf("HP: %d\n", p->stats.hp); + printf("Level: %u\tXP:\t%u\n", p->stats.lvl, p->xp); + printf("Hits: %u\tMisses:\t%u\n", p->hits, p->misses); + printf("Kills: %u\n", p->kills); printf("Steps: %u\n", p->total_steps); + printf("Pos: %dx%d\tRoomPos: %dx%d\n", pos.x, pos.y, + roomPos.x, roomPos.y); printf("------------------------------------------\n"); } diff --git a/src/player.h b/src/player.h index 74f4902..311d3c0 100644 --- a/src/player.h +++ b/src/player.h @@ -18,6 +18,9 @@ typedef struct Player_t { unsigned int xp; unsigned int total_steps; unsigned int steps; + unsigned int hits; + unsigned int kills; + unsigned int misses; void (*handle_event)(struct Player_t*, RoomMatrix*, SDL_Event*); } Player;