2018-02-16 18:11:26 +01:00
|
|
|
/*
|
|
|
|
* BreakHack - A dungeone crawler RPG
|
|
|
|
* Copyright (C) 2018 Linus Probert <linus.probert@gmail.com>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2017-11-30 21:00:47 +01:00
|
|
|
#include <stdio.h>
|
2018-02-15 14:45:20 +01:00
|
|
|
#include <stdlib.h>
|
2017-11-30 21:00:47 +01:00
|
|
|
#include <stdbool.h>
|
2018-02-21 00:29:21 +01:00
|
|
|
#include <SDL.h>
|
|
|
|
#include <SDL_image.h>
|
2018-02-22 12:36:24 +01:00
|
|
|
#include <physfs.h>
|
2017-11-30 21:00:47 +01:00
|
|
|
|
2017-12-19 09:06:21 +01:00
|
|
|
#include "linkedlist.h"
|
2017-11-30 21:00:47 +01:00
|
|
|
#include "player.h"
|
|
|
|
#include "screenresolution.h"
|
|
|
|
#include "dimension.h"
|
2017-12-01 16:03:19 +01:00
|
|
|
#include "camera.h"
|
|
|
|
#include "map.h"
|
2017-12-02 23:32:40 +01:00
|
|
|
#include "map_lua.h"
|
2017-12-05 08:30:08 +01:00
|
|
|
#include "timer.h"
|
2017-12-05 15:03:20 +01:00
|
|
|
#include "roommatrix.h"
|
2017-12-22 06:27:58 +01:00
|
|
|
#include "gamestate.h"
|
2017-12-22 15:15:40 +01:00
|
|
|
#include "gui.h"
|
2018-01-23 22:54:02 +01:00
|
|
|
#include "util.h"
|
2018-01-24 21:14:34 +01:00
|
|
|
#include "item_builder.h"
|
2018-01-31 09:15:33 +01:00
|
|
|
#include "pointer.h"
|
2018-02-02 16:16:55 +01:00
|
|
|
#include "gui_button.h"
|
2018-02-03 23:39:49 +01:00
|
|
|
#include "particle_engine.h"
|
2018-02-08 17:01:38 +01:00
|
|
|
#include "menu.h"
|
2018-02-13 06:44:09 +01:00
|
|
|
#include "keyboard.h"
|
2018-02-14 16:04:40 +01:00
|
|
|
#include "mixer.h"
|
2018-02-15 14:45:20 +01:00
|
|
|
#include "random.h"
|
2018-02-23 11:01:25 +01:00
|
|
|
#include "skillbar.h"
|
2018-02-23 23:53:52 +01:00
|
|
|
#include "texturecache.h"
|
2018-03-13 16:51:08 +01:00
|
|
|
#include "update_data.h"
|
2018-03-17 00:04:26 +01:00
|
|
|
#include "settings.h"
|
2018-05-15 11:16:56 +02:00
|
|
|
#include "actiontextbuilder.h"
|
2018-05-20 00:02:39 +02:00
|
|
|
#include "input.h"
|
2017-11-30 21:00:47 +01:00
|
|
|
|
2018-02-19 15:09:04 +01:00
|
|
|
typedef enum Turn_t {
|
|
|
|
PLAYER,
|
|
|
|
MONSTER
|
|
|
|
} Turn;
|
|
|
|
|
2017-11-30 21:00:47 +01:00
|
|
|
static SDL_Window *gWindow = NULL;
|
|
|
|
static SDL_Renderer *gRenderer = NULL;
|
2017-12-12 11:20:08 +01:00
|
|
|
static Player *gPlayer = NULL;
|
2017-12-01 16:03:19 +01:00
|
|
|
static Map *gMap = NULL;
|
2017-12-05 15:03:20 +01:00
|
|
|
static RoomMatrix *gRoomMatrix = NULL;
|
2017-12-22 15:15:40 +01:00
|
|
|
static Gui *gGui = NULL;
|
2018-02-23 11:01:25 +01:00
|
|
|
static SkillBar *gSkillBar = NULL;
|
2018-05-20 17:25:53 +02:00
|
|
|
static Pointer *gPointer = NULL;
|
2018-01-23 12:14:44 +01:00
|
|
|
static unsigned int cLevel = 1;
|
2018-02-03 23:39:49 +01:00
|
|
|
static float deltaTime = 1.0;
|
2018-01-23 12:14:44 +01:00
|
|
|
static double renderScale = 1.0;
|
2018-02-08 17:01:38 +01:00
|
|
|
static Menu *mainMenu = NULL;
|
2018-02-13 06:44:09 +01:00
|
|
|
static Menu *inGameMenu = NULL;
|
2018-02-09 13:27:25 +01:00
|
|
|
static Timer *menuTimer = NULL;
|
2017-12-22 15:15:40 +01:00
|
|
|
static GameState gGameState;
|
2018-05-13 23:32:44 +02:00
|
|
|
static Camera *gCamera;
|
2018-01-23 12:14:44 +01:00
|
|
|
static SDL_Rect gameViewport;
|
2018-02-22 15:42:43 +01:00
|
|
|
static SDL_Rect skillBarViewport;
|
2018-01-23 12:14:44 +01:00
|
|
|
static SDL_Rect bottomGuiViewport;
|
|
|
|
static SDL_Rect rightGuiViewport;
|
2018-02-09 13:27:25 +01:00
|
|
|
static SDL_Rect menuViewport;
|
2018-02-19 15:09:04 +01:00
|
|
|
static Turn currentTurn = PLAYER;
|
2018-05-20 00:02:39 +02:00
|
|
|
static Input input;
|
2017-11-30 21:00:47 +01:00
|
|
|
|
2018-05-15 14:21:54 +02:00
|
|
|
static SDL_Color C_MENU_DEFAULT = { 255, 255, 0, 255 };
|
2018-05-22 15:48:09 +02:00
|
|
|
static SDL_Color C_MENU_OUTLINE_DEFAULT = { 0, 0, 0, 255 };
|
2018-05-15 14:21:54 +02:00
|
|
|
static SDL_Color C_MENU_HOVER = { 255, 0, 0, 255 };
|
2018-02-13 06:44:09 +01:00
|
|
|
|
|
|
|
struct MENU_ITEM {
|
|
|
|
char label[20];
|
|
|
|
void (*callback)(void*);
|
|
|
|
};
|
|
|
|
|
2018-02-09 07:26:44 +01:00
|
|
|
static void resetGame(void);
|
2018-02-13 06:44:09 +01:00
|
|
|
static void initMainMenu(void);
|
2018-02-14 11:00:34 +01:00
|
|
|
static bool is_player_dead(void);
|
2018-02-09 07:26:44 +01:00
|
|
|
|
2017-11-30 21:00:47 +01:00
|
|
|
static
|
2017-12-19 21:00:02 +01:00
|
|
|
bool initSDL(void)
|
2017-11-30 21:00:47 +01:00
|
|
|
{
|
|
|
|
int imgFlags = IMG_INIT_PNG;
|
2018-04-28 07:05:56 +02:00
|
|
|
|
|
|
|
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0)
|
|
|
|
{
|
|
|
|
error("Could not initiate SDL2: %s", SDL_GetError());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-12-03 11:09:57 +01:00
|
|
|
Dimension dim = getScreenDimensions();
|
2017-11-30 21:00:47 +01:00
|
|
|
|
2017-12-22 06:27:58 +01:00
|
|
|
if (dim.height > 1080) {
|
2018-01-24 06:41:37 +01:00
|
|
|
info("Hi resolution screen detected (%u x %u)", dim.width, dim.height);
|
2018-01-24 08:52:50 +01:00
|
|
|
renderScale = ((double) dim.height)/1080;
|
2018-01-24 06:41:37 +01:00
|
|
|
info("Scaling by %f", renderScale);
|
2017-11-30 21:00:47 +01:00
|
|
|
}
|
|
|
|
|
2017-12-22 06:27:58 +01:00
|
|
|
if ( (IMG_Init(imgFlags) & imgFlags) == 0 ) {
|
2018-01-24 06:41:37 +01:00
|
|
|
error("Unable to initiate img loading: %s",
|
2017-12-22 06:27:58 +01:00
|
|
|
IMG_GetError());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( TTF_Init() == -1 ) {
|
2018-01-24 06:41:37 +01:00
|
|
|
error("Unable to initiate ttf library: %s",
|
2017-12-22 06:27:58 +01:00
|
|
|
TTF_GetError());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-02-14 16:04:40 +01:00
|
|
|
mixer_init();
|
|
|
|
|
2018-03-07 19:15:08 +01:00
|
|
|
char title_buffer[100];
|
|
|
|
m_sprintf(title_buffer, 100, "%s %d.%d.%d %s", GAME_TITLE, MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION, RELEASE_TYPE);
|
|
|
|
gWindow = SDL_CreateWindow(title_buffer,
|
2017-11-30 21:00:47 +01:00
|
|
|
SDL_WINDOWPOS_UNDEFINED,
|
|
|
|
SDL_WINDOWPOS_UNDEFINED,
|
2018-01-23 12:14:44 +01:00
|
|
|
(int)(SCREEN_WIDTH * renderScale),
|
2018-01-24 06:41:37 +01:00
|
|
|
(int)(SCREEN_HEIGHT * renderScale),
|
2017-11-30 21:00:47 +01:00
|
|
|
SDL_WINDOW_SHOWN);
|
|
|
|
if (gWindow == NULL)
|
|
|
|
{
|
2018-01-24 06:41:37 +01:00
|
|
|
error("Unable to create window: %s", SDL_GetError());
|
2017-11-30 21:00:47 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-05-09 00:21:38 +02:00
|
|
|
gRenderer = SDL_CreateRenderer(gWindow, -1,
|
|
|
|
SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE);
|
2017-11-30 21:00:47 +01:00
|
|
|
if (gRenderer == NULL)
|
|
|
|
{
|
2018-01-24 06:41:37 +01:00
|
|
|
error("Unable to create renderer: %s", SDL_GetError());
|
2017-11-30 21:00:47 +01:00
|
|
|
return false;
|
|
|
|
}
|
2017-12-10 19:51:24 +01:00
|
|
|
if (SDL_SetRenderDrawBlendMode(gRenderer, SDL_BLENDMODE_BLEND) < 0) {
|
2018-01-24 06:41:37 +01:00
|
|
|
error("Unable to set blend mode: %s", SDL_GetError());
|
2017-12-10 19:51:24 +01:00
|
|
|
return false;
|
|
|
|
}
|
2017-11-30 21:00:47 +01:00
|
|
|
if (SDL_RenderSetLogicalSize(gRenderer, SCREEN_WIDTH, SCREEN_HEIGHT) < 0)
|
|
|
|
{
|
2018-01-24 06:41:37 +01:00
|
|
|
error("Unable to initiate scaling: %s",
|
2017-12-15 15:03:29 +01:00
|
|
|
SDL_GetError());
|
2017-11-30 21:00:47 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-01-23 12:14:44 +01:00
|
|
|
static void
|
|
|
|
initViewports(void)
|
|
|
|
{
|
|
|
|
gameViewport = (SDL_Rect) { 0, 0,
|
|
|
|
GAME_VIEW_WIDTH, GAME_VIEW_HEIGHT };
|
|
|
|
|
2018-02-22 15:42:43 +01:00
|
|
|
skillBarViewport = (SDL_Rect) { 0, GAME_VIEW_HEIGHT,
|
|
|
|
SKILL_BAR_WIDTH, SKILL_BAR_HEIGHT };
|
|
|
|
|
|
|
|
bottomGuiViewport = (SDL_Rect) { 0, GAME_VIEW_HEIGHT + SKILL_BAR_HEIGHT,
|
2018-01-23 12:14:44 +01:00
|
|
|
BOTTOM_GUI_WIDTH, BOTTOM_GUI_WIDTH };
|
|
|
|
|
|
|
|
rightGuiViewport = (SDL_Rect) { GAME_VIEW_WIDTH, 0,
|
|
|
|
RIGHT_GUI_WIDTH, RIGHT_GUI_HEIGHT };
|
2018-02-09 13:27:25 +01:00
|
|
|
|
|
|
|
menuViewport = (SDL_Rect) {
|
|
|
|
(SCREEN_WIDTH - GAME_VIEW_WIDTH)/2,
|
|
|
|
(SCREEN_HEIGHT - GAME_VIEW_HEIGHT)/2,
|
|
|
|
GAME_VIEW_WIDTH,
|
|
|
|
GAME_VIEW_HEIGHT
|
|
|
|
};
|
2018-01-23 12:14:44 +01:00
|
|
|
}
|
|
|
|
|
2018-02-08 17:01:38 +01:00
|
|
|
static bool
|
|
|
|
initGame(void)
|
2017-11-30 21:00:47 +01:00
|
|
|
{
|
2018-02-08 17:01:38 +01:00
|
|
|
initViewports();
|
2018-05-20 00:02:39 +02:00
|
|
|
input_init(&input);
|
2018-02-23 23:53:52 +01:00
|
|
|
texturecache_init(gRenderer);
|
2018-05-13 23:32:44 +02:00
|
|
|
gCamera = camera_create(gRenderer);
|
2018-02-08 17:01:38 +01:00
|
|
|
gRoomMatrix = roommatrix_create();
|
2018-05-13 23:32:44 +02:00
|
|
|
gGui = gui_create(gCamera);
|
2018-02-23 11:01:25 +01:00
|
|
|
gSkillBar = skillbar_create(gRenderer);
|
2018-02-08 17:01:38 +01:00
|
|
|
item_builder_init(gRenderer);
|
2018-05-20 17:25:53 +02:00
|
|
|
gPointer = pointer_create(gRenderer);
|
2018-02-08 17:01:38 +01:00
|
|
|
particle_engine_init();
|
2018-02-09 13:27:25 +01:00
|
|
|
menuTimer = timer_create();
|
2018-05-15 11:16:56 +02:00
|
|
|
actiontextbuilder_init(gRenderer);
|
2018-01-31 09:15:33 +01:00
|
|
|
|
|
|
|
return true;
|
2017-11-30 21:00:47 +01:00
|
|
|
}
|
|
|
|
|
2018-02-09 07:26:44 +01:00
|
|
|
static void
|
|
|
|
startGame(void *unused)
|
|
|
|
{
|
|
|
|
UNUSED(unused);
|
2018-02-13 09:50:52 +01:00
|
|
|
cLevel = 1;
|
2018-02-09 07:26:44 +01:00
|
|
|
gGameState = PLAYING;
|
2018-02-14 11:00:34 +01:00
|
|
|
if (gPlayer)
|
|
|
|
player_destroy(gPlayer);
|
|
|
|
gPlayer = player_create(WARRIOR, gRenderer);
|
2018-02-15 14:45:20 +01:00
|
|
|
mixer_play_music(GAME_MUSIC0 + get_random(2));
|
2018-02-09 07:26:44 +01:00
|
|
|
resetGame();
|
2018-03-07 16:02:56 +01:00
|
|
|
gui_clear_message_log();
|
|
|
|
gui_log("The Dungeon Crawl begins!");
|
|
|
|
gui_event_message("Welcome to the dungeon!");
|
2018-02-09 07:26:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
exitGame(void *unused)
|
|
|
|
{
|
|
|
|
UNUSED(unused);
|
|
|
|
gGameState = QUIT;
|
|
|
|
}
|
|
|
|
|
2018-02-08 17:01:38 +01:00
|
|
|
static void
|
2018-02-13 06:44:09 +01:00
|
|
|
toggleInGameMenu(void *unused)
|
2018-02-08 17:01:38 +01:00
|
|
|
{
|
2018-02-13 06:44:09 +01:00
|
|
|
UNUSED(unused);
|
2018-02-14 11:00:34 +01:00
|
|
|
if (gGameState == PLAYING || gGameState == GAME_OVER)
|
2018-02-13 06:44:09 +01:00
|
|
|
gGameState = IN_GAME_MENU;
|
2018-02-14 11:00:34 +01:00
|
|
|
else if (is_player_dead())
|
|
|
|
gGameState = GAME_OVER;
|
2018-02-13 06:44:09 +01:00
|
|
|
else
|
|
|
|
gGameState = PLAYING;
|
|
|
|
}
|
2018-02-08 17:01:38 +01:00
|
|
|
|
2018-02-13 06:44:09 +01:00
|
|
|
static void
|
|
|
|
goToMainMenu(void *unused)
|
|
|
|
{
|
|
|
|
UNUSED(unused);
|
|
|
|
gGameState = MENU;
|
|
|
|
menu_destroy(inGameMenu);
|
|
|
|
inGameMenu = NULL;
|
|
|
|
initMainMenu();
|
2018-02-14 11:00:34 +01:00
|
|
|
Position p = { 0, 0 };
|
2018-06-14 00:12:49 +02:00
|
|
|
gPlayer->sprite->pos = (Position) { 32, 32 };
|
2018-02-14 11:00:34 +01:00
|
|
|
map_set_current_room(gMap, &p);
|
2018-05-13 23:32:44 +02:00
|
|
|
camera_follow_position(gCamera, &p);
|
2018-02-13 06:44:09 +01:00
|
|
|
}
|
2018-02-09 13:27:25 +01:00
|
|
|
|
2018-02-13 06:44:09 +01:00
|
|
|
static void
|
|
|
|
createMenu(Menu **menu, struct MENU_ITEM menu_items[], unsigned int size)
|
|
|
|
{
|
|
|
|
if (*menu == NULL)
|
|
|
|
*menu = menu_create();
|
2018-02-09 13:27:25 +01:00
|
|
|
|
2018-02-13 06:44:09 +01:00
|
|
|
for (unsigned int i = 0; i < size; ++i) {
|
2018-02-22 09:44:27 +01:00
|
|
|
unsigned int hcenter;
|
2018-02-09 13:27:25 +01:00
|
|
|
|
2018-02-08 17:01:38 +01:00
|
|
|
Sprite *s1 = sprite_create();
|
2018-05-15 14:12:38 +02:00
|
|
|
sprite_load_text_texture(s1, "GUI/SDS_8x8.ttf", 0, 25, 2);
|
2018-02-08 17:01:38 +01:00
|
|
|
texture_load_from_text(s1->textures[0], menu_items[i].label,
|
2018-05-15 14:12:38 +02:00
|
|
|
C_MENU_DEFAULT, C_MENU_OUTLINE_DEFAULT, gRenderer);
|
2018-02-09 13:27:25 +01:00
|
|
|
|
|
|
|
hcenter = (SCREEN_WIDTH/2) - (s1->textures[0]->dim.width/2);
|
2018-02-22 09:44:27 +01:00
|
|
|
s1->pos = (Position) { (int) hcenter, (int) 200 + (i*50) };
|
2018-02-23 23:53:52 +01:00
|
|
|
s1->dim = s1->textures[0]->dim;
|
2018-02-08 17:01:38 +01:00
|
|
|
s1->fixed = true;
|
|
|
|
|
|
|
|
Sprite *s2 = sprite_create();
|
2018-05-15 14:12:38 +02:00
|
|
|
sprite_load_text_texture(s2, "GUI/SDS_8x8.ttf", 0, 25, 2);
|
2018-02-08 17:01:38 +01:00
|
|
|
texture_load_from_text(s2->textures[0], menu_items[i].label,
|
2018-05-15 14:12:38 +02:00
|
|
|
C_MENU_HOVER, C_MENU_OUTLINE_DEFAULT, gRenderer);
|
2018-02-09 13:27:25 +01:00
|
|
|
|
2018-02-22 09:44:27 +01:00
|
|
|
s2->pos = (Position) { (int) hcenter, (int) 200 + (i*50) };
|
2018-02-23 23:53:52 +01:00
|
|
|
s2->dim = s2->textures[0]->dim;
|
2018-02-08 17:01:38 +01:00
|
|
|
s2->fixed = true;
|
|
|
|
|
2018-02-13 06:44:09 +01:00
|
|
|
menu_item_add(*menu, s1, s2, menu_items[i].callback);
|
2018-02-08 17:01:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-13 06:44:09 +01:00
|
|
|
static void
|
|
|
|
initInGameMenu(void)
|
|
|
|
{
|
|
|
|
struct MENU_ITEM menu_items[] = {
|
|
|
|
{ "RESUME", toggleInGameMenu },
|
|
|
|
{ "MAIN MENU", goToMainMenu },
|
|
|
|
{ "QUIT", exitGame },
|
|
|
|
};
|
|
|
|
|
|
|
|
createMenu(&inGameMenu, menu_items, 3);
|
|
|
|
}
|
|
|
|
|
2018-07-09 22:53:52 +02:00
|
|
|
static void
|
|
|
|
createInGameGameOverMenu(void)
|
|
|
|
{
|
|
|
|
struct MENU_ITEM menu_items[] = {
|
2018-07-31 23:08:34 +02:00
|
|
|
{ "NEW GAME", startGame },
|
2018-07-09 22:53:52 +02:00
|
|
|
{ "MAIN MENU", goToMainMenu },
|
|
|
|
{ "QUIT", exitGame },
|
|
|
|
};
|
|
|
|
|
|
|
|
if (inGameMenu) {
|
|
|
|
menu_destroy(inGameMenu);
|
|
|
|
inGameMenu = NULL;
|
|
|
|
}
|
2018-07-31 23:08:34 +02:00
|
|
|
createMenu(&inGameMenu, menu_items, 3);
|
2018-07-09 22:53:52 +02:00
|
|
|
}
|
|
|
|
|
2018-02-13 06:44:09 +01:00
|
|
|
static void
|
|
|
|
initMainMenu(void)
|
|
|
|
{
|
|
|
|
struct MENU_ITEM menu_items[] = {
|
|
|
|
{ "PLAY", startGame },
|
|
|
|
{ "QUIT", exitGame },
|
|
|
|
};
|
|
|
|
|
|
|
|
if (gMap)
|
|
|
|
map_destroy(gMap);
|
|
|
|
|
|
|
|
gMap = map_lua_generator_single_room__run(cLevel, gRenderer);
|
|
|
|
|
|
|
|
createMenu(&mainMenu, menu_items, 2);
|
2018-02-15 14:00:59 +01:00
|
|
|
mixer_play_music(MENU_MUSIC);
|
2018-02-13 06:44:09 +01:00
|
|
|
}
|
|
|
|
|
2018-07-31 23:45:09 +02:00
|
|
|
static void
|
|
|
|
repopulate_roommatrix(void)
|
|
|
|
{
|
|
|
|
roommatrix_populate_from_map(gRoomMatrix, gMap);
|
|
|
|
roommatrix_add_lightsource(gRoomMatrix,
|
|
|
|
&gPlayer->sprite->pos);
|
|
|
|
roommatrix_build_lightmap(gRoomMatrix);
|
|
|
|
}
|
|
|
|
|
2018-02-08 17:01:38 +01:00
|
|
|
static void
|
|
|
|
resetGame(void)
|
|
|
|
{
|
2018-02-09 10:18:22 +01:00
|
|
|
SDL_FlushEvents(SDL_FIRSTEVENT, SDL_LASTEVENT);
|
|
|
|
|
2018-02-09 13:55:57 +01:00
|
|
|
if (mainMenu) {
|
|
|
|
menu_destroy(mainMenu);
|
|
|
|
mainMenu = NULL;
|
|
|
|
}
|
|
|
|
|
2018-02-13 09:50:52 +01:00
|
|
|
if (!inGameMenu)
|
|
|
|
initInGameMenu();
|
2018-02-13 06:44:09 +01:00
|
|
|
|
2018-02-08 17:01:38 +01:00
|
|
|
if (gMap)
|
|
|
|
map_destroy(gMap);
|
|
|
|
|
2018-02-14 11:00:34 +01:00
|
|
|
particle_engine_clear();
|
|
|
|
|
2018-02-08 17:01:38 +01:00
|
|
|
info("Building new map");
|
2018-02-09 09:36:24 +01:00
|
|
|
gMap = map_lua_generator_run(cLevel, gRenderer);
|
2018-02-14 11:00:34 +01:00
|
|
|
|
2018-02-08 17:01:38 +01:00
|
|
|
gPlayer->sprite->pos = (Position) {
|
|
|
|
TILE_DIMENSION, TILE_DIMENSION };
|
2018-02-09 09:36:24 +01:00
|
|
|
|
|
|
|
map_set_current_room(gMap, &gPlayer->sprite->pos);
|
2018-05-13 23:32:44 +02:00
|
|
|
camera_follow_position(gCamera, &gPlayer->sprite->pos);
|
2018-07-31 23:45:09 +02:00
|
|
|
repopulate_roommatrix();
|
2018-02-08 17:01:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
init(void)
|
2017-11-30 21:00:47 +01:00
|
|
|
{
|
2018-05-03 17:22:40 +02:00
|
|
|
if (!initSDL()) {
|
|
|
|
return false;
|
|
|
|
} else if (!initGame()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-03-17 00:04:26 +01:00
|
|
|
settings_init();
|
2018-02-08 17:01:38 +01:00
|
|
|
initMainMenu();
|
2017-12-17 13:43:41 +01:00
|
|
|
|
2018-05-13 23:32:44 +02:00
|
|
|
gCamera->pos = (Position) { 0, 0 };
|
2018-02-08 17:01:38 +01:00
|
|
|
|
|
|
|
gGameState = MENU;
|
2017-12-22 06:27:58 +01:00
|
|
|
|
2018-05-03 17:22:40 +02:00
|
|
|
return true;
|
2017-11-30 21:00:47 +01:00
|
|
|
}
|
|
|
|
|
2018-02-13 09:50:52 +01:00
|
|
|
static bool
|
2018-05-20 00:02:39 +02:00
|
|
|
handle_main_input(void)
|
2018-02-13 09:50:52 +01:00
|
|
|
{
|
2018-02-14 11:00:34 +01:00
|
|
|
if (gGameState == PLAYING
|
2018-03-17 09:03:29 +01:00
|
|
|
|| gGameState == IN_GAME_MENU
|
|
|
|
|| gGameState == GAME_OVER)
|
2018-02-14 11:00:34 +01:00
|
|
|
{
|
2018-05-20 00:02:39 +02:00
|
|
|
if (input_key_is_pressed(&input, KEY_ESC)) {
|
2018-02-13 09:50:52 +01:00
|
|
|
toggleInGameMenu(NULL);
|
|
|
|
return true;
|
|
|
|
}
|
2018-03-17 09:03:29 +01:00
|
|
|
}
|
2018-02-20 10:45:54 +01:00
|
|
|
|
2018-05-20 16:53:16 +02:00
|
|
|
if (input_modkey_is_pressed(&input, KEY_CTRL_M)) {
|
2018-03-17 09:03:29 +01:00
|
|
|
if (mixer_toggle_music(&gGameState))
|
|
|
|
gui_log("Music enabled");
|
|
|
|
else
|
|
|
|
gui_log("Music disabled");
|
|
|
|
return true;
|
|
|
|
}
|
2018-02-20 10:45:54 +01:00
|
|
|
|
2018-05-20 16:53:16 +02:00
|
|
|
if (input_modkey_is_pressed(&input, KEY_CTRL_S)) {
|
2018-03-17 09:03:29 +01:00
|
|
|
if (mixer_toggle_sound())
|
|
|
|
gui_log("Sound enabled");
|
|
|
|
else
|
|
|
|
gui_log("Sound disabled");
|
|
|
|
return true;
|
2018-02-13 09:50:52 +01:00
|
|
|
}
|
2018-03-17 09:03:29 +01:00
|
|
|
|
2018-02-13 09:50:52 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
handle_events(void)
|
2017-12-03 11:09:57 +01:00
|
|
|
{
|
|
|
|
static SDL_Event event;
|
|
|
|
bool quit = false;
|
2018-05-16 19:09:01 +02:00
|
|
|
int handleCount = 0;
|
2017-12-03 11:09:57 +01:00
|
|
|
|
2018-05-20 00:02:39 +02:00
|
|
|
input_reset(&input);
|
2017-12-03 11:09:57 +01:00
|
|
|
while (SDL_PollEvent(&event) != 0) {
|
|
|
|
if (event.type == SDL_QUIT) {
|
|
|
|
quit = true;
|
2018-02-13 09:50:52 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-05-20 00:02:39 +02:00
|
|
|
input_handle_event(&input, &event);
|
2018-05-16 19:09:01 +02:00
|
|
|
|
|
|
|
handleCount++;
|
2018-05-20 00:02:39 +02:00
|
|
|
if (handleCount >= 20) {
|
2018-05-16 19:09:01 +02:00
|
|
|
debug("Flushing event queue");
|
|
|
|
SDL_PumpEvents();
|
|
|
|
SDL_FlushEvents(SDL_FIRSTEVENT, SDL_LASTEVENT);
|
|
|
|
break;
|
|
|
|
}
|
2017-12-03 11:09:57 +01:00
|
|
|
}
|
2018-02-02 16:16:55 +01:00
|
|
|
|
2017-12-03 11:09:57 +01:00
|
|
|
return quit;
|
|
|
|
}
|
|
|
|
|
2018-01-30 15:16:14 +01:00
|
|
|
static bool
|
2018-02-14 11:00:34 +01:00
|
|
|
is_player_dead(void)
|
2018-01-30 15:16:14 +01:00
|
|
|
{
|
|
|
|
if (gPlayer->stats.hp <= 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-12-22 06:27:58 +01:00
|
|
|
static void
|
|
|
|
check_next_level(void)
|
|
|
|
{
|
|
|
|
Room *room = gMap->rooms[gMap->currentRoom.x][gMap->currentRoom.y];
|
|
|
|
Position pos = position_to_matrix_coords(&gPlayer->sprite->pos);
|
|
|
|
|
|
|
|
MapTile *tile = room->tiles[pos.x][pos.y];
|
|
|
|
if (!tile) {
|
2018-01-24 06:41:37 +01:00
|
|
|
error("Looks like we are out of place");
|
2017-12-22 06:27:58 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (tile->levelExit) {
|
2018-02-15 14:00:59 +01:00
|
|
|
mixer_play_effect(NEXT_LEVEL);
|
2018-02-15 14:45:20 +01:00
|
|
|
mixer_play_music(GAME_MUSIC0 + get_random(2));
|
2018-02-09 09:36:24 +01:00
|
|
|
++cLevel;
|
2018-02-08 17:01:38 +01:00
|
|
|
resetGame();
|
2017-12-22 06:27:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-13 21:47:49 +01:00
|
|
|
static void
|
|
|
|
populateUpdateData(UpdateData *data, float deltatime)
|
|
|
|
{
|
|
|
|
data->player = gPlayer;
|
|
|
|
data->map = gMap;
|
|
|
|
data->matrix = gRoomMatrix;
|
2018-05-20 00:02:39 +02:00
|
|
|
data->input = &input;
|
2018-03-13 21:47:49 +01:00
|
|
|
data->deltatime = deltatime;
|
|
|
|
}
|
|
|
|
|
2017-12-22 15:15:40 +01:00
|
|
|
static void
|
2018-07-28 14:28:55 +02:00
|
|
|
run_game_update(void)
|
2017-12-22 15:15:40 +01:00
|
|
|
{
|
2018-03-13 21:47:49 +01:00
|
|
|
static UpdateData updateData;
|
2018-03-23 22:03:34 +01:00
|
|
|
static unsigned int playerLevel = 1;
|
2018-03-13 21:47:49 +01:00
|
|
|
|
2018-05-20 00:02:39 +02:00
|
|
|
if (gGameState == IN_GAME_MENU)
|
|
|
|
menu_update(inGameMenu, &input);
|
|
|
|
|
2018-02-24 21:15:13 +01:00
|
|
|
map_clear_dead_monsters(gMap, gPlayer);
|
2018-01-24 21:14:34 +01:00
|
|
|
map_clear_collected_items(gMap);
|
2017-12-22 15:15:40 +01:00
|
|
|
|
2018-03-13 21:47:49 +01:00
|
|
|
populateUpdateData(&updateData, deltaTime);
|
2018-03-23 22:03:34 +01:00
|
|
|
if (playerLevel != gPlayer->stats.lvl) {
|
|
|
|
playerLevel = gPlayer->stats.lvl;
|
|
|
|
skillbar_check_skill_activation(gSkillBar, gPlayer);
|
|
|
|
}
|
2018-05-20 00:02:39 +02:00
|
|
|
|
|
|
|
if (gGameState == PLAYING && currentTurn == PLAYER)
|
|
|
|
player_update(&updateData);
|
|
|
|
|
2018-02-01 09:04:19 +01:00
|
|
|
gui_update_player_stats(gGui, gPlayer, gMap, gRenderer);
|
2018-05-13 23:32:44 +02:00
|
|
|
camera_update(gCamera, updateData.deltatime);
|
2018-02-03 23:39:49 +01:00
|
|
|
particle_engine_update(deltaTime);
|
2018-05-20 00:02:39 +02:00
|
|
|
roommatrix_update(&updateData);
|
2018-05-15 11:16:56 +02:00
|
|
|
actiontextbuilder_update(&updateData);
|
2018-05-20 00:02:39 +02:00
|
|
|
skillbar_update(gSkillBar, &updateData);
|
2018-05-17 23:14:42 +02:00
|
|
|
camera_follow_position(gCamera, &gPlayer->sprite->pos);
|
|
|
|
map_set_current_room(gMap, &gPlayer->sprite->pos);
|
|
|
|
map_update(&updateData);
|
2018-01-31 20:59:55 +01:00
|
|
|
|
2018-02-19 15:09:04 +01:00
|
|
|
if (currentTurn == PLAYER) {
|
2018-05-16 19:09:01 +02:00
|
|
|
if (player_turn_over(gPlayer)) {
|
2018-02-19 15:09:04 +01:00
|
|
|
currentTurn = MONSTER;
|
|
|
|
player_reset_steps(gPlayer);
|
2018-07-31 23:45:09 +02:00
|
|
|
repopulate_roommatrix();
|
2018-02-19 15:09:04 +01:00
|
|
|
}
|
2018-03-13 23:36:39 +01:00
|
|
|
} else if (currentTurn == MONSTER) {
|
|
|
|
if (map_move_monsters(gMap, gRoomMatrix)) {
|
2018-02-19 15:09:04 +01:00
|
|
|
currentTurn = PLAYER;
|
2018-07-31 23:45:09 +02:00
|
|
|
repopulate_roommatrix();
|
2018-03-13 23:36:39 +01:00
|
|
|
}
|
2017-12-22 15:15:40 +01:00
|
|
|
}
|
2018-07-28 14:28:55 +02:00
|
|
|
}
|
2017-12-22 15:15:40 +01:00
|
|
|
|
2018-07-28 14:28:55 +02:00
|
|
|
static void
|
|
|
|
run_game_render(void)
|
|
|
|
{
|
2018-02-09 09:36:24 +01:00
|
|
|
SDL_SetRenderDrawColor(gRenderer, 0, 0, 0, 0);
|
2017-12-22 15:15:40 +01:00
|
|
|
SDL_RenderClear(gRenderer);
|
|
|
|
|
2018-01-23 12:14:44 +01:00
|
|
|
SDL_RenderSetViewport(gRenderer, &gameViewport);
|
2018-05-13 23:32:44 +02:00
|
|
|
map_render(gMap, gCamera);
|
|
|
|
particle_engine_render_game(gCamera);
|
2018-02-14 11:00:34 +01:00
|
|
|
|
|
|
|
if (!is_player_dead())
|
2018-05-13 23:32:44 +02:00
|
|
|
player_render(gPlayer, gCamera);
|
2018-02-06 16:47:45 +01:00
|
|
|
|
2018-05-17 21:41:23 +02:00
|
|
|
map_render_top_layer(gMap, gCamera);
|
|
|
|
|
2018-07-28 14:28:55 +02:00
|
|
|
if (!is_player_dead())
|
|
|
|
player_render_toplayer(gPlayer, gCamera);
|
2018-07-09 19:26:06 +02:00
|
|
|
|
2018-02-06 16:47:45 +01:00
|
|
|
if (gPlayer->class == MAGE || gPlayer->class == PALADIN)
|
2018-05-13 23:32:44 +02:00
|
|
|
roommatrix_render_mouse_square(gRoomMatrix, gCamera);
|
2018-02-14 11:00:34 +01:00
|
|
|
|
2018-05-13 23:32:44 +02:00
|
|
|
roommatrix_render_lightmap(gRoomMatrix, gCamera);
|
2018-05-15 11:19:28 +02:00
|
|
|
actiontextbuilder_render(gCamera);
|
2018-05-13 23:32:44 +02:00
|
|
|
gui_render_event_message(gGui, gCamera);
|
2018-01-23 12:14:44 +01:00
|
|
|
|
|
|
|
SDL_RenderSetViewport(gRenderer, &rightGuiViewport);
|
2018-05-13 23:32:44 +02:00
|
|
|
gui_render_panel(gGui, gCamera);
|
2018-01-23 12:14:44 +01:00
|
|
|
|
2018-02-22 15:42:43 +01:00
|
|
|
SDL_RenderSetViewport(gRenderer, &skillBarViewport);
|
2018-05-13 23:32:44 +02:00
|
|
|
skillbar_render(gSkillBar, gPlayer, gCamera);
|
2018-02-22 15:42:43 +01:00
|
|
|
|
2018-01-23 12:14:44 +01:00
|
|
|
SDL_RenderSetViewport(gRenderer, &bottomGuiViewport);
|
2018-05-13 23:32:44 +02:00
|
|
|
gui_render_log(gGui, gCamera);
|
2017-12-22 15:15:40 +01:00
|
|
|
|
2018-01-31 09:15:33 +01:00
|
|
|
SDL_RenderSetViewport(gRenderer, NULL);
|
2018-05-13 23:32:44 +02:00
|
|
|
particle_engine_render_global(gCamera);
|
2018-05-20 00:02:39 +02:00
|
|
|
|
2018-02-13 06:44:09 +01:00
|
|
|
if (gGameState == IN_GAME_MENU) {
|
|
|
|
SDL_Rect dimmer = { 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT };
|
|
|
|
SDL_SetRenderDrawColor(gRenderer, 0, 0, 0, 150);
|
|
|
|
SDL_RenderFillRect(gRenderer, &dimmer);
|
2018-05-13 23:32:44 +02:00
|
|
|
menu_render(inGameMenu, gCamera);
|
2018-02-13 06:44:09 +01:00
|
|
|
}
|
2018-05-20 17:25:53 +02:00
|
|
|
pointer_render(gPointer, gCamera);
|
2018-01-31 09:15:33 +01:00
|
|
|
|
2017-12-22 15:15:40 +01:00
|
|
|
SDL_RenderPresent(gRenderer);
|
2018-07-28 14:28:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
run_game(void)
|
|
|
|
{
|
|
|
|
run_game_update();
|
|
|
|
|
|
|
|
run_game_render();
|
2017-12-22 15:15:40 +01:00
|
|
|
|
2018-02-14 11:00:34 +01:00
|
|
|
if (gGameState == PLAYING && is_player_dead()) {
|
2018-05-13 23:32:44 +02:00
|
|
|
camera_shake(VECTOR2D_RIGHT, 800);
|
2018-02-14 11:00:34 +01:00
|
|
|
gui_log("The dungeon consumed you");
|
2018-03-07 16:02:56 +01:00
|
|
|
gui_event_message("You died!");
|
2018-02-15 14:00:59 +01:00
|
|
|
mixer_play_effect(SPLAT);
|
2018-01-30 15:16:14 +01:00
|
|
|
gGameState = GAME_OVER;
|
2018-07-09 22:53:52 +02:00
|
|
|
createInGameGameOverMenu();
|
2018-07-31 23:08:34 +02:00
|
|
|
toggleInGameMenu(NULL);
|
2018-05-21 21:03:59 +02:00
|
|
|
} else {
|
|
|
|
check_next_level();
|
2018-02-14 11:00:34 +01:00
|
|
|
}
|
2017-12-22 15:15:40 +01:00
|
|
|
}
|
|
|
|
|
2018-02-08 17:01:38 +01:00
|
|
|
static void
|
|
|
|
run_menu(void)
|
|
|
|
{
|
2018-02-09 13:27:25 +01:00
|
|
|
if (!timer_started(menuTimer))
|
|
|
|
timer_start(menuTimer);
|
|
|
|
|
|
|
|
roommatrix_populate_from_map(gRoomMatrix, gMap);
|
|
|
|
roommatrix_build_lightmap(gRoomMatrix);
|
|
|
|
if (timer_get_ticks(menuTimer) > 1000) {
|
|
|
|
timer_stop(menuTimer);
|
|
|
|
timer_start(menuTimer);
|
|
|
|
map_move_monsters(gMap, gRoomMatrix);
|
|
|
|
}
|
|
|
|
|
2018-05-20 00:02:39 +02:00
|
|
|
menu_update(mainMenu, &input);
|
|
|
|
if (gGameState != MENU)
|
|
|
|
return;
|
|
|
|
|
2018-02-09 09:36:24 +01:00
|
|
|
SDL_SetRenderDrawColor(gRenderer, 0, 0, 0, 0);
|
2018-02-08 17:01:38 +01:00
|
|
|
SDL_RenderClear(gRenderer);
|
2018-02-09 13:27:25 +01:00
|
|
|
SDL_RenderSetViewport(gRenderer, &menuViewport);
|
2018-05-13 23:32:44 +02:00
|
|
|
map_render(gMap, gCamera);
|
|
|
|
roommatrix_render_lightmap(gRoomMatrix, gCamera);
|
2018-02-09 13:27:25 +01:00
|
|
|
|
2018-02-08 17:01:38 +01:00
|
|
|
SDL_RenderSetViewport(gRenderer, NULL);
|
2018-05-13 23:32:44 +02:00
|
|
|
menu_render(mainMenu, gCamera);
|
2018-05-20 17:25:53 +02:00
|
|
|
pointer_render(gPointer, gCamera);
|
2018-02-09 13:27:25 +01:00
|
|
|
|
2018-02-08 17:01:38 +01:00
|
|
|
SDL_RenderPresent(gRenderer);
|
|
|
|
}
|
|
|
|
|
2017-11-30 21:00:47 +01:00
|
|
|
static
|
2017-12-19 21:00:02 +01:00
|
|
|
void run(void)
|
2017-11-30 21:00:47 +01:00
|
|
|
{
|
2018-02-03 23:39:49 +01:00
|
|
|
static int oldTime = 0;
|
|
|
|
static int currentTime = 0;
|
|
|
|
|
2017-11-30 21:00:47 +01:00
|
|
|
bool quit = false;
|
2017-12-05 08:30:08 +01:00
|
|
|
Timer* fpsTimer = timer_create();
|
2017-11-30 21:00:47 +01:00
|
|
|
|
|
|
|
while (!quit)
|
|
|
|
{
|
2017-12-05 08:30:08 +01:00
|
|
|
timer_start(fpsTimer);
|
2017-11-30 21:00:47 +01:00
|
|
|
|
2017-12-03 11:09:57 +01:00
|
|
|
quit = handle_events();
|
2018-05-20 00:02:39 +02:00
|
|
|
handle_main_input();
|
2018-05-20 17:25:53 +02:00
|
|
|
pointer_handle_input(gPointer, &input);
|
2017-11-30 21:00:47 +01:00
|
|
|
|
2017-12-22 15:15:40 +01:00
|
|
|
switch (gGameState) {
|
|
|
|
case PLAYING:
|
2018-02-13 06:44:09 +01:00
|
|
|
case IN_GAME_MENU:
|
2018-02-14 11:00:34 +01:00
|
|
|
case GAME_OVER:
|
2017-12-22 15:15:40 +01:00
|
|
|
run_game();
|
|
|
|
break;
|
|
|
|
case MENU:
|
2018-02-08 17:01:38 +01:00
|
|
|
run_menu();
|
2017-12-22 15:15:40 +01:00
|
|
|
break;
|
2018-02-09 07:26:44 +01:00
|
|
|
case QUIT:
|
|
|
|
quit = true;
|
|
|
|
break;
|
2017-12-22 15:15:40 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2017-12-22 06:27:58 +01:00
|
|
|
|
2018-02-22 09:44:27 +01:00
|
|
|
unsigned int ticks = timer_get_ticks(fpsTimer);
|
2017-11-30 21:00:47 +01:00
|
|
|
if (ticks < 1000/60)
|
|
|
|
SDL_Delay((1000/60) - ticks);
|
2017-12-05 08:30:08 +01:00
|
|
|
timer_stop(fpsTimer);
|
2018-02-03 23:39:49 +01:00
|
|
|
|
|
|
|
if (currentTime == 0)
|
|
|
|
currentTime = SDL_GetTicks();
|
|
|
|
else {
|
|
|
|
oldTime = currentTime;
|
|
|
|
currentTime = SDL_GetTicks();
|
2018-02-22 09:44:27 +01:00
|
|
|
deltaTime = (float) ((currentTime - oldTime) / 1000.0);
|
2018-02-03 23:39:49 +01:00
|
|
|
}
|
2017-11-30 21:00:47 +01:00
|
|
|
}
|
2017-12-05 08:30:08 +01:00
|
|
|
|
|
|
|
timer_destroy(fpsTimer);
|
2017-11-30 21:00:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static
|
2017-12-19 21:00:02 +01:00
|
|
|
void close(void)
|
2017-11-30 21:00:47 +01:00
|
|
|
{
|
2018-02-09 09:36:24 +01:00
|
|
|
if (gPlayer)
|
|
|
|
player_destroy(gPlayer);
|
|
|
|
if (gMap)
|
|
|
|
map_destroy(gMap);
|
|
|
|
if (mainMenu)
|
|
|
|
menu_destroy(mainMenu);
|
2018-02-13 06:44:09 +01:00
|
|
|
if (inGameMenu)
|
|
|
|
menu_destroy(inGameMenu);
|
2018-02-09 09:36:24 +01:00
|
|
|
|
2018-05-13 23:32:44 +02:00
|
|
|
camera_destroy(gCamera);
|
2017-12-06 11:44:17 +01:00
|
|
|
roommatrix_destroy(gRoomMatrix);
|
2017-12-22 15:15:40 +01:00
|
|
|
gui_destroy(gGui);
|
2018-02-23 11:01:25 +01:00
|
|
|
skillbar_destroy(gSkillBar);
|
2018-05-20 17:25:53 +02:00
|
|
|
pointer_destroy(gPointer);
|
2018-05-15 11:16:56 +02:00
|
|
|
actiontextbuilder_close();
|
2018-01-24 21:14:34 +01:00
|
|
|
item_builder_close();
|
2018-02-03 23:39:49 +01:00
|
|
|
particle_engine_close();
|
2018-02-09 13:27:25 +01:00
|
|
|
timer_destroy(menuTimer);
|
2018-02-14 16:04:40 +01:00
|
|
|
mixer_close();
|
2018-02-23 23:53:52 +01:00
|
|
|
texturecache_close();
|
2018-03-17 00:04:26 +01:00
|
|
|
settings_close();
|
2018-02-23 23:53:52 +01:00
|
|
|
|
2017-12-22 15:15:40 +01:00
|
|
|
SDL_DestroyRenderer(gRenderer);
|
2017-11-30 21:00:47 +01:00
|
|
|
SDL_DestroyWindow(gWindow);
|
|
|
|
gWindow = NULL;
|
2017-12-20 18:56:28 +01:00
|
|
|
TTF_Quit();
|
2017-11-30 21:00:47 +01:00
|
|
|
IMG_Quit();
|
|
|
|
SDL_Quit();
|
|
|
|
}
|
|
|
|
|
2017-12-21 11:46:52 +01:00
|
|
|
int main(int argc, char *argv[])
|
2017-11-30 21:00:47 +01:00
|
|
|
{
|
2017-12-21 11:46:52 +01:00
|
|
|
UNUSED(argc);
|
2018-02-22 12:36:24 +01:00
|
|
|
|
|
|
|
PHYSFS_init(argv[0]);
|
2018-02-22 19:18:38 +01:00
|
|
|
#ifndef DEBUG
|
|
|
|
PHYSFS_mount("assets.pack", NULL, 0);
|
2018-02-27 19:59:51 +01:00
|
|
|
PHYSFS_mount("data.pack", NULL, 0);
|
2018-02-22 19:18:38 +01:00
|
|
|
#else
|
2018-02-22 13:02:40 +01:00
|
|
|
PHYSFS_mount("assets", NULL, 0);
|
2018-02-23 19:32:01 +01:00
|
|
|
PHYSFS_mount("data", NULL, 0);
|
2018-02-27 19:59:51 +01:00
|
|
|
#endif // DEBUG
|
2017-12-21 11:46:52 +01:00
|
|
|
|
2017-11-30 21:00:47 +01:00
|
|
|
if (!init())
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
run();
|
|
|
|
close();
|
2018-02-22 12:36:24 +01:00
|
|
|
PHYSFS_deinit();
|
2017-11-30 21:00:47 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|