mirror of
https://github.com/HowestDAE/dae16-VerhulstBram.git
synced 2026-02-04 09:29:20 +01:00
Pre Point2f Nuke
Fixed drawing, Added general optimisations
This commit is contained in:
73
.idea/.idea.Motherload/.idea/workspace.xml
generated
73
.idea/.idea.Motherload/.idea/workspace.xml
generated
@@ -10,10 +10,20 @@
|
|||||||
<option name="autoReloadType" value="SELECTIVE" />
|
<option name="autoReloadType" value="SELECTIVE" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="26a0623a-44d5-441c-8048-32ff1dab3479" name="Changes" comment="Fix precompiled headers Added edge detection (if it works :/)">
|
<list default="true" id="26a0623a-44d5-441c-8048-32ff1dab3479" name="Changes" comment="">
|
||||||
<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$/.idea/.idea.Motherload/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.Motherload/.idea/workspace.xml" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/Engine/Texture.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/Engine/Texture.cpp" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/Engine/Texture.h" beforeDir="false" afterPath="$PROJECT_DIR$/Engine/Texture.h" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/Engine/utils.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/Engine/utils.cpp" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/Game/Animations/Animation.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/Game/Animations/Animation.cpp" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/Game/Animations/Animation.h" beforeDir="false" afterPath="$PROJECT_DIR$/Game/Animations/Animation.h" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/Game/Game.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/Game/Game.cpp" 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.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/Gui/Screen.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/Game/Gui/Screen.cpp" 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" />
|
||||||
</list>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
@@ -212,28 +222,28 @@
|
|||||||
<option name="hideEmptyMiddlePackages" value="true" />
|
<option name="hideEmptyMiddlePackages" value="true" />
|
||||||
<option name="showLibraryContents" value="true" />
|
<option name="showLibraryContents" value="true" />
|
||||||
</component>
|
</component>
|
||||||
<component name="PropertiesComponent"><![CDATA[{
|
<component name="PropertiesComponent">{
|
||||||
"keyToString": {
|
"keyToString": {
|
||||||
"C++ Project.Game.executor": "Run",
|
"C++ Project.Game.executor": "Run",
|
||||||
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
||||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||||
"ignore.virus.scanning.warn.message": "true",
|
"ignore.virus.scanning.warn.message": "true",
|
||||||
"node.js.detected.package.eslint": "true",
|
"node.js.detected.package.eslint": "true",
|
||||||
"node.js.detected.package.tslint": "true",
|
"node.js.detected.package.tslint": "true",
|
||||||
"node.js.selected.package.eslint": "(autodetect)",
|
"node.js.selected.package.eslint": "(autodetect)",
|
||||||
"node.js.selected.package.tslint": "(autodetect)",
|
"node.js.selected.package.tslint": "(autodetect)",
|
||||||
"nodejs_package_manager_path": "npm",
|
"nodejs_package_manager_path": "npm",
|
||||||
"settings.editor.selected.configurable": "editor.preferences.fonts.default",
|
"settings.editor.selected.configurable": "editor.preferences.fonts.default",
|
||||||
"vue.rearranger.settings.migration": "true"
|
"vue.rearranger.settings.migration": "true"
|
||||||
},
|
},
|
||||||
"keyToStringList": {
|
"keyToStringList": {
|
||||||
"rider.external.source.directories": [
|
"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\\DecompilerCache",
|
||||||
"C:\\Users\\Bram\\AppData\\Roaming\\JetBrains\\Rider2023.3\\resharper-host\\SourcesCache",
|
"C:\\Users\\Bram\\AppData\\Roaming\\JetBrains\\Rider2023.3\\resharper-host\\SourcesCache",
|
||||||
"C:\\Users\\Bram\\AppData\\Local\\Symbols\\src"
|
"C:\\Users\\Bram\\AppData\\Local\\Symbols\\src"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}]]></component>
|
}</component>
|
||||||
<component name="RunManager">
|
<component name="RunManager">
|
||||||
<configuration name="Game" type="CppProject" factoryName="C++ Project">
|
<configuration name="Game" type="CppProject" factoryName="C++ Project">
|
||||||
<configuration_1>
|
<configuration_1>
|
||||||
@@ -324,7 +334,13 @@
|
|||||||
<workItem from="1712269212956" duration="5658000" />
|
<workItem from="1712269212956" duration="5658000" />
|
||||||
<workItem from="1712313346695" duration="4041000" />
|
<workItem from="1712313346695" duration="4041000" />
|
||||||
<workItem from="1712322453730" duration="533000" />
|
<workItem from="1712322453730" duration="533000" />
|
||||||
<workItem from="1712328371740" duration="12603000" />
|
<workItem from="1712328371740" duration="13968000" />
|
||||||
|
<workItem from="1712404469282" duration="714000" />
|
||||||
|
<workItem from="1712414027596" duration="1111000" />
|
||||||
|
<workItem from="1712830657879" duration="548000" />
|
||||||
|
<workItem from="1713168521010" duration="1430000" />
|
||||||
|
<workItem from="1713257719220" duration="5429000" />
|
||||||
|
<workItem from="1713268116257" duration="1163000" />
|
||||||
</task>
|
</task>
|
||||||
<task id="LOCAL-00001" summary="Rework Tile detection system">
|
<task id="LOCAL-00001" summary="Rework Tile detection system">
|
||||||
<option name="closed" value="true" />
|
<option name="closed" value="true" />
|
||||||
@@ -366,7 +382,15 @@
|
|||||||
<option name="project" value="LOCAL" />
|
<option name="project" value="LOCAL" />
|
||||||
<updated>1712359406452</updated>
|
<updated>1712359406452</updated>
|
||||||
</task>
|
</task>
|
||||||
<option name="localTasksCounter" value="6" />
|
<task id="LOCAL-00006" summary="Fixed sidePieces (Need to add more cases tho)">
|
||||||
|
<option name="closed" value="true" />
|
||||||
|
<created>1712360855725</created>
|
||||||
|
<option name="number" value="00006" />
|
||||||
|
<option name="presentableId" value="LOCAL-00006" />
|
||||||
|
<option name="project" value="LOCAL" />
|
||||||
|
<updated>1712360855725</updated>
|
||||||
|
</task>
|
||||||
|
<option name="localTasksCounter" value="7" />
|
||||||
<servers />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
<component name="TypeScriptGeneratedFilesManager">
|
<component name="TypeScriptGeneratedFilesManager">
|
||||||
@@ -380,7 +404,8 @@
|
|||||||
<MESSAGE value="Basic screen system" />
|
<MESSAGE value="Basic screen system" />
|
||||||
<MESSAGE value="Update Screen system Added FuelScreen (Working buttons) Added SellScreen (Nothing working)" />
|
<MESSAGE value="Update Screen system Added FuelScreen (Working buttons) Added SellScreen (Nothing working)" />
|
||||||
<MESSAGE value="Fix precompiled headers Added edge detection (if it works :/)" />
|
<MESSAGE value="Fix precompiled headers Added edge detection (if it works :/)" />
|
||||||
<option name="LAST_COMMIT_MESSAGE" value="Fix precompiled headers Added edge detection (if it works :/)" />
|
<MESSAGE value="Fixed sidePieces (Need to add more cases tho)" />
|
||||||
|
<option name="LAST_COMMIT_MESSAGE" value="Fixed sidePieces (Need to add more cases tho)" />
|
||||||
</component>
|
</component>
|
||||||
<component name="XDebuggerManager">
|
<component name="XDebuggerManager">
|
||||||
<watches-manager>
|
<watches-manager>
|
||||||
|
|||||||
@@ -238,7 +238,7 @@ void Texture::Draw( const Point2f& dstBottomLeft, const Rectf& srcRect, bool fli
|
|||||||
dstRect.width = m_Width;
|
dstRect.width = m_Width;
|
||||||
dstRect.height = m_Height;
|
dstRect.height = m_Height;
|
||||||
}
|
}
|
||||||
Draw( dstRect, srcRect );
|
Draw( dstRect, srcRect, flip );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -341,6 +341,9 @@ bool Texture::IsCreationOk( ) const
|
|||||||
{
|
{
|
||||||
return m_CreationOk;
|
return m_CreationOk;
|
||||||
}
|
}
|
||||||
|
Rectf Texture::getSrcRect() {
|
||||||
|
return Rectf{0, 0, m_Width, m_Height};
|
||||||
|
}
|
||||||
|
|
||||||
void Texture::DrawFilledRect(const Rectf& rect) const
|
void Texture::DrawFilledRect(const Rectf& rect) const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ public:
|
|||||||
float GetHeight() const;
|
float GetHeight() const;
|
||||||
bool IsCreationOk( ) const;
|
bool IsCreationOk( ) const;
|
||||||
|
|
||||||
|
Rectf getSrcRect();
|
||||||
|
|
||||||
static int m_TextureCounter;
|
static int m_TextureCounter;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -724,3 +724,6 @@ bool utils::isMouseDown(int button) {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//utils::getScrollMovement()
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
#include "pch.h"
|
#include "pch.h"
|
||||||
#include "Animation.h"
|
#include "Animation.h"
|
||||||
|
|
||||||
|
#include "utils.h"
|
||||||
Animation::Animation(Texture* pTexture, int frames, float frameDuration, Rectf srcRect): m_pTexture(pTexture), m_SrcRect(srcRect), m_Frames(frames) {
|
Animation::Animation(Texture* pTexture, int frames, float frameDuration, Rectf srcRect): m_pTexture(pTexture), m_SrcRect(srcRect), m_Frames(frames) {
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -17,10 +19,13 @@ void Animation::Update(float elapsedSec) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void Animation::Draw(const Point2f& pos, float angle) const {
|
void Animation::Draw(const Point2f& pos) const {
|
||||||
|
Draw(pos, Rectf{ pos.x, pos.y, m_SrcRect.width, m_SrcRect.height });
|
||||||
|
}
|
||||||
|
|
||||||
|
void Animation::Draw(const Point2f& pos, const Rectf& dst) const {
|
||||||
Rectf src = m_SrcRect;
|
Rectf src = m_SrcRect;
|
||||||
src.left += m_CurrentFrame * src.width;
|
src.left += m_CurrentFrame * src.width;
|
||||||
auto dst = Rectf { pos.x, pos.y, src.width, src.height };
|
|
||||||
|
|
||||||
m_pTexture->Draw(dst, src, m_isFlipped);
|
m_pTexture->Draw(dst, src, m_isFlipped);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ public:
|
|||||||
~Animation();
|
~Animation();
|
||||||
|
|
||||||
void Update(float elapsedSec);
|
void Update(float elapsedSec);
|
||||||
void Draw(const Point2f& pos, float angle = 0.0f) const;
|
void Draw(const Point2f& pos) const;
|
||||||
|
void Draw(const Point2f& pos, const Rectf& dst) const;
|
||||||
|
|
||||||
void SetPlaying(bool isPlaying) {
|
void SetPlaying(bool isPlaying) {
|
||||||
m_isPlaying = isPlaying;
|
m_isPlaying = isPlaying;
|
||||||
|
|||||||
@@ -58,6 +58,8 @@ void Game::ProcessKeyUpEvent(const SDL_KeyboardEvent& e) {
|
|||||||
void Game::ProcessMouseMotionEvent(const SDL_MouseMotionEvent& e) {
|
void Game::ProcessMouseMotionEvent(const SDL_MouseMotionEvent& e) {
|
||||||
m_MousePos = Point2f { float(e.x), float(e.y) };
|
m_MousePos = Point2f { float(e.x), float(e.y) };
|
||||||
m_pCurrentLevel->MouseMove(Point2f { float(e.x), float(e.y) });
|
m_pCurrentLevel->MouseMove(Point2f { float(e.x), float(e.y) });
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::ProcessMouseDownEvent(const SDL_MouseButtonEvent& e) {
|
void Game::ProcessMouseDownEvent(const SDL_MouseButtonEvent& e) {
|
||||||
|
|||||||
@@ -192,7 +192,7 @@ void WorldTile::Update(Camera* camera) {
|
|||||||
Point2f mousePos = camera->TransformMouse(Point2f{utils::GetMousePos().x, 500 - utils::GetMousePos().y});
|
Point2f mousePos = camera->TransformMouse(Point2f{utils::GetMousePos().x, 500 - utils::GetMousePos().y});
|
||||||
m_Hightlight = utils::IsPointInRect(mousePos, Rectf{GetCollisionRect().pos, GetCollisionRect().size});
|
m_Hightlight = utils::IsPointInRect(mousePos, Rectf{GetCollisionRect().pos, GetCollisionRect().size});
|
||||||
if(CurrentIndex.x == 1 && CurrentIndex.y == 1) {
|
if(CurrentIndex.x == 1 && CurrentIndex.y == 1) {
|
||||||
std::cout << "Hey" << std::endl;
|
// std::cout << "Hey" << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Collision::TileCollisionRect WorldTile::GetCollisionRect() {
|
Collision::TileCollisionRect WorldTile::GetCollisionRect() {
|
||||||
|
|||||||
@@ -1,23 +1,22 @@
|
|||||||
#include "pch.h"
|
#include "pch.h"
|
||||||
#include "Screen.h"
|
#include "Screen.h"
|
||||||
|
|
||||||
Screen::Screen(const std::string& filePath, Point2f pos, Point2f size,TextureManager* manager): m_Position(pos), m_Size(size)
|
Screen::Screen(const std::string& filePath, Point2f pos, Point2f size, TextureManager* manager): m_Position(pos), m_Size(size) {
|
||||||
{
|
|
||||||
m_Background = manager->GetTexture(filePath);
|
m_Background = manager->GetTexture(filePath);
|
||||||
}
|
}
|
||||||
Screen::~Screen() {
|
Screen::~Screen() {
|
||||||
}
|
}
|
||||||
void Screen::Update(float elapsedSecs) {
|
void Screen::Update(float elapsedSecs) {
|
||||||
for(Button* b : m_Buttons) {
|
for (Button* b : m_Buttons) {
|
||||||
b->Update(elapsedSecs);
|
b->Update(elapsedSecs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void Screen::Draw() const {
|
void Screen::Draw() const {
|
||||||
Rectf dest = Rectf(m_Position, m_Size);
|
Rectf dest = Rectf(m_Position, m_Size);
|
||||||
Rectf src = Rectf(0,0, m_Background->GetWidth(), m_Background->GetHeight());
|
Rectf src = Rectf(0, 0, m_Background->GetWidth(), m_Background->GetHeight());
|
||||||
m_Background->Draw(dest, src, false);
|
m_Background->Draw(dest, src, false);
|
||||||
|
|
||||||
for(Button* b: m_Buttons) {
|
for (Button* b : m_Buttons) {
|
||||||
b->Draw();
|
b->Draw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,8 +23,8 @@ WorldLevel::WorldLevel(Camera* camera, Rectf viewport): Level(camera),
|
|||||||
// The grid is 34 x 50 big, the top center is 0,0 in world coords
|
// 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 x { 0 }; x < WORLD_WIDTH; ++x) {
|
||||||
for (size_t y { 0 }; y < WORLD_HEIGHT; ++y) {
|
for (size_t y { 0 }; y < WORLD_HEIGHT; ++y) {
|
||||||
int actualX = x - WORLD_WIDTH / 2;
|
const int actualX = x - WORLD_WIDTH / 2;
|
||||||
auto pos = Point2f { float(actualX * TILE_WIDTH), -float(y * TILE_HEIGHT) - TILE_HEIGHT };
|
Point2f pos = Point2f { float(actualX * TILE_WIDTH), -float(y * TILE_HEIGHT) - TILE_HEIGHT };
|
||||||
GroundTileType* type = Tiles::AIR;
|
GroundTileType* type = Tiles::AIR;
|
||||||
switch (utils::randRange(0, 2)) {
|
switch (utils::randRange(0, 2)) {
|
||||||
case 0:
|
case 0:
|
||||||
@@ -40,13 +40,12 @@ WorldLevel::WorldLevel(Camera* camera, Rectf viewport): Level(camera),
|
|||||||
std::cout << "??" << '\n';
|
std::cout << "??" << '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
m_gridManager.SetTileAtIndex(x, y, new WorldTile { pos, Tiles::DIRT, TextureManager::GetInstance(), &m_gridManager});
|
m_gridManager.SetTileAtIndex(x, y, new WorldTile { pos, type, TextureManager::GetInstance(), &m_gridManager});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (size_t x { 0 }; x < WORLD_WIDTH; ++x) {
|
for (size_t x { 0 }; x < WORLD_WIDTH; ++x) {
|
||||||
m_gridManager.GetTileAtIndex(x, 0)->SetTileType(Tiles::AIR);
|
m_gridManager.GetTileAtIndex(x, 0)->SetTileType(Tiles::AIR);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
WorldLevel::~WorldLevel() {
|
WorldLevel::~WorldLevel() {
|
||||||
//delete m_pTextTexture;
|
//delete m_pTextTexture;
|
||||||
@@ -57,8 +56,6 @@ void WorldLevel::Update(float elapsedSec) {
|
|||||||
SDL_GetMouseState(&mouseX, &mouseY);
|
SDL_GetMouseState(&mouseX, &mouseY);
|
||||||
m_mousePos = Point2f { float(mouseX), float(mouseY) };
|
m_mousePos = Point2f { float(mouseX), float(mouseY) };
|
||||||
m_mousePos = m_pCamera->TransformMouse(m_mousePos);
|
m_mousePos = m_pCamera->TransformMouse(m_mousePos);
|
||||||
//m_player.Update(elapsedSec, *this);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for (size_t x { 0 }; x < WORLD_WIDTH; ++x) {
|
for (size_t x { 0 }; x < WORLD_WIDTH; ++x) {
|
||||||
@@ -85,7 +82,7 @@ void WorldLevel::Update(float elapsedSec) {
|
|||||||
if(m_pSelectedTile != nullptr) {
|
if(m_pSelectedTile != nullptr) {
|
||||||
surroundingTiles surroundingTiles = m_gridManager.GetSurroundingTiles(m_pSelectedTile);
|
surroundingTiles surroundingTiles = m_gridManager.GetSurroundingTiles(m_pSelectedTile);
|
||||||
TileDirection direction = TileDirection::TopMiddle;
|
TileDirection direction = TileDirection::TopMiddle;
|
||||||
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];
|
direction = directions[i];
|
||||||
@@ -97,8 +94,7 @@ void WorldLevel::Update(float elapsedSec) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_player.Update(elapsedSec, *this);
|
||||||
//m_player.Update(elapsedSec, *this);
|
|
||||||
|
|
||||||
Screen* screen = m_screenManager->GetCurrentScreen();
|
Screen* screen = m_screenManager->GetCurrentScreen();
|
||||||
if (screen != nullptr) {
|
if (screen != nullptr) {
|
||||||
@@ -129,17 +125,6 @@ void WorldLevel::Draw() const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//loop over worldtiles
|
|
||||||
for (int x { 0 }; x < WORLD_WIDTH; ++x) {
|
|
||||||
for (int y { 0 }; y < WORLD_HEIGHT; ++y) {
|
|
||||||
if (*m_gridManager.GetTileAtIndex(x, y)->GetTileType() != Tiles::AIR) {
|
|
||||||
Collision::CollisionRect rect = m_gridManager.GetTileAtIndex(x, y)->GetCollisionRect().getCollisionRect();
|
|
||||||
utils::SetColor(Colors::GREEN);
|
|
||||||
utils::DrawRect(rect.pos, rect.size.x, rect.size.y);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
utils::SetColor(Colors::MAGENTA);
|
utils::SetColor(Colors::MAGENTA);
|
||||||
utils::FillEllipse(0, 0, 5, 5);
|
utils::FillEllipse(0, 0, 5, 5);
|
||||||
|
|
||||||
@@ -190,8 +175,8 @@ void WorldLevel::ProcessImGui() {
|
|||||||
|
|
||||||
ImGui::EndMenu();
|
ImGui::EndMenu();
|
||||||
}
|
}
|
||||||
Point2f screenPos = utils::GetMousePos();
|
const Point2f screenPos = utils::GetMousePos();
|
||||||
std::string mousePos = "Mouse Pos: (" + std::to_string(screenPos.x) + ", " + std::to_string(screenPos.y) + ")";
|
const std::string mousePos = "Mouse Pos: (" + std::to_string(screenPos.x) + ", " + std::to_string(screenPos.y) + ")";
|
||||||
if(ImGui::BeginMenu(mousePos.c_str())) {
|
if(ImGui::BeginMenu(mousePos.c_str())) {
|
||||||
|
|
||||||
ImGui::EndMenu();
|
ImGui::EndMenu();
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ class WorldLevel : public Level
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
WorldLevel(Camera* camera, Rectf viewport);
|
WorldLevel(Camera* camera, Rectf viewport);
|
||||||
~WorldLevel() override;
|
virtual ~WorldLevel() override;
|
||||||
|
|
||||||
WorldLevel(const WorldLevel& other) = default;
|
WorldLevel(const WorldLevel& other) = default;
|
||||||
WorldLevel(WorldLevel&& other) = default;
|
WorldLevel(WorldLevel&& other) = default;
|
||||||
@@ -39,7 +39,7 @@ private:
|
|||||||
WorldTile* m_pSelectedTile { nullptr };
|
WorldTile* m_pSelectedTile { nullptr };
|
||||||
|
|
||||||
// ImGui Vars
|
// ImGui Vars
|
||||||
bool m_ShowTextureManagerWindow { true };
|
bool m_ShowTextureManagerWindow { false };
|
||||||
bool m_ShowCameraWindow { false };
|
bool m_ShowCameraWindow { false };
|
||||||
bool m_ShowPlayerInfo { false };
|
bool m_ShowPlayerInfo { true };
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -16,7 +16,9 @@ Player::Player(const Point2f& Position, TextureManager* manager) : m_Position(Po
|
|||||||
m_ContactMap[Collision::CollisionDirection::Left] = nullptr;
|
m_ContactMap[Collision::CollisionDirection::Left] = nullptr;
|
||||||
m_ContactMap[Collision::CollisionDirection::Right] = nullptr;
|
m_ContactMap[Collision::CollisionDirection::Right] = nullptr;
|
||||||
|
|
||||||
m_walkAnimation = new Animation(manager->GetTexture("animations/player/player_walk.png"), 8, 0.1f, Rectf { 0, 0, 70, 70 });
|
m_walkAnimation = new Animation(
|
||||||
|
manager->GetTexture("animations/player/player_walk.png"),
|
||||||
|
8, 0.1f, Rectf { 0, 0, 70, 70 });
|
||||||
}
|
}
|
||||||
Collision::CollisionRect Player::GetCollisionRect() const {
|
Collision::CollisionRect Player::GetCollisionRect() const {
|
||||||
Collision::CollisionRect rect = { m_Position, m_Size, m_Vel };
|
Collision::CollisionRect rect = { m_Position, m_Size, m_Vel };
|
||||||
@@ -33,17 +35,28 @@ void Player::Draw() const {
|
|||||||
const int frameWidth = 70; //TODO: fix this
|
const int frameWidth = 70; //TODO: fix this
|
||||||
int halfFrameWidth = frameWidth / 2;
|
int halfFrameWidth = frameWidth / 2;
|
||||||
|
|
||||||
auto drawPos = Point2f { center.x - halfFrameWidth - 10, center.y - halfFrameWidth + 9 };
|
Point2f drawPos = Point2f { center.x - halfFrameWidth, center.y - halfFrameWidth + 9 };
|
||||||
|
|
||||||
m_walkAnimation->Draw(drawPos, 0);
|
m_walkAnimation->Draw(drawPos, Rectf { drawPos.x, drawPos.y, frameWidth, frameWidth });
|
||||||
}
|
}
|
||||||
void Player::ProcessImGui() {
|
void Player::ProcessImGui() {
|
||||||
ImGui::Begin("Collision Info", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
|
ImGui::Begin("Collision Info", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
|
||||||
ImGui::Text("is Grounded: %s", m_Grounded ? "true" : "false");
|
ImGui::Text("is Grounded: %s", m_Grounded ? "true" : "false");
|
||||||
ImGui::Text("Did just dig right: %s", m_DidJustDigRight ? "true" : "false");
|
|
||||||
bool test = !utils::isKeyPressed(SDL_SCANCODE_H);
|
|
||||||
ImGui::Text("Is Key Up H: %s", test ? "true" : "false");
|
|
||||||
ImGui::Checkbox("Draw Collision Rect", &m_DrawCollisionRect);
|
ImGui::Checkbox("Draw Collision Rect", &m_DrawCollisionRect);
|
||||||
|
std::string currentState{};
|
||||||
|
switch (m_State) {
|
||||||
|
case PlayerState::Idle:
|
||||||
|
currentState = "Idle";
|
||||||
|
break;
|
||||||
|
case PlayerState::Digging:
|
||||||
|
currentState = "Digging";
|
||||||
|
break;
|
||||||
|
case PlayerState::Walking:
|
||||||
|
currentState = "Walking";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
ImGui::Text("Player State %s", currentState.c_str());
|
||||||
|
|
||||||
|
|
||||||
//ContactMap
|
//ContactMap
|
||||||
ImGui::Text("ContactMap:");
|
ImGui::Text("ContactMap:");
|
||||||
@@ -56,9 +69,10 @@ void Player::ProcessImGui() {
|
|||||||
|
|
||||||
void Player::Update(float elapsedTime, WorldLevel& level) {
|
void Player::Update(float elapsedTime, WorldLevel& level) {
|
||||||
|
|
||||||
m_Vel = Point2f { 0, -100 };
|
|
||||||
|
|
||||||
//check for keys
|
//check for keys
|
||||||
|
if(m_State != PlayerState::Digging) {
|
||||||
|
m_Vel = Point2f { 0, -100 };
|
||||||
if (utils::isKeyDown(SDL_SCANCODE_W)) {
|
if (utils::isKeyDown(SDL_SCANCODE_W)) {
|
||||||
m_Vel.y = 100;
|
m_Vel.y = 100;
|
||||||
m_Grounded = false;
|
m_Grounded = false;
|
||||||
@@ -67,8 +81,12 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
|
|||||||
m_Vel.y = -100;
|
m_Vel.y = -100;
|
||||||
if (m_Grounded) {
|
if (m_Grounded) {
|
||||||
if (m_ContactMap[Collision::CollisionDirection::Bottom] != nullptr) {
|
if (m_ContactMap[Collision::CollisionDirection::Bottom] != nullptr) {
|
||||||
m_ContactMap[Collision::CollisionDirection::Bottom]->SetTileType(Tiles::AIR);
|
//Do the digging
|
||||||
|
m_State = PlayerState::Digging;
|
||||||
|
//Set the digging location in the center of the destination tile;
|
||||||
WorldTile* tile = m_ContactMap[Collision::CollisionDirection::Bottom];
|
WorldTile* tile = m_ContactMap[Collision::CollisionDirection::Bottom];
|
||||||
|
m_DigDestination = tile->GetPosition() + tile->GetSize() / 2;
|
||||||
|
m_ContactMap[Collision::CollisionDirection::Bottom]->SetTileType(Tiles::AIR);
|
||||||
//center of tile
|
//center of tile
|
||||||
Point2f tileCenter = tile->GetCollisionRect().getCollisionRect().pos + tile->GetCollisionRect().getCollisionRect().size / 2;
|
Point2f tileCenter = tile->GetCollisionRect().getCollisionRect().pos + tile->GetCollisionRect().getCollisionRect().size / 2;
|
||||||
m_Position = Point2f { tileCenter.x - m_Size.x / 2, tileCenter.y - m_Size.y / 2 + 5 };
|
m_Position = Point2f { tileCenter.x - m_Size.x / 2, tileCenter.y - m_Size.y / 2 + 5 };
|
||||||
@@ -176,13 +194,15 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
|
|||||||
Collision::CollisionRect rect = world_tile->GetCollisionRect().getCollisionRect(); //TODO: fix this mess
|
Collision::CollisionRect rect = world_tile->GetCollisionRect().getCollisionRect(); //TODO: fix this mess
|
||||||
Collision::ResolvePlayerVsRect(*this, elapsedTime, &rect);
|
Collision::ResolvePlayerVsRect(*this, elapsedTime, &rect);
|
||||||
}
|
}
|
||||||
|
if(m_State != PlayerState::Digging) { //Fix for when the state is JUST set to digging
|
||||||
if (m_Vel.x != 0.0f) {
|
if (m_Vel.x != 0.0f) {
|
||||||
m_State = PlayerState::Walking;
|
m_State = PlayerState::Walking;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
m_State = PlayerState::Idle;
|
m_State = PlayerState::Idle;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch (m_State) {
|
switch (m_State) {
|
||||||
case PlayerState::Idle:
|
case PlayerState::Idle:
|
||||||
@@ -191,10 +211,14 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
|
|||||||
case PlayerState::Walking:
|
case PlayerState::Walking:
|
||||||
m_walkAnimation->SetPlaying(true);
|
m_walkAnimation->SetPlaying(true);
|
||||||
break;
|
break;
|
||||||
|
case PlayerState::Digging:
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(m_State != PlayerState::Digging) {
|
||||||
m_Position = m_Position + m_Vel * elapsedTime;
|
m_Position = m_Position + m_Vel * elapsedTime;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,6 +69,8 @@ private:
|
|||||||
Point2f m_Acc;
|
Point2f m_Acc;
|
||||||
Point2f m_Gravity { 0, -9.81f };
|
Point2f m_Gravity { 0, -9.81f };
|
||||||
|
|
||||||
|
Point2f m_DigDestination{};
|
||||||
|
|
||||||
bool m_Grounded { false };
|
bool m_Grounded { false };
|
||||||
|
|
||||||
bool m_DidJustDigRight { false };
|
bool m_DidJustDigRight { false };
|
||||||
|
|||||||
Reference in New Issue
Block a user