61 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			61 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
| /**
 | |
|  * Copyright (c) 2024 Dominic Masters
 | |
|  * 
 | |
|  * This software is released under the MIT License.
 | |
|  * https://opensource.org/licenses/MIT
 | |
|  */
 | |
| 
 | |
| #include "game.h"
 | |
| #include "time.h"
 | |
| #include "input.h"
 | |
| #include "display/display.h"
 | |
| #include "rpg/world/maps/testmap.h"
 | |
| #include "ui/textbox.h"
 | |
| 
 | |
| map_t MAP;
 | |
| game_t GAME;
 | |
| 
 | |
| void gameInit() {
 | |
|   memset(&GAME, 0, sizeof(game_t));
 | |
| 
 | |
|   timeInit();
 | |
|   inputInit();
 | |
|   displayInit();
 | |
|   textboxInit();
 | |
|   
 | |
|   testMapInit(&MAP);
 | |
|   gameSetMap(&MAP);
 | |
| }
 | |
| 
 | |
| uint8_t gameUpdate(const float_t delta) {
 | |
|   timeUpdate(delta);
 | |
|   inputUpdate();
 | |
| 
 | |
|   switch(GAME.state) {
 | |
|     case GAME_STATE_RUNNING:
 | |
|       textboxUpdate();
 | |
|       if(GAME.currentMap) mapUpdate(GAME.currentMap);
 | |
|       if(inputWasPressed(INPUT_BIND_PAUSE)) GAME.state = GAME_STATE_PAUSED;
 | |
|       break;
 | |
|     
 | |
|     case GAME_STATE_PAUSED:
 | |
|       if(inputWasPressed(INPUT_BIND_PAUSE)) GAME.state = GAME_STATE_RUNNING;
 | |
|       break;
 | |
| 
 | |
|     default:
 | |
|       assertUnreachable("Invalid game state.");
 | |
|   }
 | |
| 
 | |
|   displayUpdate();
 | |
| 
 | |
|   if(GAME.shouldExit) return GAME_UPDATE_RESULT_EXIT;
 | |
|   return GAME_UPDATE_RESULT_CONTINUE;
 | |
| }
 | |
| 
 | |
| void gameSetMap(map_t *map) {
 | |
|   GAME.currentMap = map;
 | |
| }
 | |
| 
 | |
| void gameDispose() {
 | |
|   displayDispose();
 | |
| } |