menu.c (2717B)
1 #include <stdlib.h> 2 3 #include "../lib/raylib.h" 4 #include "../include/menu.h" 5 #include "../include/util.h" 6 #include "../include/const.h" 7 #include "../include/game.h" 8 #include "../include/level.h" 9 10 menu_t *menu_create(void) { 11 menu_t *menu = malloc(sizeof(menu_t)); 12 menu->idx = 0; 13 return menu; 14 } 15 16 void menu_update(menu_t *menu, game_t *game) { 17 (void) menu; 18 if (IsKeyPressed(KEY_ESCAPE)) { 19 game->state = STATE_GAME; 20 } 21 if (IsKeyPressed(KEY_Q)) { 22 game->quit = true; 23 } 24 // if (IsKeyPressed(KEY_W)) { 25 // if (menu->idx > 0) { 26 // menu->idx--; 27 // } 28 // } 29 // if (IsKeyPressed(KEY_S)) { 30 // if (menu->idx < 2) { 31 // menu->idx++; 32 // } 33 // } 34 // if (IsKeyPressed(KEY_ENTER)) { 35 // switch (menu->idx) { 36 // case 0: 37 // game->state = STATE_GAME; 38 // break; 39 // case 1: { 40 // if (game->level != LEVEL_NULL) { 41 // level_e level = game->level->type; 42 // int max_health = game->player->max_health; 43 // level_unload(game); 44 // level_load(game, level); 45 // game->player->max_health = max_health; 46 // game->player->health = max_health; 47 // game->victory = false; 48 // game->defeat = false; 49 // } 50 // game->state = STATE_GAME; 51 // break; 52 // } 53 // case 2: 54 // game->quit = true; 55 // break; 56 // default: 57 // break; 58 // } 59 // } 60 } 61 62 void menu_draw(menu_t *menu, game_t *game) { 63 (void) menu; 64 (void) game; 65 DrawRectangle(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, (Color) { 0, 0, 0, 125 }); 66 // int shift = 20; 67 // DrawRectangle(WINDOW_WIDTH / 2.0 - 100, WINDOW_HEIGHT / 2.0 - 75 + shift - 10, 200, 150, (Color) { 50, 50, 50, 255 }); 68 // DrawTextureRec( 69 // game->assets.images, 70 // (rect_t) { 0, 0, 56 * SCALE, 28 * SCALE }, 71 // pos_snap((pos_t) { WINDOW_WIDTH / 2.0 - 3.5 * TILE_WIDTH, WINDOW_HEIGHT / 2.0 - 115 }), 72 // WHITE 73 // ); 74 // text_draw((pos_t) { WINDOW_WIDTH / 2.0, WINDOW_HEIGHT / 2.0 - FONT_HEIGHT / 2.0 - 30 + shift }, "RESUME", TEXT_ALIGNMENT_CENTER, game); 75 // text_draw((pos_t) { WINDOW_WIDTH / 2.0, WINDOW_HEIGHT / 2.0 - FONT_HEIGHT / 2.0 + shift }, "RESTART", TEXT_ALIGNMENT_CENTER, game); 76 // text_draw((pos_t) { WINDOW_WIDTH / 2.0, WINDOW_HEIGHT / 2.0 - FONT_HEIGHT / 2.0 + 30 + shift }, "QUIT", TEXT_ALIGNMENT_CENTER, game); 77 // pos_t cursor_pos = (pos_t) { 78 // .x = WINDOW_WIDTH / 2.0 - 70, 79 // .y = WINDOW_HEIGHT / 2.0 - FONT_HEIGHT / 2.0 - 30 + menu->idx * 30 + shift, 80 // }; 81 // DrawTextureRec( 82 // game->assets.font, 83 // texture_rect(0, 4, FONT_WIDTH, FONT_HEIGHT), 84 // pos_snap(cursor_pos), 85 // WHITE 86 // ); 87 } 88 89 void menu_free(menu_t *menu) { 90 free(menu); 91 }