Monster levels, player death and player levels
This commit is contained in:
parent
78fd6086f5
commit
b13479b5e1
|
@ -116,7 +116,7 @@ end
|
|||
-- END FUNCTIONS
|
||||
|
||||
-- BEGIN SCRIPT
|
||||
map = create_map() -- 'map' needs to be global
|
||||
map = create_map(CURRENT_LEVEL) -- 'map' needs to be global
|
||||
room_builder.load_textures(map)
|
||||
local map_matrix = generate_path()
|
||||
|
||||
|
|
13
src/gui.c
13
src/gui.c
|
@ -61,13 +61,6 @@ gui_create()
|
|||
return gui;
|
||||
}
|
||||
|
||||
static void
|
||||
clear_sprite_list(LinkedList *list)
|
||||
{
|
||||
while (list != NULL)
|
||||
sprite_destroy(linkedlist_pop(&list));
|
||||
}
|
||||
|
||||
void
|
||||
gui_set_max_health(Gui *gui, int max, SDL_Renderer *renderer)
|
||||
{
|
||||
|
@ -79,7 +72,9 @@ gui_set_max_health(Gui *gui, int max, SDL_Renderer *renderer)
|
|||
if (((unsigned int) max / 3) == (unsigned int) linkedlist_size(gui->health))
|
||||
return;
|
||||
|
||||
clear_sprite_list(gui->health);
|
||||
// Clear sprite list
|
||||
while (gui->health != NULL)
|
||||
sprite_destroy(linkedlist_pop(&gui->health));
|
||||
|
||||
texture = gui_add_texture(gui, "assets/GUI/GUI0.png", renderer);
|
||||
|
||||
|
@ -87,7 +82,7 @@ gui_set_max_health(Gui *gui, int max, SDL_Renderer *renderer)
|
|||
Sprite *sprite = sprite_create();
|
||||
sprite->fixed = true;
|
||||
sprite->clip = (SDL_Rect) { 0, 16, 16, 16 };
|
||||
sprite->pos = (Position) { 16 + i*16, 16 };
|
||||
sprite->pos = (Position) { 16 + (i%8)*16, 16 + ((i-(i%8))/8)*16 };
|
||||
sprite_set_texture(sprite, texture, 0);
|
||||
linkedlist_append(&gui->health, sprite);
|
||||
}
|
||||
|
|
12
src/item.c
12
src/item.c
|
@ -41,19 +41,11 @@ item_collected(Item *item, Player *player)
|
|||
void
|
||||
item_destroy(Item *item)
|
||||
{
|
||||
LinkedList *items;
|
||||
|
||||
if (item->sprite)
|
||||
sprite_destroy(item->sprite);
|
||||
|
||||
items = item->items;
|
||||
while (items != NULL) {
|
||||
Item *subitem = items->data;
|
||||
items->data = NULL;
|
||||
items = items->next;
|
||||
item_destroy(subitem);
|
||||
}
|
||||
linkedlist_destroy(&items);
|
||||
while (item->items != NULL)
|
||||
item_destroy(linkedlist_pop(&item->items));
|
||||
|
||||
free(item);
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ static void
|
|||
eat_flesh(Item *item, Player *player)
|
||||
{
|
||||
int original_hp = player->stats.hp;
|
||||
player->stats.hp += (int) item->value;
|
||||
player->stats.hp += (int) item->value * player->stats.lvl;
|
||||
if (player->stats.hp > player->stats.maxhp)
|
||||
player->stats.hp = player->stats.maxhp;
|
||||
|
||||
|
@ -50,7 +50,7 @@ static void
|
|||
drink_health(Item *item, Player *player)
|
||||
{
|
||||
int original_hp = player->stats.hp;
|
||||
player->stats.hp += (int) item->value;
|
||||
player->stats.hp += (int) item->value * player->stats.lvl;
|
||||
if (player->stats.hp > player->stats.maxhp)
|
||||
player->stats.hp = player->stats.maxhp;
|
||||
|
||||
|
|
19
src/main.c
19
src/main.c
|
@ -165,6 +165,16 @@ bool handle_events(void)
|
|||
return quit;
|
||||
}
|
||||
|
||||
static bool
|
||||
check_if_dead(void)
|
||||
{
|
||||
if (gPlayer->stats.hp <= 0) {
|
||||
gui_log("The dungeon consumed you");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static void
|
||||
check_next_level(void)
|
||||
{
|
||||
|
@ -220,6 +230,9 @@ run_game(void)
|
|||
|
||||
SDL_RenderPresent(gRenderer);
|
||||
|
||||
if (check_if_dead())
|
||||
gGameState = GAME_OVER;
|
||||
|
||||
check_next_level();
|
||||
}
|
||||
|
||||
|
@ -242,13 +255,13 @@ void run(void)
|
|||
run_game();
|
||||
break;
|
||||
case MENU:
|
||||
error("MENU not implemented");
|
||||
fatal("MENU not implemented");
|
||||
break;
|
||||
case IN_GAME_MENU:
|
||||
error("IN_GAME_MENU not implemented");
|
||||
fatal("IN_GAME_MENU not implemented");
|
||||
break;
|
||||
case GAME_OVER:
|
||||
error("GAME_OVER not implemented");
|
||||
fatal("GAME_OVER not implemented");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
|
@ -155,6 +155,7 @@ map_clear_collected_items(Map *map)
|
|||
void
|
||||
map_add_monster(Map *map, Monster *m)
|
||||
{
|
||||
monster_update_stats_for_level(m, map->level);
|
||||
linkedlist_append(&map->monsters, m);
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ static
|
|||
int l_create_map(lua_State *L)
|
||||
{
|
||||
Map *map = map_create();
|
||||
map->level = luaL_checkinteger(L, 1);
|
||||
lua_pushlightuserdata(L, map);
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -239,6 +239,17 @@ monster_hit(Monster *monster, unsigned int dmg)
|
|||
monster->state.current = monster->state.challenge;
|
||||
}
|
||||
|
||||
void
|
||||
monster_update_stats_for_level(Monster *m, unsigned int level)
|
||||
{
|
||||
m->stats.lvl = level;
|
||||
m->stats.maxhp *= level;
|
||||
m->stats.hp = m->stats.maxhp;
|
||||
m->stats.dmg *= level;
|
||||
m->stats.atk *= level;
|
||||
m->stats.def *= level;
|
||||
}
|
||||
|
||||
void
|
||||
monster_drop_loot(Monster *monster, Map *map)
|
||||
{
|
||||
|
@ -248,12 +259,12 @@ monster_drop_loot(Monster *monster, Map *map)
|
|||
Item *items[2];
|
||||
unsigned int item_count = 0;
|
||||
|
||||
if ((rand() % treasure_drop_chance) == 0 || true) {
|
||||
if ((rand() % treasure_drop_chance) == 0) {
|
||||
item = item_builder_build_item(TREASURE);
|
||||
item->sprite->pos = monster->sprite->pos;
|
||||
items[item_count++] = item;
|
||||
}
|
||||
if ((rand() % item_drop_chance) == 0 || true) {
|
||||
if ((rand() % item_drop_chance) == 0) {
|
||||
item = item_builder_build_item(rand() % TREASURE);
|
||||
item->sprite->pos = monster->sprite->pos;
|
||||
items[item_count++] = item;
|
||||
|
|
|
@ -26,16 +26,25 @@ typedef struct Monster_t {
|
|||
|
||||
Monster* monster_create(SDL_Renderer*);
|
||||
|
||||
void monster_update_pos(Monster*, Position);
|
||||
void
|
||||
monster_update_pos(Monster*, Position);
|
||||
|
||||
void monster_move(Monster*, RoomMatrix*);
|
||||
void
|
||||
monster_move(Monster*, RoomMatrix*);
|
||||
|
||||
void monster_render(Monster*, Camera*);
|
||||
void
|
||||
monster_render(Monster*, Camera*);
|
||||
|
||||
void monster_hit(Monster*, unsigned int dmg);
|
||||
void
|
||||
monster_hit(Monster*, unsigned int dmg);
|
||||
|
||||
void monster_drop_loot(Monster*, Map*);
|
||||
void
|
||||
monster_update_stats_for_level(Monster*, unsigned int level);
|
||||
|
||||
void monster_destroy(Monster*);
|
||||
void
|
||||
monster_drop_loot(Monster*, Map*);
|
||||
|
||||
void
|
||||
monster_destroy(Monster*);
|
||||
|
||||
#endif // MONSTER_H_
|
||||
|
|
26
src/player.c
26
src/player.c
|
@ -14,6 +14,26 @@
|
|||
#define ROGUE_STATS { 12, 12, 5, 7, 3, 2, 1 }
|
||||
#define WARRIOR_STATS { 12, 12, 8, 9, 2, 1, 1 }
|
||||
|
||||
static void
|
||||
player_levelup(Player *player)
|
||||
{
|
||||
player->stats.lvl += 1;
|
||||
player->stats.maxhp += 3;
|
||||
player->stats.dmg += 5;
|
||||
player->stats.atk += 1;
|
||||
player->stats.def += 1;
|
||||
}
|
||||
|
||||
static void
|
||||
player_gain_xp(Player *player, unsigned int xp_gain)
|
||||
{
|
||||
player->xp += xp_gain;
|
||||
if (player->xp >= (player->stats.lvl * 50) + ((player->stats.lvl - 1) * 150)) {
|
||||
player_levelup(player);
|
||||
gui_log("You have reached level %u", player->stats.lvl);
|
||||
}
|
||||
}
|
||||
|
||||
static bool
|
||||
has_collided(Player *player, RoomMatrix *matrix)
|
||||
{
|
||||
|
@ -46,12 +66,12 @@ has_collided(Player *player, RoomMatrix *matrix)
|
|||
gui_log("You missed %s", space->monster->lclabel);
|
||||
|
||||
if (space->monster->stats.hp <= 0) {
|
||||
// TODO(Linus): This needs some love later on.
|
||||
unsigned int gained_xp = 5 * space->monster->stats.lvl;
|
||||
player->kills += 1;
|
||||
player->xp += 10;
|
||||
|
||||
gui_log("You killed %s and gained %d xp",
|
||||
space->monster->lclabel, 10);
|
||||
space->monster->lclabel, gained_xp);
|
||||
player_gain_xp(player, gained_xp);
|
||||
}
|
||||
} else if (collided) {
|
||||
gui_log("Ouch! There is something in the way");
|
||||
|
|
15
src/player.h
15
src/player.h
|
@ -25,14 +25,19 @@ typedef struct Player_t {
|
|||
void (*handle_event)(struct Player_t*, RoomMatrix*, SDL_Event*);
|
||||
} Player;
|
||||
|
||||
Player* player_create(class_t, SDL_Renderer*);
|
||||
Player*
|
||||
player_create(class_t, SDL_Renderer*);
|
||||
|
||||
void player_hit(Player*, unsigned int dmg);
|
||||
void
|
||||
player_hit(Player*, unsigned int dmg);
|
||||
|
||||
void player_reset_steps(Player*);
|
||||
void
|
||||
player_reset_steps(Player*);
|
||||
|
||||
void player_render(Player*, Camera*);
|
||||
void
|
||||
player_render(Player*, Camera*);
|
||||
|
||||
void player_destroy(Player*);
|
||||
void
|
||||
player_destroy(Player*);
|
||||
|
||||
#endif // PLAYER_H_
|
||||
|
|
Loading…
Reference in New Issue