Moving some logic into separate files
This commit is contained in:
Submodule lib/AudioFile deleted from bcb61a47e6
@ -8,6 +8,7 @@
|
|||||||
# Sources
|
# Sources
|
||||||
target_sources(${DAWN_TARGET_NAME}
|
target_sources(${DAWN_TARGET_NAME}
|
||||||
PRIVATE
|
PRIVATE
|
||||||
|
drawstatemainmenu.c
|
||||||
drawstateoverworld.c
|
drawstateoverworld.c
|
||||||
drawmap.c
|
drawmap.c
|
||||||
drawtext.c
|
drawtext.c
|
||||||
|
14
src/dawn/display/draw/drawstatemainmenu.c
Normal file
14
src/dawn/display/draw/drawstatemainmenu.c
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2024 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "drawstatemainmenu.h"
|
||||||
|
#include "display/draw/drawtext.h"
|
||||||
|
|
||||||
|
void drawStateMainMenu() {
|
||||||
|
// Draw the logo
|
||||||
|
drawText("Dawn", 4, 0, 0, COLOR_WHITE);
|
||||||
|
}
|
14
src/dawn/display/draw/drawstatemainmenu.h
Normal file
14
src/dawn/display/draw/drawstatemainmenu.h
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2024 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "display/frame.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draws the main menu state.
|
||||||
|
*/
|
||||||
|
void drawStateMainMenu();
|
@ -27,14 +27,14 @@ void drawStateOverworld() {
|
|||||||
cameraPositionY = player->y;
|
cameraPositionY = player->y;
|
||||||
}
|
}
|
||||||
|
|
||||||
// drawMap(
|
drawMap(
|
||||||
// GAME.currentMap,
|
GAME.currentMap,
|
||||||
// cameraPositionX, cameraPositionY,
|
cameraPositionX, cameraPositionY,
|
||||||
// 0, 0,
|
0, 0,
|
||||||
// FRAME_WIDTH, FRAME_HEIGHT
|
FRAME_WIDTH, FRAME_HEIGHT
|
||||||
// );
|
);
|
||||||
|
|
||||||
// Draw UI
|
// Draw UI
|
||||||
// drawUITextbox();
|
drawUITextbox();
|
||||||
drawUITestMenu();
|
// drawUITestMenu();
|
||||||
}
|
}
|
@ -11,6 +11,7 @@
|
|||||||
#include "display/draw/drawshape.h"
|
#include "display/draw/drawshape.h"
|
||||||
#include "display/draw/drawtext.h"
|
#include "display/draw/drawtext.h"
|
||||||
#include "display/draw/drawstateoverworld.h"
|
#include "display/draw/drawstateoverworld.h"
|
||||||
|
#include "display/draw/drawstatemainmenu.h"
|
||||||
|
|
||||||
char_t FRAME_BUFFER[FRAME_HEIGHT * FRAME_WIDTH];
|
char_t FRAME_BUFFER[FRAME_HEIGHT * FRAME_WIDTH];
|
||||||
uint8_t FRAME_COLOR[FRAME_HEIGHT * FRAME_WIDTH];
|
uint8_t FRAME_COLOR[FRAME_HEIGHT * FRAME_WIDTH];
|
||||||
@ -37,6 +38,9 @@ void frameUpdate() {
|
|||||||
drawStateOverworld();
|
drawStateOverworld();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case GAME_STATE_MAIN_MENU:
|
||||||
|
drawStateMainMenu();
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
# https://opensource.org/licenses/MIT
|
# https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
# Subdirs
|
# Subdirs
|
||||||
|
add_subdirectory(state)
|
||||||
|
|
||||||
# Sources
|
# Sources
|
||||||
target_sources(${DAWN_TARGET_NAME}
|
target_sources(${DAWN_TARGET_NAME}
|
||||||
|
@ -13,6 +13,11 @@
|
|||||||
#include "asset/assetmap.h"
|
#include "asset/assetmap.h"
|
||||||
#include "ui/textbox.h"
|
#include "ui/textbox.h"
|
||||||
#include "ui/testmenu.h"
|
#include "ui/testmenu.h"
|
||||||
|
#include "ui/mainmenu.h"
|
||||||
|
|
||||||
|
#include "game/state/mainmenu.h"
|
||||||
|
#include "game/state/mapchange.h"
|
||||||
|
#include "game/state/overworld.h"
|
||||||
|
|
||||||
game_t GAME;
|
game_t GAME;
|
||||||
|
|
||||||
@ -26,9 +31,10 @@ void gameInit() {
|
|||||||
|
|
||||||
textboxInit();
|
textboxInit();
|
||||||
testMenuInit();
|
testMenuInit();
|
||||||
|
mainMenuInit();
|
||||||
|
|
||||||
GAME.mapNext = MAP_LIST_TEST;
|
GAME.mapNext = MAP_LIST_TEST;
|
||||||
GAME.state = GAME_STATE_MAP_CHANGE;
|
GAME.state = GAME_STATE_INITIAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
gameupdateresult_t gameUpdate(const float_t delta) {
|
gameupdateresult_t gameUpdate(const float_t delta) {
|
||||||
@ -37,14 +43,11 @@ gameupdateresult_t gameUpdate(const float_t delta) {
|
|||||||
|
|
||||||
switch(GAME.state) {
|
switch(GAME.state) {
|
||||||
case GAME_STATE_INITIAL:
|
case GAME_STATE_INITIAL:
|
||||||
GAME.state = GAME_STATE_OVERWORLD;
|
GAME.state = GAME_STATE_MAIN_MENU;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GAME_STATE_OVERWORLD:
|
case GAME_STATE_OVERWORLD:
|
||||||
textboxUpdate();
|
gameStateOverworldUpdate();
|
||||||
testMenuUpdate();
|
|
||||||
if(GAME.currentMap) mapUpdate(GAME.currentMap);
|
|
||||||
if(inputWasPressed(INPUT_BIND_PAUSE)) GAME.state = GAME_STATE_PAUSED;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GAME_STATE_PAUSED:
|
case GAME_STATE_PAUSED:
|
||||||
@ -52,10 +55,11 @@ gameupdateresult_t gameUpdate(const float_t delta) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case GAME_STATE_MAP_CHANGE:
|
case GAME_STATE_MAP_CHANGE:
|
||||||
assetMapLoad(MAP_LIST_PATHS[GAME.mapNext], &MAP_MAIN);
|
gameStateMapChangeUpdate();
|
||||||
GAME.state = GAME_STATE_OVERWORLD;
|
break;
|
||||||
GAME.currentMap = &MAP_MAIN;
|
|
||||||
map_t *test = &MAP_MAIN;
|
case GAME_STATE_MAIN_MENU:
|
||||||
|
gameStateMainMenuUpdate();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,8 @@ typedef enum {
|
|||||||
GAME_STATE_INITIAL = 0,
|
GAME_STATE_INITIAL = 0,
|
||||||
GAME_STATE_OVERWORLD = 1,
|
GAME_STATE_OVERWORLD = 1,
|
||||||
GAME_STATE_PAUSED = 2,
|
GAME_STATE_PAUSED = 2,
|
||||||
GAME_STATE_MAP_CHANGE = 3
|
GAME_STATE_MAP_CHANGE = 3,
|
||||||
|
GAME_STATE_MAIN_MENU = 4
|
||||||
} gamestate_t;
|
} gamestate_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
14
src/dawn/game/state/CMakeLists.txt
Normal file
14
src/dawn/game/state/CMakeLists.txt
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
# Copyright (c) 2024 Dominic Masters
|
||||||
|
#
|
||||||
|
# This software is released under the MIT License.
|
||||||
|
# https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
# Subdirs
|
||||||
|
|
||||||
|
# Sources
|
||||||
|
target_sources(${DAWN_TARGET_NAME}
|
||||||
|
PRIVATE
|
||||||
|
mainmenu.c
|
||||||
|
mapchange.c
|
||||||
|
overworld.c
|
||||||
|
)
|
14
src/dawn/game/state/mainmenu.c
Normal file
14
src/dawn/game/state/mainmenu.c
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2024 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "mainmenu.h"
|
||||||
|
#include "ui/mainmenu.h"
|
||||||
|
|
||||||
|
void gameStateMainMenuUpdate() {
|
||||||
|
// Update the main menu
|
||||||
|
mainMenuUpdate();
|
||||||
|
}
|
14
src/dawn/game/state/mainmenu.h
Normal file
14
src/dawn/game/state/mainmenu.h
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2024 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "dawn.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the main menu state.
|
||||||
|
*/
|
||||||
|
void gameStateMainMenuUpdate();
|
17
src/dawn/game/state/mapchange.c
Normal file
17
src/dawn/game/state/mapchange.c
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2024 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "mapchange.h"
|
||||||
|
#include "asset/assetmap.h"
|
||||||
|
#include "game/game.h"
|
||||||
|
|
||||||
|
void gameStateMapChangeUpdate() {
|
||||||
|
assetMapLoad(MAP_LIST_PATHS[GAME.mapNext], &MAP_MAIN);
|
||||||
|
GAME.state = GAME_STATE_OVERWORLD;
|
||||||
|
GAME.currentMap = &MAP_MAIN;
|
||||||
|
map_t *test = &MAP_MAIN;
|
||||||
|
}
|
14
src/dawn/game/state/mapchange.h
Normal file
14
src/dawn/game/state/mapchange.h
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2024 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "dawn.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the map change game state.
|
||||||
|
*/
|
||||||
|
void gameStateMapChangeUpdate();
|
19
src/dawn/game/state/overworld.c
Normal file
19
src/dawn/game/state/overworld.c
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2024 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "overworld.h"
|
||||||
|
#include "game/game.h"
|
||||||
|
#include "input.h"
|
||||||
|
#include "ui/textbox.h"
|
||||||
|
#include "ui/testmenu.h"
|
||||||
|
|
||||||
|
void gameStateOverworldUpdate() {
|
||||||
|
textboxUpdate();
|
||||||
|
testMenuUpdate();
|
||||||
|
if(GAME.currentMap) mapUpdate(GAME.currentMap);
|
||||||
|
if(inputWasPressed(INPUT_BIND_PAUSE)) GAME.state = GAME_STATE_PAUSED;
|
||||||
|
}
|
14
src/dawn/game/state/overworld.h
Normal file
14
src/dawn/game/state/overworld.h
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2024 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "dawn.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the overworld game state.
|
||||||
|
*/
|
||||||
|
void gameStateOverworldUpdate();
|
@ -11,4 +11,5 @@ target_sources(${DAWN_TARGET_NAME}
|
|||||||
menu.c
|
menu.c
|
||||||
textbox.c
|
textbox.c
|
||||||
testmenu.c
|
testmenu.c
|
||||||
|
mainmenu.c
|
||||||
)
|
)
|
38
src/dawn/ui/mainmenu.c
Normal file
38
src/dawn/ui/mainmenu.c
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2024 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "mainmenu.h"
|
||||||
|
|
||||||
|
mainmenu_t MAIN_MENU;
|
||||||
|
|
||||||
|
void mainMenuInit() {
|
||||||
|
const char_t* strings[] = {
|
||||||
|
"New Game",
|
||||||
|
"Load Game",
|
||||||
|
"Options",
|
||||||
|
"Exit"
|
||||||
|
};
|
||||||
|
|
||||||
|
uint16_t columns = 1;
|
||||||
|
uint16_t rows = 4;
|
||||||
|
menuInit(&MAIN_MENU.menu, columns, rows);
|
||||||
|
memcpy(MAIN_MENU.menu.strings, strings, sizeof(strings));
|
||||||
|
MAIN_MENU.menu.selectCallback = mainMenuSelectCallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
void mainMenuUpdate() {
|
||||||
|
menuUpdate(&MAIN_MENU.menu);
|
||||||
|
}
|
||||||
|
|
||||||
|
void mainMenuSelectCallback(
|
||||||
|
const menu_t *menu,
|
||||||
|
const uint16_t x,
|
||||||
|
const uint16_t y,
|
||||||
|
const char_t *str
|
||||||
|
) {
|
||||||
|
printf("Selected: %s\n", str);
|
||||||
|
}
|
40
src/dawn/ui/mainmenu.h
Normal file
40
src/dawn/ui/mainmenu.h
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2024 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "ui/menu.h"
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
menu_t menu;
|
||||||
|
} mainmenu_t;
|
||||||
|
|
||||||
|
extern mainmenu_t MAIN_MENU;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes the main menu.
|
||||||
|
*/
|
||||||
|
void mainMenuInit();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the main menu.
|
||||||
|
*/
|
||||||
|
void mainMenuUpdate();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback for when a main menu item is selected.
|
||||||
|
*
|
||||||
|
* @param menu The menu that was selected.
|
||||||
|
* @param x The x position of the selected item.
|
||||||
|
* @param y The y position of the selected item.
|
||||||
|
* @param str The string of the selected item.
|
||||||
|
*/
|
||||||
|
void mainMenuSelectCallback(
|
||||||
|
const menu_t *menu,
|
||||||
|
const uint16_t x,
|
||||||
|
const uint16_t y,
|
||||||
|
const char_t *str
|
||||||
|
);
|
@ -36,6 +36,13 @@ void menuUpdate(menu_t *menu) {
|
|||||||
} else if(inputWasPressed(INPUT_BIND_RIGHT)) {
|
} else if(inputWasPressed(INPUT_BIND_RIGHT)) {
|
||||||
menu->repeatHeld = 0.0f;
|
menu->repeatHeld = 0.0f;
|
||||||
return menuPositionMove(menu, MENU_DIRECTION_RIGHT);
|
return menuPositionMove(menu, MENU_DIRECTION_RIGHT);
|
||||||
|
} else if(inputWasPressed(INPUT_BIND_ACCEPT) && menu->selectCallback) {
|
||||||
|
menu->selectCallback(
|
||||||
|
menu,
|
||||||
|
menu->x, menu->y,
|
||||||
|
menu->strings[(menu->y * menu->columns) + menu->x]
|
||||||
|
);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle repeat
|
// Handle repeat
|
||||||
|
@ -19,7 +19,9 @@ typedef enum {
|
|||||||
MENU_DIRECTION_RIGHT = 3
|
MENU_DIRECTION_RIGHT = 3
|
||||||
} menudirection_t;
|
} menudirection_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct _menu_t menu_t;
|
||||||
|
|
||||||
|
typedef struct _menu_t {
|
||||||
uint16_t x, y;
|
uint16_t x, y;
|
||||||
uint16_t rows, columns;
|
uint16_t rows, columns;
|
||||||
float_t repeatHeld;
|
float_t repeatHeld;
|
||||||
@ -27,6 +29,14 @@ typedef struct {
|
|||||||
|
|
||||||
// Visual things
|
// Visual things
|
||||||
uint16_t renderOffsetX, renderOffsetY;
|
uint16_t renderOffsetX, renderOffsetY;
|
||||||
|
|
||||||
|
// Callbacks
|
||||||
|
void (*selectCallback)(
|
||||||
|
const menu_t *menu,
|
||||||
|
const uint16_t x,
|
||||||
|
const uint16_t y,
|
||||||
|
const char_t *str
|
||||||
|
);
|
||||||
} menu_t;
|
} menu_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user