[Add] Improvements to level generation.

This commit is contained in:
Tamir Atias 2012-02-01 20:04:49 +02:00
parent 50a948152d
commit ed3eabb7e7
13 changed files with 210 additions and 123 deletions

View File

@ -810,8 +810,8 @@
<tileTexture>grass</tileTexture>
<solidTile>false</solidTile>
<entityTexture>barrel</entityTexture>
<solidEntity>true</solidEntity>
<entityTexture>null</entityTexture>
<solidEntity>false</solidEntity>
<zLevel>100</zLevel>
@ -838,8 +838,8 @@
<tileTexture>grass</tileTexture>
<solidTile>false</solidTile>
<entityTexture>barrel</entityTexture>
<solidEntity>true</solidEntity>
<entityTexture>null</entityTexture>
<solidEntity>false</solidEntity>
<zLevel>100</zLevel>
@ -2041,8 +2041,8 @@
<tileTexture>grass</tileTexture>
<solidTile>true</solidTile>
<entityTexture>tree</entityTexture>
<solidEntity>true</solidEntity>
<entityTexture>null</entityTexture>
<solidEntity>false</solidEntity>
<zLevel>100</zLevel>
@ -2195,8 +2195,8 @@
<tileTexture>grass</tileTexture>
<solidTile>false</solidTile>
<entityTexture>tree</entityTexture>
<solidEntity>true</solidEntity>
<entityTexture>null</entityTexture>
<solidEntity>false</solidEntity>
<zLevel>100</zLevel>

View File

@ -1,25 +1,25 @@
#############################################################################
# Makefile for building: Unuk-QT
# Generated by qmake (2.01a) (Qt 4.7.4) on: Wed Feb 1 16:11:23 2012
# Generated by qmake (2.01a) (Qt 4.7.4) on: Wed Feb 1 19:59:14 2012
# 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
# Command: /home/kono/QtSDK/Desktop/Qt/474/gcc/bin/qmake -spec ../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/linux-g++ CONFIG+=debug -o Makefile Unuk-QT.pro
#############################################################################
####### Compiler, tools and options
CC = gcc
CXX = g++
DEFINES = -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED
DEFINES = -DQT_GUI_LIB -DQT_CORE_LIB
CFLAGS = -pipe -g -Wall -W -D_REENTRANT $(DEFINES)
CXXFLAGS = -pipe -g -Wall -W -D_REENTRANT $(DEFINES)
INCPATH = -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I.
INCPATH = -I../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/linux-g++ -I. -I../../../QtSDK/Desktop/Qt/474/gcc/include/QtCore -I../../../QtSDK/Desktop/Qt/474/gcc/include/QtGui -I../../../QtSDK/Desktop/Qt/474/gcc/include -I.
LINK = g++
LFLAGS =
LIBS = $(SUBLIBS) -L/usr/lib -lGL -lSDL -lSDL_ttf -lSDL_image -lSDL_gfx -ltinyxml -lGLU -lQtGui -lQtCore -lpthread
LFLAGS = -Wl,-rpath,/home/kono/QtSDK/Desktop/Qt/474/gcc/lib
LIBS = $(SUBLIBS) -L/home/kono/QtSDK/Desktop/Qt/474/gcc/lib -lGL -lSDL -lSDL_ttf -lSDL_image -lSDL_gfx -ltinyxml -lGLU -lQtGui -lQtCore -lpthread
AR = ar cqs
RANLIB =
QMAKE = /usr/bin/qmake-qt4
QMAKE = /home/kono/QtSDK/Desktop/Qt/474/gcc/bin/qmake
TAR = tar -cf
COMPRESS = gzip -9f
COPY = cp -f
@ -109,25 +109,26 @@ OBJECTS = WorldManager.o \
EventHistory.o \
Bar.o \
Vec2.o
DIST = /usr/share/qt4/mkspecs/common/g++.conf \
/usr/share/qt4/mkspecs/common/unix.conf \
/usr/share/qt4/mkspecs/common/linux.conf \
/usr/share/qt4/mkspecs/qconfig.pri \
/usr/share/qt4/mkspecs/features/qt_functions.prf \
/usr/share/qt4/mkspecs/features/qt_config.prf \
/usr/share/qt4/mkspecs/features/exclusive_builds.prf \
/usr/share/qt4/mkspecs/features/default_pre.prf \
/usr/share/qt4/mkspecs/features/debug.prf \
/usr/share/qt4/mkspecs/features/default_post.prf \
/usr/share/qt4/mkspecs/features/warn_on.prf \
/usr/share/qt4/mkspecs/features/qt.prf \
/usr/share/qt4/mkspecs/features/unix/thread.prf \
/usr/share/qt4/mkspecs/features/moc.prf \
/usr/share/qt4/mkspecs/features/resources.prf \
/usr/share/qt4/mkspecs/features/uic.prf \
/usr/share/qt4/mkspecs/features/yacc.prf \
/usr/share/qt4/mkspecs/features/lex.prf \
/usr/share/qt4/mkspecs/features/include_source_dir.prf \
DIST = ../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/common/g++.conf \
../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/common/unix.conf \
../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/common/linux.conf \
../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/qconfig.pri \
../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/modules/qt_webkit_version.pri \
../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/features/qt_functions.prf \
../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/features/qt_config.prf \
../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/features/exclusive_builds.prf \
../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/features/default_pre.prf \
../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/features/debug.prf \
../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/features/default_post.prf \
../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/features/warn_on.prf \
../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/features/qt.prf \
../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/features/unix/thread.prf \
../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/features/moc.prf \
../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/features/resources.prf \
../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/features/uic.prf \
../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/features/yacc.prf \
../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/features/lex.prf \
../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/features/include_source_dir.prf \
Unuk-QT.pro
QMAKE_TARGET = Unuk-QT
DESTDIR =
@ -160,51 +161,49 @@ all: Makefile $(TARGET)
$(TARGET): $(OBJECTS)
$(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJCOMP) $(LIBS)
Makefile: Unuk-QT.pro /usr/share/qt4/mkspecs/linux-g++/qmake.conf /usr/share/qt4/mkspecs/common/g++.conf \
/usr/share/qt4/mkspecs/common/unix.conf \
/usr/share/qt4/mkspecs/common/linux.conf \
/usr/share/qt4/mkspecs/qconfig.pri \
/usr/share/qt4/mkspecs/features/qt_functions.prf \
/usr/share/qt4/mkspecs/features/qt_config.prf \
/usr/share/qt4/mkspecs/features/exclusive_builds.prf \
/usr/share/qt4/mkspecs/features/default_pre.prf \
/usr/share/qt4/mkspecs/features/debug.prf \
/usr/share/qt4/mkspecs/features/default_post.prf \
/usr/share/qt4/mkspecs/features/warn_on.prf \
/usr/share/qt4/mkspecs/features/qt.prf \
/usr/share/qt4/mkspecs/features/unix/thread.prf \
/usr/share/qt4/mkspecs/features/moc.prf \
/usr/share/qt4/mkspecs/features/resources.prf \
/usr/share/qt4/mkspecs/features/uic.prf \
/usr/share/qt4/mkspecs/features/yacc.prf \
/usr/share/qt4/mkspecs/features/lex.prf \
/usr/share/qt4/mkspecs/features/include_source_dir.prf \
/usr/lib/libQtGui.prl \
/usr/lib/libQtCore.prl
$(QMAKE) -spec /usr/share/qt4/mkspecs/linux-g++ CONFIG+=debug -o Makefile Unuk-QT.pro
/usr/share/qt4/mkspecs/common/g++.conf:
/usr/share/qt4/mkspecs/common/unix.conf:
/usr/share/qt4/mkspecs/common/linux.conf:
/usr/share/qt4/mkspecs/qconfig.pri:
/usr/share/qt4/mkspecs/features/qt_functions.prf:
/usr/share/qt4/mkspecs/features/qt_config.prf:
/usr/share/qt4/mkspecs/features/exclusive_builds.prf:
/usr/share/qt4/mkspecs/features/default_pre.prf:
/usr/share/qt4/mkspecs/features/debug.prf:
/usr/share/qt4/mkspecs/features/default_post.prf:
/usr/share/qt4/mkspecs/features/warn_on.prf:
/usr/share/qt4/mkspecs/features/qt.prf:
/usr/share/qt4/mkspecs/features/unix/thread.prf:
/usr/share/qt4/mkspecs/features/moc.prf:
/usr/share/qt4/mkspecs/features/resources.prf:
/usr/share/qt4/mkspecs/features/uic.prf:
/usr/share/qt4/mkspecs/features/yacc.prf:
/usr/share/qt4/mkspecs/features/lex.prf:
/usr/share/qt4/mkspecs/features/include_source_dir.prf:
/usr/lib/libQtGui.prl:
/usr/lib/libQtCore.prl:
Makefile: Unuk-QT.pro ../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/linux-g++/qmake.conf ../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/common/g++.conf \
../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/common/unix.conf \
../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/common/linux.conf \
../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/qconfig.pri \
../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/modules/qt_webkit_version.pri \
../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/features/qt_functions.prf \
../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/features/qt_config.prf \
../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/features/exclusive_builds.prf \
../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/features/default_pre.prf \
../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/features/debug.prf \
../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/features/default_post.prf \
../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/features/warn_on.prf \
../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/features/qt.prf \
../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/features/unix/thread.prf \
../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/features/moc.prf \
../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/features/resources.prf \
../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/features/uic.prf \
../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/features/yacc.prf \
../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/features/lex.prf \
../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/features/include_source_dir.prf
$(QMAKE) -spec ../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/linux-g++ CONFIG+=debug -o Makefile Unuk-QT.pro
../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/common/g++.conf:
../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/common/unix.conf:
../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/common/linux.conf:
../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/qconfig.pri:
../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/modules/qt_webkit_version.pri:
../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/features/qt_functions.prf:
../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/features/qt_config.prf:
../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/features/exclusive_builds.prf:
../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/features/default_pre.prf:
../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/features/debug.prf:
../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/features/default_post.prf:
../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/features/warn_on.prf:
../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/features/qt.prf:
../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/features/unix/thread.prf:
../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/features/moc.prf:
../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/features/resources.prf:
../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/features/uic.prf:
../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/features/yacc.prf:
../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/features/lex.prf:
../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/features/include_source_dir.prf:
qmake: FORCE
@$(QMAKE) -spec /usr/share/qt4/mkspecs/linux-g++ CONFIG+=debug -o Makefile Unuk-QT.pro
@$(QMAKE) -spec ../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/linux-g++ CONFIG+=debug -o Makefile Unuk-QT.pro
dist:
@$(CHK_DIR_EXISTS) .tmp/Unuk-QT1.0.0 || $(MKDIR) .tmp/Unuk-QT1.0.0
@ -273,7 +272,8 @@ WorldManager.o: ../src/libUnuk/Engine/WorldManager.cpp ../src/libUnuk/Engine/Wor
../src/libUnuk/System/Rect.h \
../src/libUnuk/Engine/AStar.h \
../src/libUnuk/Engine/AStarBase.h \
../src/Unuk/Player.h
../src/Unuk/Player.h \
../src/libUnuk/UI/EventHistory.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o WorldManager.o ../src/libUnuk/Engine/WorldManager.cpp
ParticleEmitter.o: ../src/libUnuk/Engine/ParticleEmitter.cpp ../src/libUnuk/Engine/ParticleEmitter.h \
@ -489,7 +489,8 @@ Player.o: ../src/Unuk/Player.cpp ../src/Unuk/Player.h \
../src/libUnuk/UI/Text.h \
../src/libUnuk/UI/Font.h \
../src/libUnuk/UI/Bar.h \
../src/libUnuk/System/Rect.h
../src/libUnuk/System/Rect.h \
../src/libUnuk/UI/EventHistory.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o Player.o ../src/Unuk/Player.cpp
main.o: ../src/Unuk/main.cpp ../src/libUnuk/UI/MainMenu.h \
@ -523,8 +524,7 @@ main.o: ../src/Unuk/main.cpp ../src/libUnuk/UI/MainMenu.h \
../src/Unuk/Game.h \
../src/Unuk/Player.h \
../src/libUnuk/UI/IngameMenu.h \
../src/libUnuk/UI/ButtonToggle.h \
../src/libUnuk/UI/EventHistory.h
../src/libUnuk/UI/ButtonToggle.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o main.o ../src/Unuk/main.cpp
Globals.o: ../src/Unuk/Globals.cpp ../src/Unuk/Globals.h
@ -557,10 +557,10 @@ Game.o: ../src/Unuk/Game.cpp ../src/Unuk/Game.h \
../src/libUnuk/UI/Button.h \
../src/libUnuk/System/Input.h \
../src/libUnuk/UI/ButtonToggle.h \
../src/libUnuk/UI/EventHistory.h \
../src/libUnuk/Engine/NPC.h \
../src/libUnuk/Engine/AStar.h \
../src/libUnuk/Engine/AStarBase.h
../src/libUnuk/Engine/AStarBase.h \
../src/libUnuk/UI/EventHistory.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o Game.o ../src/Unuk/Game.cpp
LevelGen.o: ../src/libUnuk/LevelGen/LevelGen.cpp ../src/libUnuk/LevelGen/LevelGen.h \

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by Qt Creator 2.4.0, 2012-02-01T12:52:42. -->
<!-- Written by Qt Creator 2.4.0, 2012-02-01T20:01:14. -->
<qtcreator>
<data>
<variable>ProjectExplorer.Project.ActiveTarget</variable>

View File

@ -1,6 +1,8 @@
#include "Game.h"
#include "../libUnuk/Engine/NPC.h"
#include "../libUnuk/Engine/WorldManager.h"
#include "../Unuk/Globals.h"
#include "../libUnuk/UI/EventHistory.h"
Game::Game(void) {
Debug::logger->message("Creating characters..");
@ -16,8 +18,12 @@ Game::~Game(void) {
}
gameNavVal_t Game::Run(const string savegameIDArg) {
_player->SetXY(50, 50);
_player->LoadSprites("../Data/Media/Images/Characters/Player.png", 40, 45);
int spawnX;
int spawnY;
_map.FindSpawnPoint(spawnX, spawnY);
_player->SetXY(spawnX*64, spawnY*64);
_player->LoadSprites("../Data/Media/Images/Characters/Player.png", 40, 45);
LoadSavegame(savegameIDArg);
@ -70,6 +76,8 @@ gameNavVal_t Game::Run(const string savegameIDArg) {
_playerExp.SetXY(15, 57);
_playerExp.SetTextBlended("Player Level XX (XX/XX)", vsmall, COLOUR_WHITE);
eventHistory = new EventHistory();
_gameRunning = true;
while(_gameRunning) {
bool stillRunning = true;
@ -152,6 +160,9 @@ gameNavVal_t Game::Run(const string savegameIDArg) {
frameTimer.Start();
frame++;
}
delete eventHistory;
return _runGameReturnValue;
}
@ -166,7 +177,7 @@ void Game::HandleInput(void) {
if(event.key.keysym.sym == SDLK_p)
debugEnabled = !debugEnabled;
if(event.key.keysym.sym == SDLK_0)
_eventHistory.LogEvent("Item gained.");
eventHistory->LogEvent("Item gained.");
}
else if(event.type == SDL_QUIT) {
_gameRunning = false;
@ -235,7 +246,7 @@ void Game::Render(void) {
_npcHealth.RenderLiteral();
}
_eventHistory.Render();
eventHistory->Render();
} else {
_ingameMenu.Render();

View File

@ -16,7 +16,6 @@
#include "../libUnuk/System/Debug.h"
#include "../libUnuk/UI/Text.h"
#include "../libUnuk/UI/Bar.h"
#include "../libUnuk/UI/EventHistory.h"
#include "../libUnuk/Engine/MemClass.h"
using namespace std;
@ -62,6 +61,4 @@ private:
Text _playerExp;
Bar _playerHealthBar;
Bar _playerExpBar;
EventHistory _eventHistory;
};

View File

@ -10,6 +10,8 @@ int levelHeight;
bool debugEnabled = true;
EventHistory* eventHistory = NULL;
int plrKeyUp;
int plrKeyDown;
int plrKeyeft;

View File

@ -10,3 +10,7 @@ extern int levelWidth;
extern int levelHeight;
extern bool debugEnabled;
class EventHistory;
extern EventHistory* eventHistory;

View File

@ -1,4 +1,6 @@
#include "Player.h"
#include "Globals.h"
#include "../libUnuk/UI/EventHistory.h"
// Pixels * 60 / sec.
const float Player::PLAYER_SPEED = Character::CHARACTER_SPEED + 0.5f;
@ -117,8 +119,13 @@ void Player::SetLevel(int level) {
}
void Player::SetExp(int exp) {
std::stringstream evtMsg;
evtMsg << "Gained " << exp << " Experience Points.";
eventHistory->LogEvent(evtMsg.str());
_exp += exp;
if(_exp >= _expNeeded) {
eventHistory->LogEvent("Player leveled up!");
SetLevel(_level + 1);
}
}

View File

@ -185,6 +185,8 @@ void Character::Move(void) {
* if any other map method is used in a similar manner.
*/
bool Character::CheckTileCollisions(void) {
tileX = x / 64;
tileY = y / 64;
for(int i = -1; i < 2; i++) {
for(int j = -1; j < 2; j++) {
if(map->GetTileSolidity(tileX + i, tileY + j))

View File

@ -1,6 +1,8 @@
#include "WorldManager.h"
#include "NPC.h"
#include "../../Unuk/Player.h"
#include "../../Unuk/Globals.h"
#include "../UI/EventHistory.h"
WorldManager::WorldManager(void) {
}
@ -54,6 +56,17 @@ NPC* WorldManager::GetNPC(int index) {
return NULL;
}
bool WorldManager::HasNPCIn(int xArg, int yArg) {
for(std::list<NPC*>::iterator i = _npcs.begin(); i != _npcs.end(); ++i) {
NPC* npc = (*i);
if(xArg >= npc->GetX() && xArg <= (npc->GetX() + npc->GetWidth()) &&
yArg >= npc->GetY() && yArg <= (npc->GetY() + npc->GetHeight())) {
return true;
}
}
return false;
}
void WorldManager::OnPlayerAttack(Player* player) {
int playerX = (int)(player->GetX() / 32.0f);
int playerY = (int)(player->GetY() / 32.0f);
@ -96,8 +109,11 @@ void WorldManager::OnPlayerAttack(Player* player) {
npc->OnAttack();
if(npc->GetHealth() <= 0) {
eventHistory->LogEvent("Killed Bald Naked Dude!");
int expGain = 3 + (rand() % 2);
player->SetExp(player->GetExp() + expGain);
i = _npcs.erase(i);
delete npc;
}

View File

@ -16,6 +16,8 @@ public:
void RemoveNPC(int index);
NPC* GetNPC(int index);
bool HasNPCIn(int xArg, int yArg);
int GetNPCCount() { return _npcs.size(); }
void OnPlayerAttack(Player* player);

View File

@ -133,27 +133,36 @@ void LevelGen::Load(const string filename) {
NPC* npc = new NPC(this);
npc->SetXY(300, 300);
int spawnX;
int spawnY;
//FindSpawnPoint(spawnX, spawnY);
//npc->SetXY(spawnX, spawnY); // try to uncomment this, try to find out what's going on.. --konom
npc->SetXY(100, 200);
npc->LoadSprites("../Data/Media/Images/Characters/template.png", 40,45);
_world.AddNPC(npc);
npc = new NPC(this);
npc->SetXY(150, 350);
//FindSpawnPoint(spawnX, spawnY);
npc->SetXY(300, 250);
npc->LoadSprites("../Data/Media/Images/Characters/template.png", 40,45);
_world.AddNPC(npc);
npc = new NPC(this);
npc->SetXY(100, 250);
//FindSpawnPoint(spawnX, spawnY);
npc->SetXY(400, 100);
npc->LoadSprites("../Data/Media/Images/Characters/template.png", 40,45);
_world.AddNPC(npc);
npc = new NPC(this);
npc->SetXY(170, 250);
//FindSpawnPoint(spawnX, spawnY);
npc->SetXY(200, 400);
npc->LoadSprites("../Data/Media/Images/Characters/template.png", 40,45);
_world.AddNPC(npc);
npc = new NPC(this);
npc->SetXY(170, 230);
//FindSpawnPoint(spawnX, spawnY);
npc->SetXY(250, 250);
npc->LoadSprites("../Data/Media/Images/Characters/template.png", 40,45);
_world.AddNPC(npc);
}
@ -208,34 +217,67 @@ void LevelGen::Unload(void) {
}
void LevelGen::DoMagic(void) {
int nextEntityGen = 1 + (rand() % 20);
GenerateEntities("tree", 25);
GenerateEntities("hedge", 15);
GenerateEntities("barrel", 40);
MakeWalkingPaths();
}
const char* entityTextures[6] = {
"../Data/Media/Images/Entities/tree.png",
"../Data/Media/Images/Entities/hedge.png",
"../Data/Media/Images/Entities/barrel.png",
"../Data/Media/Images/Entities/closedChest.png",
"../Data/Media/Images/Entities/closedChestMetal.png",
"../Data/Media/Images/Entities/closedChestMetal2.png",
};
void LevelGen::GenerateEntities(const string& name, int frequency) {
int nextEntityGen = 1 + (rand() % frequency);
std::string filename = "../Data/Media/Images/Entities/" + name + ".png";
for(int x = 0; x < TILE_ARRAY_SIZE; x++) {
for(int y = 0; y < TILE_ARRAY_SIZE; y++) {
nextEntityGen--;
if(!_tile[x][y].GetTileSolidity() && nextEntityGen <= 0) {
for(int x = 0; x < SCREEN_WIDTH/64 + 1; x++) {
for(int y = 0; y < SCREEN_HEIGHT/64; y++) {
nextEntityGen--;
if(!_tile[x][y].GetTileSolidity() && !_tile[x][y].GetEntitySolitity() && nextEntityGen <= 0) {
_tile[x][y].SetEntityTexture(_entityTextures.AddAlpha(filename));
int texId = rand() % 5;
_tile[x][y].SetEntityTexture(_entityTextures.AddAlpha(entityTextures[texId]));
_tile[x][y].SetEntityXY(_tile[x][y].GetTileX() + TILE_WIDTH / 2 - _tile[x][y].GetEntityWidth() / 2,
_tile[x][y].GetTileY() + TILE_HEIGHT / 2 - _tile[x][y].GetEntityHeight() / 2);
_tile[x][y].SetEntityXY(_tile[x][y].GetTileX() + TILE_WIDTH / 2 - _tile[x][y].GetEntityWidth() / 2,
_tile[x][y].GetTileY() + TILE_HEIGHT / 2 - _tile[x][y].GetEntityHeight() / 2);
_tile[x][y].SetEntitySolidity(true);
_tile[x][y].SetEntitySolidity(true);
nextEntityGen = 1 + (rand() % 10);
}
}
nextEntityGen = 1 + (rand() % frequency);
}
}
}
}
void LevelGen::MakeWalkingPaths(void) {
int lastOpenY = rand() % 5;
for(int x = 0; x < SCREEN_WIDTH/64 + 1; x++) {
bool pathFound = false;
for(int y = 0; y < SCREEN_HEIGHT/64; y++) {
if(!_tile[x][y].GetEntitySolitity()) {
pathFound = true;
break;
} else {
lastOpenY = y;
}
}
if(!pathFound) {
_tile[x][lastOpenY].SetEntityTexture(NULL);
_tile[x][lastOpenY].SetEntitySolidity(false);
}
}
}
void LevelGen::FindSpawnPoint(int& xArg, int& yArg) {
xArg = rand() % SCREEN_WIDTH;
yArg = rand() % SCREEN_HEIGHT;
int tileX = xArg / 64;
int tileY = yArg / 64;
if(!_tile[tileX][tileY].GetEntitySolitity() && !_world.HasNPCIn(xArg, yArg)) {
return;
}
FindSpawnPoint(xArg, yArg);
}
string LevelGen::GetCurrentMap(void) {

View File

@ -25,6 +25,8 @@ public:
void Update(void);
void Render(void);
void FindSpawnPoint(int& xArg, int& yArg);
bool GetTileSolidity(int xArg, int yArg);
int GetTileX(int xArg, int yArg);
int GetTileY(int xArg, int yArg);
@ -48,6 +50,8 @@ public:
private:
void Unload(void);
void DoMagic(void);
void GenerateEntities(const std::string& name, int frequency);
void MakeWalkingPaths(void);
string _currentMap;
int x;