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

View File

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

View File

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

View File

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