[Add] Warps.
[Add] Map is now centered when smaller than screen size.
This commit is contained in:
parent
efb695e973
commit
1c37fb6344
@ -99,6 +99,7 @@
|
|||||||
<ClInclude Include="..\..\src\Level\Level.h" />
|
<ClInclude Include="..\..\src\Level\Level.h" />
|
||||||
<ClInclude Include="..\..\src\Level\MapTile.h" />
|
<ClInclude Include="..\..\src\Level\MapTile.h" />
|
||||||
<ClInclude Include="..\..\src\Level\Tileset.h" />
|
<ClInclude Include="..\..\src\Level\Tileset.h" />
|
||||||
|
<ClInclude Include="..\..\Src\Level\Warp.h" />
|
||||||
<ClInclude Include="..\..\src\Main\Game.h" />
|
<ClInclude Include="..\..\src\Main\Game.h" />
|
||||||
<ClInclude Include="..\..\src\Main\TitleScreen.h" />
|
<ClInclude Include="..\..\src\Main\TitleScreen.h" />
|
||||||
<ClInclude Include="..\..\src\Math\FPS.h" />
|
<ClInclude Include="..\..\src\Math\FPS.h" />
|
||||||
@ -182,6 +183,11 @@
|
|||||||
<Project>{b4a2ecf2-d1e0-4e73-a59f-bcce49c37cc6}</Project>
|
<Project>{b4a2ecf2-d1e0-4e73-a59f-bcce49c37cc6}</Project>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClCompile Include="..\..\Src\Level\Warp.cpp">
|
||||||
|
<FileType>Document</FileType>
|
||||||
|
</ClCompile>
|
||||||
|
</ItemGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
<ImportGroup Label="ExtensionTargets">
|
<ImportGroup Label="ExtensionTargets">
|
||||||
</ImportGroup>
|
</ImportGroup>
|
||||||
|
@ -195,6 +195,9 @@
|
|||||||
<ClInclude Include="..\..\src\UI\Menu.h">
|
<ClInclude Include="..\..\src\UI\Menu.h">
|
||||||
<Filter>UI</Filter>
|
<Filter>UI</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\Src\Level\Warp.h">
|
||||||
|
<Filter>Level</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="..\..\src\Main\main.cpp">
|
<ClCompile Include="..\..\src\Main\main.cpp">
|
||||||
@ -317,5 +320,8 @@
|
|||||||
<ClCompile Include="..\..\src\UI\Menu.cpp">
|
<ClCompile Include="..\..\src\UI\Menu.cpp">
|
||||||
<Filter>UI</Filter>
|
<Filter>UI</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\Src\Level\Warp.cpp">
|
||||||
|
<Filter>Level</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
BIN
Data/Img/OpenArt/woodland_indoor_0.png
Normal file
BIN
Data/Img/OpenArt/woodland_indoor_0.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.0 MiB |
@ -57,11 +57,18 @@
|
|||||||
eJztl8ESwyAIRJP//+leemA6oIC7BhvejIemlV0QNb2upir3d2TnZeYyyHi5lYHWYsaWc5ha2TpFNFZ0Inn86jCY5SGf7exbK8bMm/xs/darZ3lA1yGSR0ZzpI/cvzvy8PiIxNR8ovaaxxsrDxSM+LP9dSnfIzQ1ndWY6L70ajLy0OqP0rHOCkadGHW3YiPvHQZe/dH6R+Iw8Xiovh5VPEiifrS9m723VkF4qNDj/5AHsi+eXgvpRT47ich6sOu9Yz13vEecmAdDI3IXN03TNE3zHqz3z9GoSOa/cUVOywPVJ5m5qJ5k9XamBitarF5YzaPK+RLVP+n8a5rmnXwA7bUBUA==
|
eJztl8ESwyAIRJP//+leemA6oIC7BhvejIemlV0QNb2upir3d2TnZeYyyHi5lYHWYsaWc5ha2TpFNFZ0Inn86jCY5SGf7exbK8bMm/xs/darZ3lA1yGSR0ZzpI/cvzvy8PiIxNR8ovaaxxsrDxSM+LP9dSnfIzQ1ndWY6L70ajLy0OqP0rHOCkadGHW3YiPvHQZe/dH6R+Iw8Xiovh5VPEiifrS9m723VkF4qNDj/5AHsi+eXgvpRT47ich6sOu9Yz13vEecmAdDI3IXN03TNE3zHqz3z9GoSOa/cUVOywPVJ5m5qJ5k9XamBitarF5YzaPK+RLVP+n8a5rmnXwA7bUBUA==
|
||||||
</data>
|
</data>
|
||||||
</layer>
|
</layer>
|
||||||
<objectgroup name="NPCs" width="50" height="50">
|
<objectgroup name="Events" width="50" height="50">
|
||||||
<object name="NPC!!!" type="NPC" x="544" y="320" width="32" height="32">
|
<object name="NPC!!!" type="NPC" x="544" y="320" width="32" height="32">
|
||||||
<properties>
|
<properties>
|
||||||
<property name="image" value="Player"/>
|
<property name="image" value="Player"/>
|
||||||
</properties>
|
</properties>
|
||||||
</object>
|
</object>
|
||||||
|
<object name="Warp to house" type="warp" x="605" y="188" width="34" height="59">
|
||||||
|
<properties>
|
||||||
|
<property name="map" value="../Data/Map/house.tmx"/>
|
||||||
|
<property name="x" value="7"/>
|
||||||
|
<property name="y" value="13"/>
|
||||||
|
</properties>
|
||||||
|
</object>
|
||||||
</objectgroup>
|
</objectgroup>
|
||||||
</map>
|
</map>
|
||||||
|
38
Data/Map/house.tmx
Normal file
38
Data/Map/house.tmx
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<map version="1.0" orientation="orthogonal" width="15" height="15" tilewidth="32" tileheight="32">
|
||||||
|
<tileset firstgid="1" name="woodland_indoor_0" tilewidth="32" tileheight="32">
|
||||||
|
<image source="../Img/OpenArt/woodland_indoor_0.png" width="512" height="512"/>
|
||||||
|
</tileset>
|
||||||
|
<tileset firstgid="257" name="CollisionTileset" tilewidth="32" tileheight="32">
|
||||||
|
<image source="../Img/CollisionTileset.png" width="32" height="32"/>
|
||||||
|
</tileset>
|
||||||
|
<layer name="Layer 1" width="15" height="15">
|
||||||
|
<data encoding="base64" compression="zlib">
|
||||||
|
eJy10dEJgDAMBNDrCI5gZtFOou4/gvGvHHc1flh4EEJC4dIANALRUxYBps9WAabPQoDpV1R3xxdUvxlzC6pn/3CeQTXv8Y04N5ehumc1vy+zzN3zb9W7Pba0pz7Zde9IZ7omMzc2PRZ3
|
||||||
|
</data>
|
||||||
|
</layer>
|
||||||
|
<layer name="Layer 2" width="15" height="15">
|
||||||
|
<data encoding="base64" compression="zlib">
|
||||||
|
eJxjYEAFzAz4gRwQywOxApR/DojPA/EFIBYmoFcPiPWB2ADKvwfE94H4AQF92PS+A+L3ROjDpvcfEP8nUu8oYGBoAeJWIG7Do2YpGgaBg0A8BYinAvE0ID5Mgp0gvUugZi0jUe9QAwA5/BXY
|
||||||
|
</data>
|
||||||
|
</layer>
|
||||||
|
<layer name="Layer 3" width="15" height="15">
|
||||||
|
<data encoding="base64" compression="zlib">
|
||||||
|
eJxjYBheQAWIVcnUawLEplR0CzLgAWJeMvXKALEsFd1CT7AciDuAuGugHTKIAQBabAK+
|
||||||
|
</data>
|
||||||
|
</layer>
|
||||||
|
<layer name="Collision" width="15" height="15">
|
||||||
|
<data encoding="base64" compression="zlib">
|
||||||
|
eJxjZGRgYCQRgwCpetD1IgNc4vjUIJtHql5c8oQArjCgtl5iw54YfcQCWugdKPcQaz419eKLL0JqAIUTAME=
|
||||||
|
</data>
|
||||||
|
</layer>
|
||||||
|
<objectgroup name="Events" width="15" height="15">
|
||||||
|
<object name="Warp to village" type="warp" x="210" y="433" width="61" height="34">
|
||||||
|
<properties>
|
||||||
|
<property name="map" value="../Data/Map/Ugly.tmx"/>
|
||||||
|
<property name="x" value="19"/>
|
||||||
|
<property name="y" value="7"/>
|
||||||
|
</properties>
|
||||||
|
</object>
|
||||||
|
</objectgroup>
|
||||||
|
</map>
|
@ -4,7 +4,7 @@
|
|||||||
#include "../Sound/SoundEffect.h"
|
#include "../Sound/SoundEffect.h"
|
||||||
#include "../Level/Level.h"
|
#include "../Level/Level.h"
|
||||||
|
|
||||||
Actor::Actor(const Level* level) {
|
Actor::Actor(Level* level) {
|
||||||
_level = level;
|
_level = level;
|
||||||
|
|
||||||
_stepSFX[0] = sfxManager.Load("../Data/SFX/step_cloth1.wav");
|
_stepSFX[0] = sfxManager.Load("../Data/SFX/step_cloth1.wav");
|
||||||
@ -16,6 +16,7 @@ Actor::Actor(const Level* level) {
|
|||||||
_velocity = 4.0f;
|
_velocity = 4.0f;
|
||||||
_direction = FRONT;
|
_direction = FRONT;
|
||||||
_preventMovement = NONE;
|
_preventMovement = NONE;
|
||||||
|
_distanceTraveled = 0;
|
||||||
|
|
||||||
x = 0.0f;
|
x = 0.0f;
|
||||||
y = 0.0f;
|
y = 0.0f;
|
||||||
@ -62,6 +63,10 @@ void Actor::Update(float dt) {
|
|||||||
float collisionYOffset = GetMaxHeight() / 2.0f;
|
float collisionYOffset = GetMaxHeight() / 2.0f;
|
||||||
|
|
||||||
if(x != oldX || y != oldY) {
|
if(x != oldX || y != oldY) {
|
||||||
|
float dx = x - oldX;
|
||||||
|
float dy = y - oldY;
|
||||||
|
_distanceTraveled += sqrtf(dx*dx + dy*dy);
|
||||||
|
|
||||||
if(_level->CheckCollision(x, y + collisionYOffset, GetAnimation()->GetMaxWidth(), GetAnimation()->GetMaxHeight() - collisionYOffset)) {
|
if(_level->CheckCollision(x, y + collisionYOffset, GetAnimation()->GetMaxWidth(), GetAnimation()->GetMaxHeight() - collisionYOffset)) {
|
||||||
x = oldX;
|
x = oldX;
|
||||||
y = oldY;
|
y = oldY;
|
||||||
|
@ -24,9 +24,11 @@ public:
|
|||||||
HURT
|
HURT
|
||||||
};
|
};
|
||||||
|
|
||||||
Actor(const Level* level);
|
Actor(Level* level);
|
||||||
~Actor(void);
|
~Actor(void);
|
||||||
|
|
||||||
|
void SetLevel(Level* level) { _level = level; }
|
||||||
|
|
||||||
void LoadSprites(const String& basename);
|
void LoadSprites(const String& basename);
|
||||||
|
|
||||||
virtual void Update(float dt);
|
virtual void Update(float dt);
|
||||||
@ -50,7 +52,7 @@ protected:
|
|||||||
|
|
||||||
AnimatingSprite* GetAnimation(void);
|
AnimatingSprite* GetAnimation(void);
|
||||||
|
|
||||||
const Level* _level;
|
Level* _level;
|
||||||
|
|
||||||
float _velocity;
|
float _velocity;
|
||||||
|
|
||||||
@ -62,6 +64,8 @@ protected:
|
|||||||
Facing _direction;
|
Facing _direction;
|
||||||
Facing _preventMovement;
|
Facing _preventMovement;
|
||||||
|
|
||||||
|
float _distanceTraveled;
|
||||||
|
|
||||||
float x;
|
float x;
|
||||||
float y;
|
float y;
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#include "NPC.h"
|
#include "NPC.h"
|
||||||
|
|
||||||
NPC::NPC(const Level* level) : Actor(level) {
|
NPC::NPC(Level* level) : Actor(level) {
|
||||||
}
|
}
|
||||||
|
|
||||||
NPC::~NPC(void) {
|
NPC::~NPC(void) {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
class NPC : public Actor {
|
class NPC : public Actor {
|
||||||
public:
|
public:
|
||||||
NPC(const Level* level);
|
NPC(Level* level);
|
||||||
~NPC(void);
|
~NPC(void);
|
||||||
|
|
||||||
void Update(float dt);
|
void Update(float dt);
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
#include "Player.h"
|
#include "Player.h"
|
||||||
#include "../IO/Input.h"
|
#include "../IO/Input.h"
|
||||||
|
#include "../Level/Level.h"
|
||||||
|
#include "../Level/Warp.h"
|
||||||
|
#include "../Main/Game.h"
|
||||||
|
|
||||||
Player::Player(const Level* level) : Actor(level) {
|
Player::Player(Level* level) : Actor(level) {
|
||||||
_direction = Actor::RIGHT;
|
_direction = Actor::RIGHT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -10,6 +13,14 @@ Player::~Player(void) {
|
|||||||
|
|
||||||
void Player::Update(float dt) {
|
void Player::Update(float dt) {
|
||||||
Actor::Update(dt);
|
Actor::Update(dt);
|
||||||
|
|
||||||
|
if(_distanceTraveled > 32.0f) {
|
||||||
|
Warp* warp = _level->CheckWarp(x, y, GetMaxWidth(), GetMaxHeight());
|
||||||
|
if(warp) {
|
||||||
|
_level->GetGame()->Warp(warp->GetTargetMap(), warp->GetTargetX(), warp->GetTargetY());
|
||||||
|
_distanceTraveled = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::Render(void) {
|
void Player::Render(void) {
|
||||||
|
@ -9,7 +9,7 @@ class Level;
|
|||||||
|
|
||||||
class Player : public Actor{
|
class Player : public Actor{
|
||||||
public:
|
public:
|
||||||
Player(const Level* level);
|
Player(Level* level);
|
||||||
~Player(void);
|
~Player(void);
|
||||||
|
|
||||||
void Update(float dt);
|
void Update(float dt);
|
||||||
|
@ -4,10 +4,12 @@
|
|||||||
#include "Level.h"
|
#include "Level.h"
|
||||||
#include "Layer.h"
|
#include "Layer.h"
|
||||||
#include "Tileset.h"
|
#include "Tileset.h"
|
||||||
|
#include "Warp.h"
|
||||||
#include "../Sound/Music.h"
|
#include "../Sound/Music.h"
|
||||||
#include "../System/Debug.h"
|
#include "../System/Debug.h"
|
||||||
#include "../TMXParser/Tmx.h"
|
#include "../TMXParser/Tmx.h"
|
||||||
#include "../Actor/NPC.h"
|
#include "../Actor/NPC.h"
|
||||||
|
#include "../Math/Rect.h"
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#ifndef strcasecmp
|
#ifndef strcasecmp
|
||||||
@ -18,7 +20,8 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Level::Level() {
|
Level::Level(Game* game) {
|
||||||
|
_game = game;
|
||||||
_width = 0;
|
_width = 0;
|
||||||
_height = 0;
|
_height = 0;
|
||||||
_tileWidth = 0;
|
_tileWidth = 0;
|
||||||
@ -41,7 +44,12 @@ Level::~Level() {
|
|||||||
for(std::list<NPC*>::iterator i = _npcs.begin(); i != _npcs.end(); ++i) {
|
for(std::list<NPC*>::iterator i = _npcs.begin(); i != _npcs.end(); ++i) {
|
||||||
delete (*i);
|
delete (*i);
|
||||||
}
|
}
|
||||||
_npcs.end();
|
_npcs.clear();
|
||||||
|
|
||||||
|
for(std::list<Warp*>::iterator i = _warps.begin(); i != _warps.end(); ++i) {
|
||||||
|
delete (*i);
|
||||||
|
}
|
||||||
|
_warps.clear();
|
||||||
|
|
||||||
if(_collisions) {
|
if(_collisions) {
|
||||||
delete[] _collisions;
|
delete[] _collisions;
|
||||||
@ -134,6 +142,15 @@ bool Level::Load(const std::string& filename) {
|
|||||||
npc->SetXY(tmxObject->GetX(), tmxObject->GetY());
|
npc->SetXY(tmxObject->GetX(), tmxObject->GetY());
|
||||||
_npcs.push_back(npc);
|
_npcs.push_back(npc);
|
||||||
}
|
}
|
||||||
|
else if(!strncasecmp(tmxObject->GetName().c_str(), "Warp", 4)) {
|
||||||
|
Warp* warp = new Warp();
|
||||||
|
warp->SetXY(tmxObject->GetX(), tmxObject->GetY());
|
||||||
|
warp->SetWidthHeight(tmxObject->GetWidth(), tmxObject->GetHeight());
|
||||||
|
warp->SetTargetMap(tmxObject->GetProperties().GetLiteralProperty("map").c_str());
|
||||||
|
warp->SetTargetX(tmxObject->GetProperties().GetNumericProperty("x") * 32);
|
||||||
|
warp->SetTargetY(tmxObject->GetProperties().GetNumericProperty("y") * 32);
|
||||||
|
_warps.push_back(warp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,8 +189,8 @@ void Level::Draw(int xOffset, int yOffset) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool Level::CheckCollision(float x, float y, float w, float h) const {
|
bool Level::CheckCollision(float x, float y, float w, float h) const {
|
||||||
if(x < 0.0f || x > (float)(_width * _tileWidth) ||
|
if(x < 0.0f || x >= (float)((_width - 1) * _tileWidth) ||
|
||||||
y < 0.0f || y > (float)(_height * _tileHeight)) {
|
y < 0.0f || y >= (float)((_height - 1) * _tileHeight)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -222,3 +239,17 @@ bool Level::CheckCollision(float x, float y, float w, float h) const {
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Warp* Level::CheckWarp(float x, float y, float w, float h) const {
|
||||||
|
Rect objectArea(x, y, w, h);
|
||||||
|
for(std::list<Warp*>::const_iterator i = _warps.cbegin(); i != _warps.cend(); ++i) {
|
||||||
|
Warp* warp = (*i);
|
||||||
|
Rect warpArea(
|
||||||
|
warp->GetX(), warp->GetY(),
|
||||||
|
warp->GetWidth(), warp->GetHeight());
|
||||||
|
if(warpArea.CollidesWith(objectArea)) {
|
||||||
|
return warp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
@ -3,31 +3,37 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
|
||||||
|
class Game;
|
||||||
class Layer;
|
class Layer;
|
||||||
class Tileset;
|
class Tileset;
|
||||||
class Music;
|
class Music;
|
||||||
class NPC;
|
class NPC;
|
||||||
|
class Warp;
|
||||||
|
|
||||||
class Level {
|
class Level {
|
||||||
public:
|
public:
|
||||||
Level();
|
Level(Game* game);
|
||||||
~Level();
|
~Level(void);
|
||||||
|
|
||||||
bool Load(const std::string& filename);
|
bool Load(const std::string& filename);
|
||||||
|
|
||||||
void PlayBGM();
|
void PlayBGM(void);
|
||||||
|
|
||||||
void Update(float dt);
|
void Update(float dt);
|
||||||
void Draw(int xOffset, int yOffset);
|
void Draw(int xOffset, int yOffset);
|
||||||
|
|
||||||
|
Game* GetGame() { return _game; }
|
||||||
|
|
||||||
int GetWidth() const { return _width; }
|
int GetWidth() const { return _width; }
|
||||||
int GetHeight() const { return _height; }
|
int GetHeight() const { return _height; }
|
||||||
int GetTileWidth() const { return _tileWidth; }
|
int GetTileWidth() const { return _tileWidth; }
|
||||||
int GetTileHeight() const { return _tileHeight; }
|
int GetTileHeight() const { return _tileHeight; }
|
||||||
|
|
||||||
bool CheckCollision(float x, float y, float w, float h) const;
|
bool CheckCollision(float x, float y, float w, float h) const;
|
||||||
|
Warp* CheckWarp(float x, float y, float w, float h) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Game* _game;
|
||||||
int _width;
|
int _width;
|
||||||
int _height;
|
int _height;
|
||||||
int _tileWidth;
|
int _tileWidth;
|
||||||
@ -35,6 +41,7 @@ private:
|
|||||||
std::list<Layer*> _layers;
|
std::list<Layer*> _layers;
|
||||||
std::list<Tileset*> _tilesets;
|
std::list<Tileset*> _tilesets;
|
||||||
std::list<NPC*> _npcs;
|
std::list<NPC*> _npcs;
|
||||||
|
std::list<Warp*> _warps;
|
||||||
Music* _bgm;
|
Music* _bgm;
|
||||||
bool* _collisions;
|
bool* _collisions;
|
||||||
};
|
};
|
||||||
|
11
src/Level/Warp.cpp
Normal file
11
src/Level/Warp.cpp
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#include "Warp.h"
|
||||||
|
|
||||||
|
Warp::Warp(void) {
|
||||||
|
x = 0;
|
||||||
|
y = 0;
|
||||||
|
w = 0;
|
||||||
|
h = 0;
|
||||||
|
_targetMap = "";
|
||||||
|
_targetX = 0;
|
||||||
|
_targetY = 0;
|
||||||
|
}
|
39
src/Level/Warp.h
Normal file
39
src/Level/Warp.h
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "../System/String.h"
|
||||||
|
#include "../Math/Vec2.h"
|
||||||
|
|
||||||
|
class Warp {
|
||||||
|
public:
|
||||||
|
Warp(void);
|
||||||
|
|
||||||
|
int GetX(void) const { return x; }
|
||||||
|
int GetY(void) const { return y; }
|
||||||
|
int GetWidth(void) const { return w; }
|
||||||
|
int GetHeight(void) const { return h; }
|
||||||
|
void SetX(int x) { this->x = x; }
|
||||||
|
void SetY(int y) { this->y = y; }
|
||||||
|
void SetXY(int x, int y) { SetX(x); SetY(y); }
|
||||||
|
void SetWidth(int w) { this->w = w; }
|
||||||
|
void SetHeight(int h) { this->h = h;}
|
||||||
|
void SetWidthHeight(int w, int h) { SetWidth(w); SetHeight(h); }
|
||||||
|
|
||||||
|
const String& GetTargetMap() const { return _targetMap;}
|
||||||
|
void SetTargetMap(const String& targetMap) { _targetMap = targetMap; }
|
||||||
|
|
||||||
|
int GetTargetX(void) const { return _targetX; }
|
||||||
|
int GetTargetY(void) const { return _targetY; }
|
||||||
|
void SetTargetX(int targetX) { _targetX = targetX; }
|
||||||
|
void SetTargetY(int targetY) { _targetY = targetY; }
|
||||||
|
void SetTargetXY(int targetX, int targetY) { SetTargetX(targetX); SetTargetY(targetY); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
int x;
|
||||||
|
int y;
|
||||||
|
int w;
|
||||||
|
int h;
|
||||||
|
|
||||||
|
String _targetMap;
|
||||||
|
int _targetX;
|
||||||
|
int _targetY;
|
||||||
|
};
|
@ -22,11 +22,8 @@
|
|||||||
#include "TitleScreen.h"
|
#include "TitleScreen.h"
|
||||||
|
|
||||||
Game::Game(void) {
|
Game::Game(void) {
|
||||||
_level = new Level();
|
_level = new Level(this);
|
||||||
_player = new Player(_level);
|
_player = new Player(_level);
|
||||||
_NPC = new NPC(_level);
|
|
||||||
|
|
||||||
_NPC->SetXY(30.0f, 30.0f);
|
|
||||||
|
|
||||||
_testFont = new Font();
|
_testFont = new Font();
|
||||||
|
|
||||||
@ -72,7 +69,6 @@ void Game::Render(void) {
|
|||||||
void Game::Shutdown(void) {
|
void Game::Shutdown(void) {
|
||||||
Debug::logger->message("\n ----- Cleaning Engine -----");
|
Debug::logger->message("\n ----- Cleaning Engine -----");
|
||||||
delete _testFont;
|
delete _testFont;
|
||||||
delete _NPC;
|
|
||||||
delete _player;
|
delete _player;
|
||||||
delete _level;
|
delete _level;
|
||||||
if(_inGameMenu) {
|
if(_inGameMenu) {
|
||||||
@ -103,6 +99,23 @@ void Game::OnResize(int width, int height) {
|
|||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Game::Warp(const String& mapName, int x, int y) {
|
||||||
|
Level* newLevel = new Level(this);
|
||||||
|
|
||||||
|
if(!newLevel->Load(mapName.GetPointer())) {
|
||||||
|
delete newLevel;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
delete _level;
|
||||||
|
_level = newLevel;
|
||||||
|
|
||||||
|
_player->SetXY(x, y);
|
||||||
|
_player->SetLevel(_level);
|
||||||
|
|
||||||
|
_level->PlayBGM();
|
||||||
|
}
|
||||||
|
|
||||||
void Game::UpdateTitle(float dt) {
|
void Game::UpdateTitle(float dt) {
|
||||||
_titleScreen->Update(dt);
|
_titleScreen->Update(dt);
|
||||||
|
|
||||||
@ -144,7 +157,6 @@ void Game::UpdateGame(float dt) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
_player->Update(dt);
|
_player->Update(dt);
|
||||||
_NPC->Update(dt);
|
|
||||||
_level->Update(dt);
|
_level->Update(dt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -166,14 +178,27 @@ void Game::RenderGame(void) {
|
|||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
|
|
||||||
|
float xOffset;
|
||||||
|
float yOffset;
|
||||||
|
|
||||||
|
int levelWidthPixels = _level->GetWidth() * _level->GetTileWidth();
|
||||||
|
int levelHeightPixels = _level->GetHeight() * _level->GetTileHeight();
|
||||||
|
|
||||||
|
if(levelWidthPixels < windowWidth && levelHeightPixels < windowHeight) {
|
||||||
|
xOffset = levelWidthPixels / 2 - windowWidth / 2;
|
||||||
|
yOffset = levelHeightPixels / 2 - windowHeight / 2;
|
||||||
|
glTranslatef((int)-xOffset, (int)-yOffset, 0.0f);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
float windowCenterX = ((float)windowWidth / 2.0f) - ((float)_player->GetMaxWidth() / 2.0f);
|
float windowCenterX = ((float)windowWidth / 2.0f) - ((float)_player->GetMaxWidth() / 2.0f);
|
||||||
float windowCenterY = ((float)windowHeight / 2.0f) - ((float)_player->GetMaxHeight() / 2.0f);
|
float windowCenterY = ((float)windowHeight / 2.0f) - ((float)_player->GetMaxHeight() / 2.0f);
|
||||||
|
|
||||||
float xOffset = _player->GetX() - windowCenterX;
|
xOffset = _player->GetX() - windowCenterX;
|
||||||
float yOffset = _player->GetY() - windowCenterY;
|
yOffset = _player->GetY() - windowCenterY;
|
||||||
|
|
||||||
float maxXOffset = (_level->GetWidth() * _level->GetTileWidth()) - (float)windowWidth;
|
float maxXOffset = (float)(levelWidthPixels - windowWidth);
|
||||||
float maxYOffset = (_level->GetHeight() * _level->GetTileHeight()) - (float)windowHeight;
|
float maxYOffset = (float)(levelHeightPixels - windowHeight);
|
||||||
|
|
||||||
if(xOffset < 0.0f) xOffset = 0.0f;
|
if(xOffset < 0.0f) xOffset = 0.0f;
|
||||||
if(yOffset < 0.0f) yOffset = 0.0f;
|
if(yOffset < 0.0f) yOffset = 0.0f;
|
||||||
@ -181,11 +206,11 @@ void Game::RenderGame(void) {
|
|||||||
if(yOffset > maxYOffset) yOffset = maxYOffset;
|
if(yOffset > maxYOffset) yOffset = maxYOffset;
|
||||||
|
|
||||||
glTranslatef((int)-xOffset, (int)-yOffset, 0.0f);
|
glTranslatef((int)-xOffset, (int)-yOffset, 0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
// Render our shit..
|
// Render our shit..
|
||||||
_level->Draw(xOffset, yOffset);
|
_level->Draw(xOffset, yOffset);
|
||||||
_player->Render();
|
_player->Render();
|
||||||
_NPC->Render();
|
|
||||||
_testFont->SetColor(0.0f, 1.0f, 1.0f, 1.0f);
|
_testFont->SetColor(0.0f, 1.0f, 1.0f, 1.0f);
|
||||||
_testFont->RenderText(
|
_testFont->RenderText(
|
||||||
_player->GetX() - 5,
|
_player->GetX() - 5,
|
||||||
@ -214,7 +239,6 @@ void Game::NewGame(void) {
|
|||||||
_level->PlayBGM();
|
_level->PlayBGM();
|
||||||
|
|
||||||
_player->LoadSprites("Player");
|
_player->LoadSprites("Player");
|
||||||
_NPC->LoadSprites("Player");
|
|
||||||
|
|
||||||
_testFont->Load("../Data/Font/Fairydust.ttf", 16);
|
_testFont->Load("../Data/Font/Fairydust.ttf", 16);
|
||||||
_testFont->SetColor(0.0f, 1.0f, 1.0f, 1.0f);
|
_testFont->SetColor(0.0f, 1.0f, 1.0f, 1.0f);
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "../IO/Input.h"
|
#include "../IO/Input.h"
|
||||||
#include "../Actor/NPC.h"
|
|
||||||
#include "../Actor/Player.h"
|
#include "../Actor/Player.h"
|
||||||
#include "../Font/Font.h"
|
#include "../Font/Font.h"
|
||||||
|
|
||||||
@ -24,6 +23,8 @@ public:
|
|||||||
|
|
||||||
void OnResize(int width, int height);
|
void OnResize(int width, int height);
|
||||||
|
|
||||||
|
void Warp(const String& mapName, int x, int y);
|
||||||
|
|
||||||
bool IsRunning() { return _running; }
|
bool IsRunning() { return _running; }
|
||||||
void SetRunning(bool running) { _running = running; }
|
void SetRunning(bool running) { _running = running; }
|
||||||
|
|
||||||
@ -40,7 +41,6 @@ private:
|
|||||||
|
|
||||||
Font* _testFont;
|
Font* _testFont;
|
||||||
Player* _player;
|
Player* _player;
|
||||||
NPC* _NPC;
|
|
||||||
Level* _level;
|
Level* _level;
|
||||||
|
|
||||||
TitleScreen* _titleScreen;
|
TitleScreen* _titleScreen;
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "Vec2.h"
|
||||||
|
|
||||||
struct Rect
|
struct Rect
|
||||||
{
|
{
|
||||||
float x;
|
float x;
|
||||||
@ -14,4 +16,20 @@ struct Rect
|
|||||||
this->w = w;
|
this->w = w;
|
||||||
this->h = h;
|
this->h = h;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CollidesWith(const Rect& other) const {
|
||||||
|
if(x > (other.x + other.w))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if(y > (other.y + other.h))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if((x + w) < other.x)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if((y + h) < other.y)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user