Moved Map Loader to XML. Changed const int return values to enumerators.
I need sleep. Night.
This commit is contained in:
parent
04ac0e839b
commit
6fc252a692
13611
Data/Media/Maps/map
Normal file
13611
Data/Media/Maps/map
Normal file
File diff suppressed because it is too large
Load Diff
BIN
Unuk-QT/Unuk-QT
BIN
Unuk-QT/Unuk-QT
Binary file not shown.
@ -4,7 +4,7 @@ Game::Game(void) {
|
||||
m_player = new Player(&m_map);
|
||||
m_npc = new NPC(&m_map);
|
||||
|
||||
m_runGameReturnValue = GAME_RETURN_TO_MMENU;
|
||||
m_runGameReturnValue = gameMainMenu;
|
||||
}
|
||||
|
||||
Game::~Game(void) {
|
||||
@ -12,8 +12,8 @@ Game::~Game(void) {
|
||||
delete m_npc;
|
||||
}
|
||||
|
||||
int Game::Run(const string savegameIDArg) {
|
||||
m_player->SetXY(100, 50);
|
||||
gameNavVal_t Game::Run(const string savegameIDArg) {
|
||||
m_player->SetXY(50, 50);
|
||||
m_player->LoadSprites("../Data/Media/Images/Characters/template.png", 40, 45);
|
||||
|
||||
m_npc->SetXY(300, 300);
|
||||
@ -35,14 +35,14 @@ int Game::Run(const string savegameIDArg) {
|
||||
Timer updateTimer;
|
||||
|
||||
m_gameRenderTime.SetXY(10, 10);
|
||||
m_gameRenderTime.SetTextBlended("Render - XX", "vsmall", COLOUR_BLACK);
|
||||
m_gameRenderTime.SetTextBlended("Render - XX", vsmall, COLOUR_BLACK);
|
||||
|
||||
m_gameUpdateTime.SetXY(10, 30);
|
||||
m_gameUpdateTime.SetTextBlended("Update - XX", "vsmall", COLOUR_BLACK);
|
||||
m_gameUpdateTime.SetTextBlended("Update - XX", vsmall, COLOUR_BLACK);
|
||||
|
||||
stringstream playerXYString;
|
||||
m_playerXY.SetXY(10, 50);
|
||||
m_playerXY.SetTextBlended("Player coords - XX XX", "vsmall", COLOUR_BLACK);
|
||||
m_playerXY.SetTextBlended("Player coords - XX XX", vsmall, COLOUR_BLACK);
|
||||
|
||||
m_gameRunning = true;
|
||||
while(m_gameRunning) {
|
||||
@ -73,12 +73,12 @@ int Game::Run(const string savegameIDArg) {
|
||||
|
||||
// Check to see if we are allowed to display debug info.
|
||||
if(debugEnabled) {
|
||||
m_gameUpdateTime.SetTextBlended("Update - " + updateTimer.GetTicksStr(), "vsmall", COLOUR_BLACK);
|
||||
m_gameRenderTime.SetTextBlended("Render - " + renderTimer.GetTicksStr(), "vsmall", COLOUR_BLACK);
|
||||
m_gameUpdateTime.SetTextBlended("Update - " + updateTimer.GetTicksStr(), vsmall, COLOUR_BLACK);
|
||||
m_gameRenderTime.SetTextBlended("Render - " + renderTimer.GetTicksStr(), vsmall, COLOUR_BLACK);
|
||||
|
||||
playerXYString.str("");
|
||||
playerXYString << "Player coords: x" << m_player->GetX() << ", y" << m_player->GetY();
|
||||
m_playerXY.SetTextBlended(playerXYString.str(), "vsmall", COLOUR_BLACK);
|
||||
m_playerXY.SetTextBlended(playerXYString.str(), vsmall, COLOUR_BLACK);
|
||||
}
|
||||
}
|
||||
// Restrict the fps.
|
||||
@ -107,24 +107,24 @@ void Game::HandleInput(void) {
|
||||
}
|
||||
else if(event.type == SDL_QUIT) {
|
||||
m_gameRunning = false;
|
||||
m_runGameReturnValue = GAME_QUIT_GAME;
|
||||
m_runGameReturnValue = gameQuitGame;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
switch(m_ingameMenu.HandleInput()) {
|
||||
case INGAME_MENU_NOTHING:
|
||||
case ingameMenuNothing:
|
||||
break;
|
||||
case INGAME_MENU_RESUME:
|
||||
case ingameMenuResume:
|
||||
m_ingameMenu.SetStatus(false);
|
||||
break;
|
||||
case INGAME_MENU_SAVE_GAME:
|
||||
case ingameMenuSaveGame:
|
||||
break;
|
||||
case INGAME_MENU_LOAD_GAME:
|
||||
case ingameMenuLoadGame:
|
||||
break;
|
||||
case INGAME_MENU_OPTIONS:
|
||||
case ingameMenuOptions:
|
||||
break;
|
||||
case INGAME_MENU_EXIT_TO_MMENU:
|
||||
case ingameMenuMainMenu:
|
||||
m_gameRunning = false;
|
||||
break;
|
||||
}
|
||||
@ -132,7 +132,7 @@ void Game::HandleInput(void) {
|
||||
if(event.type == SDL_QUIT) {
|
||||
m_gameRunning = false;
|
||||
m_ingameMenu.SetStatus(false);
|
||||
m_runGameReturnValue = GAME_QUIT_GAME;
|
||||
m_runGameReturnValue = gameQuitGame;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -203,7 +203,6 @@ void Game::LoadSavegame(const string savegameIDArg) {
|
||||
// <map> - Parse the map file.
|
||||
dataElem = dataElem->NextSiblingElement("map");
|
||||
assert(dataElem != NULL);
|
||||
printf("%s\n", dataElem->GetText());
|
||||
m_map.Load(dataElem->GetText());
|
||||
// </map>
|
||||
}
|
||||
|
@ -19,15 +19,14 @@
|
||||
#include "../libUnuk/Text.h"
|
||||
using namespace std;
|
||||
|
||||
const int GAME_RETURN_TO_MMENU = 0;
|
||||
const int GAME_QUIT_GAME = 1;
|
||||
enum gameNavVal_t { gameMainMenu, gameQuitGame };
|
||||
|
||||
class Game {
|
||||
public:
|
||||
Game(void);
|
||||
~Game(void);
|
||||
|
||||
int Run(const string savegameIDArg);
|
||||
gameNavVal_t Run(const string savegameIDArg);
|
||||
|
||||
private:
|
||||
void HandleInput(void);
|
||||
@ -37,9 +36,13 @@ private:
|
||||
void LoadSavegame(const string savegameIDArg);
|
||||
void SaveSavegame(void);
|
||||
|
||||
static const int MAX_FPS = 6000;
|
||||
static const int GAME_UPDATES_PER_SECOND = 60;
|
||||
static const int SKIP_TICKS = 1000 / GAME_UPDATES_PER_SECOND;
|
||||
|
||||
bool m_gameRunning;
|
||||
|
||||
int m_runGameReturnValue;
|
||||
gameNavVal_t m_runGameReturnValue;
|
||||
|
||||
string m_saveGameID;
|
||||
string m_mapID;
|
||||
@ -48,10 +51,6 @@ private:
|
||||
Text m_gameRenderTime;
|
||||
Text m_playerXY;
|
||||
|
||||
static const int MAX_FPS = 6000;
|
||||
static const int GAME_UPDATES_PER_SECOND = 60;
|
||||
static const int SKIP_TICKS = 1000 / GAME_UPDATES_PER_SECOND;
|
||||
|
||||
IngameMenu m_ingameMenu;
|
||||
Map m_map;
|
||||
|
||||
|
@ -57,7 +57,7 @@ void Player::HandleInput(void) {
|
||||
|
||||
void Player::Update(void) {
|
||||
Move();
|
||||
SetCamera();
|
||||
//SetCamera();
|
||||
}
|
||||
|
||||
void Player::SetName(string nameArg) {
|
||||
|
@ -50,33 +50,34 @@ int main() {
|
||||
Timer fpsCalc;
|
||||
fpsCalc.Start();
|
||||
|
||||
int gameReturnVal;
|
||||
bool menuRunning = true;
|
||||
while(menuRunning) {
|
||||
menu->Render();
|
||||
SDL_Flip(screen);
|
||||
|
||||
switch(menu->HandleInput()) {
|
||||
case MAIN_MENU_NOTHING:
|
||||
case mainMenuNothing:
|
||||
break;
|
||||
case MAIN_MENU_NEW_GAME:
|
||||
case mainMenuNewGame:
|
||||
delete menu;
|
||||
game = new Game;
|
||||
|
||||
gameReturnVal = game->Run("save.xml");
|
||||
|
||||
if(gameReturnVal == GAME_RETURN_TO_MMENU)
|
||||
switch(game->Run("save")) {
|
||||
case gameMainMenu:
|
||||
menu = new MainMenu;
|
||||
else if(gameReturnVal == GAME_QUIT_GAME)
|
||||
break;
|
||||
case gameQuitGame:
|
||||
menuRunning = false;
|
||||
break;
|
||||
}
|
||||
|
||||
delete game;
|
||||
break;
|
||||
case MAIN_MENU_LOAD_GAME:
|
||||
case mainMenuLoadGame:
|
||||
break;
|
||||
case MAIN_MENU_OPTIONS:
|
||||
case mainMenuOptions:
|
||||
break;
|
||||
case MAIN_MENU_EXIT:
|
||||
case mainMenuExitGame:
|
||||
menuRunning = false;
|
||||
delete menu;
|
||||
break;
|
||||
|
@ -43,16 +43,16 @@ void Button::SetTextRGB(Uint8 r, Uint8 g, Uint8 b) {
|
||||
m_textColour.g = g;
|
||||
m_textColour.b = b;
|
||||
|
||||
m_text.SetTextBlended(m_text.GetText(), "small", m_textColour);
|
||||
m_text.SetTextBlended(m_text.GetText(), small, m_textColour);
|
||||
}
|
||||
|
||||
void Button::SetTextRGB(SDL_Color colour) {
|
||||
m_textColour = colour;
|
||||
m_text.SetTextBlended(m_text.GetText(), "small", colour);
|
||||
m_text.SetTextBlended(m_text.GetText(), small, colour);
|
||||
}
|
||||
|
||||
void Button::SetText(string textArg) {
|
||||
m_text.SetTextBlended(textArg, "small", m_textColour);
|
||||
m_text.SetTextBlended(textArg, small, m_textColour);
|
||||
|
||||
w = m_text.GetWidth();
|
||||
h = m_text.GetHeight();
|
||||
|
@ -54,7 +54,7 @@ void Character::LoadSprites(string filename, int wArg, int hArg) {
|
||||
void Character::AddSpeachBubble(string text) {
|
||||
m_speachBubble.push_back(text);
|
||||
|
||||
m_speachBubbleText.SetTextBlended(text, "small", 0, 0, 0);
|
||||
//m_speachBubbleText.SetTextBlended(text, "small", 0, 0, 0);
|
||||
|
||||
if(m_speachBubbleTimer.IsStarted() == false)
|
||||
m_speachBubbleTimer.Start();
|
||||
@ -125,7 +125,7 @@ void Character::Update(void) {
|
||||
}
|
||||
} else {
|
||||
if(m_speachBubble.front() != m_speachBubbleText.GetText()) {
|
||||
m_speachBubbleText.SetTextBlended(m_speachBubble.front(), "small", 0, 0, 0);
|
||||
//m_speachBubbleText.SetTextBlended(m_speachBubble.front(), "small", 0, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -136,27 +136,19 @@ void Character::Move(void) {
|
||||
tileX = ((x + (w / 2)) / TILE_WIDTH);
|
||||
tileY = ((y + (h / 2)) / TILE_HEIGHT);
|
||||
|
||||
if((x < 0) || (x + w) > levelWidth)
|
||||
x -= xVel;
|
||||
if(CheckTileCollisions())
|
||||
x -= xVel;
|
||||
if(CheckEntityCollisions())
|
||||
x -= xVel;
|
||||
if(CheckCharacterCollisions())
|
||||
x -= xVel;
|
||||
if((x < 0) || (x + w) > levelWidth) x -= xVel;
|
||||
if(CheckTileCollisions()) x -= xVel;
|
||||
if(CheckEntityCollisions()) x -= xVel;
|
||||
if(CheckCharacterCollisions()) x -= xVel;
|
||||
|
||||
y += yVel;
|
||||
tileX = ((x + (w / 2)) / TILE_WIDTH);
|
||||
tileY = ((y + (h / 2)) / TILE_HEIGHT);
|
||||
|
||||
if((y < 0) || (y + h) > levelHeight)
|
||||
y -= yVel;
|
||||
if(CheckTileCollisions())
|
||||
y -= yVel;
|
||||
if(CheckEntityCollisions())
|
||||
y -= yVel;
|
||||
if(CheckCharacterCollisions())
|
||||
y -= yVel;
|
||||
if((y < 0) || (y + h) > levelHeight) y -= yVel;
|
||||
if(CheckTileCollisions()) y -= yVel;
|
||||
if(CheckEntityCollisions()) y -= yVel;
|
||||
if(CheckCharacterCollisions()) y -= yVel;
|
||||
}
|
||||
|
||||
bool Character::CheckTileCollisions(void) {
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "IngameMenu.h"
|
||||
|
||||
IngameMenu::IngameMenu(void) {
|
||||
m_isActive = false;
|
||||
m_active = false;
|
||||
|
||||
btnResume.SetOutRGB(200, 200, 200);
|
||||
btnResume.SetOverRGB(255, 255, 255);
|
||||
@ -38,7 +38,7 @@ IngameMenu::~IngameMenu(void) {
|
||||
|
||||
}
|
||||
|
||||
int IngameMenu::HandleInput(void) {
|
||||
ingameMenuNavVal_t IngameMenu::HandleInput(void) {
|
||||
while(SDL_PollEvent(&event)) {
|
||||
btnResume.CheckMouseOver();
|
||||
btnSaveGame.CheckMouseOver();
|
||||
@ -48,24 +48,24 @@ int IngameMenu::HandleInput(void) {
|
||||
|
||||
if(event.key.type == SDL_KEYDOWN) {
|
||||
if(event.key.keysym.sym == SDLK_ESCAPE)
|
||||
return INGAME_MENU_RESUME;
|
||||
return ingameMenuResume;
|
||||
}
|
||||
else if(event.type == SDL_MOUSEBUTTONUP) {
|
||||
if(event.button.button == SDL_BUTTON_LEFT) {
|
||||
if(btnResume.CheckMouseOver())
|
||||
return INGAME_MENU_RESUME;
|
||||
return ingameMenuResume;
|
||||
else if(btnSaveGame.CheckMouseOver())
|
||||
return INGAME_MENU_SAVE_GAME;
|
||||
return ingameMenuSaveGame;
|
||||
else if(btnLoadGame.CheckMouseOver())
|
||||
return INGAME_MENU_LOAD_GAME;
|
||||
return ingameMenuLoadGame;
|
||||
else if(btnOptions.CheckMouseOver())
|
||||
return INGAME_MENU_OPTIONS;
|
||||
return ingameMenuOptions;
|
||||
else if(btnExitToMenu.CheckMouseOver())
|
||||
return INGAME_MENU_EXIT_TO_MMENU;
|
||||
return ingameMenuMainMenu;
|
||||
}
|
||||
}
|
||||
}
|
||||
return INGAME_MENU_NOTHING;
|
||||
return ingameMenuNothing;
|
||||
}
|
||||
|
||||
void IngameMenu::Render(void) {
|
||||
|
@ -1,27 +1,33 @@
|
||||
#ifndef _INGAMEMENU_H_
|
||||
#define _INGAMEMENU_H_
|
||||
#include "Menu.h"
|
||||
|
||||
const int INGAME_MENU_NOTHING = 0;
|
||||
const int INGAME_MENU_RESUME = 1;
|
||||
const int INGAME_MENU_SAVE_GAME = 2;
|
||||
const int INGAME_MENU_LOAD_GAME = 3;
|
||||
const int INGAME_MENU_OPTIONS = 4;
|
||||
const int INGAME_MENU_EXIT_TO_MMENU = 5;
|
||||
#include "../Unuk/Globals.h"
|
||||
#include "../Unuk/Constants.h"
|
||||
#include "Button.h"
|
||||
#include "ButtonToggle.h"
|
||||
|
||||
class IngameMenu : public Menu {
|
||||
enum ingameMenuNavVal_t {
|
||||
ingameMenuNothing,
|
||||
ingameMenuResume,
|
||||
ingameMenuSaveGame,
|
||||
ingameMenuLoadGame,
|
||||
ingameMenuOptions,
|
||||
ingameMenuMainMenu
|
||||
};
|
||||
|
||||
class IngameMenu {
|
||||
public:
|
||||
IngameMenu(void);
|
||||
~IngameMenu(void);
|
||||
|
||||
int HandleInput(void);
|
||||
ingameMenuNavVal_t HandleInput(void);
|
||||
void Render(void);
|
||||
|
||||
void SetStatus(bool arg) { m_isActive = arg; }
|
||||
bool GetStatus(void) { return m_isActive; }
|
||||
void SetStatus(bool arg) { m_active = arg; }
|
||||
bool GetStatus(void) { return m_active; }
|
||||
|
||||
private:
|
||||
bool m_isActive;
|
||||
bool m_active;
|
||||
|
||||
Button btnResume;
|
||||
Button btnSaveGame;
|
||||
|
@ -10,7 +10,7 @@ MainMenu::MainMenu(void) {
|
||||
btnNewGameActive = false;
|
||||
|
||||
lblNewGame.SetXY(275, 160);
|
||||
lblNewGame.SetTextBlended("This will delete your current game, are you sure?", "vsmall", 0, 0, 0);
|
||||
lblNewGame.SetTextBlended("This will delete your current game, are you sure?", vsmall, 0, 0, 0);
|
||||
|
||||
rectNewGame.SetRGB(200, 200, 200);
|
||||
rectNewGame.SetXY(250, 150);
|
||||
@ -47,9 +47,9 @@ MainMenu::MainMenu(void) {
|
||||
btnExit.SetXY(100, 300);
|
||||
|
||||
lblMenu.SetXY(100, 75);
|
||||
lblMenu.SetTextBlended("Unuk", "vlarge", 0, 0, 0);
|
||||
lblMenu.SetTextBlended("Unuk", vlarge, 0, 0, 0);
|
||||
|
||||
m_background.Load("MainMenu");
|
||||
//m_background.Load("MainMenu");
|
||||
|
||||
camera.x = 0;
|
||||
camera.y = 0;
|
||||
@ -59,7 +59,7 @@ MainMenu::~MainMenu(void) {
|
||||
|
||||
}
|
||||
|
||||
int MainMenu::HandleInput(void) {
|
||||
mainMenuNavVal_t MainMenu::HandleInput(void) {
|
||||
while(SDL_PollEvent(&event)) {
|
||||
btnNewGame.CheckMouseOver();
|
||||
if(btnNewGameActive) {
|
||||
@ -76,29 +76,29 @@ int MainMenu::HandleInput(void) {
|
||||
if(btnNewGame.CheckMouseOver())
|
||||
btnNewGameActive = !btnNewGameActive;
|
||||
else if(btnLoadGame.CheckMouseOver())
|
||||
return MAIN_MENU_LOAD_GAME;
|
||||
return mainMenuLoadGame;
|
||||
else if(btnOptions.CheckMouseOver())
|
||||
return MAIN_MENU_OPTIONS;
|
||||
return mainMenuOptions;
|
||||
else if(btnExit.CheckMouseOver())
|
||||
return MAIN_MENU_EXIT;
|
||||
return mainMenuOptions;
|
||||
|
||||
if(btnNewGameActive) {
|
||||
if(btnNewGameYes.CheckMouseOver())
|
||||
return MAIN_MENU_NEW_GAME;
|
||||
return mainMenuNewGame;
|
||||
else if(btnNewGameNo.CheckMouseOver())
|
||||
btnNewGameActive = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(event.type == SDL_QUIT) {
|
||||
return MAIN_MENU_EXIT;
|
||||
return mainMenuExitGame;
|
||||
}
|
||||
}
|
||||
return MAIN_MENU_NOTHING;
|
||||
return mainMenuNothing;
|
||||
}
|
||||
|
||||
void MainMenu::Render(void) {
|
||||
m_background.Render();
|
||||
//m_background.Render();
|
||||
|
||||
lblMenu.Render();
|
||||
|
||||
|
@ -1,23 +1,25 @@
|
||||
#ifndef _MAINMENU_H_
|
||||
#define _MAINMENU_H_
|
||||
#include "../Unuk/Constants.h"
|
||||
#include "Menu.h"
|
||||
#include "Button.h"
|
||||
#include "Map.h"
|
||||
#include "Rect.h"
|
||||
#include "Text.h"
|
||||
|
||||
const int MAIN_MENU_NOTHING = 0;
|
||||
const int MAIN_MENU_NEW_GAME = 1;
|
||||
const int MAIN_MENU_LOAD_GAME = 2;
|
||||
const int MAIN_MENU_OPTIONS = 3;
|
||||
const int MAIN_MENU_EXIT = 4;
|
||||
enum mainMenuNavVal_t {
|
||||
mainMenuNothing,
|
||||
mainMenuNewGame,
|
||||
mainMenuLoadGame,
|
||||
mainMenuOptions,
|
||||
mainMenuExitGame
|
||||
};
|
||||
|
||||
class MainMenu : public Menu {
|
||||
class MainMenu {
|
||||
public:
|
||||
MainMenu(void);
|
||||
~MainMenu(void);
|
||||
|
||||
int HandleInput(void);
|
||||
mainMenuNavVal_t HandleInput(void);
|
||||
void Render(void);
|
||||
|
||||
private:
|
||||
|
@ -1,107 +1,164 @@
|
||||
#include "Map.h"
|
||||
|
||||
Map::Map(void) {
|
||||
//m_characters = CharacterManager;
|
||||
|
||||
}
|
||||
|
||||
Map::~Map(void) {
|
||||
//delete m_characters;
|
||||
|
||||
}
|
||||
|
||||
void Map::Load(const string filename) {
|
||||
Unload();
|
||||
m_currentMap = filename;
|
||||
string fullMapPath = "../Data/Media/Maps/" + filename;
|
||||
ifstream mapFile(fullMapPath.c_str());
|
||||
assert(mapFile.is_open());
|
||||
TiXmlDocument mapFile(fullMapPath);
|
||||
|
||||
Unload();
|
||||
assert(mapFile.LoadFile() == true);
|
||||
|
||||
// Read in from the map file, one line at a time.
|
||||
string line;
|
||||
while(getline(mapFile, line)) {
|
||||
m_mapRows = 1;
|
||||
// Getting dirty with some XML. This seems like a nicer
|
||||
// approach to loading maps, rather than parsing tet files.
|
||||
TiXmlElement* rootElem = NULL;
|
||||
TiXmlElement* lineElem = NULL;
|
||||
TiXmlElement* tileElem = NULL;
|
||||
TiXmlElement* dataElem = NULL;
|
||||
|
||||
istringstream iss(line);
|
||||
// We will set x and y positions to zero for now, as we
|
||||
// are going to set them withing the XML file.
|
||||
x = 0;
|
||||
y = 0;
|
||||
|
||||
string tileName;
|
||||
while(iss >> tileName) {
|
||||
string fullTilePath = "../Data/Media/Images/Tiles/" + tileName + ".png";
|
||||
m_tile[m_mapRows][m_mapColumns].SetTileTexture(m_tileTextures.Add(fullTilePath));
|
||||
// <map> - Let's start parsing the map.
|
||||
rootElem = mapFile.FirstChildElement("map");
|
||||
assert(rootElem != NULL);
|
||||
if(rootElem) {
|
||||
// <line> - We want to tile one line at a time. line represents
|
||||
// the row we are tiling.
|
||||
lineElem = rootElem->FirstChildElement("line");
|
||||
assert(lineElem != NULL);
|
||||
while(lineElem) {
|
||||
y++;
|
||||
x = 0;
|
||||
|
||||
// Read the tile solidity.
|
||||
bool tileSolidity;
|
||||
iss >> tileSolidity;
|
||||
m_tile[m_mapRows][m_mapColumns].SetTileSolidity(tileSolidity);
|
||||
// <tile> - Then we will select the tile. and increment x to keep tiling that row.
|
||||
tileElem = lineElem->FirstChildElement("tile");
|
||||
assert(tileElem != NULL);
|
||||
while(tileElem) {
|
||||
x++;
|
||||
m_tile[x][y].SetTileXY((x - 1) * TILE_WIDTH, (y - 1) * TILE_HEIGHT);
|
||||
|
||||
// Set the tile x and y variable.
|
||||
m_tile[m_mapRows][m_mapColumns].SetTileXY((m_mapRows - 1) * TILE_WIDTH, (m_mapColumns - 1) * TILE_HEIGHT);
|
||||
// <tileTexture> - Apply a teture to the tile.
|
||||
dataElem = tileElem->FirstChildElement("tileTexture");
|
||||
assert(dataElem != NULL);
|
||||
stringstream tilePath;
|
||||
tilePath << "../Data/Media/Images/Tiles/" << dataElem->GetText() << ".png";
|
||||
m_tile[x][y].SetTileTexture(m_tileTextures.Add(tilePath.str()));
|
||||
// <tileTexture> - Finished applying the texture, move to the next sibling.
|
||||
|
||||
// Read the entity textures.
|
||||
string entityName;
|
||||
iss >> entityName;
|
||||
// <solidTile> - Check to see if the tile is solid or not.
|
||||
dataElem = dataElem->NextSiblingElement("solidTile");
|
||||
assert(dataElem != NULL);
|
||||
string tileSolidity = dataElem->GetText();
|
||||
assert(tileSolidity == "false" || tileSolidity == "true");
|
||||
if(tileSolidity == "false")
|
||||
m_tile[x][y].SetTileSolidity(false);
|
||||
else
|
||||
m_tile[x][y].SetTileSolidity(true);
|
||||
// </solidTile>
|
||||
|
||||
if(entityName == "n") {
|
||||
m_tile[m_mapRows][m_mapColumns].SetEntityTexture(NULL);
|
||||
} else {
|
||||
string entityPath = "../Data/Media/Images/Entities/" + entityName + ".png";
|
||||
// <entityTexture>
|
||||
dataElem = dataElem->NextSiblingElement("entityTexture");
|
||||
assert(dataElem != NULL);
|
||||
string entityName = dataElem->GetText();
|
||||
if(entityName == "null")
|
||||
m_tile[x][y].SetEntityTexture(NULL);
|
||||
else {
|
||||
stringstream entityPath;
|
||||
entityPath << "../Data/Media/Images/Entities/" << entityName << ".png";
|
||||
m_tile[x][y].SetEntityTexture(m_entityTextures.AddAlpha(entityPath.str()));
|
||||
|
||||
m_tile[m_mapRows][m_mapColumns].SetEntityTexture(m_entityTextures.AddAlpha(entityPath));
|
||||
m_tile[x][y].SetEntityXY(m_tile[x][y].GetTileX() - (m_tile[x][y].GetEntityWidth() / 2 + TILE_WIDTH / 2),
|
||||
m_tile[x][y].GetTileY() - (m_tile[x][y].GetEntityHeight() / 2 + TILE_HEIGHT / 2));
|
||||
}
|
||||
// </entityTexture>
|
||||
|
||||
// Set the entities x and y variables.
|
||||
m_tile[m_mapRows][m_mapColumns].SetEntityXY(
|
||||
m_tile[m_mapRows][m_mapColumns].GetTileX() - (m_tile[m_mapRows][m_mapColumns].GetEntityWidth() / 2 + TILE_WIDTH / 2),
|
||||
m_tile[m_mapRows][m_mapColumns].GetTileY() - (m_tile[m_mapRows][m_mapColumns].GetEntityHeight() / 2 + TILE_HEIGHT / 2));
|
||||
// <SolidEntity>
|
||||
dataElem = dataElem->NextSiblingElement("solidEntity");
|
||||
assert(dataElem != NULL);
|
||||
string entitySolidity = dataElem->GetText();
|
||||
assert(entitySolidity == "false" || entitySolidity == "true");
|
||||
if(entitySolidity == "false")
|
||||
m_tile[x][y].SetEntitySolidity(false);
|
||||
else
|
||||
m_tile[x][y].SetEntitySolidity(true);
|
||||
// </solidEntity>
|
||||
|
||||
// <zlevel>
|
||||
dataElem = dataElem->NextSiblingElement("zlevel");
|
||||
assert(dataElem != NULL);
|
||||
m_tile[x][y].SetZLevel(atoi(dataElem->GetText()));
|
||||
// </zlevel>
|
||||
|
||||
// <mapTransition>
|
||||
dataElem = dataElem->NextSiblingElement("mapTransition");
|
||||
assert(dataElem != NULL);
|
||||
m_tile[x][y].SetMapTransitionName(dataElem->GetText());
|
||||
// </mapTransition>
|
||||
|
||||
// <mapTransX>
|
||||
dataElem = dataElem->NextSiblingElement("mapTransX");
|
||||
assert(dataElem != NULL);
|
||||
int mapTransX = atoi(dataElem->GetText());
|
||||
// </mapTransX>
|
||||
|
||||
// <mapTransY>
|
||||
dataElem = dataElem->NextSiblingElement("mapTransY");
|
||||
assert(dataElem != NULL);
|
||||
int mapTransY = atoi(dataElem->GetText());
|
||||
// </mapTransY>
|
||||
|
||||
tileElem = tileElem->NextSiblingElement("tile");
|
||||
}
|
||||
// Read the entity solidity.
|
||||
bool entitySolidity;
|
||||
iss >> entitySolidity;
|
||||
m_tile[m_mapRows][m_mapColumns].SetEntitySolidity(entitySolidity);
|
||||
//</tile>
|
||||
|
||||
// Read the tile zlevel.
|
||||
int zLevel;
|
||||
iss >> zLevel;
|
||||
m_tile[m_mapRows][m_mapColumns].SetZLevel(zLevel);
|
||||
|
||||
// Read the map transition value.
|
||||
string mapTransitionName;
|
||||
iss >> mapTransitionName;
|
||||
m_tile[m_mapRows][m_mapColumns].SetMapTransitionName(mapTransitionName);
|
||||
|
||||
// Read the transition x and y.
|
||||
int mapTransitionX, mapTransitionY;
|
||||
iss >> mapTransitionX;
|
||||
iss >> mapTransitionY;
|
||||
m_tile[m_mapRows][m_mapColumns].SetMapTransitionXY(mapTransitionX, mapTransitionY);
|
||||
|
||||
m_mapRows++;
|
||||
assert(m_mapRows < TILE_ARRAY_SIZE);
|
||||
lineElem = lineElem->NextSiblingElement("line");
|
||||
}
|
||||
m_mapColumns++;
|
||||
assert(m_mapColumns < TILE_ARRAY_SIZE);
|
||||
// </line>
|
||||
}
|
||||
levelWidth = (m_mapRows - 1) * TILE_WIDTH;
|
||||
levelHeight = (m_mapColumns - 1) * TILE_HEIGHT;
|
||||
// </map>
|
||||
levelWidth = (x - 1) * TILE_WIDTH;
|
||||
levelHeight = (y - 1) * TILE_HEIGHT;
|
||||
|
||||
//character->Load(filename);
|
||||
}
|
||||
|
||||
void Map::Render(void) {
|
||||
for(int j = 1; j < x; j++)
|
||||
for(int i = 1; i < y; i++) {
|
||||
ApplySurface(m_tile[j][i].GetTileX(), m_tile[j][i].GetTileY(), m_tile[j][i].GetTileTexture(), screen);
|
||||
|
||||
if(m_tile[j][i].GetEntityTexture() != NULL)
|
||||
ApplySurface(m_tile[j][i].GetEntityX(), m_tile[j][i].GetEntityY(), m_tile[j][i].GetEntityTexture(), screen);
|
||||
}
|
||||
return;
|
||||
|
||||
int xOrig = (camera.x / TILE_WIDTH) + 1;
|
||||
int yOrig = (camera.y / TILE_HEIGHT) + 1;
|
||||
|
||||
int xEnd = xOrig + (SCREEN_WIDTH / TILE_WIDTH);
|
||||
int yEnd = yOrig + (SCREEN_HEIGHT / TILE_HEIGHT);
|
||||
|
||||
if(xEnd < m_mapRows)
|
||||
if(xEnd < x)
|
||||
xEnd++;
|
||||
if(yEnd < m_mapColumns)
|
||||
if(yEnd < y)
|
||||
yEnd++;
|
||||
|
||||
for(int j = xOrig; j < xEnd; j++)
|
||||
for(int i = yOrig; i < yEnd; i++) {
|
||||
for(int j = 1; j < xEnd; j++)
|
||||
for(int i = 1; i < yEnd; i++) {
|
||||
ApplySurface(m_tile[j][i].GetTileX(), m_tile[j][i].GetTileY(),
|
||||
m_tile[j][i].GetTileTexture(), screen);
|
||||
if(m_tile[j][i].GetEntityTexture() != NULL) {
|
||||
Debug::logger->message("Entity");
|
||||
ApplySurface(m_tile[j][i].GetEntityX(), m_tile[j][i].GetEntityY(),
|
||||
m_tile[j][i].GetEntityTexture(), screen);
|
||||
}
|
||||
@ -112,18 +169,13 @@ void Map::Unload(void) {
|
||||
m_tileTextures.Unload();
|
||||
m_entityTextures.Unload();
|
||||
|
||||
// Start at 1,1 so we do not have to be concerned about messy
|
||||
// bounds checking when accessing the tile array within the game loop.
|
||||
m_mapRows = 1;
|
||||
m_mapColumns = 1;
|
||||
|
||||
// As we are not doing bounds checking inside the game loop
|
||||
// we don't want there to be a solid entity with w,h of ($RAND)
|
||||
// creating an invisible wall anywhere.
|
||||
for(int i = 0; i < TILE_ARRAY_SIZE; i++) {
|
||||
for(int j = 0; j < TILE_ARRAY_SIZE; j++) {
|
||||
m_tile[i][j].SetTileTexture(NULL);
|
||||
m_tile[i][j].SetTileSolidity(false);
|
||||
m_tile[i][j].SetEntityTexture(NULL);
|
||||
m_tile[i][j].SetEntitySolidity(false);
|
||||
m_tile[i][j].SetMapTransitionName("null");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <assert.h>
|
||||
#include <tinyxml.h>
|
||||
|
||||
#include "../Unuk/Globals.h"
|
||||
#include "../Unuk/Constants.h"
|
||||
@ -13,6 +14,7 @@
|
||||
#include "ApplySurface.h"
|
||||
#include "TextureManager.h"
|
||||
#include "MapTile.h"
|
||||
#include "Debug.h"
|
||||
using namespace std;
|
||||
|
||||
//class CharacterManager;
|
||||
@ -47,12 +49,11 @@ private:
|
||||
void Unload(void);
|
||||
|
||||
string m_currentMap;
|
||||
int m_mapColumns;
|
||||
int m_mapRows;
|
||||
int x;
|
||||
int y;
|
||||
|
||||
TextureManager m_tileTextures;
|
||||
TextureManager m_entityTextures;
|
||||
//CharacterManager* m_characters;
|
||||
|
||||
static const int TILE_ARRAY_SIZE = 150;
|
||||
MapTile m_tile[TILE_ARRAY_SIZE][TILE_ARRAY_SIZE];
|
||||
|
@ -62,10 +62,10 @@ private:
|
||||
int m_entityH;
|
||||
|
||||
// -1 is a 'special' tile, the next tile that the player walks
|
||||
// on is the new player z-level.
|
||||
// on is the players new zlevel.
|
||||
int m_zLevel;
|
||||
|
||||
//If not 'n', switch map when the player walks on this tile.
|
||||
// If not 'null', switch map when the player walks on this tile.
|
||||
string m_mapTransitionName;
|
||||
int m_mapTransitionX;
|
||||
int m_mapTransitionY;
|
||||
|
@ -50,78 +50,68 @@ void Text::SetXY(int xArg, int yArg) {
|
||||
y = yArg;
|
||||
}
|
||||
|
||||
int Text::SetTextBlended(string textArg, string size, SDL_Color colour) {
|
||||
int Text::SetTextBlended(string textArg, textSizes_t size, SDL_Color colour) {
|
||||
m_textContents = textArg;
|
||||
|
||||
if(m_text != NULL) {
|
||||
SDL_FreeSurface(m_text);
|
||||
}
|
||||
|
||||
if(size == "vsmall") {
|
||||
if(size == vsmall) {
|
||||
m_text = TTF_RenderText_Blended(vSmallFont, textArg.c_str(), colour);
|
||||
return 1;
|
||||
}
|
||||
else if(size == "small") {
|
||||
else if(size == small) {
|
||||
m_text = TTF_RenderText_Blended(smallFont, textArg.c_str(), colour);
|
||||
return 1;
|
||||
}
|
||||
else if(size == "medium") {
|
||||
else if(size == medium) {
|
||||
m_text = TTF_RenderText_Blended(mediumFont, textArg.c_str(), colour);
|
||||
return 1;
|
||||
}
|
||||
else if(size == "large") {
|
||||
else if(size == large) {
|
||||
m_text = TTF_RenderText_Blended(largeFont, textArg.c_str(), colour);
|
||||
return 1;
|
||||
}
|
||||
else if(size == "vlarge") {
|
||||
} else {
|
||||
m_text = TTF_RenderText_Blended(vLargeFont, textArg.c_str(), colour);
|
||||
return 1;
|
||||
} else {
|
||||
Debug::logger->message("Text::SetTextBlended(): Invalid size argument %s. Defaulted to small.", size.c_str());
|
||||
m_text = TTF_RenderText_Blended(smallFont, textArg.c_str(), colour);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int Text::SetTextBlended(string textArg, string size, Uint8 r, Uint8 g, Uint8 b) {
|
||||
int Text::SetTextBlended(string textArg, textSizes_t size, Uint8 r, Uint8 g, Uint8 b) {
|
||||
SDL_Color f = { r, g, b };
|
||||
return SetTextBlended(textArg, size, f);
|
||||
}
|
||||
|
||||
int Text::SetTextShaded(string textArg, string size, SDL_Color colour, SDL_Color bgColour) {
|
||||
int Text::SetTextShaded(string textArg, textSizes_t size, SDL_Color colour, SDL_Color bgColour) {
|
||||
m_textContents = textArg;
|
||||
|
||||
if(m_text != NULL) {
|
||||
SDL_FreeSurface(m_text);
|
||||
}
|
||||
|
||||
if(size == "vsmall") {
|
||||
if(size == vsmall) {
|
||||
m_text = TTF_RenderText_Shaded(vSmallFont, textArg.c_str(), colour, bgColour);
|
||||
return 1;
|
||||
}
|
||||
else if(size == "small") {
|
||||
else if(size == small) {
|
||||
m_text = TTF_RenderText_Shaded(smallFont, textArg.c_str(), colour, bgColour);
|
||||
return 1;
|
||||
}
|
||||
else if(size == "medium") {
|
||||
else if(size == medium) {
|
||||
m_text = TTF_RenderText_Shaded(mediumFont, textArg.c_str(), colour, bgColour);
|
||||
return 1;
|
||||
}
|
||||
else if(size == "large") {
|
||||
else if(size == large) {
|
||||
m_text = TTF_RenderText_Shaded(largeFont, textArg.c_str(), colour, bgColour);
|
||||
return 1;
|
||||
}
|
||||
else if(size == "vlarge") {
|
||||
} else {
|
||||
m_text = TTF_RenderText_Shaded(vLargeFont, textArg.c_str(), colour, bgColour);
|
||||
return 1;
|
||||
} else {
|
||||
Debug::logger->message("Text::SetTextBlended(): Invalid size argument %s. Defaulted to small.", size.c_str());
|
||||
m_text = TTF_RenderText_Shaded(smallFont, textArg.c_str(), colour, bgColour);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int Text::SetTextShaded(string textArg, string size, Uint8 rF, Uint8 gF, Uint8 bF, Uint8 rB, Uint8 gB, Uint8 bB) {
|
||||
int Text::SetTextShaded(string textArg, textSizes_t size, Uint8 rF, Uint8 gF, Uint8 bF, Uint8 rB, Uint8 gB, Uint8 bB) {
|
||||
SDL_Color f = { rF, gF, bF };
|
||||
SDL_Color b = { rB, gB, bB };
|
||||
return SetTextShaded(textArg, size, f, b);
|
||||
|
@ -10,6 +10,8 @@
|
||||
#include "Debug.h"
|
||||
using namespace std;
|
||||
|
||||
enum textSizes_t { vsmall, small, medium, large, vlarge };
|
||||
|
||||
class Text {
|
||||
public:
|
||||
Text(void);
|
||||
@ -28,10 +30,10 @@ public:
|
||||
|
||||
void SetXY(int xArg, int yArg);
|
||||
|
||||
int SetTextBlended(string textArg, string size, SDL_Color);
|
||||
int SetTextBlended(string textArg, string size, Uint8 r, Uint8 g, Uint8 b);
|
||||
int SetTextShaded(string textArg, string size, SDL_Color, SDL_Color);
|
||||
int SetTextShaded(string textArg, string size, Uint8 rF, Uint8 gF, Uint8 bF, Uint8 rB, Uint8 gB, Uint8 bB);
|
||||
int SetTextBlended(string textArg, textSizes_t size, SDL_Color);
|
||||
int SetTextBlended(string textArg, textSizes_t size, Uint8 r, Uint8 g, Uint8 b);
|
||||
int SetTextShaded(string textArg, textSizes_t size, SDL_Color, SDL_Color);
|
||||
int SetTextShaded(string textArg, textSizes_t size, Uint8 rF, Uint8 gF, Uint8 bF, Uint8 rB, Uint8 gB, Uint8 bB);
|
||||
|
||||
void Render(void);
|
||||
void Render(int xArg, int yArg);
|
||||
|
@ -17,7 +17,7 @@ void TextureManager::Unload(void) {
|
||||
}
|
||||
|
||||
SDL_Surface* TextureManager::Add(string filename) {
|
||||
assert(m_allocated < TEXTURE_NODE_SIZE);
|
||||
assert(m_allocated < TEXTURE_ARR_SIZE - 1);
|
||||
|
||||
// Has the texture been loaded already?
|
||||
for(int i = 0; i < m_allocated; i++) {
|
||||
@ -35,7 +35,7 @@ SDL_Surface* TextureManager::Add(string filename) {
|
||||
}
|
||||
|
||||
SDL_Surface* TextureManager::AddAlpha(string filename) {
|
||||
assert(m_allocated < TEXTURE_NODE_SIZE);
|
||||
assert(m_allocated < TEXTURE_ARR_SIZE - 1);
|
||||
|
||||
// Has the texture been loaded already?
|
||||
for(int i = 0; i < m_allocated; i++) {
|
||||
|
@ -10,8 +10,8 @@ using namespace std;
|
||||
* The Texture Manager will keep a small "Database"
|
||||
* of the name of the texture that is loaded and the
|
||||
* actual texture so we can query it with the filename
|
||||
* and it will return an index that we can use to retrieve
|
||||
* the texture.
|
||||
* and it will return the teture if it is already in memory
|
||||
* or load the tture if it is not.
|
||||
*/
|
||||
class TextureManager {
|
||||
public:
|
||||
@ -31,8 +31,8 @@ private:
|
||||
};
|
||||
|
||||
// We should not need more than a hundred..
|
||||
static const int TEXTURE_NODE_SIZE = 100;
|
||||
textureNode textures[TEXTURE_NODE_SIZE];
|
||||
static const int TEXTURE_ARR_SIZE = 100;
|
||||
textureNode textures[TEXTURE_ARR_SIZE];
|
||||
|
||||
int m_allocated;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user