Refactored the map class to hell. Should be easy add animated tiles and interactive entities now.
This commit is contained in:
parent
4b7369e788
commit
e7bfbc3966
@ -9,7 +9,7 @@
|
||||
|
||||
<zLevel>100</zLevel>
|
||||
|
||||
<mapTransition>null</mapTransition>
|
||||
<mapTransition>map</mapTransition>
|
||||
<mapTransX>0</mapTransX>
|
||||
<mapTransY>0</mapTransY>
|
||||
</tile>
|
||||
@ -18,7 +18,7 @@
|
||||
<tileTexture>ice</tileTexture>
|
||||
<solidTile>false</solidTile>
|
||||
|
||||
<entityTexture>tree</entityTexture>
|
||||
<entityTexture>openChest</entityTexture>
|
||||
<solidEntity>true</solidEntity>
|
||||
|
||||
<zLevel>100</zLevel>
|
||||
|
61
Data/Media/Maps/map2
Normal file
61
Data/Media/Maps/map2
Normal file
@ -0,0 +1,61 @@
|
||||
<map>
|
||||
<line>
|
||||
<tile>
|
||||
<tileTexture>grass</tileTexture>
|
||||
<solidTile>false</solidTile>
|
||||
|
||||
<entityTexture>null</entityTexture>
|
||||
<solidEntity>false</solidEntity>
|
||||
|
||||
<zLevel>100</zLevel>
|
||||
|
||||
<mapTransition>null</mapTransition>
|
||||
<mapTransX>0</mapTransX>
|
||||
<mapTransY>0</mapTransY>
|
||||
</tile>
|
||||
|
||||
<tile>
|
||||
<tileTexture>grass</tileTexture>
|
||||
<solidTile>false</solidTile>
|
||||
|
||||
<entityTexture>null</entityTexture>
|
||||
<solidEntity>false</solidEntity>
|
||||
|
||||
<zLevel>100</zLevel>
|
||||
|
||||
<mapTransition>null</mapTransition>
|
||||
<mapTransX>0</mapTransX>
|
||||
<mapTransY>0</mapTransY>
|
||||
</tile>
|
||||
</line>
|
||||
|
||||
<line>
|
||||
<tile>
|
||||
<tileTexture>rock</tileTexture>
|
||||
<solidTile>false</solidTile>
|
||||
|
||||
<entityTexture>null</entityTexture>
|
||||
<solidEntity>false</solidEntity>
|
||||
|
||||
<zLevel>100</zLevel>
|
||||
|
||||
<mapTransition>null</mapTransition>
|
||||
<mapTransX>0</mapTransX>
|
||||
<mapTransY>0</mapTransY>
|
||||
</tile>
|
||||
|
||||
<tile>
|
||||
<tileTexture>snow</tileTexture>
|
||||
<solidTile>true</solidTile>
|
||||
|
||||
<entityTexture>null</entityTexture>
|
||||
<solidEntity>false</solidEntity>
|
||||
|
||||
<zLevel>100</zLevel>
|
||||
|
||||
<mapTransition>null</mapTransition>
|
||||
<mapTransX>0</mapTransX>
|
||||
<mapTransY>0</mapTransY>
|
||||
</tile>
|
||||
</line>
|
||||
</map>
|
@ -1,6 +1,6 @@
|
||||
#############################################################################
|
||||
# Makefile for building: Unuk-QT
|
||||
# Generated by qmake (2.01a) (Qt 4.7.3) on: Wed Dec 14 00:58:57 2011
|
||||
# Generated by qmake (2.01a) (Qt 4.7.3) on: Fri Dec 16 01:33:02 2011
|
||||
# Project: Unuk-QT.pro
|
||||
# Template: app
|
||||
# Command: /usr/bin/qmake-qt4 -spec /usr/share/qt4/mkspecs/linux-g++ CONFIG+=debug -o Makefile Unuk-QT.pro
|
||||
@ -66,7 +66,8 @@ SOURCES = ../src/libUnuk/Debug.cpp \
|
||||
../src/libUnuk/NPC.cpp \
|
||||
../src/Unuk/Player.cpp \
|
||||
../src/Unuk/Game.cpp \
|
||||
../src/libUnuk/Entity.cpp
|
||||
../src/libUnuk/MapElement.cpp \
|
||||
../src/libUnuk/MapEntities.cpp
|
||||
OBJECTS = Debug.o \
|
||||
main.o \
|
||||
Input.o \
|
||||
@ -90,7 +91,8 @@ OBJECTS = Debug.o \
|
||||
NPC.o \
|
||||
Player.o \
|
||||
Game.o \
|
||||
Entity.o
|
||||
MapElement.o \
|
||||
MapEntities.o
|
||||
DIST = /usr/share/qt4/mkspecs/common/g++.conf \
|
||||
/usr/share/qt4/mkspecs/common/unix.conf \
|
||||
/usr/share/qt4/mkspecs/common/linux.conf \
|
||||
@ -190,7 +192,7 @@ qmake: FORCE
|
||||
|
||||
dist:
|
||||
@$(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 ../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
|
||||
$(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/MapElement.h ../src/libUnuk/MapEntities.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/MapElement.cpp ../src/libUnuk/MapEntities.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
|
||||
@ -237,28 +239,28 @@ Debug.o: ../src/libUnuk/Debug.cpp ../src/libUnuk/Debug.h
|
||||
|
||||
main.o: ../src/Unuk/main.cpp ../src/libUnuk/MainMenu.h \
|
||||
../src/Unuk/Constants.h \
|
||||
../src/libUnuk/Menu.h \
|
||||
../src/Unuk/Globals.h \
|
||||
../src/libUnuk/Button.h \
|
||||
../src/Unuk/Globals.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/MapElement.h \
|
||||
../src/libUnuk/TextureManager.h \
|
||||
../src/libUnuk/MapEntities.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
|
||||
../src/libUnuk/IngameMenu.h \
|
||||
../src/libUnuk/ButtonToggle.h
|
||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o main.o ../src/Unuk/main.cpp
|
||||
|
||||
Input.o: ../src/libUnuk/Input.cpp ../src/libUnuk/Input.h
|
||||
@ -316,9 +318,10 @@ Map.o: ../src/libUnuk/Map.cpp ../src/libUnuk/Map.h \
|
||||
../src/libUnuk/ImageLoader.h \
|
||||
../src/libUnuk/Debug.h \
|
||||
../src/libUnuk/ApplySurface.h \
|
||||
../src/libUnuk/TextureManager.h \
|
||||
../src/libUnuk/MapTile.h \
|
||||
../src/libUnuk/Entity.h
|
||||
../src/libUnuk/MapElement.h \
|
||||
../src/libUnuk/TextureManager.h \
|
||||
../src/libUnuk/MapEntities.h
|
||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o Map.o ../src/libUnuk/Map.cpp
|
||||
|
||||
Button.o: ../src/libUnuk/Button.cpp ../src/libUnuk/Button.h \
|
||||
@ -351,25 +354,23 @@ ParticleEmitter.o: ../src/libUnuk/ParticleEmitter.cpp ../src/libUnuk/ParticleEmi
|
||||
|
||||
MainMenu.o: ../src/libUnuk/MainMenu.cpp ../src/libUnuk/MainMenu.h \
|
||||
../src/Unuk/Constants.h \
|
||||
../src/libUnuk/Menu.h \
|
||||
../src/Unuk/Globals.h \
|
||||
../src/libUnuk/Button.h \
|
||||
../src/Unuk/Globals.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/MapElement.h \
|
||||
../src/libUnuk/TextureManager.h \
|
||||
../src/libUnuk/MapEntities.h
|
||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o MainMenu.o ../src/libUnuk/MainMenu.cpp
|
||||
|
||||
IngameMenu.o: ../src/libUnuk/IngameMenu.cpp ../src/libUnuk/IngameMenu.h \
|
||||
../src/libUnuk/Menu.h \
|
||||
../src/Unuk/Globals.h \
|
||||
../src/Unuk/Constants.h \
|
||||
../src/libUnuk/Button.h \
|
||||
@ -393,9 +394,10 @@ Character.o: ../src/libUnuk/Character.cpp ../src/libUnuk/Character.h \
|
||||
../src/libUnuk/ImageLoader.h \
|
||||
../src/libUnuk/Collision.h \
|
||||
../src/libUnuk/Map.h \
|
||||
../src/libUnuk/TextureManager.h \
|
||||
../src/libUnuk/MapTile.h \
|
||||
../src/libUnuk/Entity.h \
|
||||
../src/libUnuk/MapElement.h \
|
||||
../src/libUnuk/TextureManager.h \
|
||||
../src/libUnuk/MapEntities.h \
|
||||
../src/libUnuk/Timer.h \
|
||||
../src/libUnuk/Text.h \
|
||||
../src/libUnuk/Font.h
|
||||
@ -410,9 +412,10 @@ NPC.o: ../src/libUnuk/NPC.cpp ../src/libUnuk/NPC.h \
|
||||
../src/libUnuk/ImageLoader.h \
|
||||
../src/libUnuk/Collision.h \
|
||||
../src/libUnuk/Map.h \
|
||||
../src/libUnuk/TextureManager.h \
|
||||
../src/libUnuk/MapTile.h \
|
||||
../src/libUnuk/Entity.h \
|
||||
../src/libUnuk/MapElement.h \
|
||||
../src/libUnuk/TextureManager.h \
|
||||
../src/libUnuk/MapEntities.h \
|
||||
../src/libUnuk/Timer.h \
|
||||
../src/libUnuk/Text.h \
|
||||
../src/libUnuk/Font.h
|
||||
@ -427,9 +430,10 @@ Player.o: ../src/Unuk/Player.cpp ../src/Unuk/Player.h \
|
||||
../src/libUnuk/ImageLoader.h \
|
||||
../src/libUnuk/Collision.h \
|
||||
../src/libUnuk/Map.h \
|
||||
../src/libUnuk/TextureManager.h \
|
||||
../src/libUnuk/MapTile.h \
|
||||
../src/libUnuk/Entity.h \
|
||||
../src/libUnuk/MapElement.h \
|
||||
../src/libUnuk/TextureManager.h \
|
||||
../src/libUnuk/MapEntities.h \
|
||||
../src/libUnuk/Timer.h \
|
||||
../src/libUnuk/Text.h \
|
||||
../src/libUnuk/Font.h
|
||||
@ -445,14 +449,14 @@ Game.o: ../src/Unuk/Game.cpp ../src/Unuk/Game.h \
|
||||
../src/libUnuk/ImageLoader.h \
|
||||
../src/libUnuk/Collision.h \
|
||||
../src/libUnuk/Map.h \
|
||||
../src/libUnuk/TextureManager.h \
|
||||
../src/libUnuk/MapTile.h \
|
||||
../src/libUnuk/Entity.h \
|
||||
../src/libUnuk/MapElement.h \
|
||||
../src/libUnuk/TextureManager.h \
|
||||
../src/libUnuk/MapEntities.h \
|
||||
../src/libUnuk/Timer.h \
|
||||
../src/libUnuk/Text.h \
|
||||
../src/libUnuk/Font.h \
|
||||
../src/libUnuk/IngameMenu.h \
|
||||
../src/libUnuk/Menu.h \
|
||||
../src/libUnuk/Button.h \
|
||||
../src/libUnuk/Input.h \
|
||||
../src/libUnuk/Rect.h \
|
||||
@ -460,8 +464,22 @@ Game.o: ../src/Unuk/Game.cpp ../src/Unuk/Game.h \
|
||||
../src/libUnuk/NPC.h
|
||||
$(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
|
||||
MapElement.o: ../src/libUnuk/MapElement.cpp ../src/libUnuk/MapElement.h \
|
||||
../src/Unuk/Globals.h \
|
||||
../src/libUnuk/ApplySurface.h \
|
||||
../src/libUnuk/Debug.h \
|
||||
../src/libUnuk/TextureManager.h \
|
||||
../src/libUnuk/ImageLoader.h
|
||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o MapElement.o ../src/libUnuk/MapElement.cpp
|
||||
|
||||
MapEntities.o: ../src/libUnuk/MapEntities.cpp ../src/libUnuk/MapEntities.h \
|
||||
../src/libUnuk/MapElement.h \
|
||||
../src/Unuk/Globals.h \
|
||||
../src/libUnuk/ApplySurface.h \
|
||||
../src/libUnuk/Debug.h \
|
||||
../src/libUnuk/TextureManager.h \
|
||||
../src/libUnuk/ImageLoader.h
|
||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o MapEntities.o ../src/libUnuk/MapEntities.cpp
|
||||
|
||||
####### Install
|
||||
|
||||
|
@ -35,7 +35,8 @@ HEADERS += ../src/libUnuk/Debug.h \
|
||||
../src/libUnuk/NPC.h \
|
||||
../src/Unuk/Player.h \
|
||||
../src/Unuk/Game.h \
|
||||
../src/libUnuk/Entity.h
|
||||
../src/libUnuk/MapElement.h \
|
||||
../src/libUnuk/MapEntities.h
|
||||
SOURCES += ../src/libUnuk/Debug.cpp \
|
||||
../src/Unuk/main.cpp \
|
||||
../src/libUnuk/Input.cpp \
|
||||
@ -59,4 +60,5 @@ SOURCES += ../src/libUnuk/Debug.cpp \
|
||||
../src/libUnuk/NPC.cpp \
|
||||
../src/Unuk/Player.cpp \
|
||||
../src/Unuk/Game.cpp \
|
||||
../src/libUnuk/Entity.cpp
|
||||
../src/libUnuk/MapElement.cpp \
|
||||
../src/libUnuk/MapEntities.cpp
|
||||
|
@ -151,9 +151,14 @@ void Character::Move(void) {
|
||||
if(CheckCharacterCollisions()) y -= yVel;
|
||||
}
|
||||
|
||||
/*
|
||||
* Bounds checking only included in map.GetTileSolidity() and
|
||||
* map.GetEntitySolidity(). Remember to add bounds checking
|
||||
* if any other map method is used in a similar manner.
|
||||
*/
|
||||
bool Character::CheckTileCollisions(void) {
|
||||
for(int i = -2; i < 3; i++) {
|
||||
for(int j = -2; j < 3; j++) {
|
||||
for(int i = -1; i < 2; i++) {
|
||||
for(int j = -1; j < 2; j++) {
|
||||
if(map->GetTileSolidity(tileX + i, tileY + j))
|
||||
if(CheckCollisionXY(x, y, w, h, map->GetTileX(tileX + i, tileY + j),
|
||||
map->GetTileY(tileX + i, tileY + j), TILE_WIDTH, TILE_HEIGHT))
|
||||
|
@ -1 +0,0 @@
|
||||
#include "Entity.h"
|
@ -1,16 +0,0 @@
|
||||
#ifndef _ENTITY_H_
|
||||
#define _ENTITY_H_
|
||||
|
||||
class Entity {
|
||||
public:
|
||||
|
||||
private:
|
||||
bool m_solid;
|
||||
|
||||
int x;
|
||||
int y;
|
||||
int w;
|
||||
int h;
|
||||
};
|
||||
|
||||
#endif
|
@ -25,8 +25,8 @@ void Map::Load(const string filename) {
|
||||
|
||||
// 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;
|
||||
x = -1;
|
||||
y = -1;
|
||||
|
||||
// <map> - Let's start parsing the map.
|
||||
rootElem = mapFile.FirstChildElement("map");
|
||||
@ -38,14 +38,14 @@ void Map::Load(const string filename) {
|
||||
assert(lineElem != NULL);
|
||||
while(lineElem) {
|
||||
y++;
|
||||
x = 0;
|
||||
x = -1;
|
||||
|
||||
// <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);
|
||||
m_tile[x][y].SetTileXY(x * TILE_WIDTH, y * TILE_HEIGHT);
|
||||
|
||||
// <tileTexture> - Apply a teture to the tile.
|
||||
dataElem = tileElem->FirstChildElement("tileTexture");
|
||||
@ -70,9 +70,7 @@ void Map::Load(const string filename) {
|
||||
dataElem = dataElem->NextSiblingElement("entityTexture");
|
||||
assert(dataElem != NULL);
|
||||
string entityName = dataElem->GetText();
|
||||
if(entityName == "null")
|
||||
m_tile[x][y].SetEntityTexture(NULL);
|
||||
else {
|
||||
if(entityName != "null") {
|
||||
stringstream entityPath;
|
||||
entityPath << "../Data/Media/Images/Entities/" << entityName << ".png";
|
||||
m_tile[x][y].SetEntityTexture(m_entityTextures.AddAlpha(entityPath.str()));
|
||||
@ -126,41 +124,32 @@ void Map::Load(const string filename) {
|
||||
// </line>
|
||||
}
|
||||
// </map>
|
||||
levelWidth = (x - 1) * TILE_WIDTH;
|
||||
levelHeight = (y - 1) * TILE_HEIGHT;
|
||||
levelWidth = x * TILE_WIDTH;
|
||||
levelHeight = y * 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);
|
||||
int xOrig = (camera.x / TILE_WIDTH);
|
||||
int yOrig = (camera.y / TILE_HEIGHT);
|
||||
|
||||
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);
|
||||
int xEnd = (SCREEN_WIDTH / TILE_WIDTH);
|
||||
int yEnd = (SCREEN_HEIGHT / TILE_HEIGHT);
|
||||
|
||||
if(xEnd < x)
|
||||
xEnd++;
|
||||
else
|
||||
xEnd = x;
|
||||
|
||||
if(yEnd < y)
|
||||
yEnd++;
|
||||
else
|
||||
yEnd = y;
|
||||
|
||||
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);
|
||||
for(int i = xOrig; i < xEnd; i++) {
|
||||
for(int j = yOrig; j < yEnd; j++) {
|
||||
m_tile[i][j].Render();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -168,66 +157,60 @@ void Map::Render(void) {
|
||||
void Map::Unload(void) {
|
||||
m_tileTextures.Unload();
|
||||
m_entityTextures.Unload();
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
string Map::GetCurrentMap(void) {
|
||||
return m_currentMap;
|
||||
}
|
||||
|
||||
bool Map::GetTileSolidity(int row, int column) {
|
||||
return m_tile[row + 1][column + 1].GetTileSolidity();
|
||||
bool Map::GetTileSolidity(int xArg, int yArg) {
|
||||
return m_tile[xArg + 1][yArg + 1].GetTileSolidity();
|
||||
}
|
||||
|
||||
int Map::GetTileX(int row, int column) {
|
||||
return m_tile[row + 1][column + 1].GetTileX();
|
||||
int Map::GetTileX(int xArg, int yArg) {
|
||||
return m_tile[xArg + 1][yArg + 1].GetTileX();
|
||||
}
|
||||
|
||||
int Map::GetTileY(int row, int column) {
|
||||
return m_tile[row + 1][column + 1].GetTileY();
|
||||
int Map::GetTileY(int xArg, int yArg) {
|
||||
return m_tile[xArg + 1][yArg + 1].GetTileY();
|
||||
}
|
||||
|
||||
bool Map::GetEntitySolidity(int row, int column) {
|
||||
return m_tile[row + 1][column + 1].GetEntitySolitity();
|
||||
bool Map::GetEntitySolidity(int xArg, int yArg) {
|
||||
if(xArg > x || yArg > y || yArg < 0 || yArg < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return m_tile[xArg + 1][yArg + 1].GetEntitySolitity();
|
||||
}
|
||||
|
||||
int Map::GetEntityX(int row, int column) {
|
||||
return m_tile[row + 1][column + 1].GetEntityX();
|
||||
int Map::GetEntityX(int xArg, int yArg) {
|
||||
return m_tile[xArg + 1][yArg + 1].GetEntityX();
|
||||
}
|
||||
|
||||
int Map::GetEntityY(int row, int column) {
|
||||
return m_tile[row + 1][column + 1].GetEntityY();
|
||||
int Map::GetEntityY(int xArg, int yArg) {
|
||||
return m_tile[xArg + 1][yArg + 1].GetEntityY();
|
||||
}
|
||||
|
||||
int Map::GetEntityWidth(int row, int column) {
|
||||
return m_tile[row + 1][column + 1].GetEntityWidth();
|
||||
int Map::GetEntityWidth(int xArg, int yArg) {
|
||||
return m_tile[xArg + 1][yArg + 1].GetEntityWidth();
|
||||
}
|
||||
|
||||
int Map::GetEntityHeight(int row, int column) {
|
||||
return m_tile[row + 1][column + 1].GetEntityHeight();
|
||||
int Map::GetEntityHeight(int xArg, int yArg) {
|
||||
return m_tile[xArg + 1][yArg + 1].GetEntityHeight();
|
||||
}
|
||||
|
||||
int Map::GetTileZLevel(int row, int column) {
|
||||
return m_tile[row + 1][column + 1].GetZLevel();
|
||||
int Map::GetTileZLevel(int xArg, int yArg) {
|
||||
return m_tile[xArg + 1][yArg + 1].GetZLevel();
|
||||
}
|
||||
|
||||
string Map::GetMapTransitionName(int row, int column) {
|
||||
return m_tile[row + 1][column + 1].GetMapTransitionName();
|
||||
string Map::GetMapTransitionName(int xArg, int yArg) {
|
||||
return m_tile[xArg + 1][yArg + 1].GetMapTransitionName();
|
||||
}
|
||||
|
||||
int Map::GetMapTransitionX(int row, int column) {
|
||||
return m_tile[row + 1][column + 1].GetMapTransitionX();
|
||||
int Map::GetMapTransitionX(int xArg, int yArg) {
|
||||
return m_tile[xArg + 1][yArg + 1].GetMapTransitionX();
|
||||
}
|
||||
|
||||
int Map::GetMapTransitionY(int row, int column) {
|
||||
return m_tile[row + 1][column + 1].GetMapTransitionY();
|
||||
int Map::GetMapTransitionY(int xArg, int yArg) {
|
||||
return m_tile[xArg + 1][yArg + 1].GetMapTransitionY();
|
||||
}
|
||||
|
@ -12,7 +12,6 @@
|
||||
#include "../Unuk/Constants.h"
|
||||
#include "ImageLoader.h"
|
||||
#include "ApplySurface.h"
|
||||
#include "TextureManager.h"
|
||||
#include "MapTile.h"
|
||||
#include "Debug.h"
|
||||
using namespace std;
|
||||
@ -27,21 +26,21 @@ public:
|
||||
void Load(const string filename);
|
||||
void Render(void);
|
||||
|
||||
bool GetTileSolidity(int row, int column);
|
||||
int GetTileX(int row, int column);
|
||||
int GetTileY(int row, int column);
|
||||
bool GetTileSolidity(int xArg, int yArg);
|
||||
int GetTileX(int xArg, int yArg);
|
||||
int GetTileY(int xArg, int yArg);
|
||||
|
||||
bool GetEntitySolidity(int row, int column);
|
||||
int GetEntityX(int row, int column);
|
||||
int GetEntityY(int row, int column);
|
||||
int GetEntityWidth(int row, int column);
|
||||
int GetEntityHeight(int row, int column);
|
||||
bool GetEntitySolidity(int xArg, int yArg);
|
||||
int GetEntityX(int xArg, int yArg);
|
||||
int GetEntityY(int xArg, int yArg);
|
||||
int GetEntityWidth(int xArg, int yArg);
|
||||
int GetEntityHeight(int xArg, int yArg);
|
||||
|
||||
int GetTileZLevel(int row, int column);
|
||||
int GetTileZLevel(int xArg, int yArg);
|
||||
|
||||
string GetMapTransitionName(int row, int column);
|
||||
int GetMapTransitionX(int row, int column);
|
||||
int GetMapTransitionY(int row, int column);
|
||||
string GetMapTransitionName(int xArg, int yArg);
|
||||
int GetMapTransitionX(int xArg, int yArg);
|
||||
int GetMapTransitionY(int xArg, int yArg);
|
||||
|
||||
string GetCurrentMap(void);
|
||||
|
||||
@ -52,11 +51,11 @@ private:
|
||||
int x;
|
||||
int y;
|
||||
|
||||
TextureManager m_tileTextures;
|
||||
TextureManager m_entityTextures;
|
||||
|
||||
static const int TILE_ARRAY_SIZE = 150;
|
||||
MapTile m_tile[TILE_ARRAY_SIZE][TILE_ARRAY_SIZE];
|
||||
|
||||
TextureManager m_tileTextures;
|
||||
TextureManager m_entityTextures;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
39
src/libUnuk/MapElement.cpp
Normal file
39
src/libUnuk/MapElement.cpp
Normal file
@ -0,0 +1,39 @@
|
||||
#include "MapElement.h"
|
||||
|
||||
MapElement::MapElement(void) {
|
||||
|
||||
}
|
||||
|
||||
MapElement::~MapElement(void) {
|
||||
|
||||
}
|
||||
|
||||
void MapElement::SetTexture(SDL_Surface* arg) {
|
||||
m_texture = arg;
|
||||
}
|
||||
|
||||
void MapElement::Render(void) {
|
||||
ApplySurface(x, y, m_texture, screen);
|
||||
}
|
||||
|
||||
void MapElement::Update(void) {
|
||||
|
||||
}
|
||||
|
||||
void MapElement::SetSolidity(bool arg) {
|
||||
m_solid = arg;
|
||||
}
|
||||
|
||||
bool MapElement::GetSolidity(void) {
|
||||
return m_solid;
|
||||
}
|
||||
|
||||
void MapElement::SetXY(int xArg, int yArg) {
|
||||
x = xArg,
|
||||
y = yArg;
|
||||
}
|
||||
|
||||
int MapElement::GetX(void) { return x; }
|
||||
int MapElement::GetY(void) { return y; }
|
||||
int MapElement::GetWidth(void) { return m_texture->w; }
|
||||
int MapElement::GetHeight(void) { return m_texture->h; }
|
39
src/libUnuk/MapElement.h
Normal file
39
src/libUnuk/MapElement.h
Normal file
@ -0,0 +1,39 @@
|
||||
#ifndef _MAPELEMENT_H_
|
||||
#define _MAPELEMENT_H_
|
||||
#include <SDL/SDL.h>
|
||||
#include <string>
|
||||
|
||||
#include "../Unuk/Globals.h"
|
||||
#include "ApplySurface.h"
|
||||
#include "TextureManager.h"
|
||||
|
||||
class MapElement {
|
||||
public:
|
||||
MapElement(void);
|
||||
~MapElement(void);
|
||||
|
||||
static void SetTextureManager(TextureManager* arg);
|
||||
|
||||
virtual void SetTexture(SDL_Surface* arg);
|
||||
virtual void Render(void);
|
||||
virtual void Update(void);
|
||||
|
||||
void SetSolidity(bool arg);
|
||||
bool GetSolidity(void);
|
||||
|
||||
void SetXY(int xArg, int yArg);
|
||||
int GetX(void);
|
||||
int GetY(void);
|
||||
int GetWidth(void);
|
||||
int GetHeight(void);
|
||||
|
||||
protected:
|
||||
SDL_Surface* m_texture;
|
||||
|
||||
bool m_solid;
|
||||
|
||||
int x;
|
||||
int y;
|
||||
};
|
||||
|
||||
#endif
|
16
src/libUnuk/MapEntities.cpp
Normal file
16
src/libUnuk/MapEntities.cpp
Normal file
@ -0,0 +1,16 @@
|
||||
#include "MapEntities.h"
|
||||
|
||||
MapEntityGeneric::MapEntityGeneric(void) {
|
||||
m_texture = NULL;
|
||||
|
||||
}
|
||||
|
||||
MapEntityGeneric::~MapEntityGeneric(void) {
|
||||
|
||||
}
|
||||
|
||||
void MapEntityGeneric::Render(void) {
|
||||
if(m_texture != NULL) {
|
||||
MapElement::Render();
|
||||
}
|
||||
}
|
17
src/libUnuk/MapEntities.h
Normal file
17
src/libUnuk/MapEntities.h
Normal file
@ -0,0 +1,17 @@
|
||||
#ifndef _MAPENTITIES_H_
|
||||
#define _MAPENTITIES_H_
|
||||
|
||||
#include "MapElement.h"
|
||||
|
||||
class MapEntityGeneric : public MapElement {
|
||||
public:
|
||||
MapEntityGeneric(void);
|
||||
~MapEntityGeneric(void);
|
||||
|
||||
void Render(void);
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
#endif
|
@ -4,43 +4,44 @@
|
||||
#include <string>
|
||||
#include <SDL/SDL.h>
|
||||
|
||||
#include "Entity.h"
|
||||
#include "../Unuk/Constants.h"
|
||||
#include "ApplySurface.h"
|
||||
#include "MapElement.h"
|
||||
#include "MapEntities.h"
|
||||
using namespace std;
|
||||
|
||||
class MapTile {
|
||||
public:
|
||||
MapTile(void) { m_entitySolidity = false; }
|
||||
MapTile(void) { }
|
||||
~MapTile(void) { }
|
||||
|
||||
void SetTileTexture(SDL_Surface* surface) { m_tileTexture = surface; }
|
||||
SDL_Surface* GetTileTexture(void) { return m_tileTexture; }
|
||||
void Render(void) { m_tile.Render(), m_entity.Render(); }
|
||||
|
||||
void SetTileSolidity(bool arg) { m_tileSolidity = arg; }
|
||||
bool GetTileSolidity(void) { return m_tileSolidity; }
|
||||
void SetTileXY(int xArg, int yArg) { m_tileX = xArg, m_tileY = yArg; }
|
||||
int GetTileX(void) { return m_tileX; }
|
||||
int GetTileY(void) { return m_tileY; }
|
||||
// Tile Mutators.
|
||||
SDL_Surface SetTileTexture(SDL_Surface* arg) { m_tile.SetTexture(arg); }
|
||||
void SetTileSolidity(bool arg) { m_tile.SetSolidity(arg); }
|
||||
bool GetTileSolidity(void) { return m_tile.GetSolidity(); }
|
||||
void SetTileXY(int xArg, int yArg) { m_tile.GetX(), m_tile.GetY(); }
|
||||
int GetTileX(void) { return m_tile.GetX(); }
|
||||
int GetTileY(void) { return m_tile.GetY(); }
|
||||
|
||||
void SetEntityTexture(SDL_Surface* surface) {
|
||||
m_entityTexture = surface;
|
||||
if(m_entityTexture != NULL) {
|
||||
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; }
|
||||
void SetEntityXY(int xArg, int yArg) { m_entityX = xArg, m_entityY = yArg; }
|
||||
int GetEntityX(void) { return m_entityX; }
|
||||
int GetEntityY(void) { return m_entityY; }
|
||||
// Entity Mutators.
|
||||
void SetEntityTexture(SDL_Surface* arg) { m_entity.SetTexture(arg); }
|
||||
void SetEntityXY(int xArg, int yArg) { m_entity.SetXY(xArg, yArg); }
|
||||
void SetEntitySolidity(bool arg) { m_entity.SetSolidity(arg); }
|
||||
bool GetEntitySolitity(void) { return m_entity.GetSolidity(); }
|
||||
|
||||
int GetEntityWidth(void) { return m_entityW; }
|
||||
int GetEntityHeight(void) { return m_entityH; }
|
||||
// Entity Mutators.
|
||||
int GetEntityX(void) { return m_entity.GetX(); }
|
||||
int GetEntityY(void) { return m_entity.GetY(); }
|
||||
int GetEntityWidth(void) { return m_entity.GetWidth(); }
|
||||
int GetEntityHeight(void) { return m_entity.GetHeight(); }
|
||||
|
||||
// ZLevel Mutators.
|
||||
void SetZLevel(int arg) { m_zLevel = arg; }
|
||||
int GetZLevel(void) { return m_zLevel; }
|
||||
|
||||
// Map Transition Mutators.
|
||||
void SetMapTransitionName(string arg) { m_mapTransitionName = arg; }
|
||||
string GetMapTransitionName(void) { return m_mapTransitionName; }
|
||||
|
||||
@ -49,17 +50,8 @@ public:
|
||||
int GetMapTransitionY(void) { return m_mapTransitionY; }
|
||||
|
||||
private:
|
||||
SDL_Surface* m_entityTexture;
|
||||
bool m_tileSolidity;
|
||||
int m_tileX;
|
||||
int m_tileY;
|
||||
|
||||
SDL_Surface* m_tileTexture;
|
||||
bool m_entitySolidity;
|
||||
int m_entityX;
|
||||
int m_entityY;
|
||||
int m_entityW;
|
||||
int m_entityH;
|
||||
MapElement m_tile;
|
||||
MapEntityGeneric m_entity;
|
||||
|
||||
// -1 is a 'special' tile, the next tile that the player walks
|
||||
// on is the players new zlevel.
|
||||
|
Loading…
Reference in New Issue
Block a user