From ed3eabb7e73b28bf6e76630cc11e0c19eb72b15e Mon Sep 17 00:00:00 2001 From: Tamir Atias Date: Wed, 1 Feb 2012 20:04:49 +0200 Subject: [PATCH] [Add] Improvements to level generation. --- Data/Media/Maps/map | 16 +-- Unuk-QT/Makefile | 152 ++++++++++++++-------------- Unuk-QT/Unuk-QT.pro.user | 2 +- src/Unuk/Game.cpp | 19 +++- src/Unuk/Game.h | 5 +- src/Unuk/Globals.cpp | 2 + src/Unuk/Globals.h | 4 + src/Unuk/Player.cpp | 7 ++ src/libUnuk/Engine/Character.cpp | 2 + src/libUnuk/Engine/WorldManager.cpp | 16 +++ src/libUnuk/Engine/WorldManager.h | 2 + src/libUnuk/LevelGen/LevelGen.cpp | 102 +++++++++++++------ src/libUnuk/LevelGen/LevelGen.h | 4 + 13 files changed, 210 insertions(+), 123 deletions(-) diff --git a/Data/Media/Maps/map b/Data/Media/Maps/map index 0e5b0cf..b4373b6 100644 --- a/Data/Media/Maps/map +++ b/Data/Media/Maps/map @@ -810,8 +810,8 @@ grass false - barrel - true + null + false 100 @@ -838,8 +838,8 @@ grass false - barrel - true + null + false 100 @@ -2041,8 +2041,8 @@ grass true - tree - true + null + false 100 @@ -2195,8 +2195,8 @@ grass false - tree - true + null + false 100 diff --git a/Unuk-QT/Makefile b/Unuk-QT/Makefile index 53827dd..dbe43f2 100644 --- a/Unuk-QT/Makefile +++ b/Unuk-QT/Makefile @@ -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 \ diff --git a/Unuk-QT/Unuk-QT.pro.user b/Unuk-QT/Unuk-QT.pro.user index 93d5b5a..5e42dc6 100644 --- a/Unuk-QT/Unuk-QT.pro.user +++ b/Unuk-QT/Unuk-QT.pro.user @@ -1,6 +1,6 @@ - + ProjectExplorer.Project.ActiveTarget diff --git a/src/Unuk/Game.cpp b/src/Unuk/Game.cpp index d8a78cc..a7efd55 100644 --- a/src/Unuk/Game.cpp +++ b/src/Unuk/Game.cpp @@ -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(); diff --git a/src/Unuk/Game.h b/src/Unuk/Game.h index aaf34f0..2895d77 100644 --- a/src/Unuk/Game.h +++ b/src/Unuk/Game.h @@ -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; @@ -28,7 +27,7 @@ public: ~Game(void); gameNavVal_t Run(const string savegameIDArg); - + private: void HandleInput(void); void UpdateGame(void); @@ -62,6 +61,4 @@ private: Text _playerExp; Bar _playerHealthBar; Bar _playerExpBar; - - EventHistory _eventHistory; }; diff --git a/src/Unuk/Globals.cpp b/src/Unuk/Globals.cpp index fbe29f4..0ad4ff3 100644 --- a/src/Unuk/Globals.cpp +++ b/src/Unuk/Globals.cpp @@ -10,6 +10,8 @@ int levelHeight; bool debugEnabled = true; +EventHistory* eventHistory = NULL; + int plrKeyUp; int plrKeyDown; int plrKeyeft; diff --git a/src/Unuk/Globals.h b/src/Unuk/Globals.h index 5945f65..bec022d 100644 --- a/src/Unuk/Globals.h +++ b/src/Unuk/Globals.h @@ -10,3 +10,7 @@ extern int levelWidth; extern int levelHeight; extern bool debugEnabled; + +class EventHistory; + +extern EventHistory* eventHistory; diff --git a/src/Unuk/Player.cpp b/src/Unuk/Player.cpp index f5d5fc9..eeb5ab5 100644 --- a/src/Unuk/Player.cpp +++ b/src/Unuk/Player.cpp @@ -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); } } diff --git a/src/libUnuk/Engine/Character.cpp b/src/libUnuk/Engine/Character.cpp index 879968f..b8b9f4e 100644 --- a/src/libUnuk/Engine/Character.cpp +++ b/src/libUnuk/Engine/Character.cpp @@ -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)) diff --git a/src/libUnuk/Engine/WorldManager.cpp b/src/libUnuk/Engine/WorldManager.cpp index 579184f..18b2fe4 100644 --- a/src/libUnuk/Engine/WorldManager.cpp +++ b/src/libUnuk/Engine/WorldManager.cpp @@ -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::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; } diff --git a/src/libUnuk/Engine/WorldManager.h b/src/libUnuk/Engine/WorldManager.h index dfa77e3..9225f41 100644 --- a/src/libUnuk/Engine/WorldManager.h +++ b/src/libUnuk/Engine/WorldManager.h @@ -15,6 +15,8 @@ public: void AddNPC(NPC* npc); void RemoveNPC(int index); NPC* GetNPC(int index); + + bool HasNPCIn(int xArg, int yArg); int GetNPCCount() { return _npcs.size(); } diff --git a/src/libUnuk/LevelGen/LevelGen.cpp b/src/libUnuk/LevelGen/LevelGen.cpp index e64d1ed..19ec206 100644 --- a/src/libUnuk/LevelGen/LevelGen.cpp +++ b/src/libUnuk/LevelGen/LevelGen.cpp @@ -132,28 +132,37 @@ void LevelGen::Load(const string filename) { //character->Load(filename); NPC* npc = new NPC(this); + + int spawnX; + int spawnY; - npc->SetXY(300, 300); + //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); - - 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", - }; - - 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) { + GenerateEntities("tree", 25); + GenerateEntities("hedge", 15); + GenerateEntities("barrel", 40); + MakeWalkingPaths(); +} + +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 < 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)); + + _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); - int texId = rand() % 5; - _tile[x][y].SetEntityTexture(_entityTextures.AddAlpha(entityTextures[texId])); + _tile[x][y].SetEntitySolidity(true); - _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); - - 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) { diff --git a/src/libUnuk/LevelGen/LevelGen.h b/src/libUnuk/LevelGen/LevelGen.h index 799a78a..eb81430 100644 --- a/src/libUnuk/LevelGen/LevelGen.h +++ b/src/libUnuk/LevelGen/LevelGen.h @@ -24,6 +24,8 @@ public: void Load(const string filename); void Update(void); void Render(void); + + void FindSpawnPoint(int& xArg, int& yArg); bool GetTileSolidity(int xArg, int yArg); int GetTileX(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;