mirror of
https://github.com/HowestDAE/dae16-VerhulstBram.git
synced 2025-12-16 03:41:48 +01:00
Fix digging
This commit is contained in:
63
.idea/.idea.Motherload/.idea/workspace.xml
generated
63
.idea/.idea.Motherload/.idea/workspace.xml
generated
@@ -11,17 +11,17 @@
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="26a0623a-44d5-441c-8048-32ff1dab3479" name="Changes" comment="">
|
||||
<change afterPath="$PROJECT_DIR$/Game/Levels/World/Building.cpp" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/Game/Levels/World/Building.h" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/.idea.Motherload/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.Motherload/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Assets/FuelStation.aseprite" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/FuelStation.aseprite" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Game/Game.vcxproj" beforeDir="false" afterPath="$PROJECT_DIR$/Game/Game.vcxproj" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Engine/utils.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/Engine/utils.cpp" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Engine/utils.h" beforeDir="false" afterPath="$PROJECT_DIR$/Engine/utils.h" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Game/GridSystem/WorldGridManager.h" beforeDir="false" afterPath="$PROJECT_DIR$/Game/GridSystem/WorldGridManager.h" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Game/GridSystem/WorldTile.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/Game/GridSystem/WorldTile.cpp" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Game/GridSystem/WorldTile.h" beforeDir="false" afterPath="$PROJECT_DIR$/Game/GridSystem/WorldTile.h" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Game/Levels/World/WorldLevel.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/Game/Levels/World/WorldLevel.cpp" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Game/Levels/World/WorldLevel.h" beforeDir="false" afterPath="$PROJECT_DIR$/Game/Levels/World/WorldLevel.h" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Game/Player.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/Game/Player.cpp" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Game/Player.h" beforeDir="false" afterPath="$PROJECT_DIR$/Game/Player.h" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Game/TextureManager.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/Game/TextureManager.cpp" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Game/main.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/Game/main.cpp" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
@@ -31,19 +31,15 @@
|
||||
<component name="Git.Settings">
|
||||
<option name="RECENT_BRANCH_BY_REPOSITORY">
|
||||
<map>
|
||||
<entry key="$PROJECT_DIR$" value="71d364d9d8b80fad541dc883c727d8984c247f4b" />
|
||||
<entry key="$PROJECT_DIR$" value="ebda39f690147cf0dfe51c6e4e121c4f1e3606e8" />
|
||||
</map>
|
||||
</option>
|
||||
</component>
|
||||
<component name="HighlightingSettingsPerFile">
|
||||
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
|
||||
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
|
||||
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
|
||||
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
|
||||
<setting file="file://$PROJECT_DIR$/../../../../../../Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/MSVC/14.37.32822/include/vector" root0="SKIP_HIGHLIGHTING" />
|
||||
<setting file="file://$PROJECT_DIR$/Game/Animations/Animation.h" root0="FORCE_HIGHLIGHTING" />
|
||||
<setting file="file://$PROJECT_DIR$/Game/Camera.cpp" root0="FORCE_HIGHLIGHTING" />
|
||||
<setting file="mock://C:/Users/Bram/Desktop/Programming 2/Exam/dae16-VerhulstBram/Game/GridSystem/WorldTile.cpp" root0="SKIP_HIGHLIGHTING" />
|
||||
<setting file="mock://C:/Users/Bram/Desktop/Programming 2/Exam/dae16-VerhulstBram/Game/main.cpp" root0="SKIP_HIGHLIGHTING" />
|
||||
<setting file="file://$PROJECT_DIR$/Game/pch.cpp" root0="FORCE_HIGHLIGHTING" />
|
||||
<setting file="file://$PROJECT_DIR$/Game/pch.h" root0="FORCE_HIGHLIGHTING" />
|
||||
</component>
|
||||
@@ -63,28 +59,28 @@
|
||||
<option name="hideEmptyMiddlePackages" value="true" />
|
||||
<option name="showLibraryContents" value="true" />
|
||||
</component>
|
||||
<component name="PropertiesComponent"><![CDATA[{
|
||||
"keyToString": {
|
||||
"C++ Project.Game.executor": "Run",
|
||||
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||
"ignore.virus.scanning.warn.message": "true",
|
||||
"node.js.detected.package.eslint": "true",
|
||||
"node.js.detected.package.tslint": "true",
|
||||
"node.js.selected.package.eslint": "(autodetect)",
|
||||
"node.js.selected.package.tslint": "(autodetect)",
|
||||
"nodejs_package_manager_path": "npm",
|
||||
"settings.editor.selected.configurable": "preferences.sourceCode.C++",
|
||||
"vue.rearranger.settings.migration": "true"
|
||||
<component name="PropertiesComponent">{
|
||||
"keyToString": {
|
||||
"C++ Project.Game.executor": "Run",
|
||||
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||
"ignore.virus.scanning.warn.message": "true",
|
||||
"node.js.detected.package.eslint": "true",
|
||||
"node.js.detected.package.tslint": "true",
|
||||
"node.js.selected.package.eslint": "(autodetect)",
|
||||
"node.js.selected.package.tslint": "(autodetect)",
|
||||
"nodejs_package_manager_path": "npm",
|
||||
"settings.editor.selected.configurable": "com.github.MitI_7.IDEOMApplicationPlugin",
|
||||
"vue.rearranger.settings.migration": "true"
|
||||
},
|
||||
"keyToStringList": {
|
||||
"rider.external.source.directories": [
|
||||
"C:\\Users\\Bram\\AppData\\Roaming\\JetBrains\\Rider2023.3\\resharper-host\\DecompilerCache",
|
||||
"C:\\Users\\Bram\\AppData\\Roaming\\JetBrains\\Rider2023.3\\resharper-host\\SourcesCache",
|
||||
"C:\\Users\\Bram\\AppData\\Local\\Symbols\\src"
|
||||
"keyToStringList": {
|
||||
"rider.external.source.directories": [
|
||||
"C:\\Users\\Bram\\AppData\\Roaming\\JetBrains\\Rider2023.3\\resharper-host\\DecompilerCache",
|
||||
"C:\\Users\\Bram\\AppData\\Roaming\\JetBrains\\Rider2023.3\\resharper-host\\SourcesCache",
|
||||
"C:\\Users\\Bram\\AppData\\Local\\Symbols\\src"
|
||||
]
|
||||
}
|
||||
}]]></component>
|
||||
}</component>
|
||||
<component name="RunManager">
|
||||
<configuration name="Game" type="CppProject" factoryName="C++ Project">
|
||||
<configuration_1>
|
||||
@@ -189,6 +185,13 @@
|
||||
<workItem from="1713354379040" duration="2279000" />
|
||||
<workItem from="1713377152822" duration="1364000" />
|
||||
<workItem from="1713440849218" duration="1218000" />
|
||||
<workItem from="1713450313096" duration="4942000" />
|
||||
<workItem from="1713462845365" duration="4464000" />
|
||||
<workItem from="1713525299050" duration="2330000" />
|
||||
<workItem from="1713544818472" duration="1549000" />
|
||||
<workItem from="1713546379562" duration="319000" />
|
||||
<workItem from="1713609308065" duration="368000" />
|
||||
<workItem from="1713624356487" duration="6843000" />
|
||||
</task>
|
||||
<task id="LOCAL-00001" summary="Rework Tile detection system">
|
||||
<option name="closed" value="true" />
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
#include <iostream>
|
||||
#include "utils.h"
|
||||
|
||||
#include "colors.h"
|
||||
|
||||
#pragma region OpenGLDrawFunctionality
|
||||
void utils::SetColor(const Color4f& color) {
|
||||
glColor4f(color.r, color.g, color.b, color.a);
|
||||
@@ -228,6 +230,18 @@ void utils::DrawPolygon(const Vector2f* pVertices, size_t nrVertices, bool close
|
||||
void utils::FillPolygon(const std::vector<Vector2f>& vertices) {
|
||||
FillPolygon(vertices.data(), vertices.size());
|
||||
}
|
||||
void utils::DrawArrow(const Vector2f& start, const Vector2f& end, float lineWidth, float arrowSize) {
|
||||
// Origin is bottom left
|
||||
utils::DrawLine(start, end);
|
||||
Vector2f arrowEnd = end - start;
|
||||
Vector2f dir = end - start;
|
||||
|
||||
utils::SetColor(Colors::RED);
|
||||
utils::DrawLine(end, end + Vector2f{ dir.y, -dir.x }.Normalized() * arrowSize);
|
||||
utils::DrawLine(end, end + Vector2f{ -dir.y, dir.x }.Normalized() * arrowSize);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void utils::FillPolygon(const Vector2f* pVertices, size_t nrVertices) {
|
||||
glBegin(GL_POLYGON);
|
||||
|
||||
@@ -60,6 +60,8 @@ namespace utils
|
||||
void DrawPolygon( const Vector2f* pVertices, size_t nrVertices, bool closed = true, float lineWidth = 1.0f );
|
||||
void FillPolygon( const std::vector<Vector2f>& vertices);
|
||||
void FillPolygon( const Vector2f* pVertices, size_t nrVertices);
|
||||
|
||||
void DrawArrow(const Vector2f& start, const Vector2f& end, float lineWidth = 1.0f, float arrowSize = 10.0f);
|
||||
#pragma endregion OpenGLDrawFunctionality
|
||||
|
||||
#pragma region CollisionFunctionality
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
#include "structs.h"
|
||||
|
||||
class GroundTileType;
|
||||
static const int WORLD_WIDTH = 34;
|
||||
static const int WORLD_HEIGHT = 34;
|
||||
|
||||
@@ -40,6 +41,18 @@ struct surroundingTiles
|
||||
WorldTile* GetTile(TileDirection direction) {
|
||||
return m_tiles[direction];
|
||||
}
|
||||
|
||||
// bool IsAllType(const GroundTileType& type) {
|
||||
// for (const auto& tile : m_tiles) {
|
||||
// if (tile.second == nullptr) {
|
||||
// return false;
|
||||
// }
|
||||
// if (tile.second->GetTileType() != &type) {
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
};
|
||||
|
||||
class WorldGridManager
|
||||
|
||||
@@ -32,6 +32,51 @@ WorldTile::~WorldTile() {
|
||||
delete m_pTexture;
|
||||
}
|
||||
void WorldTile::Draw() {
|
||||
|
||||
|
||||
switch (m_GroundTileType->getType()) {
|
||||
case GroundTileTypes::Air: {
|
||||
//check if it's all around dirt
|
||||
bool allDirt = true;
|
||||
for (int i = 0; i < 8; i++) {
|
||||
const WorldTile* tile = m_SurroundingTiles.GetTile(static_cast<TileDirection>(i));
|
||||
if(tile != nullptr) { //Tile exists
|
||||
const GroundTileTypes type = tile->GetTileType()->getType();
|
||||
if(type != Tiles::DIRT->getType()) {
|
||||
allDirt = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(allDirt) {
|
||||
m_pAllTexture->Draw(m_Position);
|
||||
return;
|
||||
}
|
||||
if(*m_GroundTileType == Tiles::AIR) {
|
||||
this->DrawSide(TileDirection::TopLeft);
|
||||
this->DrawSide(TileDirection::TopRight);
|
||||
this->DrawSide(TileDirection::BottomLeft);
|
||||
this->DrawSide(TileDirection::BottomRight);
|
||||
|
||||
this->DrawSide(TileDirection::TopMiddle);
|
||||
this->DrawSide(TileDirection::BottomMiddle);
|
||||
this->DrawSide(TileDirection::MiddleLeft);
|
||||
this->DrawSide(TileDirection::MiddleRight);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
case GroundTileTypes::Dirt:
|
||||
case GroundTileTypes::Hard:
|
||||
case GroundTileTypes::Stone:
|
||||
case GroundTileTypes::Iron:
|
||||
m_pTexture->Draw(m_Position);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (*m_GroundTileType != Tiles::AIR) {
|
||||
m_pTexture->Draw(m_Position);
|
||||
if (m_Hightlight) {
|
||||
@@ -40,35 +85,9 @@ void WorldTile::Draw() {
|
||||
}
|
||||
}
|
||||
|
||||
//check if it's all around dirt
|
||||
bool allDirt = true;
|
||||
for (int i = 0; i < 8; i++) {
|
||||
const WorldTile* tile = m_SurroundingTiles.GetTile(static_cast<TileDirection>(i));
|
||||
if(tile != nullptr) { //Tile exists
|
||||
const GroundTileTypes type = tile->GetTileType()->getType();
|
||||
if(type != Tiles::DIRT->getType()) {
|
||||
allDirt = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(allDirt) {
|
||||
m_pAllTexture->Draw(m_Position);
|
||||
return;
|
||||
}
|
||||
|
||||
if(*m_GroundTileType == Tiles::AIR) {
|
||||
this->DrawSide(TileDirection::TopLeft);
|
||||
this->DrawSide(TileDirection::TopRight);
|
||||
this->DrawSide(TileDirection::BottomLeft);
|
||||
this->DrawSide(TileDirection::BottomRight);
|
||||
|
||||
this->DrawSide(TileDirection::TopMiddle);
|
||||
this->DrawSide(TileDirection::BottomMiddle);
|
||||
this->DrawSide(TileDirection::MiddleLeft);
|
||||
this->DrawSide(TileDirection::MiddleRight);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void WorldTile::Update(const Camera* camera) {
|
||||
|
||||
@@ -18,7 +18,7 @@ enum class GroundTileTypes
|
||||
class GroundTileType
|
||||
{
|
||||
public:
|
||||
GroundTileType(const std::string& filePath, GroundTileTypes type): m_filePath(filePath), m_type(type) {
|
||||
GroundTileType(const std::string&& filePath, GroundTileTypes type): m_filePath(filePath), m_type(type) {
|
||||
}
|
||||
virtual ~GroundTileType() = default;
|
||||
bool operator==(const GroundTileType& rhs) const {
|
||||
@@ -53,7 +53,7 @@ private:
|
||||
class RandomGroundTile : public GroundTileType
|
||||
{
|
||||
public:
|
||||
RandomGroundTile(const std::string& filePath, GroundTileTypes type, int maxRandom): GroundTileType(filePath, type), m_maxRandom(maxRandom) {
|
||||
RandomGroundTile(const std::string& filePath, GroundTileTypes type, int maxRandom): GroundTileType(std::move(filePath), type), m_maxRandom(maxRandom) {
|
||||
}
|
||||
|
||||
~RandomGroundTile() override = default;
|
||||
@@ -96,6 +96,8 @@ namespace Tiles
|
||||
static GroundTileType* HARD_LEFT = new GroundTileType("tiles/dirt/special/hardLeft.png", GroundTileTypes::Hard);
|
||||
static GroundTileType* HARD_RIGHT = new GroundTileType("tiles/dirt/special/hardRight.png", GroundTileTypes::Hard);
|
||||
static GroundTileType* HARD_MIDDLE = new GroundTileType("tiles/dirt/special/hardMiddle.png", GroundTileTypes::Hard);
|
||||
|
||||
static GroundTileType* GRASS = new RandomGroundTile("tiles/dirt/special/grass[0].png", GroundTileTypes::Dirt, 2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,6 +127,7 @@ public:
|
||||
}
|
||||
void SetTileType(GroundTileType* type) {
|
||||
m_GroundTileType = type;
|
||||
m_pTexture = TextureManager::GetInstance()->GetTexture(type->getPath()); //Chage the texture when setting a new type
|
||||
}
|
||||
|
||||
Collision::TileCollisionRect GetCollisionRect();
|
||||
@@ -133,7 +136,6 @@ public:
|
||||
|
||||
private:
|
||||
void DrawSide(const TileDirection& direction);
|
||||
|
||||
|
||||
Vector2f m_Position;
|
||||
GroundTileType* m_GroundTileType;
|
||||
|
||||
@@ -19,7 +19,7 @@ WorldLevel::WorldLevel(Camera* camera, Rectf viewport): Level(camera),
|
||||
m_player(Player { Vector2f { 0, 100 }, TextureManager::GetInstance() }),
|
||||
m_mousePos { 0, 0 },
|
||||
m_viewport(viewport),
|
||||
m_screenManager(ScreenManager::GetInstance()) {
|
||||
m_screenManager(ScreenManager::GetInstance()) {
|
||||
// The grid is 34 x 50 big, the top center is 0,0 in world coords
|
||||
for (size_t x { 0 }; x < WORLD_WIDTH; ++x) {
|
||||
for (size_t y { 0 }; y < WORLD_HEIGHT; ++y) {
|
||||
@@ -39,22 +39,21 @@ WorldLevel::WorldLevel(Camera* camera, Rectf viewport): Level(camera),
|
||||
default:
|
||||
std::cout << "??" << '\n';
|
||||
}
|
||||
|
||||
m_gridManager.SetTileAtIndex(x, y, new WorldTile { pos, type, TextureManager::GetInstance(), &m_gridManager});
|
||||
|
||||
m_gridManager.SetTileAtIndex(x, y, new WorldTile { pos, Tiles::DIRT, TextureManager::GetInstance(), &m_gridManager });
|
||||
}
|
||||
}
|
||||
for (size_t x { 0 }; x < WORLD_WIDTH; ++x) {
|
||||
for (int x { 0 }; x < WORLD_WIDTH; ++x) {
|
||||
m_gridManager.GetTileAtIndex(x, 0)->SetTileType(Tiles::AIR);
|
||||
m_gridManager.GetTileAtIndex(x, 1)->SetTileType(Tiles::IRON);
|
||||
}
|
||||
m_refeulBuilding = new Building { "buildings/fuelStation.png", Vector2f { -700, -50 }, TextureManager::GetInstance() };
|
||||
m_gridManager.GetTileAtWorldPos(Vector2f{-700, -50})->SetTileType(Tiles::Special::HARD_LEFT);
|
||||
m_gridManager.GetTileAtWorldPos(Vector2f{-650, -50})->SetTileType(Tiles::Special::HARD_MIDDLE);
|
||||
m_gridManager.GetTileAtWorldPos(Vector2f{-600, -50})->SetTileType(Tiles::Special::HARD_RIGHT);
|
||||
|
||||
m_gridManager.GetTileAtWorldPos(Vector2f { -700, -50 })->SetTileType(Tiles::Special::HARD_LEFT);
|
||||
m_gridManager.GetTileAtWorldPos(Vector2f { -650, -50 })->SetTileType(Tiles::Special::HARD_MIDDLE);
|
||||
m_gridManager.GetTileAtWorldPos(Vector2f { -600, -50 })->SetTileType(Tiles::Special::HARD_RIGHT);
|
||||
}
|
||||
WorldLevel::~WorldLevel() {
|
||||
//delete m_pTextTexture;
|
||||
|
||||
}
|
||||
void WorldLevel::Update(float elapsedSec) {
|
||||
int mouseX, mouseY;
|
||||
@@ -62,7 +61,7 @@ void WorldLevel::Update(float elapsedSec) {
|
||||
m_mousePos = Vector2f { float(mouseX), float(mouseY) };
|
||||
m_mousePos = m_pCamera->TransformMouse(m_mousePos);
|
||||
|
||||
|
||||
|
||||
for (size_t x { 0 }; x < WORLD_WIDTH; ++x) {
|
||||
for (size_t y { 0 }; y < WORLD_HEIGHT; ++y) {
|
||||
m_gridManager.GetTileAtIndex(x, y)->m_Hightlight = false;
|
||||
@@ -84,15 +83,16 @@ void WorldLevel::Update(float elapsedSec) {
|
||||
}
|
||||
|
||||
//Get the diogonal tiles of the selected tile
|
||||
if(m_pSelectedTile != nullptr) {
|
||||
if (m_pSelectedTile != nullptr) {
|
||||
surroundingTiles surroundingTiles = m_gridManager.GetSurroundingTiles(m_pSelectedTile);
|
||||
TileDirection direction = TileDirection::TopMiddle;
|
||||
const std::array<TileDirection, 8> directions = {TileDirection::TopLeft, TileDirection::TopMiddle, TileDirection::TopRight, TileDirection::MiddleLeft, TileDirection::MiddleRight, TileDirection::BottomLeft, TileDirection::BottomMiddle, TileDirection::BottomRight};
|
||||
const std::array<TileDirection, 8> directions = { TileDirection::TopLeft, TileDirection::TopMiddle, TileDirection::TopRight, TileDirection::MiddleLeft,
|
||||
TileDirection::MiddleRight, TileDirection::BottomLeft, TileDirection::BottomMiddle, TileDirection::BottomRight };
|
||||
|
||||
for(int i = 0; i < 8; i++) {
|
||||
for (int i = 0; i < 8; i++) {
|
||||
direction = directions[i];
|
||||
if(surroundingTiles.GetTile(direction) != nullptr) {
|
||||
if(surroundingTiles.GetTile(direction)->GetTileType() != Tiles::AIR) {
|
||||
if (surroundingTiles.GetTile(direction) != nullptr) {
|
||||
if (surroundingTiles.GetTile(direction)->GetTileType() != Tiles::AIR) {
|
||||
//surroundingTiles.GetTile(direction)->m_Hightlight = true;
|
||||
}
|
||||
}
|
||||
@@ -105,14 +105,13 @@ void WorldLevel::Update(float elapsedSec) {
|
||||
if (screen != nullptr) {
|
||||
screen->Update(elapsedSec);
|
||||
}
|
||||
|
||||
|
||||
//Vector2f playerPos = m_player.GetPosition();
|
||||
//Vector2f newCameraPos = playerPos;
|
||||
//m_pCamera->SetPosition(newCameraPos);
|
||||
|
||||
//place the player in the center of the camera
|
||||
//m_pCamera->SetPosition(Vector2f{playerPos.x - m_viewport.width / 2, playerPos.y - m_viewport.height / 2});
|
||||
|
||||
}
|
||||
void WorldLevel::Draw() const {
|
||||
m_pCamera->BeginRendering();
|
||||
@@ -131,15 +130,18 @@ void WorldLevel::Draw() const {
|
||||
}
|
||||
|
||||
utils::SetColor(Colors::MAGENTA);
|
||||
utils::FillEllipse(0, 0, 5, 5);
|
||||
utils::FillEllipse(-5, -5, 5, 5);
|
||||
|
||||
m_player.Draw();
|
||||
if(m_pSelectedTile != nullptr) {
|
||||
if (m_pSelectedTile != nullptr) {
|
||||
m_pSelectedTile->Draw();
|
||||
}
|
||||
|
||||
m_refeulBuilding->Draw();
|
||||
|
||||
m_player.Draw();
|
||||
|
||||
utils::SetColor(Colors::GREEN);
|
||||
utils::DrawArrow(Vector2f{0, 0}, m_mousePos);
|
||||
|
||||
m_pCamera->EndRendering();
|
||||
|
||||
utils::FillRect(utils::GetMousePos(), 10, 10);
|
||||
@@ -153,6 +155,32 @@ void WorldLevel::MouseMove(const Vector2f& mousePos) {
|
||||
}
|
||||
|
||||
void WorldLevel::ProcessImGui() {
|
||||
ImGui::Begin("Selected Tile");
|
||||
std::string tileType = "None";
|
||||
if (m_pSelectedTile != nullptr) {
|
||||
switch (m_pSelectedTile->GetTileType()->getType()) {
|
||||
case GroundTileTypes::Air:
|
||||
tileType = "Air";
|
||||
break;
|
||||
case GroundTileTypes::Dirt:
|
||||
tileType = "Dirt";
|
||||
break;
|
||||
case GroundTileTypes::Iron:
|
||||
tileType = "Iron";
|
||||
break;
|
||||
case GroundTileTypes::Hard:
|
||||
tileType = "Hard";
|
||||
break;
|
||||
case GroundTileTypes::Stone:
|
||||
tileType = "Stone";
|
||||
break;
|
||||
default:
|
||||
tileType = "Unknown";
|
||||
break;
|
||||
}
|
||||
}
|
||||
ImGui::Text("Selected Tile: %s", tileType.c_str());
|
||||
ImGui::End();
|
||||
if (ImGui::BeginMainMenuBar()) {
|
||||
if (ImGui::BeginMenu("Properties")) {
|
||||
if (ImGui::MenuItem("TextureManager Info")) {
|
||||
@@ -166,29 +194,28 @@ void WorldLevel::ProcessImGui() {
|
||||
}
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
if(ImGui::BeginMenu("Screens")) {
|
||||
if(ImGui::MenuItem("Open Fuel screen")) {
|
||||
if (ImGui::BeginMenu("Screens")) {
|
||||
if (ImGui::MenuItem("Open Fuel screen")) {
|
||||
ScreenManager::GetInstance()->OpenScreen(ScreenManager::Fuel);
|
||||
}
|
||||
|
||||
|
||||
if(ImGui::MenuItem("Open Sell screen")) {
|
||||
|
||||
if (ImGui::MenuItem("Open Sell screen")) {
|
||||
ScreenManager::GetInstance()->OpenScreen(ScreenManager::SellScreen);
|
||||
}
|
||||
|
||||
if(ImGui::MenuItem("Close Screen")) {
|
||||
ScreenManager::GetInstance()->CloseScreen();
|
||||
if (ImGui::MenuItem("Close Screen")) {
|
||||
ScreenManager::GetInstance()->CloseScreen();
|
||||
}
|
||||
|
||||
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
const Vector2f screenPos = utils::GetMousePos();
|
||||
const std::string mousePos = "Mouse Pos: (" + std::to_string(screenPos.x) + ", " + std::to_string(screenPos.y) + ")";
|
||||
if(ImGui::BeginMenu(mousePos.c_str())) {
|
||||
|
||||
ImGui::EndMenu();
|
||||
if (ImGui::BeginMenu(mousePos.c_str())) {
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
|
||||
|
||||
ImGui::EndMainMenuBar();
|
||||
}
|
||||
|
||||
|
||||
107
Game/Player.cpp
107
Game/Player.cpp
@@ -21,6 +21,7 @@ Player::Player(const Vector2f& Position, TextureManager* manager) : m_Position(P
|
||||
8, 0.1f, Rectf { 0, 0, 70, 70 });
|
||||
m_currentAnimation = m_walkAnimation;
|
||||
}
|
||||
|
||||
Collision::CollisionRect Player::GetCollisionRect() const {
|
||||
Collision::CollisionRect rect = { m_Position, m_Size, m_Vel };
|
||||
return rect;
|
||||
@@ -36,15 +37,17 @@ void Player::Draw() const {
|
||||
const int frameWidth = 70; //TODO: fix this
|
||||
int halfFrameWidth = frameWidth / 2;
|
||||
float bobOffset = m_BobUp ? 1 : 0;
|
||||
Vector2f drawPos = Vector2f { center.x - halfFrameWidth, center.y - halfFrameWidth + 9 + bobOffset} ;
|
||||
Vector2f drawPos = Vector2f { center.x - halfFrameWidth, center.y - halfFrameWidth + 9 + bobOffset };
|
||||
|
||||
m_walkAnimation->Draw(drawPos, Rectf { drawPos.x, drawPos.y , frameWidth, frameWidth });
|
||||
m_walkAnimation->Draw(drawPos, Rectf { drawPos.x, drawPos.y, frameWidth, frameWidth });
|
||||
utils::DrawEllipse(m_DigDestination, 5, 5);
|
||||
utils::DrawEllipse(m_DigStart, 5, 5);
|
||||
}
|
||||
void Player::ProcessImGui() {
|
||||
ImGui::Begin("Collision Info", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
|
||||
ImGui::Text("is Grounded: %s", m_Grounded ? "true" : "false");
|
||||
ImGui::Checkbox("Draw Collision Rect", &m_DrawCollisionRect);
|
||||
std::string currentState{};
|
||||
std::string currentState {};
|
||||
switch (m_State) {
|
||||
case PlayerState::Idle:
|
||||
currentState = "Idle";
|
||||
@@ -59,8 +62,8 @@ void Player::ProcessImGui() {
|
||||
ImGui::Text("Player State %s", currentState.c_str());
|
||||
ImGui::Text("Bob counter: %f", m_BobTimer);
|
||||
ImGui::Text("Bob up: %s", m_BobUp ? "true" : "false");
|
||||
|
||||
|
||||
|
||||
|
||||
//ContactMap
|
||||
ImGui::Text("ContactMap:");
|
||||
ImGui::Text("Top: %s", m_ContactMap[Collision::CollisionDirection::Top] != nullptr ? "true" : "false");
|
||||
@@ -69,53 +72,88 @@ void Player::ProcessImGui() {
|
||||
ImGui::Text("Right: %s", m_ContactMap[Collision::CollisionDirection::Right] != nullptr ? "true" : "false");
|
||||
ImGui::End();
|
||||
}
|
||||
void Player::Dig(Collision::CollisionDirection dir, WorldLevel& level) {
|
||||
m_State = PlayerState::Digging;
|
||||
m_DigProgress = 0;
|
||||
m_DigTile = m_ContactMap[dir];
|
||||
//Set the digging location in the center of the destination tile;
|
||||
const WorldTile* tile = m_ContactMap[dir];
|
||||
//Add case for bottom because otherwise i clip through the floor
|
||||
m_DigDestination = tile->GetPosition();
|
||||
if (dir == Collision::Bottom) {
|
||||
m_DigDestination += Vector2f { 0, 2 };
|
||||
//Center
|
||||
m_DigDestination.x += tile->GetSize().x / 2 - m_Size.x / 2;
|
||||
}
|
||||
if(dir == Collision::Left) {
|
||||
m_DigDestination += Vector2f{ 2, 0};
|
||||
}
|
||||
m_ContactMap[dir] = nullptr;
|
||||
}
|
||||
|
||||
bool Player::CanDig(Collision::CollisionDirection dir, WorldLevel& level) {
|
||||
WorldTile* tile = m_ContactMap[dir];
|
||||
if (tile == nullptr) {
|
||||
return false;
|
||||
}
|
||||
GroundTileType type = *tile->GetTileType();
|
||||
//TODO: Add a list of non diggable tiles
|
||||
|
||||
if (type == Tiles::Special::HARD_LEFT || type == Tiles::Special::HARD_MIDDLE || type == Tiles::Special::HARD_RIGHT) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Player::Update(float elapsedTime, WorldLevel& level) {
|
||||
m_BobTimer += elapsedTime;
|
||||
if(m_BobTimer >= m_BobTime) {
|
||||
if (m_BobTimer >= m_BobTime) {
|
||||
m_BobUp = !m_BobUp;
|
||||
m_BobTimer = 0.0f;
|
||||
}
|
||||
|
||||
//check for keys
|
||||
if(m_State != PlayerState::Digging) {
|
||||
if (m_State != PlayerState::Digging) {
|
||||
m_Vel = Vector2f { 0, -100 };
|
||||
if (utils::isKeyDown(SDL_SCANCODE_W)) {
|
||||
m_Vel.y = 100;
|
||||
m_Grounded = false;
|
||||
}
|
||||
if (utils::isKeyPressed(SDL_SCANCODE_S)) {
|
||||
m_Vel.y = -100;
|
||||
if (m_Grounded) {
|
||||
if (m_ContactMap[Collision::CollisionDirection::Bottom] != nullptr) {
|
||||
//Do the digging
|
||||
m_State = PlayerState::Digging;
|
||||
m_DigProgress = 0;
|
||||
m_DigTile = m_ContactMap[Collision::CollisionDirection::Bottom];
|
||||
//Set the digging location in the center of the destination tile;
|
||||
const WorldTile* tile = m_ContactMap[Collision::CollisionDirection::Bottom];
|
||||
m_DigDestination = tile->GetPosition() + Vector2f{0, 0};
|
||||
m_ContactMap[Collision::CollisionDirection::Bottom] = nullptr;
|
||||
if (this->CanDig(Collision::Bottom, level)) {
|
||||
this->Dig(Collision::CollisionDirection::Bottom, level);
|
||||
}
|
||||
}
|
||||
else {
|
||||
m_Vel.y = -100;
|
||||
}
|
||||
}
|
||||
if (utils::isKeyDown(SDL_SCANCODE_A)) {
|
||||
m_walkAnimation->SetFlipped(false);
|
||||
m_Vel.x = -100;
|
||||
if (m_Grounded && !m_DidJustDigLeft) {
|
||||
//Check if the player doesnt come from digging a tile
|
||||
if (this->CanDig(Collision::CollisionDirection::Left, level)) {
|
||||
this->Dig(Collision::CollisionDirection::Left, level);
|
||||
m_DidJustDigLeft = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (m_DidJustDigLeft) {
|
||||
if (!utils::isKeyDown(SDL_SCANCODE_A)) {
|
||||
m_DidJustDigLeft = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (utils::isKeyDown(SDL_SCANCODE_D)) {
|
||||
m_Vel.x = 100;
|
||||
m_walkAnimation->SetFlipped(true);
|
||||
if (m_Grounded && !m_DidJustDigRight) {
|
||||
//Check if the player doesnt come from digging a tile
|
||||
if (m_ContactMap[Collision::CollisionDirection::Right] != nullptr) {
|
||||
m_ContactMap[Collision::CollisionDirection::Right]->SetTileType(Tiles::AIR);
|
||||
WorldTile* tile = m_ContactMap[Collision::CollisionDirection::Right];
|
||||
//center of tile
|
||||
const Vector2f tileCenter = tile->GetCollisionRect().getCollisionRect().pos + tile->GetCollisionRect().getCollisionRect().size / 2;
|
||||
m_Position = Vector2f { tileCenter.x - m_Size.x / 2, tileCenter.y - m_Size.y / 2 + 5 };
|
||||
|
||||
m_ContactMap[Collision::CollisionDirection::Right] = nullptr;
|
||||
if (this->CanDig(Collision::CollisionDirection::Right, level)) {
|
||||
this->Dig(Collision::CollisionDirection::Right, level);
|
||||
m_DidJustDigRight = true;
|
||||
}
|
||||
}
|
||||
@@ -126,6 +164,7 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
m_walkAnimation->Update(elapsedTime);
|
||||
|
||||
|
||||
@@ -155,8 +194,7 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
|
||||
}
|
||||
}
|
||||
|
||||
std::sort(contactTimes.begin(), contactTimes.end(), [](const std::pair<int, float>& a, const std::pair<int, float>& b)
|
||||
{
|
||||
std::sort(contactTimes.begin(), contactTimes.end(), [](const std::pair<int, float>& a, const std::pair<int, float>& b) {
|
||||
return a.second < b.second;
|
||||
});
|
||||
|
||||
@@ -198,7 +236,7 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
|
||||
Collision::CollisionRect rect = world_tile->GetCollisionRect().getCollisionRect(); //TODO: fix this mess
|
||||
Collision::ResolvePlayerVsRect(*this, elapsedTime, &rect);
|
||||
}
|
||||
if(m_State != PlayerState::Digging) { //Fix for when the state is JUST set to digging
|
||||
if (m_State != PlayerState::Digging) { //Fix for when the state is JUST set to digging
|
||||
if (m_Vel.x != 0.0f) {
|
||||
m_State = PlayerState::Walking;
|
||||
}
|
||||
@@ -207,7 +245,6 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch (m_State) {
|
||||
case PlayerState::Idle:
|
||||
m_walkAnimation->SetPlaying(false);
|
||||
@@ -218,11 +255,17 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
|
||||
case PlayerState::Digging: {
|
||||
m_walkAnimation->SetPlaying(false);
|
||||
//Diganimation
|
||||
|
||||
if (!m_Digging) { //TODO: fix for setting the start position
|
||||
m_Digging = true;
|
||||
m_DigStart = m_Position;
|
||||
}
|
||||
|
||||
m_DigProgress += elapsedTime;
|
||||
//lerp to the destination
|
||||
float progress = utils::map(m_DigProgress, 0.0f, m_DigTime, 0.0f, 1.0f);
|
||||
std::cout << progress << '\n';
|
||||
m_Position = utils::lerp(m_Position, m_DigDestination, progress);
|
||||
m_Position = utils::lerp(m_DigStart, m_DigDestination, progress);
|
||||
if (progress >= 0.5f && !m_HasDeletedTile) {
|
||||
m_DigTile->SetTileType(Tiles::AIR);
|
||||
m_DigTile = nullptr;
|
||||
@@ -231,15 +274,15 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
|
||||
if (progress >= 1.0f) {
|
||||
m_State = PlayerState::Idle;
|
||||
m_HasDeletedTile = false;
|
||||
m_Digging = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
if(m_State != PlayerState::Digging) {
|
||||
if (m_State != PlayerState::Digging) {
|
||||
m_Position = m_Position + m_Vel * elapsedTime;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,6 +59,9 @@ public:
|
||||
void ProcessImGui();
|
||||
|
||||
private:
|
||||
void Dig(Collision::CollisionDirection dir, WorldLevel& level);
|
||||
bool CanDig(Collision::CollisionDirection dir, WorldLevel& level);
|
||||
|
||||
Vector2f m_Position;
|
||||
Vector2f m_Size;
|
||||
|
||||
@@ -73,15 +76,18 @@ private:
|
||||
bool m_BobUp{ true };
|
||||
|
||||
Vector2f m_DigDestination{};
|
||||
bool m_Digging{ false };
|
||||
Vector2f m_DigStart{};
|
||||
float m_DigProgress{};
|
||||
bool m_HasDeletedTile{ false };
|
||||
WorldTile* m_DigTile{ nullptr };
|
||||
|
||||
const float m_DigTime{ 1.0f };
|
||||
const float m_DigTime{ 0.5f };
|
||||
|
||||
bool m_Grounded { false };
|
||||
|
||||
bool m_DidJustDigRight { false };
|
||||
bool m_DidJustDigLeft { false };
|
||||
Animation* m_currentAnimation{ nullptr };
|
||||
Animation* m_walkAnimation;
|
||||
Animation* m_turnAnimation;
|
||||
|
||||
@@ -18,4 +18,7 @@ Texture * TextureManager::GetTexture(const std::string& name) {
|
||||
}
|
||||
TextureManager::~TextureManager() {
|
||||
//TODO: Loop over the m_Textures to delete them
|
||||
for ( const auto &p : m_Textures ) {
|
||||
delete p.second;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include <ctime>
|
||||
#include "Game.h"
|
||||
|
||||
|
||||
#define DEBUG
|
||||
void StartHeapControl();
|
||||
void DumpMemoryLeaks();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user