Compare commits
10 Commits
8d56c747be
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3c83e566dd | ||
|
|
8866f33c09 | ||
|
|
600050c198 | ||
|
|
d5c002c2b2 | ||
|
|
8c3a485c2d | ||
|
|
d3b932df22 | ||
|
|
77784a167e | ||
|
|
b6be73019f | ||
|
|
64915567dc | ||
|
|
a1a2406084 |
3
.gitignore
vendored
@@ -403,4 +403,5 @@ FodyWeavers.xsd
|
||||
|
||||
|
||||
.idea/
|
||||
/.idea/
|
||||
.idea/*
|
||||
.idea/workspace.xml
|
||||
|
||||
129
.idea/.idea.Motherload/.idea/workspace.xml
generated
@@ -11,15 +11,16 @@
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="26a0623a-44d5-441c-8048-32ff1dab3479" name="Changes" comment="">
|
||||
<change afterPath="$PROJECT_DIR$/Game/Levels/World/OrbitingObject.cpp" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/Game/Levels/World/OrbitingObject.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$/Engine/BaseGame.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/Engine/BaseGame.cpp" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Game/Game.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/Game/Game.cpp" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Game/Game.vcxproj" beforeDir="false" afterPath="$PROJECT_DIR$/Game/Game.vcxproj" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Game/Game.vcxproj.filters" beforeDir="false" afterPath="$PROJECT_DIR$/Game/Game.vcxproj.filters" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Game/GroundTileTypeManager.h" beforeDir="false" afterPath="$PROJECT_DIR$/Game/GroundTileTypeManager.h" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Game/GameManager.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/Game/GameManager.cpp" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Game/GameManager.h" beforeDir="false" afterPath="$PROJECT_DIR$/Game/GameManager.h" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Game/Gui/Screens/MainScreen.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/Game/Gui/Screens/MainScreen.cpp" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Game/Gui/Screens/MainScreen.h" beforeDir="false" afterPath="$PROJECT_DIR$/Game/Gui/Screens/MainScreen.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/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" />
|
||||
@@ -29,17 +30,11 @@
|
||||
<component name="Git.Settings">
|
||||
<option name="RECENT_BRANCH_BY_REPOSITORY">
|
||||
<map>
|
||||
<entry key="$PROJECT_DIR$" value="b406c8ffccf41d69fdf385448c8d0c2d49b2f970" />
|
||||
<entry key="$PROJECT_DIR$" value="d3b932df22970cf2f14e9dd79721ccae1d938a38" />
|
||||
</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="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="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
|
||||
@@ -49,9 +44,16 @@
|
||||
<setting file="file://$PROJECT_DIR$/../../../../../../Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/MSVC/14.37.32822/include/algorithm" root0="SKIP_HIGHLIGHTING" />
|
||||
<setting file="file://$PROJECT_DIR$/../../../../../../Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/MSVC/14.37.32822/include/type_traits" 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="mock://C:/Users/Bram/Desktop/Programming 2/Exam/dae16-VerhulstBram/Engine/BaseGame.cpp" root0="SKIP_HIGHLIGHTING" />
|
||||
<setting file="file://$PROJECT_DIR$/Game/Animations/Animation.h" root0="FORCE_HIGHLIGHTING" />
|
||||
<setting file="file://$PROJECT_DIR$/../../../../../../Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/MSVC/14.37.32822/include/xstring" root0="SKIP_HIGHLIGHTING" />
|
||||
<setting file="file://$PROJECT_DIR$/Engine/BaseGame.cpp" root0="FORCE_HIGHLIGHTING" />
|
||||
<setting file="file://$PROJECT_DIR$/Engine/BaseGame.h" root0="FORCE_HIGHLIGHTING" />
|
||||
<setting file="file://$PROJECT_DIR$/Engine/Texture.cpp" root0="FORCE_HIGHLIGHTING" />
|
||||
<setting file="file://$PROJECT_DIR$/Engine/utils.cpp" root0="FORCE_HIGHLIGHTING" />
|
||||
<setting file="file://$PROJECT_DIR$/Engine/utils.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/Levels/World/Building.cpp" root0="SKIP_HIGHLIGHTING" />
|
||||
<setting file="file://$PROJECT_DIR$/Game/Player.cpp" root0="FORCE_HIGHLIGHTING" />
|
||||
<setting file="file://$PROJECT_DIR$/Game/Player.h" root0="FORCE_HIGHLIGHTING" />
|
||||
<setting file="file://$PROJECT_DIR$/Game/pch.cpp" root0="FORCE_HIGHLIGHTING" />
|
||||
<setting file="file://$PROJECT_DIR$/Game/pch.h" root0="FORCE_HIGHLIGHTING" />
|
||||
<setting file="file://$PROJECT_DIR$/Libraries/SDLMain/SDL2-2.26.3/include/SDL.h" root0="SKIP_HIGHLIGHTING" />
|
||||
@@ -78,7 +80,7 @@
|
||||
</component>
|
||||
<component name="PropertiesComponent">{
|
||||
"keyToString": {
|
||||
"C++ Project.Game.executor": "Run",
|
||||
"C++ Project.Game.executor": "Debug",
|
||||
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||
"ignore.virus.scanning.warn.message": "true",
|
||||
@@ -229,6 +231,26 @@
|
||||
<workItem from="1714026889126" duration="4211000" />
|
||||
<workItem from="1714046400732" duration="2462000" />
|
||||
<workItem from="1714372163827" duration="2962000" />
|
||||
<workItem from="1714459066696" duration="21789000" />
|
||||
<workItem from="1714640485259" duration="321000" />
|
||||
<workItem from="1714641751956" duration="3705000" />
|
||||
<workItem from="1714652168988" duration="1613000" />
|
||||
<workItem from="1714653831106" duration="2710000" />
|
||||
<workItem from="1714763594789" duration="1983000" />
|
||||
<workItem from="1714824060444" duration="811000" />
|
||||
<workItem from="1715031948901" duration="46000" />
|
||||
<workItem from="1715063584283" duration="11702000" />
|
||||
<workItem from="1715170674144" duration="2320000" />
|
||||
<workItem from="1715206284291" duration="5406000" />
|
||||
<workItem from="1715254613428" duration="3973000" />
|
||||
<workItem from="1715293126957" duration="547000" />
|
||||
<workItem from="1715334251448" duration="4485000" />
|
||||
<workItem from="1715360147026" duration="5634000" />
|
||||
<workItem from="1715583954732" duration="5283000" />
|
||||
<workItem from="1715669033601" duration="11720000" />
|
||||
<workItem from="1715762731245" duration="3986000" />
|
||||
<workItem from="1715773968873" duration="3580000" />
|
||||
<workItem from="1715814533138" duration="12142000" />
|
||||
</task>
|
||||
<task id="LOCAL-00001" summary="Rework Tile detection system">
|
||||
<option name="closed" value="true" />
|
||||
@@ -318,7 +340,71 @@
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1713863838768</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="12" />
|
||||
<task id="LOCAL-00012" summary="Add fps">
|
||||
<option name="closed" value="true" />
|
||||
<created>1714460546894</created>
|
||||
<option name="number" value="00012" />
|
||||
<option name="presentableId" value="LOCAL-00012" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1714460546894</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00013" summary="Add player turning (Finally)">
|
||||
<option name="closed" value="true" />
|
||||
<created>1714471045905</created>
|
||||
<option name="number" value="00013" />
|
||||
<option name="presentableId" value="LOCAL-00013" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1714471045905</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00014" summary="Update gitignore">
|
||||
<option name="closed" value="true" />
|
||||
<created>1714471502013</created>
|
||||
<option name="number" value="00014" />
|
||||
<option name="presentableId" value="LOCAL-00014" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1714471502013</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00015" summary="Remove All Memory leaks">
|
||||
<option name="closed" value="true" />
|
||||
<created>1714654669410</created>
|
||||
<option name="number" value="00015" />
|
||||
<option name="presentableId" value="LOCAL-00015" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1714654669410</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00016" summary="Fix digging">
|
||||
<option name="closed" value="true" />
|
||||
<created>1715070920513</created>
|
||||
<option name="number" value="00016" />
|
||||
<option name="presentableId" value="LOCAL-00016" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1715070920513</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00017" summary="Started on GuiIcon, General fixes">
|
||||
<option name="closed" value="true" />
|
||||
<created>1715208368790</created>
|
||||
<option name="number" value="00017" />
|
||||
<option name="presentableId" value="LOCAL-00017" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1715208368790</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00018" summary="Add Particles (basic)">
|
||||
<option name="closed" value="true" />
|
||||
<created>1715255455692</created>
|
||||
<option name="number" value="00018" />
|
||||
<option name="presentableId" value="LOCAL-00018" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1715255455692</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00019" summary="Add Text rendering and Hull / Fuel Meters">
|
||||
<option name="closed" value="true" />
|
||||
<created>1715817878533</created>
|
||||
<option name="number" value="00019" />
|
||||
<option name="presentableId" value="LOCAL-00019" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1715817878533</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="20" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="TypeScriptGeneratedFilesManager">
|
||||
@@ -336,10 +422,17 @@
|
||||
<MESSAGE value="Fixed sidePieces (Need to add more cases tho)" />
|
||||
<MESSAGE value="Pre Point2f Nuke Fixed drawing, Added general optimisations" />
|
||||
<MESSAGE value="Remove Point2f, replace with Vector2f" />
|
||||
<MESSAGE value="Fix digging" />
|
||||
<MESSAGE value="Added Buildings Fixed rendering bugs with edges" />
|
||||
<MESSAGE value="Add alot of memory leak fixes" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="Add alot of memory leak fixes" />
|
||||
<MESSAGE value="Add fps" />
|
||||
<MESSAGE value="Add player turning (Finally)" />
|
||||
<MESSAGE value="Update gitignore" />
|
||||
<MESSAGE value="Remove All Memory leaks" />
|
||||
<MESSAGE value="Fix digging" />
|
||||
<MESSAGE value="Started on GuiIcon, General fixes" />
|
||||
<MESSAGE value="Add Particles (basic)" />
|
||||
<MESSAGE value="Add Text rendering and Hull / Fuel Meters" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="Add Text rendering and Hull / Fuel Meters" />
|
||||
</component>
|
||||
<component name="XSLT-Support.FileAssociations.UIState">
|
||||
<expand />
|
||||
|
||||
15
.idea/.idea.Prog2Engine/.idea/.gitignore
generated
vendored
@@ -1,15 +0,0 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Rider ignored files
|
||||
/modules.xml
|
||||
/projectSettingsUpdater.xml
|
||||
/contentModel.xml
|
||||
/.idea.Prog2Engine.iml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
# GitHub Copilot persisted chat sessions
|
||||
/copilot/chatSessions
|
||||
1
.idea/.idea.Prog2Engine/.idea/.name
generated
@@ -1 +0,0 @@
|
||||
Prog2Engine
|
||||
4
.idea/.idea.Prog2Engine/.idea/encodings.xml
generated
@@ -1,4 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
|
||||
</project>
|
||||
8
.idea/.idea.Prog2Engine/.idea/indexLayout.xml
generated
@@ -1,8 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="UserContentModel">
|
||||
<attachedFolders />
|
||||
<explicitIncludes />
|
||||
<explicitExcludes />
|
||||
</component>
|
||||
</project>
|
||||
6
.idea/.idea.Prog2Engine/.idea/vcs.xml
generated
@@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
BIN
Assets/Player/PlayerDig.aseprite
Normal file
BIN
Assets/Player/PlayerDigStart.aseprite
Normal file
BIN
Assets/Player/PlayerTurn.aseprite
Normal file
@@ -107,7 +107,7 @@ void BaseGame::InitializeGameEngine()
|
||||
|
||||
// Setup Dear ImGui style
|
||||
ImGui::StyleColorsDark();
|
||||
//ImGui::StyleColorsLight();
|
||||
// ImGui::StyleColorsLight();
|
||||
|
||||
// Setup Platform/Renderer backends
|
||||
ImGui_ImplSDL2_InitForOpenGL(m_pWindow, m_pContext);
|
||||
@@ -146,6 +146,10 @@ void BaseGame::InitializeGameEngine()
|
||||
return;
|
||||
}
|
||||
|
||||
m_pIcon = IMG_Load("icon.png");
|
||||
SDL_SetWindowIcon(m_pWindow, m_pIcon);
|
||||
|
||||
// delete icon;
|
||||
|
||||
//Initialize controller
|
||||
m_pGameController = nullptr;
|
||||
@@ -165,6 +169,8 @@ void BaseGame::InitializeGameEngine()
|
||||
|
||||
SDL_GameControllerAddMappingsFromFile("gamecontrollerdb.txt");
|
||||
|
||||
SDL_RendererInfo m_RendererInfo;
|
||||
SDL_GetRendererInfo(SDL_GetRenderer(m_pWindow), &m_RendererInfo);
|
||||
|
||||
m_Initialized = true;
|
||||
}
|
||||
@@ -270,6 +276,8 @@ void BaseGame::CleanupGameEngine()
|
||||
ImGui_ImplSDL2_Shutdown();
|
||||
ImGui::DestroyContext();
|
||||
|
||||
SDL_FreeSurface(m_pIcon);
|
||||
|
||||
SDL_GL_DeleteContext(m_pContext);
|
||||
|
||||
SDL_DestroyWindow(m_pWindow);
|
||||
|
||||
@@ -59,6 +59,8 @@ private:
|
||||
|
||||
SDL_GameController* m_pGameController;
|
||||
|
||||
SDL_Surface* m_pIcon;
|
||||
|
||||
// FUNCTIONS
|
||||
void InitializeGameEngine();
|
||||
void CleanupGameEngine();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "Text.h"
|
||||
|
||||
#include <iostream>
|
||||
Text::Text(const std::string& text, const std::string& fontPath, int size, const Color4f& color): m_Text(text), m_FontPath(fontPath), m_Color(color) {
|
||||
Text::Text(const std::string& text, const std::string& fontPath, int size, const Color4f& color): m_Text(text), m_FontPath(fontPath), m_Size(size), m_Color(color) {
|
||||
m_Texture = new Texture(text, fontPath, size, color);
|
||||
m_IsCreatedOk = m_Texture->IsCreationOk();
|
||||
if(!m_IsCreatedOk) {
|
||||
@@ -14,5 +14,17 @@ Text::~Text() {
|
||||
}
|
||||
}
|
||||
void Text::Draw(const Vector2f& pos) const {
|
||||
m_Texture->Draw(pos);
|
||||
if(m_IsCreatedOk) {
|
||||
m_Texture->Draw(pos);
|
||||
} else {
|
||||
std::cout << "Trying to render a Text that is not correctly made,\nText: " << m_Text << std::endl;
|
||||
}
|
||||
}
|
||||
void Text::ChangeText(const std::string& text) {
|
||||
if(m_IsCreatedOk && m_Texture->IsCreationOk()) {
|
||||
delete m_Texture;
|
||||
m_Texture = new Texture(text, m_FontPath, m_Size, m_Color);
|
||||
} else {
|
||||
std::cout << "This is wierd??: " << m_Text << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,11 +13,14 @@ public:
|
||||
|
||||
void Draw(const Vector2f& pos) const;
|
||||
|
||||
void ChangeText(const std::string& text);
|
||||
|
||||
|
||||
|
||||
private:
|
||||
std::string m_Text;
|
||||
std::string m_FontPath;
|
||||
int m_Size;
|
||||
Color4f m_Color;
|
||||
Texture* m_Texture;
|
||||
bool m_IsCreatedOk{ false };
|
||||
|
||||
@@ -692,6 +692,12 @@ float utils::map(float value, float start1, float stop1, float start2, float sto
|
||||
float newVal = (value - start1) / (stop1 - start1) * (stop2 - start2) + start2;
|
||||
return newVal;
|
||||
}
|
||||
float utils::clamp(float value, float min, float max) {
|
||||
return std::max(min, std::min(value, max));
|
||||
}
|
||||
Vector2f utils::clamp(const Vector2f& value, const Vector2f& min, const Vector2f& max) {
|
||||
return Vector2f { clamp(value.x, min.x, max.x), clamp(value.y, min.y, max.y) };
|
||||
}
|
||||
bool utils::isKeyDown(int keycode) {
|
||||
const Uint8* pStates = SDL_GetKeyboardState(nullptr);
|
||||
if (pStates != nullptr) {
|
||||
|
||||
@@ -111,6 +111,9 @@ namespace utils
|
||||
Vector2f lerp(const Vector2f& a, const Vector2f& b, float t);
|
||||
|
||||
float map(float value, float start1, float stop1, float start2, float stop2);
|
||||
|
||||
float clamp(float value, float min, float max);
|
||||
Vector2f clamp(const Vector2f& value, const Vector2f& min, const Vector2f& max);
|
||||
#pragma endregion CollisionFunctionality
|
||||
|
||||
bool isKeyDown(SDL_Keycode keycode);
|
||||
|
||||
@@ -1,29 +1,57 @@
|
||||
#include "pch.h"
|
||||
#include "Animation.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#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, bool isLooping): m_pTexture(pTexture), m_SrcRect(srcRect), m_Frames(frames),
|
||||
m_isLooping(isLooping), m_FrameDuration(frameDuration) {
|
||||
|
||||
}
|
||||
void Animation::Update(float elapsedSec) {
|
||||
if (m_isPlaying) {
|
||||
m_FrameTimer -= elapsedSec;
|
||||
if (m_FrameTimer <= 0.0f) {
|
||||
m_FrameTimer = 0.1f;
|
||||
m_FrameTimer = m_FrameDuration;
|
||||
++m_CurrentFrame;
|
||||
if (m_CurrentFrame >= m_Frames) {
|
||||
m_CurrentFrame = 0;
|
||||
if (!m_isLooping) {
|
||||
m_hasPlayedOnce = true;
|
||||
m_isPlaying = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
void Animation::Draw(const Vector2f& pos) const {
|
||||
Draw(pos, Rectf{ pos.x, pos.y, m_SrcRect.width, m_SrcRect.height });
|
||||
Draw(pos, Rectf { pos.x, pos.y, m_SrcRect.width, m_SrcRect.height });
|
||||
}
|
||||
|
||||
void Animation::Draw(const Vector2f& pos, const Rectf& dst) const {
|
||||
Rectf src = m_SrcRect;
|
||||
src.left += static_cast<float>(m_CurrentFrame) * src.width;
|
||||
|
||||
|
||||
m_pTexture->Draw(dst, src, m_isFlipped);
|
||||
}
|
||||
void Animation::SetPlaying(bool isPlaying) {
|
||||
m_isPlaying = isPlaying;
|
||||
}
|
||||
void Animation::SetFlipped(bool isFlipped) {
|
||||
m_isFlipped = isFlipped;
|
||||
}
|
||||
void Animation::Reset() {
|
||||
m_CurrentFrame = 0;
|
||||
m_hasPlayedOnce = false;
|
||||
m_isPlaying = true;
|
||||
m_FrameTimer = m_FrameDuration;
|
||||
}
|
||||
bool Animation::IsDone() const {
|
||||
return m_hasPlayedOnce && !m_isLooping;
|
||||
}
|
||||
int Animation::GetFrameCount() const {
|
||||
return m_Frames;
|
||||
}
|
||||
void Animation::SetFrame(int frame) {
|
||||
m_CurrentFrame = frame;
|
||||
}
|
||||
|
||||
@@ -4,19 +4,21 @@
|
||||
class Animation
|
||||
{
|
||||
public:
|
||||
Animation(Texture* pTexture, int frames, float frameDuration, Rectf srcRect);
|
||||
~Animation() = default;
|
||||
Animation(Texture* pTexture, int frames, float frameDuration, Rectf srcRect, bool isLooping = true);
|
||||
|
||||
void Update(float elapsedSec);
|
||||
void Draw(const Vector2f& pos) const;
|
||||
void Draw(const Vector2f& pos, const Rectf& dst) const;
|
||||
|
||||
void SetPlaying(bool isPlaying) {
|
||||
m_isPlaying = isPlaying;
|
||||
}
|
||||
void SetFlipped(bool isFlipped) {
|
||||
m_isFlipped = isFlipped;
|
||||
}
|
||||
|
||||
void SetPlaying(bool isPlaying);
|
||||
void SetFlipped(bool isFlipped);
|
||||
|
||||
void Reset();
|
||||
bool IsDone() const;
|
||||
|
||||
int GetFrameCount() const;
|
||||
void SetFrame(int frame);
|
||||
|
||||
private:
|
||||
Texture* m_pTexture;
|
||||
@@ -26,6 +28,11 @@ private:
|
||||
int m_CurrentFrame { 0 };
|
||||
float m_FrameTimer { 0.0f };
|
||||
|
||||
float m_FrameDuration { 0.1f };
|
||||
|
||||
bool m_isPlaying { true };
|
||||
bool m_isFlipped { false };
|
||||
|
||||
bool m_isLooping { true };
|
||||
bool m_hasPlayedOnce { false };
|
||||
};
|
||||
|
||||
@@ -5,7 +5,9 @@
|
||||
#include <algorithm>
|
||||
|
||||
#include "colors.h"
|
||||
#include "GridSystem/GroundTileTypeManager.h"
|
||||
#include "utils.h"
|
||||
#include "GridSystem/WorldTile.h"
|
||||
#include "Levels/World/WorldLevel.h"
|
||||
|
||||
|
||||
@@ -28,8 +30,8 @@ void Game::Initialize() {
|
||||
|
||||
void Game::Cleanup() {
|
||||
|
||||
//TODO: ask how 2 delete the TextureManager
|
||||
ScreenManager::DestroyInstance();
|
||||
GroundTileTypeManager::DestroyInstance();
|
||||
TextureManager::DestroyInstance();
|
||||
}
|
||||
|
||||
@@ -37,7 +39,7 @@ void Game::Update(float elapsedSec) {
|
||||
const Uint8* pStates = SDL_GetKeyboardState(nullptr);
|
||||
|
||||
if (m_IsRightMouseDown) {
|
||||
const Vector2f newCameraPos = Vector2f { m_MousePos.x + m_MouseOffset.x, m_MousePos.y + m_MouseOffset.y };
|
||||
const Vector2f newCameraPos = Vector2f { m_MousePosition.x + m_MouseOffset.x, m_MousePosition.y + m_MouseOffset.y };
|
||||
m_Camera.SetPosition(Vector2f { -newCameraPos.x, -newCameraPos.y });
|
||||
}
|
||||
else {
|
||||
@@ -55,39 +57,26 @@ void Game::Draw() const {
|
||||
|
||||
void Game::ProcessKeyDownEvent(const SDL_KeyboardEvent& e) {
|
||||
//std::cout << "KEYDOWN event: " << e.keysym.sym << std::endl;
|
||||
if(e.keysym.sym == SDLK_BACKQUOTE) {
|
||||
m_imGui = !m_imGui;
|
||||
}
|
||||
}
|
||||
|
||||
void Game::ProcessKeyUpEvent(const SDL_KeyboardEvent& e) {
|
||||
}
|
||||
|
||||
void Game::ProcessMouseMotionEvent(const SDL_MouseMotionEvent& e) {
|
||||
m_MousePos = Vector2f { float(e.x), float(e.y) };
|
||||
m_MousePosition = Vector2f { float(e.x), float(e.y) };
|
||||
m_pCurrentLevel->MouseMove(Vector2f { float(e.x), float(e.y) });
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void Game::ProcessMouseDownEvent(const SDL_MouseButtonEvent& e) {
|
||||
m_IsRightMouseDown = e.button == SDL_BUTTON_RIGHT;
|
||||
m_MouseOffset = Vector2f { -m_Camera.GetPosition().x - m_MousePos.x, -m_Camera.GetPosition().y - m_MousePos.y };
|
||||
m_MouseOffset = Vector2f { -m_Camera.GetPosition().x - m_MousePosition.x, -m_Camera.GetPosition().y - m_MousePosition.y };
|
||||
}
|
||||
|
||||
void Game::ProcessMouseUpEvent(const SDL_MouseButtonEvent& e) {
|
||||
m_IsRightMouseDown = e.button == SDL_BUTTON_RIGHT ? false : m_IsRightMouseDown;
|
||||
//std::cout << "MOUSEBUTTONUP event: ";
|
||||
//switch ( e.button )
|
||||
//{
|
||||
//case SDL_BUTTON_LEFT:
|
||||
// std::cout << " left button " << std::endl;
|
||||
// break;
|
||||
//case SDL_BUTTON_RIGHT:k
|
||||
// std::cout << " right button " << std::endl;
|
||||
// break;
|
||||
//case SDL_BUTTON_MIDDLE:
|
||||
// std::cout << " middle button " << std::endl;
|
||||
// break;
|
||||
//}
|
||||
}
|
||||
void Game::ProcessMouseWheelEvent(const SDL_MouseWheelEvent& e) {
|
||||
float newScale = m_Camera.GetScale() - e.preciseY * 0.1f;
|
||||
@@ -97,5 +86,7 @@ void Game::ProcessMouseWheelEvent(const SDL_MouseWheelEvent& e) {
|
||||
m_Camera.SetScale(newScale);
|
||||
}
|
||||
void Game::ProcessImGui() {
|
||||
m_pCurrentLevel->ProcessImGui();
|
||||
if(m_imGui) {
|
||||
m_pCurrentLevel->ProcessImGui();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,6 @@ public:
|
||||
static Rectf VIEWPORT;
|
||||
|
||||
private:
|
||||
// FUNCTIONS
|
||||
void Initialize();
|
||||
void Cleanup();
|
||||
|
||||
@@ -43,8 +42,11 @@ private:
|
||||
|
||||
Level* m_pCurrentLevel;
|
||||
|
||||
Vector2f m_MousePos {};
|
||||
Vector2f m_MousePosition {};
|
||||
Vector2f m_MouseOffset {};
|
||||
bool m_IsRightMouseDown {};
|
||||
|
||||
|
||||
bool m_imGui{ true };
|
||||
|
||||
};
|
||||
|
||||
@@ -157,6 +157,80 @@
|
||||
<ClCompile Include="Camera.cpp" />
|
||||
<ClCompile Include="Game.cpp" />
|
||||
<ClCompile Include="GameManager.cpp" />
|
||||
<ClCompile Include="GridSystem\GroundTileTypeManager.cpp">
|
||||
<RuntimeLibrary>MultiThreadedDebugDll</RuntimeLibrary>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SupportJustMyCode>true</SupportJustMyCode>
|
||||
<AssemblerOutput>NoListing</AssemblerOutput>
|
||||
<AssemblerListingLocation>x64\Debug\</AssemblerListingLocation>
|
||||
<UndefineAllPreprocessorDefinitions>false</UndefineAllPreprocessorDefinitions>
|
||||
<BrowseInformation>true</BrowseInformation>
|
||||
<BrowseInformationFile>x64\Debug\</BrowseInformationFile>
|
||||
<CompileAs>Default</CompileAs>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<DiagnosticsFormat>Column</DiagnosticsFormat>
|
||||
<DisableLanguageExtensions>false</DisableLanguageExtensions>
|
||||
<ErrorReporting>Prompt</ErrorReporting>
|
||||
<ExpandAttributedSource>false</ExpandAttributedSource>
|
||||
<ExceptionHandling>Sync</ExceptionHandling>
|
||||
<EnableASAN>false</EnableASAN>
|
||||
<EnableFuzzer>false</EnableFuzzer>
|
||||
<EnableFiberSafeOptimizations>false</EnableFiberSafeOptimizations>
|
||||
<EnableEnhancedInstructionSet>NotSet</EnableEnhancedInstructionSet>
|
||||
<FloatingPointModel>Precise</FloatingPointModel>
|
||||
<ForceConformanceInForLoopScope>true</ForceConformanceInForLoopScope>
|
||||
<GenerateModuleDependencies>false</GenerateModuleDependencies>
|
||||
<GenerateSourceDependencies>false</GenerateSourceDependencies>
|
||||
<GenerateXMLDocumentationFiles>false</GenerateXMLDocumentationFiles>
|
||||
<InlineFunctionExpansion>Default</InlineFunctionExpansion>
|
||||
<IntrinsicFunctions>false</IntrinsicFunctions>
|
||||
<IgnoreStandardIncludePath>false</IgnoreStandardIncludePath>
|
||||
<LanguageStandard>Default</LanguageStandard>
|
||||
<LanguageStandard_C>Default</LanguageStandard_C>
|
||||
<MinimalRebuild>false</MinimalRebuild>
|
||||
<ModuleDependenciesFile>x64\Debug\</ModuleDependenciesFile>
|
||||
<ModuleOutputFile>x64\Debug\</ModuleOutputFile>
|
||||
<OmitDefaultLibName>false</OmitDefaultLibName>
|
||||
<FavorSizeOrSpeed>Neither</FavorSizeOrSpeed>
|
||||
<WholeProgramOptimization>false</WholeProgramOptimization>
|
||||
<ObjectFileName>x64\Debug\</ObjectFileName>
|
||||
<CallingConvention>Cdecl</CallingConvention>
|
||||
<ProgramDataBaseFileName>x64\Debug\vc143.pdb</ProgramDataBaseFileName>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
<PrecompiledHeaderOutputFile>x64\Debug\Game.pch</PrecompiledHeaderOutputFile>
|
||||
<PreprocessToFile>false</PreprocessToFile>
|
||||
<PreprocessKeepComments>false</PreprocessKeepComments>
|
||||
<PreprocessSuppressLineNumbers>false</PreprocessSuppressLineNumbers>
|
||||
<RemoveUnreferencedCodeData>true</RemoveUnreferencedCodeData>
|
||||
<ScanSourceForModuleDependencies>false</ScanSourceForModuleDependencies>
|
||||
<ShowIncludes>false</ShowIncludes>
|
||||
<SourceDependenciesFile>x64\Debug\</SourceDependenciesFile>
|
||||
<SuppressStartupBanner>true</SuppressStartupBanner>
|
||||
<BufferSecurityCheck>true</BufferSecurityCheck>
|
||||
<SmallerTypeCheck>false</SmallerTypeCheck>
|
||||
<SpectreMitigation>false</SpectreMitigation>
|
||||
<StructMemberAlignment>Default</StructMemberAlignment>
|
||||
<TrackerLogDirectory>x64\Debug\Game.tlog\</TrackerLogDirectory>
|
||||
<TranslateIncludes>false</TranslateIncludes>
|
||||
<MinimalRebuildFromTracking>true</MinimalRebuildFromTracking>
|
||||
<TreatWarningAsError>false</TreatWarningAsError>
|
||||
<TreatWChar_tAsBuiltInType>true</TreatWChar_tAsBuiltInType>
|
||||
<UseFullPaths>true</UseFullPaths>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<XMLDocumentationFileName>x64\Debug\</XMLDocumentationFileName>
|
||||
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
|
||||
<IntelJCCErratum>false</IntelJCCErratum>
|
||||
<BuildStlModules>false</BuildStlModules>
|
||||
<TreatAngleIncludeAsExternal>false</TreatAngleIncludeAsExternal>
|
||||
<ExternalWarningLevel>InheritWarningLevel</ExternalWarningLevel>
|
||||
<TreatExternalTemplatesAsInternal>true</TreatExternalTemplatesAsInternal>
|
||||
<DisableAnalyzeExternal>false</DisableAnalyzeExternal>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;_UNICODE;UNICODE;</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<LinkCompiled>true</LinkCompiled>
|
||||
</ClCompile>
|
||||
<ClCompile Include="GridSystem\WorldGridManager.cpp">
|
||||
<RuntimeLibrary>MultiThreadedDebugDll</RuntimeLibrary>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
@@ -307,10 +381,86 @@
|
||||
<LinkCompiled>true</LinkCompiled>
|
||||
<BrowseInformation Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</BrowseInformation>
|
||||
</ClCompile>
|
||||
<ClCompile Include="GroundTileTypeManager.cpp" />
|
||||
<ClCompile Include="Gui\Button.cpp" />
|
||||
<ClCompile Include="Gui\GuiButton.cpp" />
|
||||
<ClCompile Include="Gui\GuiElement.cpp" />
|
||||
<ClCompile Include="Gui\GuiMeter.cpp" />
|
||||
<ClCompile Include="Gui\GuiText.cpp">
|
||||
<RuntimeLibrary>MultiThreadedDebugDll</RuntimeLibrary>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SupportJustMyCode>true</SupportJustMyCode>
|
||||
<AssemblerOutput>NoListing</AssemblerOutput>
|
||||
<AssemblerListingLocation>x64\Debug\</AssemblerListingLocation>
|
||||
<UndefineAllPreprocessorDefinitions>false</UndefineAllPreprocessorDefinitions>
|
||||
<BrowseInformation>true</BrowseInformation>
|
||||
<BrowseInformationFile>x64\Debug\</BrowseInformationFile>
|
||||
<CompileAs>Default</CompileAs>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<DiagnosticsFormat>Column</DiagnosticsFormat>
|
||||
<DisableLanguageExtensions>false</DisableLanguageExtensions>
|
||||
<ErrorReporting>Prompt</ErrorReporting>
|
||||
<ExpandAttributedSource>false</ExpandAttributedSource>
|
||||
<ExceptionHandling>Sync</ExceptionHandling>
|
||||
<EnableASAN>false</EnableASAN>
|
||||
<EnableFuzzer>false</EnableFuzzer>
|
||||
<EnableFiberSafeOptimizations>false</EnableFiberSafeOptimizations>
|
||||
<EnableEnhancedInstructionSet>NotSet</EnableEnhancedInstructionSet>
|
||||
<FloatingPointModel>Precise</FloatingPointModel>
|
||||
<ForceConformanceInForLoopScope>true</ForceConformanceInForLoopScope>
|
||||
<GenerateModuleDependencies>false</GenerateModuleDependencies>
|
||||
<GenerateSourceDependencies>false</GenerateSourceDependencies>
|
||||
<GenerateXMLDocumentationFiles>false</GenerateXMLDocumentationFiles>
|
||||
<InlineFunctionExpansion>Default</InlineFunctionExpansion>
|
||||
<IntrinsicFunctions>false</IntrinsicFunctions>
|
||||
<IgnoreStandardIncludePath>false</IgnoreStandardIncludePath>
|
||||
<LanguageStandard>Default</LanguageStandard>
|
||||
<LanguageStandard_C>Default</LanguageStandard_C>
|
||||
<MinimalRebuild>false</MinimalRebuild>
|
||||
<ModuleDependenciesFile>x64\Debug\</ModuleDependenciesFile>
|
||||
<ModuleOutputFile>x64\Debug\</ModuleOutputFile>
|
||||
<OmitDefaultLibName>false</OmitDefaultLibName>
|
||||
<FavorSizeOrSpeed>Neither</FavorSizeOrSpeed>
|
||||
<WholeProgramOptimization>false</WholeProgramOptimization>
|
||||
<ObjectFileName>x64\Debug\</ObjectFileName>
|
||||
<CallingConvention>Cdecl</CallingConvention>
|
||||
<ProgramDataBaseFileName>x64\Debug\vc143.pdb</ProgramDataBaseFileName>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
<PrecompiledHeaderOutputFile>x64\Debug\Game.pch</PrecompiledHeaderOutputFile>
|
||||
<PreprocessToFile>false</PreprocessToFile>
|
||||
<PreprocessKeepComments>false</PreprocessKeepComments>
|
||||
<PreprocessSuppressLineNumbers>false</PreprocessSuppressLineNumbers>
|
||||
<RemoveUnreferencedCodeData>true</RemoveUnreferencedCodeData>
|
||||
<ScanSourceForModuleDependencies>false</ScanSourceForModuleDependencies>
|
||||
<ShowIncludes>false</ShowIncludes>
|
||||
<SourceDependenciesFile>x64\Debug\</SourceDependenciesFile>
|
||||
<SuppressStartupBanner>true</SuppressStartupBanner>
|
||||
<BufferSecurityCheck>true</BufferSecurityCheck>
|
||||
<SmallerTypeCheck>false</SmallerTypeCheck>
|
||||
<SpectreMitigation>false</SpectreMitigation>
|
||||
<StructMemberAlignment>Default</StructMemberAlignment>
|
||||
<TrackerLogDirectory>x64\Debug\Game.tlog\</TrackerLogDirectory>
|
||||
<TranslateIncludes>false</TranslateIncludes>
|
||||
<MinimalRebuildFromTracking>true</MinimalRebuildFromTracking>
|
||||
<TreatWarningAsError>false</TreatWarningAsError>
|
||||
<TreatWChar_tAsBuiltInType>true</TreatWChar_tAsBuiltInType>
|
||||
<UseFullPaths>true</UseFullPaths>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<XMLDocumentationFileName>x64\Debug\</XMLDocumentationFileName>
|
||||
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
|
||||
<IntelJCCErratum>false</IntelJCCErratum>
|
||||
<BuildStlModules>false</BuildStlModules>
|
||||
<TreatAngleIncludeAsExternal>false</TreatAngleIncludeAsExternal>
|
||||
<ExternalWarningLevel>InheritWarningLevel</ExternalWarningLevel>
|
||||
<TreatExternalTemplatesAsInternal>true</TreatExternalTemplatesAsInternal>
|
||||
<DisableAnalyzeExternal>false</DisableAnalyzeExternal>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;_UNICODE;UNICODE;</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<LinkCompiled>true</LinkCompiled>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Gui\Screen.cpp" />
|
||||
<ClCompile Include="Gui\Screens\FuelScreen.cpp" />
|
||||
<ClCompile Include="Gui\Screens\MainScreen.cpp" />
|
||||
<ClCompile Include="Gui\Screens\ScreenManager.cpp" />
|
||||
<ClCompile Include="Levels\Level.cpp">
|
||||
<RuntimeLibrary>MultiThreadedDebugDll</RuntimeLibrary>
|
||||
@@ -389,6 +539,7 @@
|
||||
</ClCompile>
|
||||
<ClCompile Include="Levels\MainMenu\MainMenuLevel.cpp" />
|
||||
<ClCompile Include="Levels\World\Building.cpp" />
|
||||
<ClCompile Include="Levels\World\OrbitingObject.cpp" />
|
||||
<ClCompile Include="Levels\World\WorldLevel.cpp">
|
||||
<RuntimeLibrary>MultiThreadedDebugDll</RuntimeLibrary>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
@@ -465,6 +616,7 @@
|
||||
<BrowseInformation Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</BrowseInformation>
|
||||
</ClCompile>
|
||||
<ClCompile Include="main.cpp" />
|
||||
<ClCompile Include="Particle\Particle.cpp" />
|
||||
<ClCompile Include="pch.cpp" />
|
||||
<ClCompile Include="Player.cpp" />
|
||||
<ClCompile Include="TextureManager.cpp" />
|
||||
@@ -474,17 +626,23 @@
|
||||
<ClInclude Include="Camera.h" />
|
||||
<ClInclude Include="Game.h" />
|
||||
<ClInclude Include="GameManager.h" />
|
||||
<ClInclude Include="GridSystem\GroundTileTypeManager.h" />
|
||||
<ClInclude Include="GridSystem\WorldGridManager.h" />
|
||||
<ClInclude Include="GridSystem\WorldTile.h" />
|
||||
<ClInclude Include="GroundTileTypeManager.h" />
|
||||
<ClInclude Include="Gui\Button.h" />
|
||||
<ClInclude Include="Gui\GuiButton.h" />
|
||||
<ClInclude Include="Gui\GuiElement.h" />
|
||||
<ClInclude Include="Gui\GuiMeter.h" />
|
||||
<ClInclude Include="Gui\GuiText.h" />
|
||||
<ClInclude Include="Gui\Screen.h" />
|
||||
<ClInclude Include="Gui\Screens\FuelScreen.h" />
|
||||
<ClInclude Include="Gui\Screens\MainScreen.h" />
|
||||
<ClInclude Include="Gui\Screens\ScreenManager.h" />
|
||||
<ClInclude Include="Levels\Level.h" />
|
||||
<ClInclude Include="Levels\MainMenu\MainMenuLevel.h" />
|
||||
<ClInclude Include="Levels\World\Building.h" />
|
||||
<ClInclude Include="Levels\World\OrbitingObject.h" />
|
||||
<ClInclude Include="Levels\World\WorldLevel.h" />
|
||||
<ClInclude Include="Particle\Particle.h" />
|
||||
<ClInclude Include="pch.h" />
|
||||
<ClInclude Include="Player.h" />
|
||||
<ClInclude Include="TextureManager.h" />
|
||||
|
||||
@@ -1,2 +1,50 @@
|
||||
#include "pch.h"
|
||||
#include "GameManager.h"
|
||||
|
||||
GameManager* GameManager::m_pInstance = nullptr;
|
||||
|
||||
GameManager& GameManager::GetInstance() {
|
||||
if (m_pInstance == nullptr) {
|
||||
m_pInstance = new GameManager();
|
||||
}
|
||||
return *m_pInstance;
|
||||
}
|
||||
void GameManager::SetMainScreen(MainScreen* pMainScreen) {
|
||||
m_pMainScreen = pMainScreen;
|
||||
//TODO: not the best but ¯\_(ツ)_/¯
|
||||
}
|
||||
void GameManager::SetFuel(int fuel) {
|
||||
m_Fuel = fuel;
|
||||
}
|
||||
int GameManager::GetFuel() const {
|
||||
return m_Fuel;
|
||||
}
|
||||
void GameManager::DecreaseFuel(int fuel) {
|
||||
m_Fuel -= fuel;
|
||||
}
|
||||
void GameManager::AddFuel(int fuel) {
|
||||
m_Fuel += fuel;
|
||||
}
|
||||
void GameManager::SetHullIntegrity(int hullIntegrity) {
|
||||
m_HullIntegrity = hullIntegrity;
|
||||
}
|
||||
int GameManager::GetHullIntegrity() const {
|
||||
return m_HullIntegrity;
|
||||
}
|
||||
void GameManager::DamageHull(int damage) {
|
||||
m_HullIntegrity -= damage;
|
||||
}
|
||||
void GameManager::SetScore(int score) {
|
||||
m_Score = score;
|
||||
}
|
||||
int GameManager::GetScore() const {
|
||||
return m_Score;
|
||||
}
|
||||
void GameManager::IncreaseScore(int score) {
|
||||
m_Score += score;
|
||||
}
|
||||
void GameManager::Update(float elapsedSecs) {
|
||||
m_pMainScreen->SetFuelMeterValue(m_Fuel);
|
||||
m_pMainScreen->SetHullMeterValue(m_HullIntegrity);
|
||||
m_pMainScreen->SetScore(std::to_string(m_Score));
|
||||
}
|
||||
|
||||
@@ -1,12 +1,38 @@
|
||||
#pragma once
|
||||
#include "Player.h"
|
||||
#include "Gui/Screens/MainScreen.h"
|
||||
|
||||
class GameManager
|
||||
{
|
||||
class GameManager {
|
||||
public:
|
||||
float balance{ 0.0f };
|
||||
float fuel{ 0.0f };
|
||||
static GameManager& GetInstance();
|
||||
static GameManager* m_pInstance;
|
||||
|
||||
|
||||
void SetMainScreen(MainScreen* pMainScreen);
|
||||
|
||||
void SetFuel(int fuel);
|
||||
int GetFuel() const;
|
||||
void DecreaseFuel(int fuel);
|
||||
void AddFuel(int fuel);
|
||||
|
||||
void SetHullIntegrity(int hullIntegrity);
|
||||
int GetHullIntegrity() const;
|
||||
void DamageHull(int damage);
|
||||
|
||||
void SetScore(int score);
|
||||
int GetScore() const;
|
||||
void IncreaseScore(int score);
|
||||
|
||||
void Update(float elapsedSecs);
|
||||
|
||||
private:
|
||||
GameManager() = default;
|
||||
|
||||
|
||||
float m_Balance{ 0.0f };
|
||||
int m_HullIntegrity{ 100 };
|
||||
int m_Fuel{ 100 };
|
||||
int m_Score{ 0 };
|
||||
MainScreen* m_pMainScreen{ nullptr };
|
||||
};
|
||||
|
||||
|
||||
31
Game/GridSystem/GroundTileTypeManager.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#include "pch.h"
|
||||
#include "GroundTileTypeManager.h"
|
||||
|
||||
#include "GridSystem/WorldTile.h"
|
||||
|
||||
GroundTileTypeManager* GroundTileTypeManager::m_pInstance = nullptr;
|
||||
|
||||
GroundTileTypeManager* GroundTileTypeManager::GetInstance() {
|
||||
if (m_pInstance == nullptr) {
|
||||
m_pInstance = new GroundTileTypeManager();
|
||||
}
|
||||
return m_pInstance;
|
||||
}
|
||||
void GroundTileTypeManager::DestroyInstance() {
|
||||
delete m_pInstance->AIR;
|
||||
delete m_pInstance->DIRT;
|
||||
delete m_pInstance->STONE;
|
||||
delete m_pInstance->LAVA;
|
||||
delete m_pInstance->IRON;
|
||||
delete m_pInstance->BRONZE;
|
||||
delete m_pInstance->GOLD;
|
||||
delete m_pInstance->HARD_LEFT;
|
||||
delete m_pInstance->HARD_RIGHT;
|
||||
delete m_pInstance->HARD_MIDDLE;
|
||||
delete m_pInstance->GRASS;
|
||||
|
||||
delete m_pInstance;
|
||||
}
|
||||
GroundTileTypeManager::GroundTileTypeManager() = default;
|
||||
|
||||
GroundTileTypeManager::~GroundTileTypeManager() = default;
|
||||
@@ -20,31 +20,15 @@ WorldGridManager::~WorldGridManager() {
|
||||
delete m_worldTiles[x][y];
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "Deleting static" << std::endl;
|
||||
// delete Tiles::AIR;
|
||||
// delete Tiles::DIRT;
|
||||
//
|
||||
// delete Tiles::Hazards::LAVA;
|
||||
// delete Tiles::Hazards::STONE;
|
||||
//
|
||||
// delete Tiles::Ores::BRONZE;
|
||||
// delete Tiles::Ores::GOLD;
|
||||
// delete Tiles::Ores::IRON;
|
||||
//
|
||||
// delete Tiles::Special::GRASS;
|
||||
// delete Tiles::Special::HARD_LEFT;
|
||||
// delete Tiles::Special::HARD_MIDDLE;
|
||||
// delete Tiles::Special::HARD_RIGHT;
|
||||
}
|
||||
|
||||
surroundingTiles WorldGridManager::GetSurroundingTiles(const WorldTile* world_tile) {
|
||||
surroundingTiles tiles;
|
||||
Vector2f pos = world_tile->GetPosition();
|
||||
Vector2f gridCoords = this->GetIndexFromPosition(pos);
|
||||
int x = gridCoords.x;
|
||||
const int x = (int)gridCoords.x;
|
||||
//TODO: Stupid fix, fix this
|
||||
int y = gridCoords.y - 1;
|
||||
const int y = (int)gridCoords.y - 1;
|
||||
|
||||
tiles.SetTile(TileDirection::TopLeft, this->GetTileAtIndex(x - 1, y - 1));
|
||||
tiles.SetTile(TileDirection::TopMiddle, this->GetTileAtIndex(x, y - 1));
|
||||
@@ -58,12 +42,12 @@ surroundingTiles WorldGridManager::GetSurroundingTiles(const WorldTile* world_ti
|
||||
tiles.SetTile(TileDirection::BottomRight, this->GetTileAtIndex(x + 1, y + 1));
|
||||
|
||||
return tiles;
|
||||
|
||||
|
||||
}
|
||||
Vector2f WorldGridManager::GetIndexFromPosition(Vector2f position) {
|
||||
int x = int(position.x / TILE_WIDTH + WORLD_WIDTH / 2);
|
||||
int y = int(-position.y / TILE_HEIGHT);
|
||||
return Vector2f{ float(x), float(y) };
|
||||
return Vector2f { float(x), float(y) };
|
||||
}
|
||||
WorldTile * WorldGridManager::GetTileAtIndex(const int x, const int y) const {
|
||||
if (x < 0 || x >= WORLD_WIDTH || y < 0 || y >= WORLD_HEIGHT) {
|
||||
|
||||
@@ -14,8 +14,7 @@ static const int TILE_HEIGHT = 50;
|
||||
|
||||
class WorldTile;
|
||||
|
||||
enum TileDirection
|
||||
{
|
||||
enum TileDirection {
|
||||
TopLeft,
|
||||
TopMiddle,
|
||||
TopRight,
|
||||
@@ -29,41 +28,31 @@ enum TileDirection
|
||||
BottomRight
|
||||
};
|
||||
|
||||
struct surroundingTiles
|
||||
{
|
||||
struct surroundingTiles {
|
||||
|
||||
std::vector<WorldTile *> m_tiles{ 8, nullptr};
|
||||
std::vector<WorldTile *> m_tiles { 8, nullptr };
|
||||
|
||||
void SetTile(TileDirection direction, WorldTile* tile) {
|
||||
m_tiles[static_cast<int>(direction)] = tile;
|
||||
}
|
||||
|
||||
WorldTile* GetTile(TileDirection direction) {
|
||||
WorldTile * GetTile(TileDirection direction) {
|
||||
return m_tiles[static_cast<int>(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
|
||||
{
|
||||
class WorldGridManager {
|
||||
public:
|
||||
WorldGridManager();
|
||||
~WorldGridManager();
|
||||
surroundingTiles GetSurroundingTiles(const WorldTile* world_tile);
|
||||
Vector2f GetIndexFromPosition(Vector2f position);
|
||||
static Vector2f GetIndexFromPosition(Vector2f position);
|
||||
|
||||
WorldGridManager(const WorldGridManager& other) = default;
|
||||
WorldGridManager(const WorldGridManager& other) = delete;
|
||||
WorldGridManager(WorldGridManager&& other) = default;
|
||||
WorldGridManager& operator=(const WorldGridManager& other) = delete;
|
||||
WorldGridManager& operator=(WorldGridManager&& other) = delete;
|
||||
|
||||
|
||||
WorldTile * GetTileAtIndex(const int x, const int y) const;
|
||||
WorldTile * GetTileAtWorldPos(const Vector2f& pos) const;
|
||||
|
||||
@@ -65,6 +65,7 @@ void InitializeGroundTiles() {
|
||||
{ GroundTileTypeManager::GetInstance()->IRON, 0.1f },
|
||||
};
|
||||
}
|
||||
|
||||
WorldTile::WorldTile(const Vector2f& position, GroundTileType* groundTileType, TextureManager* pTextureManager, WorldGridManager* pGridManager) : m_Position { position },
|
||||
m_GroundTileType { groundTileType }, m_pGridManager { pGridManager } {
|
||||
// const std::string dirtPath = + "tiles/dirt/dirt" + std::to_string(utils::randRange(1, 5)) + ".png";
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
#include "pch.h"
|
||||
#include "GroundTileTypeManager.h"
|
||||
|
||||
#include "GridSystem/WorldTile.h"
|
||||
|
||||
GroundTileTypeManager* GroundTileTypeManager::m_pInstance = nullptr;
|
||||
|
||||
GroundTileTypeManager* GroundTileTypeManager::GetInstance() {
|
||||
if (m_pInstance == nullptr) {
|
||||
m_pInstance = new GroundTileTypeManager();
|
||||
}
|
||||
return m_pInstance;
|
||||
}
|
||||
void GroundTileTypeManager::DestroyInstance() {
|
||||
}
|
||||
GroundTileTypeManager::GroundTileTypeManager(): AIR(new GroundTileType("", GroundTileTypes::Air)), DIRT(new RandomGroundTile("tiles/dirt/dirt[0].png", GroundTileTypes::Dirt, 5)){
|
||||
}
|
||||
// void GroundTileTypeManager::Initialize() {
|
||||
// AIR = new GroundTileType("", GroundTileTypes::Air);
|
||||
// }
|
||||
GroundTileTypeManager::~GroundTileTypeManager() {
|
||||
}
|
||||
@@ -1,28 +1,28 @@
|
||||
#include "pch.h"
|
||||
#include "Button.h"
|
||||
#include "GuiButton.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "colors.h"
|
||||
#include "utils.h"
|
||||
Button::Button(const std::string& filePath, Vector2f pos, Vector2f size, TextureManager* manager): m_Position(pos), m_Size(size) {
|
||||
GuiButton::GuiButton(const std::string& filePath, Vector2f pos, Vector2f size, TextureManager* manager): m_Position(pos), m_Size(size) {
|
||||
m_Texture = manager->GetTexture(filePath);
|
||||
if(size.x == 0 && size.y == 0) {
|
||||
m_Size = Vector2f{float(m_Texture->GetWidth()), float(m_Texture->GetHeight())};
|
||||
}
|
||||
std::cout << "Button created" << '\n';
|
||||
}
|
||||
Button::~Button() {
|
||||
GuiButton::~GuiButton() {
|
||||
std::cout << "Button destroyed" << '\n';
|
||||
}
|
||||
void Button::Draw() const {
|
||||
void GuiButton::Draw() const {
|
||||
Rectf dest = Rectf(m_Position, m_Size);
|
||||
Rectf src = Rectf(0, 0, m_Texture->GetWidth(), m_Texture->GetHeight());
|
||||
if(m_IsHovered) {
|
||||
m_Texture->Draw(dest, src, false);
|
||||
}
|
||||
}
|
||||
void Button::Update(float elapsedSec) {
|
||||
void GuiButton::Update(float elapsedSec) {
|
||||
Vector2f mousePos = utils::GetMousePos();
|
||||
Rectf buttonRect = Rectf(m_Position, m_Size);
|
||||
|
||||
@@ -2,17 +2,18 @@
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
|
||||
#include "GuiElement.h"
|
||||
#include "Texture.h"
|
||||
#include "../TextureManager.h"
|
||||
|
||||
class Button
|
||||
class GuiButton : public GuiElement
|
||||
{
|
||||
public:
|
||||
Button() = default;
|
||||
Button(const std::string& filePath, Vector2f pos, Vector2f size, TextureManager* manager);
|
||||
~Button();
|
||||
void Draw() const;
|
||||
void Update(float elapsedSec);
|
||||
GuiButton() = default;
|
||||
GuiButton(const std::string& filePath, Vector2f pos, Vector2f size, TextureManager* manager);
|
||||
~GuiButton() override;
|
||||
virtual void Draw() const override;
|
||||
virtual void Update(float elapsedSec) override;
|
||||
|
||||
void SetOnClick(std::function<void(void)> onClick) {
|
||||
m_OnClick = onClick;
|
||||
2
Game/Gui/GuiElement.cpp
Normal file
@@ -0,0 +1,2 @@
|
||||
#include "pch.h"
|
||||
#include "GuiElement.h"
|
||||
14
Game/Gui/GuiElement.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
class GuiElement
|
||||
{
|
||||
public:
|
||||
GuiElement() = default;
|
||||
virtual ~GuiElement() = default;
|
||||
|
||||
virtual void Draw() const = 0;
|
||||
virtual void Update(float elapsedSec) = 0;
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
27
Game/Gui/GuiMeter.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
#include "pch.h"
|
||||
#include "GuiMeter.h"
|
||||
|
||||
#include "TextureManager.h"
|
||||
#include "utils.h"
|
||||
GuiMeter::GuiMeter(const std::string& filePath, Vector2f pos, Vector2f frameSize, int frameCount, TextureManager* manager): GuiMeter(
|
||||
filePath, pos, frameSize, frameSize, frameCount, manager) {
|
||||
}
|
||||
GuiMeter::GuiMeter(const std::string& filePath, Vector2f pos, Vector2f frameSize, Vector2f drawSize, int frameCount, TextureManager* manager): m_Position(pos),
|
||||
m_DrawSize(drawSize), m_FrameCount(frameCount) {
|
||||
m_Animation = new Animation(manager->GetTexture(filePath), frameCount, 0.0f, Rectf { 0, 0, frameSize.x, frameSize.y }, false);
|
||||
}
|
||||
GuiMeter::~GuiMeter() {
|
||||
delete m_Animation;
|
||||
}
|
||||
void GuiMeter::Draw() const {
|
||||
m_Animation->Draw(m_Position, Rectf{m_Position, m_DrawSize});
|
||||
utils::DrawRect(Rectf { m_Position, m_DrawSize});
|
||||
}
|
||||
void GuiMeter::Update(float elapsedSec) {
|
||||
m_Value += 1;
|
||||
const int frame = static_cast<int>(utils::map(m_Value, 0.0f, m_MaxValue, 0, (float)m_Animation->GetFrameCount()));
|
||||
m_Animation->SetFrame(frame);
|
||||
}
|
||||
void GuiMeter::SetValue(float value) {
|
||||
m_Value = value;
|
||||
}
|
||||
34
Game/Gui/GuiMeter.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
#include "GuiElement.h"
|
||||
#include "Texture.h"
|
||||
#include "Animations/Animation.h"
|
||||
|
||||
class TextureManager;
|
||||
|
||||
class GuiMeter final : public GuiElement
|
||||
{
|
||||
public:
|
||||
GuiMeter(const std::string& filePath, Vector2f pos, Vector2f frameSize, int frameCount, TextureManager* manager);
|
||||
GuiMeter(const std::string& filePath, Vector2f pos, Vector2f frameSize, Vector2f drawSize, int frameCount, TextureManager* manager);
|
||||
GuiMeter(GuiMeter& other) = delete;
|
||||
GuiMeter& operator=(const GuiMeter& other) = delete;
|
||||
GuiMeter(GuiMeter&& other) = delete;
|
||||
GuiMeter& operator=(GuiMeter&& other) = delete;
|
||||
virtual ~GuiMeter() override;
|
||||
|
||||
virtual void Draw() const override;
|
||||
virtual void Update(float elapsedSec) override;
|
||||
|
||||
void SetValue(float value);
|
||||
|
||||
private:
|
||||
Animation* m_Animation{ nullptr };
|
||||
Vector2f m_Position;
|
||||
Vector2f m_DrawSize;
|
||||
|
||||
float m_Value{ 0.0f };
|
||||
const float m_MaxValue{ 100.0f };
|
||||
|
||||
int m_FrameCount;
|
||||
|
||||
};
|
||||
26
Game/Gui/GuiText.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#include "pch.h"
|
||||
#include "GuiText.h"
|
||||
|
||||
#include "colors.h"
|
||||
GuiText::GuiText(const Vector2f& position, const std::string& text, const std::string& fontPath, int size, const Color4f& color): m_Position(position), m_Text(new Text(text, fontPath, size, color)) {
|
||||
|
||||
}
|
||||
|
||||
GuiText::GuiText(): m_Position(100,100), m_Text(new Text("Undefined", "fonts/verdana.ttf", 10, Colors::WHITE)) {
|
||||
|
||||
}
|
||||
|
||||
void GuiText::Draw() const {
|
||||
m_Text->Draw(m_Position);
|
||||
}
|
||||
|
||||
void GuiText::Update(float elapsedSec) {
|
||||
}
|
||||
|
||||
void GuiText::ChangeText(const std::string& text) const {
|
||||
m_Text->ChangeText(text);
|
||||
|
||||
}
|
||||
GuiText::~GuiText() {
|
||||
delete m_Text;
|
||||
}
|
||||
20
Game/Gui/GuiText.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
#include "GuiElement.h"
|
||||
#include "Text.h"
|
||||
#include "Texture.h"
|
||||
|
||||
class GuiText : public GuiElement {
|
||||
public:
|
||||
GuiText(const Vector2f& position, const std::string& text, const std::string& fontPath, int size, const Color4f& color);
|
||||
GuiText();
|
||||
|
||||
void Draw() const override;
|
||||
void Update(float elapsedSec) override;
|
||||
|
||||
void ChangeText(const std::string& text) const;
|
||||
|
||||
~GuiText() override;
|
||||
private:
|
||||
Vector2f m_Position;
|
||||
Text* m_Text;
|
||||
};
|
||||
@@ -2,24 +2,30 @@
|
||||
#include "Screen.h"
|
||||
|
||||
Screen::Screen(const std::string& filePath, Vector2f pos, Vector2f size, TextureManager* manager): m_Position(pos), m_Size(size) {
|
||||
m_Background = manager->GetTexture(filePath);
|
||||
if(!filePath.empty()) {
|
||||
m_Background = manager->GetTexture(filePath);
|
||||
} else {
|
||||
m_Background = nullptr;
|
||||
}
|
||||
}
|
||||
Screen::~Screen() {
|
||||
for (Button* b : m_Buttons) {
|
||||
for (GuiElement* b : m_Elements) {
|
||||
delete b;
|
||||
}
|
||||
}
|
||||
void Screen::Update(float elapsedSecs) {
|
||||
for (Button* b : m_Buttons) {
|
||||
for (GuiElement* b : m_Elements) {
|
||||
b->Update(elapsedSecs);
|
||||
}
|
||||
}
|
||||
void Screen::Draw() const {
|
||||
Rectf dest = Rectf(m_Position, m_Size);
|
||||
Rectf src = Rectf(0, 0, m_Background->GetWidth(), m_Background->GetHeight());
|
||||
m_Background->Draw(dest, src, false);
|
||||
if(m_Background != nullptr) { //Incase there is no background
|
||||
Rectf dest = Rectf(m_Position, m_Size);
|
||||
Rectf src = Rectf(0, 0, m_Background->GetWidth(), m_Background->GetHeight());
|
||||
m_Background->Draw(dest, src, false);
|
||||
}
|
||||
|
||||
for (Button* b : m_Buttons) {
|
||||
b->Draw();
|
||||
for (GuiElement* GuiElement : m_Elements) {
|
||||
GuiElement->Draw();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
#include <vector>
|
||||
|
||||
#include "Button.h"
|
||||
#include "GuiButton.h"
|
||||
#include "structs.h"
|
||||
#include "Texture.h"
|
||||
#include "../TextureManager.h"
|
||||
@@ -14,7 +14,7 @@ public:
|
||||
|
||||
virtual ~Screen();
|
||||
|
||||
void AddButton(Button* button) { m_Buttons.push_back(button); }
|
||||
void AddElement(GuiElement* element) { m_Elements.push_back(element); }
|
||||
|
||||
virtual void Update(float elapsedSecs);
|
||||
virtual void Draw() const;
|
||||
@@ -24,5 +24,5 @@ private:
|
||||
|
||||
Texture* m_Background{ nullptr };
|
||||
|
||||
std::vector<Button*> m_Buttons;
|
||||
std::vector<GuiElement*> m_Elements;
|
||||
};
|
||||
|
||||
@@ -15,34 +15,33 @@ FuelScreen::FuelScreen(const std::string& filePath, Vector2f pos, Vector2f size,
|
||||
const Vector2f closeButtonOffset = Vector2f { 460, 396 - 14 };
|
||||
Vector2f closeButtonPos = fuelScreenCenter + closeButtonOffset;
|
||||
closeButtonPos.y -= 18;
|
||||
Button* closeFuelButton = new Button { "gui/close.png", closeButtonPos, Vector2f{0,0}, TextureManager::GetInstance() };
|
||||
GuiButton* closeFuelButton = new GuiButton { "gui/close.png", closeButtonPos, Vector2f{0,0}, TextureManager::GetInstance() };
|
||||
closeFuelButton->SetOnClick([this]() { ScreenManager::GetInstance()->CloseScreen(); });
|
||||
this->AddButton(closeFuelButton);
|
||||
this->AddElement(closeFuelButton);
|
||||
|
||||
const Vector2f oneDollarButtonPos = Vector2f { 451, 287 };
|
||||
Button* fiveDollarButton = new Button { "gui/fuel/5dollars.png", oneDollarButtonPos , Vector2f{0,0}, TextureManager::GetInstance() };
|
||||
this->AddButton(fiveDollarButton);
|
||||
GuiButton* fiveDollarButton = new GuiButton { "gui/fuel/5dollars.png", oneDollarButtonPos , Vector2f{0,0}, TextureManager::GetInstance() };
|
||||
this->AddElement(fiveDollarButton);
|
||||
|
||||
const Vector2f tenDollarButtonPos = oneDollarButtonPos + Vector2f { 113, -1 };
|
||||
Button* tenDollarButton = new Button { "gui/fuel/10dollars.png", tenDollarButtonPos, Vector2f{0,0}, TextureManager::GetInstance() };
|
||||
this->AddButton(tenDollarButton);
|
||||
GuiButton* tenDollarButton = new GuiButton { "gui/fuel/10dollars.png", tenDollarButtonPos, Vector2f{0,0}, TextureManager::GetInstance() };
|
||||
this->AddElement(tenDollarButton);
|
||||
|
||||
const Vector2f twentyFiveDollarButtonPos = oneDollarButtonPos + Vector2f { 0, -89 };
|
||||
Button* twentyFiveDollarButton = new Button { "gui/fuel/25dollars.png", twentyFiveDollarButtonPos, Vector2f{0,0}, TextureManager::GetInstance() };
|
||||
this->AddButton(twentyFiveDollarButton);
|
||||
GuiButton* twentyFiveDollarButton = new GuiButton { "gui/fuel/25dollars.png", twentyFiveDollarButtonPos, Vector2f{0,0}, TextureManager::GetInstance() };
|
||||
this->AddElement(twentyFiveDollarButton);
|
||||
|
||||
const Vector2f fiftyDollarButtonPos = twentyFiveDollarButtonPos + Vector2f { 114, 0 };
|
||||
Button* fiftyDollarButton = new Button { "gui/fuel/50dollars.png", fiftyDollarButtonPos, Vector2f{0,0}, TextureManager::GetInstance() };
|
||||
this->AddButton(fiftyDollarButton);
|
||||
GuiButton* fiftyDollarButton = new GuiButton { "gui/fuel/50dollars.png", fiftyDollarButtonPos, Vector2f{0,0}, TextureManager::GetInstance() };
|
||||
this->AddElement(fiftyDollarButton);
|
||||
|
||||
const Vector2f fillTankButtonPos = Vector2f { 450, 108 };
|
||||
Button* fillTankButton = new Button { "gui/fuel/fillTank.png", fillTankButtonPos, Vector2f{0,0}, TextureManager::GetInstance() };
|
||||
this->AddButton(fillTankButton);
|
||||
GuiButton* fillTankButton = new GuiButton { "gui/fuel/fillTank.png", fillTankButtonPos, Vector2f{0,0}, TextureManager::GetInstance() };
|
||||
this->AddElement(fillTankButton);
|
||||
|
||||
}
|
||||
|
||||
FuelScreen::~FuelScreen() {
|
||||
}
|
||||
FuelScreen::~FuelScreen() = default;
|
||||
|
||||
void FuelScreen::Draw() const {
|
||||
Screen::Draw();
|
||||
|
||||
45
Game/Gui/Screens/MainScreen.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
#include "pch.h"
|
||||
#include "MainScreen.h"
|
||||
|
||||
#include "colors.h"
|
||||
#include "utils.h"
|
||||
#include "Gui/GuiText.h"
|
||||
MainScreen::MainScreen(TextureManager* manager) : Screen("", Vector2f{0, 0}, Vector2f{900.f, 500.f}, manager) {
|
||||
Vector2f ScreenSize = utils::GetViewport();
|
||||
Vector2f FuelFrameSize{ 336, 77 };
|
||||
Vector2f HullFrameSize{ 61, 76 };
|
||||
|
||||
m_FuelMeter = new GuiMeter("gui/main/fuel/fuel.png", Vector2f{HullFrameSize.x + 10, ScreenSize.y - FuelFrameSize.y }, FuelFrameSize,FuelFrameSize / 1.3, 21, manager);
|
||||
this->AddElement(m_FuelMeter);
|
||||
|
||||
m_HullMeter = new GuiMeter("gui/main/hull/hull.png", Vector2f{5, ScreenSize.y - HullFrameSize.y - 10 }, HullFrameSize, HullFrameSize, 50, manager);
|
||||
this->AddElement(m_HullMeter);
|
||||
|
||||
Vector2f DepthMeterPosition{10, ScreenSize.y - 120};
|
||||
m_DepthText = new GuiText(DepthMeterPosition, "Depth: 20", "fonts/Arial.ttf", 20, Colors::YELLOW);
|
||||
this->AddElement(m_DepthText);
|
||||
|
||||
Vector2f ScoreMeterPosition{10, ScreenSize.y - 150};
|
||||
m_ScoreText = new GuiText(ScoreMeterPosition, "Score: 0", "fonts/Arial.ttf", 20, Colors::YELLOW);
|
||||
this->AddElement(m_ScoreText);
|
||||
}
|
||||
MainScreen::~MainScreen() = default;
|
||||
void MainScreen::Draw() const {
|
||||
Screen::Draw();
|
||||
}
|
||||
void MainScreen::Update(float elapsedSecs) {
|
||||
Screen::Update(elapsedSecs);
|
||||
}
|
||||
void MainScreen::SetFuelMeterValue(float value) const {
|
||||
m_FuelMeter->SetValue(value);
|
||||
}
|
||||
void MainScreen::SetHullMeterValue(float value) const {
|
||||
m_HullMeter->SetValue(value);
|
||||
}
|
||||
void MainScreen::SetDepth(const std::string& text) const {
|
||||
m_DepthText->ChangeText(text);
|
||||
}
|
||||
void MainScreen::SetScore(const std::string& text) const {
|
||||
m_ScoreText->ChangeText(text);
|
||||
}
|
||||
|
||||
27
Game/Gui/Screens/MainScreen.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
#include "Gui/GuiMeter.h"
|
||||
#include "Gui/GuiText.h"
|
||||
#include "Gui/Screen.h"
|
||||
|
||||
class MainScreen: public Screen {
|
||||
public:
|
||||
explicit MainScreen(TextureManager* manager);
|
||||
virtual ~MainScreen() override;
|
||||
|
||||
virtual void Draw() const override;
|
||||
virtual void Update(float elapsedSecs) override;
|
||||
|
||||
void SetFuelMeterValue(float value) const;
|
||||
void SetHullMeterValue(float value) const;
|
||||
|
||||
void SetDepth(const std::string& text) const;
|
||||
void SetScore(const std::string& text) const;
|
||||
|
||||
private:
|
||||
GuiMeter* m_FuelMeter;
|
||||
GuiMeter* m_HullMeter;
|
||||
|
||||
GuiText* m_DepthText;
|
||||
GuiText* m_ScoreText;
|
||||
|
||||
};
|
||||
@@ -9,5 +9,4 @@ Level::Level() : m_pCamera(nullptr) {
|
||||
Level::Level(Camera* camera) {
|
||||
m_pCamera = camera;
|
||||
}
|
||||
Level::~Level() {
|
||||
}
|
||||
Level::~Level() = default;
|
||||
@@ -6,7 +6,7 @@ class Level
|
||||
{
|
||||
public:
|
||||
Level();
|
||||
Level(Camera* camera);
|
||||
explicit Level(Camera* camera);
|
||||
virtual ~Level();
|
||||
|
||||
Level(const Level& other) = default;
|
||||
|
||||
@@ -6,8 +6,8 @@ Building::Building(const std::string& filePath, const Vector2f& position, Textur
|
||||
m_Texture = pTextureManager->GetTexture(filePath);
|
||||
m_Size = Vector2f(m_Texture->GetWidth(), m_Texture->GetHeight());
|
||||
}
|
||||
Building::~Building() {
|
||||
}
|
||||
Building::~Building() = default;
|
||||
|
||||
void Building::Draw() const {
|
||||
m_Texture->Draw(m_Position);
|
||||
}
|
||||
|
||||
@@ -6,8 +6,10 @@ class Building
|
||||
{
|
||||
public:
|
||||
Building(const std::string& filePath, const Vector2f& position, TextureManager* pTextureManager);
|
||||
Building(const Building& other) = delete;
|
||||
Building(Building&& other) = delete;
|
||||
Building(const Building& other) = default;
|
||||
Building(Building&& other) = default;
|
||||
Building& operator=(const Building& other) = default;
|
||||
Building& operator=(Building&& other) = default;
|
||||
|
||||
~Building();
|
||||
|
||||
|
||||
14
Game/Levels/World/OrbitingObject.cpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#include "pch.h"
|
||||
#include "OrbitingObject.h"
|
||||
|
||||
#include <iostream>
|
||||
OrbitingObject::OrbitingObject(const Vector2f& orbit, float distance, float speed, Texture* texture, float offset): m_Texture(texture), m_Orbit(orbit), m_Speed(speed), m_Distance(distance), m_currentCycle(offset) {
|
||||
}
|
||||
void OrbitingObject::Update(float elapsedSecs) {
|
||||
m_Position = Vector2f(m_Orbit.x + cosf(m_currentCycle) * m_Distance, m_Orbit.y + sinf(m_currentCycle) * m_Distance);
|
||||
m_currentCycle += m_Speed * elapsedSecs;
|
||||
}
|
||||
void OrbitingObject::Draw() const {
|
||||
m_Texture->Draw(m_Position);
|
||||
|
||||
}
|
||||
21
Game/Levels/World/OrbitingObject.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
#include "Texture.h"
|
||||
|
||||
class OrbitingObject {
|
||||
public:
|
||||
OrbitingObject(const Vector2f& orbit, float distance, float speed, Texture* texture, float offset = 0);
|
||||
|
||||
void Update(float elapsedSecs);
|
||||
void Draw() const;
|
||||
|
||||
|
||||
private:
|
||||
Texture* m_Texture;
|
||||
Vector2f m_Position;
|
||||
Vector2f m_Orbit;
|
||||
float m_Distance;
|
||||
float m_Speed;
|
||||
|
||||
float m_currentCycle{ 0 };
|
||||
|
||||
};
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
#include "Collision.h"
|
||||
#include "colors.h"
|
||||
#include "GroundTileTypeManager.h"
|
||||
#include "../../GridSystem/GroundTileTypeManager.h"
|
||||
#include "utils.h"
|
||||
#include "GridSystem/WorldTile.h"
|
||||
#include "Gui/Screens/ScreenManager.h"
|
||||
@@ -16,11 +16,11 @@
|
||||
|
||||
class GroundTileType;
|
||||
WorldLevel::WorldLevel(Camera* camera, Rectf viewport): Level(camera),
|
||||
m_gridManager(WorldGridManager()),
|
||||
m_player(Player { Vector2f { 0, 100 }, TextureManager::GetInstance() }),
|
||||
m_mousePos { 0, 0 },
|
||||
m_viewport(viewport),
|
||||
m_screenManager(ScreenManager::GetInstance()) {
|
||||
m_GridManager(WorldGridManager()),
|
||||
m_Player(Player { Vector2f { 0, 100 }, TextureManager::GetInstance() }),
|
||||
m_MousePos { 0, 0 },
|
||||
m_Viewport(viewport),
|
||||
m_ScreenManager(ScreenManager::GetInstance()) {
|
||||
InitializeGroundTiles();
|
||||
// The grid is 34 x 50 big, the top center is 0,0 in world coords
|
||||
for (int x { 0 }; x < WORLD_WIDTH; ++x) {
|
||||
@@ -28,121 +28,120 @@ WorldLevel::WorldLevel(Camera* camera, Rectf viewport): Level(camera),
|
||||
const int actualX = x - WORLD_WIDTH / 2;
|
||||
Vector2f pos = Vector2f { float(actualX * TILE_WIDTH), -float(y * TILE_HEIGHT) - TILE_HEIGHT };
|
||||
GroundTileType* type = getRandomGroundTile();
|
||||
m_gridManager.SetTileAtIndex(x, y, new WorldTile { pos, type, TextureManager::GetInstance(), &m_gridManager });
|
||||
m_GridManager.SetTileAtIndex(x, y, new WorldTile { pos, type, TextureManager::GetInstance(), &m_GridManager });
|
||||
}
|
||||
}
|
||||
for (int x { 0 }; x < WORLD_WIDTH; ++x) {
|
||||
m_gridManager.GetTileAtIndex(x, 0)->SetTileType(GroundTileTypeManager::GetInstance()->AIR);
|
||||
m_gridManager.GetTileAtIndex(x, 1)->SetTileType(GroundTileTypeManager::GetInstance()->GRASS);
|
||||
m_GridManager.GetTileAtIndex(x, 0)->SetTileType(GroundTileTypeManager::GetInstance()->AIR);
|
||||
m_GridManager.GetTileAtIndex(x, 1)->SetTileType(GroundTileTypeManager::GetInstance()->GRASS);
|
||||
}
|
||||
m_refeulBuilding = new Building { "buildings/fuelStation.png", Vector2f { -700, -52 }, TextureManager::GetInstance() };
|
||||
m_gridManager.GetTileAtWorldPos(Vector2f { -700, -50 })->SetTileType(GroundTileTypeManager::GetInstance()->HARD_LEFT);
|
||||
m_gridManager.GetTileAtWorldPos(Vector2f { -650, -50 })->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
|
||||
m_gridManager.GetTileAtWorldPos(Vector2f { -600, -50 })->SetTileType(GroundTileTypeManager::GetInstance()->HARD_RIGHT);
|
||||
m_Buildings.emplace_back(Building { "buildings/fuelStation.png", Vector2f { -700, -52 }, TextureManager::GetInstance() });
|
||||
m_GridManager.GetTileAtWorldPos(Vector2f { -750, -50 })->SetTileType(GroundTileTypeManager::GetInstance()->HARD_LEFT);
|
||||
m_GridManager.GetTileAtWorldPos(Vector2f { -700, -50 })->SetTileType(GroundTileTypeManager::GetInstance()->HARD_LEFT);
|
||||
m_GridManager.GetTileAtWorldPos(Vector2f { -650, -50 })->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
|
||||
m_GridManager.GetTileAtWorldPos(Vector2f { -600, -50 })->SetTileType(GroundTileTypeManager::GetInstance()->HARD_RIGHT);
|
||||
|
||||
m_mineralBuilding = new Building { "buildings/mineralStation.png", Vector2f { -350, -52 }, TextureManager::GetInstance() };
|
||||
m_gridManager.GetTileAtWorldPos(Vector2f {-400, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_LEFT);
|
||||
m_gridManager.GetTileAtWorldPos(Vector2f {-350, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
|
||||
m_gridManager.GetTileAtWorldPos(Vector2f {-300, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
|
||||
m_gridManager.GetTileAtWorldPos(Vector2f {-250, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
|
||||
m_gridManager.GetTileAtWorldPos(Vector2f {-200, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
|
||||
m_gridManager.GetTileAtWorldPos(Vector2f {-150, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_RIGHT);
|
||||
m_Buildings.emplace_back(Building { "buildings/mineralStation.png", Vector2f { -350, -52 }, TextureManager::GetInstance() });
|
||||
m_GridManager.GetTileAtWorldPos(Vector2f {-400, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_LEFT);
|
||||
m_GridManager.GetTileAtWorldPos(Vector2f {-350, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
|
||||
m_GridManager.GetTileAtWorldPos(Vector2f {-300, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
|
||||
m_GridManager.GetTileAtWorldPos(Vector2f {-250, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
|
||||
m_GridManager.GetTileAtWorldPos(Vector2f {-200, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
|
||||
m_GridManager.GetTileAtWorldPos(Vector2f {-150, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_RIGHT);
|
||||
|
||||
m_junkBuilding = new Building { "buildings/junkStation.png", Vector2f { 250, -52 }, TextureManager::GetInstance() };
|
||||
m_gridManager.GetTileAtWorldPos(Vector2f {200, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_LEFT);
|
||||
m_gridManager.GetTileAtWorldPos(Vector2f {250, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
|
||||
m_gridManager.GetTileAtWorldPos(Vector2f {300, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
|
||||
m_gridManager.GetTileAtWorldPos(Vector2f {350, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
|
||||
m_gridManager.GetTileAtWorldPos(Vector2f {400, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
|
||||
m_gridManager.GetTileAtWorldPos(Vector2f {450, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_RIGHT);
|
||||
m_Buildings.emplace_back(Building { "buildings/junkStation.png", Vector2f { 250, -52 }, TextureManager::GetInstance() });
|
||||
m_GridManager.GetTileAtWorldPos(Vector2f {200, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_LEFT);
|
||||
m_GridManager.GetTileAtWorldPos(Vector2f {250, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
|
||||
m_GridManager.GetTileAtWorldPos(Vector2f {300, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
|
||||
m_GridManager.GetTileAtWorldPos(Vector2f {350, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
|
||||
m_GridManager.GetTileAtWorldPos(Vector2f {400, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
|
||||
m_GridManager.GetTileAtWorldPos(Vector2f {450, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_RIGHT);
|
||||
|
||||
m_repairBuilding = new Building { "buildings/repairStation.png", Vector2f { 700, -52 }, TextureManager::GetInstance() };
|
||||
m_gridManager.GetTileAtWorldPos(Vector2f {650, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_LEFT);
|
||||
m_gridManager.GetTileAtWorldPos(Vector2f {700, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
|
||||
m_gridManager.GetTileAtWorldPos(Vector2f {750, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
|
||||
m_gridManager.GetTileAtWorldPos(Vector2f {800, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_RIGHT);
|
||||
m_Buildings.emplace_back(Building { "buildings/repairStation.png", Vector2f { 700, -52 }, TextureManager::GetInstance() });
|
||||
m_GridManager.GetTileAtWorldPos(Vector2f {650, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_LEFT);
|
||||
m_GridManager.GetTileAtWorldPos(Vector2f {700, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
|
||||
m_GridManager.GetTileAtWorldPos(Vector2f {750, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
|
||||
m_GridManager.GetTileAtWorldPos(Vector2f {800, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_RIGHT);
|
||||
// Texture* test = new Texture("gui/main/fuel_guage.png");
|
||||
m_topCover = TextureManager::GetInstance()->GetTexture("topBackground.png");
|
||||
|
||||
m_MainScreen = new MainScreen(TextureManager::GetInstance());
|
||||
|
||||
m_Sun = new OrbitingObject(Vector2f{0, -1000}, 1200, 0.5f, TextureManager::GetInstance()->GetTexture("sun.png"));
|
||||
m_Moon = new OrbitingObject(Vector2f{0, -1000}, 1200, 0.5f, TextureManager::GetInstance()->GetTexture("moon.png"), M_PI);
|
||||
|
||||
}
|
||||
WorldLevel::~WorldLevel() {
|
||||
delete m_refeulBuilding;
|
||||
delete m_mineralBuilding;
|
||||
delete m_junkBuilding;
|
||||
delete m_repairBuilding;
|
||||
//delete m_pTextTexture;
|
||||
delete m_MainScreen;
|
||||
}
|
||||
void WorldLevel::Update(float elapsedSec) {
|
||||
m_fps = 1 / elapsedSec;
|
||||
m_Fps = 1 / elapsedSec;
|
||||
|
||||
int mouseX, mouseY;
|
||||
SDL_GetMouseState(&mouseX, &mouseY);
|
||||
m_mousePos = Vector2f { float(mouseX), float(mouseY) };
|
||||
m_mousePos = m_pCamera->TransformMouse(m_mousePos);
|
||||
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;
|
||||
}
|
||||
}
|
||||
for (size_t x { 0 }; x < WORLD_WIDTH; ++x) {
|
||||
for (size_t y { 0 }; y < WORLD_HEIGHT; ++y) {
|
||||
m_gridManager.GetTileAtIndex(x, y)->Update(m_pCamera);
|
||||
if (m_gridManager.GetTileAtIndex(x, y)->GetCollisionRect().Contains(m_mousePos)) {
|
||||
m_pSelectedTile = m_gridManager.GetTileAtIndex(x, y);
|
||||
// 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;
|
||||
// }
|
||||
// }
|
||||
|
||||
m_Sun->Update(elapsedSec);
|
||||
m_Moon->Update(elapsedSec);
|
||||
|
||||
for (int x { 0 }; x < WORLD_WIDTH; ++x) {
|
||||
for (int y { 0 }; y < WORLD_HEIGHT; ++y) {
|
||||
m_GridManager.GetTileAtIndex(x, y)->Update(m_pCamera);
|
||||
if (m_GridManager.GetTileAtIndex(x, y)->GetCollisionRect().Contains(m_MousePos)) {
|
||||
m_pSelectedTile = m_GridManager.GetTileAtIndex(x, y);
|
||||
//selectedTile->m_Hightlight = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (Building building : m_Buildings) {
|
||||
building.Update(elapsedSec);
|
||||
}
|
||||
|
||||
|
||||
if (m_pSelectedTile != nullptr) {
|
||||
if (utils::isMouseDown(SDL_BUTTON_LEFT)) {
|
||||
m_pSelectedTile->SetTileType(GroundTileTypeManager::GetInstance()->AIR);
|
||||
}
|
||||
}
|
||||
|
||||
//Get the diogonal tiles of the selected tile
|
||||
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 };
|
||||
|
||||
for (int i = 0; i < 8; i++) {
|
||||
direction = directions[i];
|
||||
if (surroundingTiles.GetTile(direction) != nullptr) {
|
||||
if (surroundingTiles.GetTile(direction)->GetTileType() != GroundTileTypeManager::GetInstance()->AIR) {
|
||||
//surroundingTiles.GetTile(direction)->m_Hightlight = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_player.Update(elapsedSec, *this);
|
||||
m_Player.Update(elapsedSec, *this);
|
||||
|
||||
//Move the camera when the player gets to the edge
|
||||
if(m_FollowPlayer) {
|
||||
Vector2f playerPos = m_player.GetPosition();
|
||||
Vector2f playerPos = m_Player.GetPosition();
|
||||
Vector2f newCameraPos = m_pCamera->GetPosition();
|
||||
if (playerPos.x < newCameraPos.x + 50) {
|
||||
newCameraPos.x = playerPos.x - 50;
|
||||
}
|
||||
if (playerPos.x > newCameraPos.x + m_viewport.width - 100) {
|
||||
newCameraPos.x = playerPos.x - m_viewport.width + 100;
|
||||
if (playerPos.x > newCameraPos.x + m_Viewport.width - 100) {
|
||||
newCameraPos.x = playerPos.x - m_Viewport.width + 100;
|
||||
}
|
||||
if (playerPos.y < newCameraPos.y + 50) {
|
||||
newCameraPos.y = playerPos.y - 50;
|
||||
}
|
||||
if (playerPos.y > newCameraPos.y + m_viewport.height - 50) {
|
||||
newCameraPos.y = playerPos.y - m_viewport.height + 50;
|
||||
if (playerPos.y > newCameraPos.y + m_Viewport.height - 100) {
|
||||
newCameraPos.y = playerPos.y - m_Viewport.height + 100;
|
||||
}
|
||||
m_pCamera->SetPosition(newCameraPos);
|
||||
}
|
||||
|
||||
Screen* screen = m_screenManager->GetCurrentScreen();
|
||||
Screen* screen = m_ScreenManager->GetCurrentScreen();
|
||||
if (screen != nullptr) {
|
||||
screen->Update(elapsedSec);
|
||||
}
|
||||
|
||||
m_MainScreen->Update(elapsedSec);
|
||||
m_MainScreen->SetDepth(std::to_string((int)-m_Player.GetPosition().y - 50) + " ft.");
|
||||
|
||||
//Vector2f playerPos = m_player.GetPosition();
|
||||
//Vector2f newCameraPos = playerPos;
|
||||
//m_pCamera->SetPosition(newCameraPos);
|
||||
@@ -151,18 +150,21 @@ void WorldLevel::Update(float elapsedSec) {
|
||||
//m_pCamera->SetPosition(Vector2f{playerPos.x - m_viewport.width / 2, playerPos.y - m_viewport.height / 2});
|
||||
}
|
||||
void WorldLevel::Draw() const {
|
||||
|
||||
m_pCamera->BeginRendering();
|
||||
// m_topCover->Draw(Vector2f{-850,-70} );
|
||||
m_topCover->Draw(Rectf{-850, -70, 850, -70 + 32}, Rectf{0, 0, WORLD_WIDTH * 50, 32});
|
||||
|
||||
for (Collision::CollisionRect rect : m_Rects) {
|
||||
utils::DrawRect(rect.pos, rect.size.x, rect.size.y);
|
||||
}
|
||||
|
||||
utils::SetColor(Colors::WHITE);
|
||||
utils::FillEllipse(m_mousePos, 2, 2);
|
||||
utils::FillEllipse(m_MousePos, 2, 2);
|
||||
|
||||
for (size_t x { 0 }; x < WORLD_WIDTH; ++x) {
|
||||
for (size_t y { 0 }; y < WORLD_HEIGHT; ++y) {
|
||||
m_gridManager.GetTileAtIndex(x, y)->Draw();
|
||||
for (int x { 0 }; x < WORLD_WIDTH; ++x) {
|
||||
for (int y { 0 }; y < WORLD_HEIGHT; ++y) {
|
||||
m_GridManager.GetTileAtIndex(x, y)->Draw();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,28 +175,34 @@ void WorldLevel::Draw() const {
|
||||
m_pSelectedTile->Draw();
|
||||
}
|
||||
|
||||
m_refeulBuilding->Draw();
|
||||
m_mineralBuilding->Draw();
|
||||
m_junkBuilding->Draw();
|
||||
m_repairBuilding->Draw();
|
||||
m_player.Draw();
|
||||
for(Building building : m_Buildings) {
|
||||
building.Draw();
|
||||
}
|
||||
|
||||
m_Player.Draw();
|
||||
|
||||
utils::SetColor(Colors::GREEN);
|
||||
utils::DrawArrow(Vector2f{0, 0}, m_mousePos);
|
||||
utils::DrawArrow(Vector2f{0, 0}, m_MousePos);
|
||||
|
||||
m_Sun->Draw();
|
||||
m_Moon->Draw();
|
||||
|
||||
m_pCamera->EndRendering();
|
||||
|
||||
utils::FillRect(utils::GetMousePos(), 10, 10);
|
||||
|
||||
utils::DrawRect(50, 50, m_viewport.width - 100, m_viewport.height - 100);
|
||||
utils::DrawRect(50, 50, m_Viewport.width - 100, m_Viewport.height - 100);
|
||||
|
||||
const Screen* screen = m_screenManager->GetCurrentScreen();
|
||||
const Screen* screen = m_ScreenManager->GetCurrentScreen();
|
||||
if (screen != nullptr) {
|
||||
screen->Draw();
|
||||
}
|
||||
m_MainScreen->Draw();
|
||||
|
||||
|
||||
}
|
||||
void WorldLevel::MouseMove(const Vector2f& mousePos) {
|
||||
m_mousePos = mousePos;
|
||||
m_MousePos = mousePos;
|
||||
}
|
||||
|
||||
void WorldLevel::ProcessImGui() {
|
||||
@@ -259,7 +267,7 @@ void WorldLevel::ProcessImGui() {
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
|
||||
if (ImGui::BeginMenu(std::to_string(m_fps).c_str())) {
|
||||
if (ImGui::BeginMenu(std::to_string(m_Fps).c_str())) {
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
|
||||
@@ -280,7 +288,7 @@ void WorldLevel::ProcessImGui() {
|
||||
ImGui::Text("Camera Scale: %f", m_pCamera->GetScale());
|
||||
ImGui::Text("Is Right Mouse Down: %s", utils::isMouseDown(0) ? "true" : "false");
|
||||
if (ImGui::Button("Reset Camera")) {
|
||||
m_pCamera->SetPosition(Vector2f { -m_viewport.width / 2, -m_viewport.height / 2 });
|
||||
m_pCamera->SetPosition(Vector2f { -m_Viewport.width / 2, -m_Viewport.height / 2 });
|
||||
m_pCamera->SetScale(1.0f);
|
||||
}
|
||||
ImGui::Checkbox("Follow Player", &m_FollowPlayer);
|
||||
@@ -289,9 +297,12 @@ void WorldLevel::ProcessImGui() {
|
||||
|
||||
if (m_ShowPlayerInfo) {
|
||||
ImGui::Begin("Player Info", &m_ShowPlayerInfo, ImGuiWindowFlags_AlwaysAutoResize);
|
||||
ImGui::Text("Player Position: (%f, %f)", m_player.GetPosition().x, m_player.GetPosition().y);
|
||||
ImGui::Text("Player Velocity: (%f, %f)", m_player.GetVelocity().x, m_player.GetVelocity().y);
|
||||
ImGui::Text("Player Position: (%f, %f)", m_Player.GetPosition().x, m_Player.GetPosition().y);
|
||||
ImGui::Text("Player Velocity: (%f, %f)", m_Player.GetVelocity().x, m_Player.GetVelocity().y);
|
||||
ImGui::End();
|
||||
m_player.ProcessImGui();
|
||||
m_Player.ProcessImGui();
|
||||
}
|
||||
}
|
||||
WorldGridManager& WorldLevel::GetGridManager() {
|
||||
return m_GridManager;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,11 @@
|
||||
#include "GridSystem/WorldGridManager.h"
|
||||
#include "Gui/Screens/ScreenManager.h"
|
||||
#include "Camera.h"
|
||||
#include "OrbitingObject.h"
|
||||
#include "Text.h"
|
||||
#include "Gui/GuiMeter.h"
|
||||
#include "Gui/Screens/MainScreen.h"
|
||||
#include "Particle/Particle.h"
|
||||
|
||||
class WorldLevel : public Level
|
||||
{
|
||||
@@ -22,35 +27,38 @@ public:
|
||||
void MouseMove(const Vector2f& mousePos) override;
|
||||
void ProcessImGui() override;
|
||||
|
||||
WorldGridManager& GetGridManager() {
|
||||
return m_gridManager;
|
||||
}
|
||||
WorldGridManager& GetGridManager();
|
||||
|
||||
std::vector<Collision::CollisionRect> m_Rects;
|
||||
|
||||
|
||||
private:
|
||||
double m_fps{ 0.0f };
|
||||
double m_Fps{ 0.0f };
|
||||
|
||||
WorldGridManager m_gridManager {};
|
||||
Player m_player;
|
||||
Vector2f m_mousePos {};
|
||||
WorldGridManager m_GridManager;
|
||||
Player m_Player;
|
||||
Vector2f m_MousePos {};
|
||||
|
||||
Rectf m_viewport;
|
||||
Rectf m_Viewport;
|
||||
|
||||
ScreenManager* m_screenManager;
|
||||
ScreenManager* m_ScreenManager;
|
||||
|
||||
WorldTile* m_pSelectedTile { nullptr };
|
||||
|
||||
Building* m_refeulBuilding;
|
||||
Building* m_mineralBuilding;
|
||||
Building* m_junkBuilding;
|
||||
Building* m_repairBuilding;
|
||||
std::vector<Building> m_Buildings{};
|
||||
|
||||
|
||||
MainScreen* m_MainScreen{};
|
||||
|
||||
OrbitingObject* m_Sun{ nullptr };
|
||||
OrbitingObject* m_Moon{ nullptr };
|
||||
|
||||
Texture* m_topCover{ nullptr };
|
||||
|
||||
// ImGui Vars
|
||||
bool m_ShowTextureManagerWindow { false };
|
||||
bool m_ShowCameraWindow { false };
|
||||
bool m_ShowPlayerInfo { true };
|
||||
|
||||
bool m_FollowPlayer { false };
|
||||
bool m_FollowPlayer { true };
|
||||
};
|
||||
|
||||
19
Game/Particle/Particle.cpp
Normal file
@@ -0,0 +1,19 @@
|
||||
#include "pch.h"
|
||||
#include "Particle.h"
|
||||
Particle::Particle(const Vector2f& pos, const Vector2f& velocity, float lifetime, Texture* pTexture): m_Position { pos }, m_Velocity { velocity }, m_LifeTime { lifetime },
|
||||
m_pTexture { pTexture } {
|
||||
}
|
||||
void Particle::Update(float elapsedSec) {
|
||||
m_Acceleration = Vector2f { 0.0f, -9.81f * 20};
|
||||
m_Velocity += m_Acceleration * elapsedSec;
|
||||
m_Position += m_Velocity * elapsedSec;
|
||||
m_LifeTime -= elapsedSec;
|
||||
m_Acceleration = Vector2f { 0.0f, 0.0f };
|
||||
|
||||
}
|
||||
void Particle::Draw() const {
|
||||
m_pTexture->Draw(m_Position);
|
||||
}
|
||||
bool Particle::IsDead() const {
|
||||
return m_LifeTime <= 0.0f;
|
||||
}
|
||||
20
Game/Particle/Particle.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
#include "Texture.h"
|
||||
|
||||
class Particle {
|
||||
public:
|
||||
Particle() = default;
|
||||
Particle(const Vector2f& pos, const Vector2f& velocity,float lifetime, Texture* pTexture);
|
||||
void Update(float elapsedSec);
|
||||
void Draw() const;
|
||||
bool IsDead() const;
|
||||
|
||||
private:
|
||||
Vector2f m_Position;
|
||||
Vector2f m_Velocity;
|
||||
Vector2f m_Acceleration;
|
||||
|
||||
float m_LifeTime;
|
||||
|
||||
Texture* m_pTexture;
|
||||
};
|
||||
207
Game/Player.cpp
@@ -5,7 +5,7 @@
|
||||
#include <algorithm>
|
||||
|
||||
#include "colors.h"
|
||||
#include "GroundTileTypeManager.h"
|
||||
#include "GridSystem/GroundTileTypeManager.h"
|
||||
#include "utils.h"
|
||||
#include "Levels/World/WorldLevel.h"
|
||||
#include "Animations/Animation.h"
|
||||
@@ -19,14 +19,28 @@ Player::Player(const Vector2f& Position, TextureManager* manager) : m_Position(P
|
||||
|
||||
m_walkAnimation = new Animation(
|
||||
manager->GetTexture("animations/player/player_walk.png"),
|
||||
8, 0.1f, Rectf { 0, 0, 70, 70 });
|
||||
8, 0.1f, Rectf { 0, 0, 70, 70 }, true);
|
||||
m_turnAnimation = new Animation(
|
||||
manager->GetTexture("animations/player/player_turn.png"),
|
||||
5, 0.07f, Rectf { 0, 0, 70, 70 }, false);
|
||||
m_digStartAnimation = new Animation(
|
||||
manager->GetTexture("animations/player/player_dig_start.png"),
|
||||
7, 0.07f, Rectf { 0, 0, 70, 70 }, false);
|
||||
m_digAnimation = new Animation(
|
||||
manager->GetTexture("animations/player/player_dig.png"),
|
||||
7, 0.05f, Rectf { 0, 0, 70, 70 }, true);
|
||||
|
||||
m_currentAnimation = m_walkAnimation;
|
||||
}
|
||||
Player::Player(Player&& other) {
|
||||
|
||||
}
|
||||
|
||||
Player::~Player() {
|
||||
delete m_walkAnimation;
|
||||
// delete m_turnAnimation;
|
||||
// delete m_digAnimation;
|
||||
delete m_turnAnimation;
|
||||
delete m_digAnimation;
|
||||
delete m_digStartAnimation;
|
||||
}
|
||||
|
||||
Collision::CollisionRect Player::GetCollisionRect() const {
|
||||
@@ -43,18 +57,29 @@ 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 };
|
||||
int bobOffset = m_BobUp ? 1 : 0;
|
||||
|
||||
m_walkAnimation->Draw(drawPos, Rectf { drawPos.x, drawPos.y, frameWidth, frameWidth });
|
||||
utils::DrawEllipse(m_DigDestination, 5, 5);
|
||||
utils::DrawEllipse(m_DigStart, 5, 5);
|
||||
float rotateOffset = std::abs(m_Vel.x) / 40;
|
||||
Vector2f drawPos = Vector2f { center.x, center.y + 9 + bobOffset };
|
||||
glPushMatrix();
|
||||
glTranslatef(drawPos.x - halfFrameWidth, drawPos.y - halfFrameWidth, 0);
|
||||
if (!m_Grounded && std::abs(m_Vel.y) > 0.1f) {
|
||||
glRotatef(m_Direction == PlayerDirection::Left ? rotateOffset : -rotateOffset, 0, 0, 1);
|
||||
}
|
||||
{
|
||||
m_currentAnimation->Draw(Vector2f { 0, 0 }, Rectf { 0, 0, frameWidth, frameWidth });
|
||||
|
||||
}
|
||||
glPopMatrix();
|
||||
for (Particle* particle : m_DigParticles) {
|
||||
particle->Draw();
|
||||
}
|
||||
}
|
||||
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 { "No idea" };
|
||||
switch (m_State) {
|
||||
case PlayerState::Idle:
|
||||
currentState = "Idle";
|
||||
@@ -65,10 +90,31 @@ void Player::ProcessImGui() {
|
||||
case PlayerState::Walking:
|
||||
currentState = "Walking";
|
||||
break;
|
||||
case PlayerState::Flying:
|
||||
currentState = "Flying";
|
||||
break;
|
||||
}
|
||||
ImGui::Text("Player State %s", currentState.c_str());
|
||||
ImGui::Text("Is digging Primed: %s", m_IsDiggingPrimed ? "true" : "false");
|
||||
ImGui::Text("Bob counter: %f", m_BobTimer);
|
||||
ImGui::Text("Bob up: %s", m_BobUp ? "true" : "false");
|
||||
ImGui::Text("Is Grounded: %s", m_Grounded ? "true" : "false");
|
||||
std::string direction {};
|
||||
switch (m_Direction) {
|
||||
case PlayerDirection::Down:
|
||||
direction = "Down";
|
||||
break;
|
||||
case PlayerDirection::Left:
|
||||
direction = "Left";
|
||||
break;
|
||||
case PlayerDirection::Right:
|
||||
direction = "Right";
|
||||
break;
|
||||
case PlayerDirection::Up:
|
||||
direction = "Up";
|
||||
break;
|
||||
}
|
||||
ImGui::Text("Direction: %s", direction.c_str());
|
||||
|
||||
|
||||
//ContactMap
|
||||
@@ -92,8 +138,8 @@ void Player::Dig(Collision::CollisionDirection dir, WorldLevel& level) {
|
||||
//Center
|
||||
m_DigDestination.x += tile->GetSize().x / 2 - m_Size.x / 2;
|
||||
}
|
||||
if(dir == Collision::Left) {
|
||||
m_DigDestination += Vector2f{ 2, 0};
|
||||
if (dir == Collision::Left) {
|
||||
m_DigDestination += Vector2f { 2, 0 };
|
||||
}
|
||||
m_ContactMap[dir] = nullptr;
|
||||
}
|
||||
@@ -106,7 +152,8 @@ bool Player::CanDig(Collision::CollisionDirection dir, WorldLevel& level) {
|
||||
GroundTileType type = *tile->GetTileType();
|
||||
//TODO: Add a list of non diggable tiles
|
||||
|
||||
if (type == GroundTileTypeManager::GetInstance()->HARD_LEFT || type == GroundTileTypeManager::GetInstance()->HARD_MIDDLE || type == GroundTileTypeManager::GetInstance()->HARD_RIGHT) {
|
||||
if (type == GroundTileTypeManager::GetInstance()->HARD_LEFT || type == GroundTileTypeManager::GetInstance()->HARD_MIDDLE || type == GroundTileTypeManager::GetInstance()->
|
||||
HARD_RIGHT) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -120,29 +167,52 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
|
||||
m_BobTimer = 0.0f;
|
||||
}
|
||||
|
||||
std::vector<Particle *> particlesToDelete {};
|
||||
for (Particle* particle : m_DigParticles) {
|
||||
particle->Update(elapsedTime);
|
||||
if (particle->IsDead()) {
|
||||
particlesToDelete.push_back(particle);
|
||||
}
|
||||
}
|
||||
for (Particle* particle : particlesToDelete) {
|
||||
m_DigParticles.erase(std::remove(m_DigParticles.begin(), m_DigParticles.end(), particle), m_DigParticles.end());
|
||||
delete particle;
|
||||
}
|
||||
|
||||
//check for keys
|
||||
if (m_State != PlayerState::Digging) {
|
||||
// m_Acc = Vector2f { 0, -100 };
|
||||
if (utils::isKeyDown(SDL_SCANCODE_W)) {
|
||||
m_State = PlayerState::Flying;
|
||||
m_Vel.y = m_Speed;
|
||||
m_Grounded = false;
|
||||
}
|
||||
if (utils::isKeyPressed(SDL_SCANCODE_S)) {
|
||||
if (m_Grounded) {
|
||||
if (this->CanDig(Collision::Bottom, level)) {
|
||||
m_DigDirection = DigDirection::Down;
|
||||
m_currentAnimation = m_digStartAnimation;
|
||||
m_currentAnimation->Reset();
|
||||
m_IsDiggingPrimed = false;
|
||||
this->Dig(Collision::CollisionDirection::Bottom, level);
|
||||
}
|
||||
}
|
||||
else {
|
||||
//m_Acc.y = -100;
|
||||
}
|
||||
}
|
||||
if (utils::isKeyDown(SDL_SCANCODE_A)) {
|
||||
m_walkAnimation->SetFlipped(false);
|
||||
if (!m_IsTurning) {
|
||||
m_walkAnimation->SetFlipped(false);
|
||||
}
|
||||
m_Acc.x = -m_Speed;
|
||||
if (m_Direction == PlayerDirection::Right) {
|
||||
m_IsTurning = true;
|
||||
m_currentAnimation = m_turnAnimation;
|
||||
m_currentAnimation->SetFlipped(true);
|
||||
m_currentAnimation->Reset();
|
||||
}
|
||||
m_Direction = PlayerDirection::Left;
|
||||
if (m_Grounded && !m_DidJustDigLeft) {
|
||||
//Check if the player doesnt come from digging a tile
|
||||
if (this->CanDig(Collision::CollisionDirection::Left, level)) {
|
||||
m_DigDirection = DigDirection::Left;
|
||||
this->Dig(Collision::CollisionDirection::Left, level);
|
||||
m_DidJustDigLeft = true;
|
||||
}
|
||||
@@ -155,11 +225,23 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
|
||||
}
|
||||
|
||||
if (utils::isKeyDown(SDL_SCANCODE_D)) {
|
||||
if (!m_IsTurning) {
|
||||
m_walkAnimation->SetFlipped(true);
|
||||
}
|
||||
m_Acc.x = m_Speed;
|
||||
m_walkAnimation->SetFlipped(true);
|
||||
|
||||
if (m_Direction == PlayerDirection::Left) {
|
||||
m_IsTurning = true;
|
||||
m_currentAnimation = m_turnAnimation;
|
||||
m_currentAnimation->SetFlipped(false);
|
||||
m_currentAnimation->Reset();
|
||||
}
|
||||
|
||||
m_Direction = PlayerDirection::Right;
|
||||
if (m_Grounded && !m_DidJustDigRight) {
|
||||
//Check if the player doesnt come from digging a tile
|
||||
if (this->CanDig(Collision::CollisionDirection::Right, level)) {
|
||||
m_DigDirection = DigDirection::Right;
|
||||
this->Dig(Collision::CollisionDirection::Right, level);
|
||||
m_DidJustDigRight = true;
|
||||
}
|
||||
@@ -173,26 +255,36 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
|
||||
|
||||
m_Vel = m_Vel + m_Gravity * elapsedTime;
|
||||
m_Vel = m_Vel + m_Acc * elapsedTime;
|
||||
m_Vel = utils::clamp(m_Vel, Vector2f { -m_Speed, -m_Speed }, Vector2f { m_Speed, m_Speed });
|
||||
|
||||
//air resistance
|
||||
//only if not moving
|
||||
if(abs(m_Acc.x) < 0.1f) {
|
||||
m_Vel.x = m_Vel.x * 0.85f;
|
||||
if (abs(m_Acc.x) < 0.1f) {
|
||||
m_Vel.x = m_Vel.x * 0.90f;
|
||||
}
|
||||
|
||||
m_Acc = Vector2f { 0, 0 };
|
||||
|
||||
|
||||
m_walkAnimation->Update(elapsedTime);
|
||||
|
||||
m_currentAnimation->Update(elapsedTime);
|
||||
|
||||
if (m_currentAnimation->IsDone() && m_IsTurning) {
|
||||
m_currentAnimation = m_walkAnimation;
|
||||
m_IsTurning = false;
|
||||
}
|
||||
|
||||
|
||||
if (m_currentAnimation == m_digStartAnimation) {
|
||||
|
||||
}
|
||||
|
||||
#pragma region Collision
|
||||
m_ContactMap[Collision::CollisionDirection::Top] = nullptr;
|
||||
m_ContactMap[Collision::CollisionDirection::Bottom] = nullptr;
|
||||
m_ContactMap[Collision::CollisionDirection::Left] = nullptr;
|
||||
m_ContactMap[Collision::CollisionDirection::Right] = nullptr;
|
||||
m_Grounded = false;
|
||||
|
||||
|
||||
float t = 0, min_t = INFINITY;
|
||||
Vector2f intersectionPoint, normal;
|
||||
|
||||
@@ -212,7 +304,8 @@ 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;
|
||||
});
|
||||
|
||||
@@ -254,12 +347,14 @@ 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_Vel.x != 0.0f) {
|
||||
m_State = PlayerState::Walking;
|
||||
#pragma endregion
|
||||
|
||||
if (m_State == PlayerState::Walking || m_State == PlayerState::Idle) { //Fix for when the state is JUST set to digging
|
||||
if (std::abs(m_Vel.x) < 0.1f) {
|
||||
m_State = PlayerState::Idle;
|
||||
}
|
||||
else {
|
||||
m_State = PlayerState::Idle;
|
||||
m_State = PlayerState::Walking;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -271,30 +366,44 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
|
||||
m_walkAnimation->SetPlaying(true);
|
||||
break;
|
||||
case PlayerState::Digging: {
|
||||
m_walkAnimation->SetPlaying(false);
|
||||
// m_walkAnimation->SetPlaying(false);
|
||||
//Diganimation
|
||||
|
||||
if (!m_Digging) { //TODO: fix for setting the start position
|
||||
m_Digging = true;
|
||||
m_DigStart = m_Position;
|
||||
m_Vel = Vector2f { 0, 0 };
|
||||
m_currentAnimation->Update(elapsedTime);
|
||||
if (m_currentAnimation->IsDone() && m_State == PlayerState::Digging && !m_IsDiggingPrimed) {
|
||||
m_IsDiggingPrimed = true;
|
||||
m_currentAnimation = m_digAnimation;
|
||||
}
|
||||
|
||||
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_DigStart, m_DigDestination, progress);
|
||||
if (progress >= 0.5f && !m_HasDeletedTile) {
|
||||
m_DigTile->SetTileType(GroundTileTypeManager::GetInstance()->AIR);
|
||||
m_DigTile = nullptr;
|
||||
m_HasDeletedTile = true;
|
||||
}
|
||||
if (progress >= 1.0f) {
|
||||
m_State = PlayerState::Idle;
|
||||
m_HasDeletedTile = false;
|
||||
m_Digging = false;
|
||||
if (m_IsDiggingPrimed) {
|
||||
if (!m_Digging) { //TODO: fix for setting the start position
|
||||
m_Digging = true;
|
||||
m_DigStart = m_Position;
|
||||
m_Vel = Vector2f { 0, 0 };
|
||||
}
|
||||
|
||||
m_DigProgress += elapsedTime;
|
||||
//lerp to the destination
|
||||
float progress = utils::map(m_DigProgress, 0.0f, m_DigTime, 0.0f, 1.0f);
|
||||
int particleProgress = (int)utils::map(m_DigProgress, 0.0f, m_DigTime, 0.0f, 100.0f);
|
||||
std::cout << progress << '\n';
|
||||
if (particleProgress % 25 == 0) {
|
||||
m_DigParticles.push_back(new Particle(m_Position, Vector2f { (float)utils::randRange(-200, 200), (float)utils::randRange(-100, -300) }, 5.f,
|
||||
TextureManager::GetInstance()->GetTexture("particles/dirt_" + std::to_string(utils::randRange(1, 8)) + ".png")));
|
||||
}
|
||||
m_Position = utils::lerp(m_DigStart, m_DigDestination, progress);
|
||||
if (progress >= 0.5f && !m_HasDeletedTile) {
|
||||
m_DigTile->SetTileType(GroundTileTypeManager::GetInstance()->AIR);
|
||||
m_DigTile = nullptr;
|
||||
m_HasDeletedTile = true;
|
||||
}
|
||||
if (progress >= 1.0f) {
|
||||
m_State = PlayerState::Idle;
|
||||
m_currentAnimation = m_walkAnimation;
|
||||
m_HasDeletedTile = false;
|
||||
m_Digging = false;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "Collision.h"
|
||||
#include "TextureManager.h"
|
||||
#include "Animations/Animation.h"
|
||||
#include "Particle/Particle.h"
|
||||
|
||||
class WorldLevel;
|
||||
|
||||
@@ -10,6 +11,8 @@ enum class PlayerState
|
||||
Idle,
|
||||
Walking,
|
||||
Digging,
|
||||
Turning,
|
||||
Flying
|
||||
};
|
||||
|
||||
enum class PlayerDirection
|
||||
@@ -32,7 +35,9 @@ class Player
|
||||
public:
|
||||
explicit Player(const Vector2f& Position, TextureManager* pTextureManager);
|
||||
Player( const Player& other ) = default;
|
||||
Player(Player&& other) = default;
|
||||
Player(Player&& other);
|
||||
Player& operator=(const Player& other) = delete;
|
||||
Player& operator=(Player&& other) = delete;
|
||||
|
||||
~Player();
|
||||
|
||||
@@ -89,19 +94,25 @@ private:
|
||||
bool m_HasDeletedTile{ false };
|
||||
WorldTile* m_DigTile{ nullptr };
|
||||
|
||||
bool m_IsDiggingPrimed{ false };
|
||||
|
||||
std::vector<Particle*> m_DigParticles{};
|
||||
|
||||
const float m_DigTime{ 0.5f };
|
||||
|
||||
bool m_Grounded { false };
|
||||
bool m_IsTurning{ false };
|
||||
|
||||
bool m_DidJustDigRight { false };
|
||||
bool m_DidJustDigLeft { false };
|
||||
Animation* m_currentAnimation{ nullptr };
|
||||
Animation* m_walkAnimation;
|
||||
Animation* m_turnAnimation{ nullptr };
|
||||
Animation* m_digStartAnimation{ nullptr };
|
||||
Animation* m_digAnimation{ nullptr };
|
||||
|
||||
PlayerState m_State { PlayerState::Idle };
|
||||
PlayerDirection m_Direction { PlayerDirection::Right };
|
||||
PlayerDirection m_Direction { PlayerDirection::Left };
|
||||
DigDirection m_DigDirection { DigDirection::Right };
|
||||
|
||||
//Testing
|
||||
|
||||
@@ -22,7 +22,6 @@ Texture * TextureManager::GetTexture(const std::string& name) {
|
||||
return pTexture;
|
||||
}
|
||||
TextureManager::~TextureManager() {
|
||||
//TODO: Loop over the m_Textures to delete them
|
||||
for (const auto& p : m_Textures) {
|
||||
delete p.second;
|
||||
}
|
||||
|
||||
@@ -3,18 +3,21 @@
|
||||
|
||||
#include "Texture.h"
|
||||
|
||||
class TextureManager
|
||||
{
|
||||
class TextureManager {
|
||||
public:
|
||||
static TextureManager * GetInstance();
|
||||
static void DestroyInstance();
|
||||
Texture* GetTexture(const std::string& name);
|
||||
|
||||
TextureManager(const TextureManager& other) = delete;
|
||||
TextureManager& operator=(const TextureManager& other) = delete;
|
||||
TextureManager(TextureManager&& other) = delete;
|
||||
TextureManager& operator=(TextureManager&& other) = delete;
|
||||
private:
|
||||
TextureManager() = default;
|
||||
~TextureManager();
|
||||
|
||||
static TextureManager* m_pInstance;
|
||||
|
||||
std::map<std::string, Texture *> m_Textures {};
|
||||
|
||||
};
|
||||
|
||||
@@ -12,13 +12,10 @@ int SDL_main(int argv, char** args) {
|
||||
|
||||
StartHeapControl();
|
||||
|
||||
new Button();
|
||||
|
||||
auto pGame { new Game { Window { "Motherload - Verhulst, Bram - 1DAEGD16E", Viewport.x, Viewport.y, false} } };
|
||||
auto pGame { new Game { Window { "Motherload - Verhulst, Bram - 1DAEGD16E", Viewport.x, Viewport.y, true} } };
|
||||
pGame->Run();
|
||||
delete pGame;
|
||||
|
||||
//DumpMemoryLeaks();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
BIN
Resources/animations/player/player_dig.png
Normal file
|
After Width: | Height: | Size: 7.2 KiB |
BIN
Resources/animations/player/player_dig_start.png
Normal file
|
After Width: | Height: | Size: 14 KiB |
BIN
Resources/animations/player/player_turn.png
Normal file
|
After Width: | Height: | Size: 17 KiB |
|
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
BIN
Resources/fonts/Arial.ttf
Normal file
BIN
Resources/gui/main/fuel/0.png
Normal file
|
After Width: | Height: | Size: 4.3 KiB |
BIN
Resources/gui/main/fuel/10.png
Normal file
|
After Width: | Height: | Size: 4.8 KiB |
BIN
Resources/gui/main/fuel/100.png
Normal file
|
After Width: | Height: | Size: 6.7 KiB |
BIN
Resources/gui/main/fuel/15.png
Normal file
|
After Width: | Height: | Size: 5.0 KiB |
BIN
Resources/gui/main/fuel/20.png
Normal file
|
After Width: | Height: | Size: 5.1 KiB |
BIN
Resources/gui/main/fuel/25.png
Normal file
|
After Width: | Height: | Size: 5.3 KiB |
BIN
Resources/gui/main/fuel/30.png
Normal file
|
After Width: | Height: | Size: 5.2 KiB |
BIN
Resources/gui/main/fuel/35.png
Normal file
|
After Width: | Height: | Size: 5.2 KiB |
BIN
Resources/gui/main/fuel/40.png
Normal file
|
After Width: | Height: | Size: 5.2 KiB |
BIN
Resources/gui/main/fuel/45.png
Normal file
|
After Width: | Height: | Size: 5.1 KiB |
BIN
Resources/gui/main/fuel/5.png
Normal file
|
After Width: | Height: | Size: 4.7 KiB |
BIN
Resources/gui/main/fuel/50.png
Normal file
|
After Width: | Height: | Size: 5.2 KiB |
BIN
Resources/gui/main/fuel/55.png
Normal file
|
After Width: | Height: | Size: 5.3 KiB |
BIN
Resources/gui/main/fuel/60.png
Normal file
|
After Width: | Height: | Size: 5.3 KiB |
BIN
Resources/gui/main/fuel/65.png
Normal file
|
After Width: | Height: | Size: 5.3 KiB |
BIN
Resources/gui/main/fuel/70.png
Normal file
|
After Width: | Height: | Size: 5.4 KiB |
BIN
Resources/gui/main/fuel/75.png
Normal file
|
After Width: | Height: | Size: 5.5 KiB |
BIN
Resources/gui/main/fuel/80.png
Normal file
|
After Width: | Height: | Size: 6.7 KiB |
BIN
Resources/gui/main/fuel/85.png
Normal file
|
After Width: | Height: | Size: 6.8 KiB |
BIN
Resources/gui/main/fuel/90.png
Normal file
|
After Width: | Height: | Size: 6.7 KiB |
BIN
Resources/gui/main/fuel/95.png
Normal file
|
After Width: | Height: | Size: 6.8 KiB |
BIN
Resources/gui/main/fuel/fuel.png
Normal file
|
After Width: | Height: | Size: 33 KiB |
BIN
Resources/gui/main/fuel_guage.png
Normal file
|
After Width: | Height: | Size: 328 KiB |
BIN
Resources/gui/main/hull/hull.png
Normal file
|
After Width: | Height: | Size: 35 KiB |
|
Before Width: | Height: | Size: 5.9 KiB After Width: | Height: | Size: 5.9 KiB |
BIN
Resources/moon.png
Normal file
|
After Width: | Height: | Size: 8.7 KiB |
BIN
Resources/particles/dirt_1.png
Normal file
|
After Width: | Height: | Size: 364 B |
BIN
Resources/particles/dirt_2.png
Normal file
|
After Width: | Height: | Size: 422 B |
BIN
Resources/particles/dirt_3.png
Normal file
|
After Width: | Height: | Size: 340 B |
BIN
Resources/particles/dirt_4.png
Normal file
|
After Width: | Height: | Size: 419 B |
BIN
Resources/particles/dirt_5.png
Normal file
|
After Width: | Height: | Size: 368 B |
BIN
Resources/particles/dirt_6.png
Normal file
|
After Width: | Height: | Size: 430 B |
BIN
Resources/particles/dirt_7.png
Normal file
|
After Width: | Height: | Size: 426 B |
BIN
Resources/particles/dirt_8.png
Normal file
|
After Width: | Height: | Size: 402 B |
BIN
Resources/sun.png
Normal file
|
After Width: | Height: | Size: 18 KiB |
BIN
Resources/topBackground.png
Normal file
|
After Width: | Height: | Size: 9.9 KiB |