Using pointers propperly when handling texture loading.

This commit is contained in:
Rtch90 2011-12-12 21:12:23 +00:00
parent ddb4e56467
commit 02f038752b
9 changed files with 119 additions and 71 deletions

View File

@ -1,6 +1,6 @@
############################################################################# #############################################################################
# Makefile for building: Unuk-QT # Makefile for building: Unuk-QT
# Generated by qmake (2.01a) (Qt 4.7.3) on: Mon Nov 21 13:46:00 2011 # Generated by qmake (2.01a) (Qt 4.7.3) on: Mon Dec 12 20:59:35 2011
# Project: Unuk-QT.pro # Project: Unuk-QT.pro
# Template: app # Template: app
# Command: /usr/bin/qmake-qt4 -spec /usr/share/qt4/mkspecs/linux-g++ CONFIG+=debug -o Makefile Unuk-QT.pro # Command: /usr/bin/qmake-qt4 -spec /usr/share/qt4/mkspecs/linux-g++ CONFIG+=debug -o Makefile Unuk-QT.pro
@ -65,7 +65,8 @@ SOURCES = ../src/libUnuk/Debug.cpp \
../src/libUnuk/Character.cpp \ ../src/libUnuk/Character.cpp \
../src/libUnuk/NPC.cpp \ ../src/libUnuk/NPC.cpp \
../src/Unuk/Player.cpp \ ../src/Unuk/Player.cpp \
../src/Unuk/Game.cpp ../src/Unuk/Game.cpp \
../src/libUnuk/Entity.cpp
OBJECTS = Debug.o \ OBJECTS = Debug.o \
main.o \ main.o \
Input.o \ Input.o \
@ -88,7 +89,8 @@ OBJECTS = Debug.o \
Character.o \ Character.o \
NPC.o \ NPC.o \
Player.o \ Player.o \
Game.o Game.o \
Entity.o
DIST = /usr/share/qt4/mkspecs/common/g++.conf \ DIST = /usr/share/qt4/mkspecs/common/g++.conf \
/usr/share/qt4/mkspecs/common/unix.conf \ /usr/share/qt4/mkspecs/common/unix.conf \
/usr/share/qt4/mkspecs/common/linux.conf \ /usr/share/qt4/mkspecs/common/linux.conf \
@ -188,7 +190,7 @@ qmake: FORCE
dist: dist:
@$(CHK_DIR_EXISTS) .tmp/Unuk-QT1.0.0 || $(MKDIR) .tmp/Unuk-QT1.0.0 @$(CHK_DIR_EXISTS) .tmp/Unuk-QT1.0.0 || $(MKDIR) .tmp/Unuk-QT1.0.0
$(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/Unuk-QT1.0.0/ && $(COPY_FILE) --parents ../src/libUnuk/Debug.h ../src/Libs/wglext.h ../src/Libs/glxext.h ../src/libUnuk/Input.h ../src/libUnuk/Rect.h ../src/libUnuk/Timer.h ../src/libUnuk/Font.h ../Constants.h ../src/Unuk/Constants.h ../src/libUnuk/ApplySurface.h ../src/Unuk/Globals.h ../src/libUnuk/ImageLoader.h ../src/libUnuk/TextureManager.h ../src/libUnuk/Texture.h ../src/libUnuk/Text.h ../src/libUnuk/MapTile.h ../src/libUnuk/Map.h ../src/libUnuk/Button.h ../src/libUnuk/ButtonToggle.h ../src/libUnuk/Menu.h ../src/libUnuk/MainMenu.h ../src/libUnuk/ParticleEmitter.h ../src/libUnuk/IngameMenu.h ../src/libUnuk/Collision.h ../src/libUnuk/Character.h ../src/libUnuk/NPC.h ../src/Unuk/Player.h ../src/Unuk/Game.h .tmp/Unuk-QT1.0.0/ && $(COPY_FILE) --parents ../src/libUnuk/Debug.cpp ../src/Unuk/main.cpp ../src/libUnuk/Input.cpp ../src/libUnuk/Timer.cpp ../src/libUnuk/Font.cpp ../src/libUnuk/ApplySurface.cpp ../src/Unuk/Globals.cpp ../src/libUnuk/Rect.cpp ../src/libUnuk/ImageLoader.cpp ../src/libUnuk/TextureManager.cpp ../src/libUnuk/Texture.cpp ../src/libUnuk/Text.cpp ../src/libUnuk/Map.cpp ../src/libUnuk/Button.cpp ../src/libUnuk/ButtonToggle.cpp ../src/libUnuk/ParticleEmitter.cpp ../src/libUnuk/MainMenu.cpp ../src/libUnuk/IngameMenu.cpp ../src/libUnuk/Collision.cpp ../src/libUnuk/Character.cpp ../src/libUnuk/NPC.cpp ../src/Unuk/Player.cpp ../src/Unuk/Game.cpp .tmp/Unuk-QT1.0.0/ && (cd `dirname .tmp/Unuk-QT1.0.0` && $(TAR) Unuk-QT1.0.0.tar Unuk-QT1.0.0 && $(COMPRESS) Unuk-QT1.0.0.tar) && $(MOVE) `dirname .tmp/Unuk-QT1.0.0`/Unuk-QT1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/Unuk-QT1.0.0 $(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/Unuk-QT1.0.0/ && $(COPY_FILE) --parents ../src/libUnuk/Debug.h ../src/Libs/wglext.h ../src/Libs/glxext.h ../src/libUnuk/Input.h ../src/libUnuk/Rect.h ../src/libUnuk/Timer.h ../src/libUnuk/Font.h ../Constants.h ../src/Unuk/Constants.h ../src/libUnuk/ApplySurface.h ../src/Unuk/Globals.h ../src/libUnuk/ImageLoader.h ../src/libUnuk/TextureManager.h ../src/libUnuk/Texture.h ../src/libUnuk/Text.h ../src/libUnuk/MapTile.h ../src/libUnuk/Map.h ../src/libUnuk/Button.h ../src/libUnuk/ButtonToggle.h ../src/libUnuk/Menu.h ../src/libUnuk/MainMenu.h ../src/libUnuk/ParticleEmitter.h ../src/libUnuk/IngameMenu.h ../src/libUnuk/Collision.h ../src/libUnuk/Character.h ../src/libUnuk/NPC.h ../src/Unuk/Player.h ../src/Unuk/Game.h ../src/libUnuk/Entity.h .tmp/Unuk-QT1.0.0/ && $(COPY_FILE) --parents ../src/libUnuk/Debug.cpp ../src/Unuk/main.cpp ../src/libUnuk/Input.cpp ../src/libUnuk/Timer.cpp ../src/libUnuk/Font.cpp ../src/libUnuk/ApplySurface.cpp ../src/Unuk/Globals.cpp ../src/libUnuk/Rect.cpp ../src/libUnuk/ImageLoader.cpp ../src/libUnuk/TextureManager.cpp ../src/libUnuk/Texture.cpp ../src/libUnuk/Text.cpp ../src/libUnuk/Map.cpp ../src/libUnuk/Button.cpp ../src/libUnuk/ButtonToggle.cpp ../src/libUnuk/ParticleEmitter.cpp ../src/libUnuk/MainMenu.cpp ../src/libUnuk/IngameMenu.cpp ../src/libUnuk/Collision.cpp ../src/libUnuk/Character.cpp ../src/libUnuk/NPC.cpp ../src/Unuk/Player.cpp ../src/Unuk/Game.cpp ../src/libUnuk/Entity.cpp .tmp/Unuk-QT1.0.0/ && (cd `dirname .tmp/Unuk-QT1.0.0` && $(TAR) Unuk-QT1.0.0.tar Unuk-QT1.0.0 && $(COMPRESS) Unuk-QT1.0.0.tar) && $(MOVE) `dirname .tmp/Unuk-QT1.0.0`/Unuk-QT1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/Unuk-QT1.0.0
clean:compiler_clean clean:compiler_clean
@ -233,10 +235,30 @@ compiler_clean:
Debug.o: ../src/libUnuk/Debug.cpp ../src/libUnuk/Debug.h Debug.o: ../src/libUnuk/Debug.cpp ../src/libUnuk/Debug.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o Debug.o ../src/libUnuk/Debug.cpp $(CXX) -c $(CXXFLAGS) $(INCPATH) -o Debug.o ../src/libUnuk/Debug.cpp
main.o: ../src/Unuk/main.cpp ../src/libUnuk/Input.h \ main.o: ../src/Unuk/main.cpp ../src/libUnuk/MainMenu.h \
../src/libUnuk/Debug.h \
../src/Unuk/Constants.h \ ../src/Unuk/Constants.h \
../src/Unuk/Globals.h ../src/libUnuk/Menu.h \
../src/Unuk/Globals.h \
../src/libUnuk/Button.h \
../src/libUnuk/Input.h \
../src/libUnuk/Text.h \
../src/libUnuk/ApplySurface.h \
../src/libUnuk/Debug.h \
../src/libUnuk/Font.h \
../src/libUnuk/Rect.h \
../src/libUnuk/ButtonToggle.h \
../src/libUnuk/Map.h \
../src/libUnuk/ImageLoader.h \
../src/libUnuk/TextureManager.h \
../src/libUnuk/MapTile.h \
../src/libUnuk/Entity.h \
../src/libUnuk/NPC.h \
../src/libUnuk/Character.h \
../src/libUnuk/Collision.h \
../src/libUnuk/Timer.h \
../src/Unuk/Game.h \
../src/Unuk/Player.h \
../src/libUnuk/IngameMenu.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o main.o ../src/Unuk/main.cpp $(CXX) -c $(CXXFLAGS) $(INCPATH) -o main.o ../src/Unuk/main.cpp
Input.o: ../src/libUnuk/Input.cpp ../src/libUnuk/Input.h Input.o: ../src/libUnuk/Input.cpp ../src/libUnuk/Input.h
@ -295,7 +317,8 @@ Map.o: ../src/libUnuk/Map.cpp ../src/libUnuk/Map.h \
../src/libUnuk/Debug.h \ ../src/libUnuk/Debug.h \
../src/libUnuk/ApplySurface.h \ ../src/libUnuk/ApplySurface.h \
../src/libUnuk/TextureManager.h \ ../src/libUnuk/TextureManager.h \
../src/libUnuk/MapTile.h ../src/libUnuk/MapTile.h \
../src/libUnuk/Entity.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o Map.o ../src/libUnuk/Map.cpp $(CXX) -c $(CXXFLAGS) $(INCPATH) -o Map.o ../src/libUnuk/Map.cpp
Button.o: ../src/libUnuk/Button.cpp ../src/libUnuk/Button.h \ Button.o: ../src/libUnuk/Button.cpp ../src/libUnuk/Button.h \
@ -328,21 +351,21 @@ ParticleEmitter.o: ../src/libUnuk/ParticleEmitter.cpp ../src/libUnuk/ParticleEmi
MainMenu.o: ../src/libUnuk/MainMenu.cpp ../src/libUnuk/MainMenu.h \ MainMenu.o: ../src/libUnuk/MainMenu.cpp ../src/libUnuk/MainMenu.h \
../src/Unuk/Constants.h \ ../src/Unuk/Constants.h \
../src/libUnuk/ParticleEmitter.h \
../src/Unuk/Globals.h \
../src/libUnuk/ImageLoader.h \
../src/libUnuk/Debug.h \
../src/libUnuk/ApplySurface.h \
../src/libUnuk/Menu.h \ ../src/libUnuk/Menu.h \
../src/Unuk/Globals.h \
../src/libUnuk/Button.h \ ../src/libUnuk/Button.h \
../src/libUnuk/Input.h \ ../src/libUnuk/Input.h \
../src/libUnuk/Text.h \ ../src/libUnuk/Text.h \
../src/libUnuk/ApplySurface.h \
../src/libUnuk/Debug.h \
../src/libUnuk/Font.h \ ../src/libUnuk/Font.h \
../src/libUnuk/Rect.h \ ../src/libUnuk/Rect.h \
../src/libUnuk/ButtonToggle.h \ ../src/libUnuk/ButtonToggle.h \
../src/libUnuk/Map.h \ ../src/libUnuk/Map.h \
../src/libUnuk/ImageLoader.h \
../src/libUnuk/TextureManager.h \ ../src/libUnuk/TextureManager.h \
../src/libUnuk/MapTile.h ../src/libUnuk/MapTile.h \
../src/libUnuk/Entity.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o MainMenu.o ../src/libUnuk/MainMenu.cpp $(CXX) -c $(CXXFLAGS) $(INCPATH) -o MainMenu.o ../src/libUnuk/MainMenu.cpp
IngameMenu.o: ../src/libUnuk/IngameMenu.cpp ../src/libUnuk/IngameMenu.h \ IngameMenu.o: ../src/libUnuk/IngameMenu.cpp ../src/libUnuk/IngameMenu.h \
@ -372,6 +395,7 @@ Character.o: ../src/libUnuk/Character.cpp ../src/libUnuk/Character.h \
../src/libUnuk/Map.h \ ../src/libUnuk/Map.h \
../src/libUnuk/TextureManager.h \ ../src/libUnuk/TextureManager.h \
../src/libUnuk/MapTile.h \ ../src/libUnuk/MapTile.h \
../src/libUnuk/Entity.h \
../src/libUnuk/Timer.h ../src/libUnuk/Timer.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o Character.o ../src/libUnuk/Character.cpp $(CXX) -c $(CXXFLAGS) $(INCPATH) -o Character.o ../src/libUnuk/Character.cpp
@ -386,6 +410,7 @@ NPC.o: ../src/libUnuk/NPC.cpp ../src/libUnuk/NPC.h \
../src/libUnuk/Map.h \ ../src/libUnuk/Map.h \
../src/libUnuk/TextureManager.h \ ../src/libUnuk/TextureManager.h \
../src/libUnuk/MapTile.h \ ../src/libUnuk/MapTile.h \
../src/libUnuk/Entity.h \
../src/libUnuk/Timer.h ../src/libUnuk/Timer.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o NPC.o ../src/libUnuk/NPC.cpp $(CXX) -c $(CXXFLAGS) $(INCPATH) -o NPC.o ../src/libUnuk/NPC.cpp
@ -400,6 +425,7 @@ Player.o: ../src/Unuk/Player.cpp ../src/Unuk/Player.h \
../src/libUnuk/Map.h \ ../src/libUnuk/Map.h \
../src/libUnuk/TextureManager.h \ ../src/libUnuk/TextureManager.h \
../src/libUnuk/MapTile.h \ ../src/libUnuk/MapTile.h \
../src/libUnuk/Entity.h \
../src/libUnuk/Timer.h ../src/libUnuk/Timer.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o Player.o ../src/Unuk/Player.cpp $(CXX) -c $(CXXFLAGS) $(INCPATH) -o Player.o ../src/Unuk/Player.cpp
@ -415,6 +441,7 @@ Game.o: ../src/Unuk/Game.cpp ../src/Unuk/Game.h \
../src/libUnuk/Map.h \ ../src/libUnuk/Map.h \
../src/libUnuk/TextureManager.h \ ../src/libUnuk/TextureManager.h \
../src/libUnuk/MapTile.h \ ../src/libUnuk/MapTile.h \
../src/libUnuk/Entity.h \
../src/libUnuk/Timer.h \ ../src/libUnuk/Timer.h \
../src/libUnuk/IngameMenu.h \ ../src/libUnuk/IngameMenu.h \
../src/libUnuk/Menu.h \ ../src/libUnuk/Menu.h \
@ -427,6 +454,9 @@ Game.o: ../src/Unuk/Game.cpp ../src/Unuk/Game.h \
../src/libUnuk/NPC.h ../src/libUnuk/NPC.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o Game.o ../src/Unuk/Game.cpp $(CXX) -c $(CXXFLAGS) $(INCPATH) -o Game.o ../src/Unuk/Game.cpp
Entity.o: ../src/libUnuk/Entity.cpp ../src/libUnuk/Entity.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o Entity.o ../src/libUnuk/Entity.cpp
####### Install ####### Install
install: FORCE install: FORCE

View File

@ -32,7 +32,8 @@ HEADERS += ../src/libUnuk/Debug.h \
../src/libUnuk/Character.h \ ../src/libUnuk/Character.h \
../src/libUnuk/NPC.h \ ../src/libUnuk/NPC.h \
../src/Unuk/Player.h \ ../src/Unuk/Player.h \
../src/Unuk/Game.h ../src/Unuk/Game.h \
../src/libUnuk/Entity.h
SOURCES += ../src/libUnuk/Debug.cpp \ SOURCES += ../src/libUnuk/Debug.cpp \
../src/Unuk/main.cpp \ ../src/Unuk/main.cpp \
../src/libUnuk/Input.cpp \ ../src/libUnuk/Input.cpp \
@ -55,4 +56,5 @@ SOURCES += ../src/libUnuk/Debug.cpp \
../src/libUnuk/Character.cpp \ ../src/libUnuk/Character.cpp \
../src/libUnuk/NPC.cpp \ ../src/libUnuk/NPC.cpp \
../src/Unuk/Player.cpp \ ../src/Unuk/Player.cpp \
../src/Unuk/Game.cpp ../src/Unuk/Game.cpp \
../src/libUnuk/Entity.cpp

View File

@ -128,11 +128,9 @@ bool Character::CheckTileCollisions(void) {
} }
bool Character::CheckEntityCollisions(void) { bool Character::CheckEntityCollisions(void) {
for(int i = -1; i < 2; i++) { for(int i = -2; i < 3; i++) {
for(int j = -1; j < 2; j++) { for(int j = -2; j < 3; j++) {
if(map->GetEntitySolidity(tileX + i, tileY + j)) { if(map->GetEntitySolidity(tileX + i, tileY + j)) {
printf("\nw - ", map->GetEntityWidth(tileX + i, tileY + j));
printf("\nh - ", map->GetEntityHeight(tileX + i, tileY + j));
if(CheckCollisionXY(x, y, w, h, map->GetEntityX(tileX + i, tileY + j), if(CheckCollisionXY(x, y, w, h, map->GetEntityX(tileX + i, tileY + j),
map->GetEntityY(tileX + i, tileY + j), map->GetEntityY(tileX + i, tileY + j),
map->GetEntityWidth(tileX + i, tileY + j), map->GetEntityWidth(tileX + i, tileY + j),

1
src/libUnuk/Entity.cpp Normal file
View File

@ -0,0 +1 @@
#include "Entity.h"

16
src/libUnuk/Entity.h Normal file
View File

@ -0,0 +1,16 @@
#ifndef _ENTITY_H_
#define _ENTITY_H_
class Entity {
public:
private:
bool m_solid;
int x;
int y;
int w;
int h;
};
#endif

View File

@ -30,7 +30,7 @@ void Map::Load(const string filename) {
string tileName; string tileName;
while(iss >> tileName) { while(iss >> tileName) {
string fullTilePath = "../Data/Media/Images/Tiles/" + tileName + ".png"; string fullTilePath = "../Data/Media/Images/Tiles/" + tileName + ".png";
m_tile[m_mapRows][m_mapColumns].SetTextureID(m_tileTextures->Add(fullTilePath)); m_tile[m_mapRows][m_mapColumns].SetTileTexture(m_tileTextures->Add(fullTilePath));
// Read the file solidity. // Read the file solidity.
bool tileSolidity; bool tileSolidity;
@ -45,19 +45,11 @@ void Map::Load(const string filename) {
iss >> entityName; iss >> entityName;
if(entityName == "n") { if(entityName == "n") {
m_tile[m_mapRows][m_mapColumns].SetEntityID(-1); m_tile[m_mapRows][m_mapColumns].SetEntityTexture(NULL);
} else { } else {
string entityPath = "../Data/Media/Images/Entities/" + entityName + ".png"; string entityPath = "../Data/Media/Images/Entities/" + entityName + ".png";
m_tile[m_mapRows][m_mapColumns].SetEntityID(m_entityTextures->AddAlpha(entityPath)); m_tile[m_mapRows][m_mapColumns].SetEntityTexture(m_entityTextures->AddAlpha(entityPath));
// Set the entities width and height variables.
m_tile[m_mapRows][m_mapColumns].SetEntityWidthHeight(
m_entityTextures->GetTextureWidth(m_tile[m_mapRows][m_mapColumns].GetEntityID()),
m_entityTextures->GetTextureHeight(m_tile[m_mapRows][m_mapColumns].GetEntityID()));
printf("\nw - ", m_entityTextures->GetTextureWidth(m_tile[m_mapRows][m_mapColumns].GetEntityID()));
printf("\nh - ", m_entityTextures->GetTextureHeight(m_tile[m_mapRows][m_mapColumns].GetEntityID()));
// Set the entities x and y variables. // Set the entities x and y variables.
m_tile[m_mapRows][m_mapColumns].SetEntityXY( m_tile[m_mapRows][m_mapColumns].SetEntityXY(
@ -103,17 +95,17 @@ void Map::Render(void) {
for(int j = 1; j < m_mapRows; j++) for(int j = 1; j < m_mapRows; j++)
for(int i = 1; i < m_mapColumns; i++) { for(int i = 1; i < m_mapColumns; i++) {
ApplySurface(m_tile[j][i].GetTileX(), m_tile[j][i].GetTileY(), ApplySurface(m_tile[j][i].GetTileX(), m_tile[j][i].GetTileY(),
m_tileTextures->Get(m_tile[j][i].GetTextureID()), screen); m_tile[j][i].GetTileTexture(), screen);
if(m_tile[j][i].GetEntityID() != -1) { if(m_tile[j][i].GetEntityTexture() != NULL) {
ApplySurface(m_tile[j][i].GetEntityX(), m_tile[j][i].GetEntityY(), ApplySurface(m_tile[j][i].GetEntityX(), m_tile[j][i].GetEntityY(),
m_entityTextures->Get(m_tile[j][i].GetEntityID()), screen); m_tile[j][i].GetEntityTexture(), screen);
} }
} }
} }
void Map::Unload(void) { void Map::Unload(void) {
m_tileTextures->Clear(); m_tileTextures->Unload();
m_entityTextures->Clear(); m_entityTextures->Unload();
// Start at 1,1 so we do not have to be concerned about messy // 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. // bounds checking when accessing the tile array within the game loop.
@ -125,7 +117,8 @@ void Map::Unload(void) {
// creating an invisible wall anywhere. // creating an invisible wall anywhere.
for(int i = 0; i < TILE_ARRAY_SIZE; i++) { for(int i = 0; i < TILE_ARRAY_SIZE; i++) {
for(int j = 0; j < TILE_ARRAY_SIZE; j++) { for(int j = 0; j < TILE_ARRAY_SIZE; j++) {
m_tile[i][j].SetTileSolidity(false); m_tile[i][j].SetTileTexture(NULL);
m_tile[i][j].SetEntityTexture(NULL);
} }
} }
} }

View File

@ -2,6 +2,9 @@
#define _MAPTILE_H_ #define _MAPTILE_H_
#include <list> #include <list>
#include <string> #include <string>
#include <SDL/SDL.h>
#include "Entity.h"
using namespace std; using namespace std;
class MapTile { class MapTile {
@ -9,8 +12,8 @@ public:
MapTile(void) {} MapTile(void) {}
~MapTile(void) {} ~MapTile(void) {}
void SetTextureID(int arg) { m_textureID = arg; } void SetTileTexture(SDL_Surface* surface) { m_tileTexture = surface; }
int GetTextureID(void) { return m_textureID; } SDL_Surface* GetTileTexture(void) { return m_tileTexture; }
void SetTileSolidity(bool arg) { m_tileSolidity = arg; } void SetTileSolidity(bool arg) { m_tileSolidity = arg; }
bool GetTileSolidity(void) { return m_tileSolidity; } bool GetTileSolidity(void) { return m_tileSolidity; }
@ -18,16 +21,20 @@ public:
int GetTileX(void) { return m_tileX; } int GetTileX(void) { return m_tileX; }
int GetTileY(void) { return m_tileY; } int GetTileY(void) { return m_tileY; }
void SetEntityID(int arg) { m_entityID = arg; } void SetEntityTexture(SDL_Surface* surface) {
int GetEntityID(void) { return m_entityID; } m_entityTexture = surface;
if(m_entityTexture != NULL) {
void SetEntitySolidity(bool arg) { m_entityID = arg; } m_entityW = m_entityTexture->w;
m_entityH = m_entityTexture->h;
}
}
SDL_Surface* GetEntityTexture(void) { return m_entityTexture; }
void SetEntitySolidity(bool arg) { m_entitySolidity = arg; }
bool GetEntitySolitity(void) { return m_entitySolidity; } bool GetEntitySolitity(void) { return m_entitySolidity; }
void SetEntityXY(int xArg, int yArg) { m_entityX = xArg, m_entityY = yArg; } void SetEntityXY(int xArg, int yArg) { m_entityX = xArg, m_entityY = yArg; }
int GetEntityX(void) { return m_entityX; } int GetEntityX(void) { return m_entityX; }
int GetEntityY(void) { return m_entityY; } int GetEntityY(void) { return m_entityY; }
void SetEntityWidthHeight(int wArg, int hArg) { m_entityW = wArg, m_entityH = hArg; }
int GetEntityWidth(void) { return m_entityW; } int GetEntityWidth(void) { return m_entityW; }
int GetEntityHeight(void) { return m_entityH; } int GetEntityHeight(void) { return m_entityH; }
@ -42,13 +49,12 @@ public:
int GetMapTransitionY(void) { return m_mapTransitionY; } int GetMapTransitionY(void) { return m_mapTransitionY; }
private: private:
int m_textureID; SDL_Surface* m_entityTexture;
bool m_tileSolidity; bool m_tileSolidity;
int m_tileX; int m_tileX;
int m_tileY; int m_tileY;
// Less than -1 if entity is present. SDL_Surface* m_tileTexture;
int m_entityID;
bool m_entitySolidity; bool m_entitySolidity;
int m_entityX; int m_entityX;
int m_entityY; int m_entityY;

View File

@ -5,45 +5,51 @@ TextureManager::TextureManager(void) {
} }
TextureManager::~TextureManager(void) { TextureManager::~TextureManager(void) {
Clear(); Unload();
} }
void TextureManager::Clear(void) { void TextureManager::Unload(void) {
for(int i = 0; i < m_allocated; i++) { for(int i = 0; i < m_allocated; i++) {
SDL_FreeSurface(array[i].texture); SDL_FreeSurface(textures[i].texture);
array[i].name.clear(); textures[i].name.clear();
} }
m_allocated = 0; m_allocated = 0;
} }
int TextureManager::Add(string filename) { SDL_Surface* TextureManager::Add(string filename) {
assert(m_allocated < TEXTURE_NODE_SIZE); assert(m_allocated < TEXTURE_NODE_SIZE);
// Has the texture been loaded already? // Has the texture been loaded already?
for(int i = 0; i < m_allocated; i++) { for(int i = 0; i < m_allocated; i++) {
if(array[i].name == filename) { if(textures[i].name == filename) {
return i; return textures[i].texture;
} }
} }
// If not, then load it.
textures[m_allocated].name = filename;
textures[m_allocated].texture = LoadImage(filename.c_str());
array[m_allocated].name = filename; m_allocated++;
array[m_allocated].texture = LoadImage(filename.c_str());
return m_allocated++; return textures[m_allocated - 1].texture;
} }
int TextureManager::AddAlpha(string filename) { SDL_Surface* TextureManager::AddAlpha(string filename) {
assert(m_allocated < TEXTURE_NODE_SIZE); assert(m_allocated < TEXTURE_NODE_SIZE);
// Has the texture been loaded already? // Has the texture been loaded already?
for(int i = 0; i < m_allocated; i++) { for(int i = 0; i < m_allocated; i++) {
if(array[i].name == filename) { if(textures[i].name == filename) {
return i; return textures[i].texture;
} }
} }
array[m_allocated].name = filename; // If not, then load it.
array[m_allocated].texture = LoadImageAlpha(filename.c_str());
return m_allocated++; textures[m_allocated].name = filename;
textures[m_allocated].texture = LoadImageAlpha(filename.c_str());
m_allocated++;
return textures[m_allocated -1].texture;
} }

View File

@ -18,14 +18,10 @@ public:
TextureManager(void); TextureManager(void);
~TextureManager(void); ~TextureManager(void);
SDL_Surface* Get(int n) { return array[n].texture; } void Unload(void);
int GetTextureWidth(int n) { return array[n].texture->w; }
int GetTextureHeight(int n) { return array[n].texture->h; }
void Clear(void); SDL_Surface* Add(string filename);
SDL_Surface* AddAlpha(string filename);
int Add(string filename);
int AddAlpha(string filename);
private: private:
// The textureNode will hold the name and the texture. // The textureNode will hold the name and the texture.
@ -36,7 +32,7 @@ private:
// We should not need more than a hundred.. // We should not need more than a hundred..
static const int TEXTURE_NODE_SIZE = 100; static const int TEXTURE_NODE_SIZE = 100;
textureNode array[TEXTURE_NODE_SIZE]; textureNode textures[TEXTURE_NODE_SIZE];
int m_allocated; int m_allocated;
}; };