Fixed the player menu

This commit is contained in:
Linus Probert 2018-09-13 08:05:17 +02:00
parent 02a4407eb4
commit c39f05d49e
4 changed files with 37 additions and 28 deletions

View File

@ -312,7 +312,7 @@ startGame(void)
gGameState = PLAYING;
if (gPlayer)
player_destroy(gPlayer);
gPlayer = player_create(WARRIOR, gCamera);
gPlayer = player_create(playerClass, gCamera);
mixer_play_music(GAME_MUSIC0 + get_random(2));
resetGame();
skillbar_reset(gSkillBar);
@ -575,7 +575,8 @@ handle_main_input(void)
if (gGameState == CREDITS && input_key_is_pressed(&input, KEY_ESC))
gGameState = MENU;
else if (gGameState == SCORE_SCREEN && input_key_is_pressed(&input, KEY_ESC))
else if ((gGameState == SCORE_SCREEN || gGameState == CHARACTER_MENU)
&& input_key_is_pressed(&input, KEY_ESC))
gGameState = MENU;
else if (gGameState == MENU && input_key_is_pressed(&input, KEY_ESC))
gGameState = QUIT;
@ -745,23 +746,19 @@ run_game_update(void)
map_set_current_room(gMap, &gPlayer->sprite->pos);
map_update(&updateData);
bool turnSwitch = false;
if (currentTurn == PLAYER) {
if (player_turn_over(gPlayer)) {
currentTurn = MONSTER;
player_reset_steps(gPlayer);
map_on_new_turn(gMap);
turnSwitch = true;
}
} else if (currentTurn == MONSTER) {
if (map_move_monsters(gMap, gRoomMatrix)) {
currentTurn = PLAYER;
turnSwitch = true;
}
}
map_clear_expired_entities(gMap, gPlayer);
if (turnSwitch)
if (map_clear_expired_entities(gMap, gPlayer))
repopulate_roommatrix();
}
@ -927,11 +924,13 @@ run_menu(void)
SDL_SetRenderDrawColor(gRenderer, 0, 0, 0, 0);
SDL_RenderClear(gRenderer);
SDL_RenderSetViewport(gRenderer, &menuViewport);
map_render(gMap, gCamera);
map_render_mid_layer(gMap, gCamera);
map_render_top_layer(gMap, gRoomMatrix, gCamera);
roommatrix_render_lightmap(gRoomMatrix, gCamera);
if (gGameState != CHARACTER_MENU) {
SDL_RenderSetViewport(gRenderer, &menuViewport);
map_render(gMap, gCamera);
map_render_mid_layer(gMap, gCamera);
map_render_top_layer(gMap, gRoomMatrix, gCamera);
roommatrix_render_lightmap(gRoomMatrix, gCamera);
}
SDL_RenderSetViewport(gRenderer, &mainViewport);

View File

@ -129,16 +129,18 @@ map_add_trap(Map *map, Position *pos, Trap *trap)
*oldTrap = trap;
}
void
bool
map_clear_expired_entities(Map *map, Player *player)
{
LinkedList *filtered = linkedlist_create();
bool anythingCleared = false;
while (map->monsters) {
Monster *monster = linkedlist_pop(&map->monsters);
if (monster->stats.hp <= 0) {
monster_drop_loot(monster, map, player);
monster_destroy(monster);
anythingCleared = true;
} else {
linkedlist_append(&filtered, monster);
}
@ -148,32 +150,40 @@ map_clear_expired_entities(Map *map, Player *player)
filtered = linkedlist_create();
while (map->items) {
Item *item = linkedlist_pop(&map->items);
if (item->collected)
if (item->collected) {
item_destroy(item);
else
anythingCleared = true;
} else {
linkedlist_append(&filtered, item);
}
}
map->items = filtered;
filtered = linkedlist_create();
while (map->artifacts) {
Artifact *a = linkedlist_pop(&map->artifacts);
if (!a->collected)
if (!a->collected) {
linkedlist_append(&filtered, a);
else
} else {
artifact_destroy(a);
anythingCleared = true;
}
}
map->artifacts = filtered;
filtered = linkedlist_create();
while (map->objects) {
Object *o = linkedlist_pop(&map->objects);
if (o->dead)
if (o->dead) {
object_destroy(o);
else
anythingCleared = true;
} else {
linkedlist_append(&filtered, o);
}
}
map->objects = filtered;
return anythingCleared;
}
void

View File

@ -91,7 +91,7 @@ map_add_monster(Map*, Monster*);
bool
map_move_monsters(Map*, RoomMatrix*);
void
bool
map_clear_expired_entities(Map*, Player*);
void

View File

@ -97,24 +97,24 @@ menu_create_character_selector(void (*onCharacterSelect)(const char *))
};
Menu *menu = menu_create();
int yoffset = 100;
int xoffset = 224;
for (size_t i = 0; i < 2; ++i) {
Sprite *s1 = sprite_create();
sprite_set_texture(s1, texturecache_add(spriteSheets[i]), 0);
s1->clip = CLIP16(0, 0);
s1->clip = CLIP16(0, 48);
s1->dim = DIM(64, 64);
s1->pos = POS((SCREEN_WIDTH + 16)/2, yoffset);
s1->pos = POS(xoffset - 32, 256);
Sprite *s2 = sprite_create();
sprite_set_texture(s2, texturecache_add(spriteSheets[i]), 0);
s2->clip = CLIP16(0, 48);
s2->clip = CLIP16(0, 0);
s2->dim = DIM(64, 64);
s2->pos = POS((SCREEN_WIDTH + 16)/2, yoffset);
s2->pos = POS(xoffset - 32, 256);
menu_item_add(menu, s1, s2, (void (*)(void *)) onCharacterSelect);
MenuItem *item = linkedlist_get(&menu->items, (Uint32) i);
item->button->usrdata = callbackData[i];
yoffset += 100;
xoffset += 224;
}
return menu;
@ -125,10 +125,10 @@ handle_keyboard_input(Menu *m, Input *input)
{
int lastSelect = -1;
if (input_key_is_pressed(input, KEY_UP)) {
if (input_key_is_pressed(input, KEY_UP | KEY_LEFT)) {
lastSelect = m->selected;
m->selected--;
} else if (input_key_is_pressed(input, KEY_DOWN)) {
} else if (input_key_is_pressed(input, KEY_DOWN | KEY_RIGHT)) {
lastSelect = m->selected;
m->selected++;
} else if (input_key_is_pressed(input, KEY_ENTER)) {