diff --git a/.idea/.idea.Motherload/.idea/workspace.xml b/.idea/.idea.Motherload/.idea/workspace.xml
index 17e454f..6d98451 100644
--- a/.idea/.idea.Motherload/.idea/workspace.xml
+++ b/.idea/.idea.Motherload/.idea/workspace.xml
@@ -11,18 +11,23 @@
-
-
-
-
+
+
+
+
+
+
-
-
+
+
+
+
+
@@ -59,6 +64,429 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -76,28 +504,28 @@
- {
+ "keyToString": {
+ "C++ Project.Game.executor": "Run",
+ "RunOnceActivity.OpenProjectViewOnStart": "true",
+ "RunOnceActivity.ShowReadmeOnStart": "true",
+ "ignore.virus.scanning.warn.message": "true",
+ "node.js.detected.package.eslint": "true",
+ "node.js.detected.package.tslint": "true",
+ "node.js.selected.package.eslint": "(autodetect)",
+ "node.js.selected.package.tslint": "(autodetect)",
+ "nodejs_package_manager_path": "npm",
+ "settings.editor.selected.configurable": "CppClangTidyOptionsId",
+ "vue.rearranger.settings.migration": "true"
},
- "keyToStringList": {
- "rider.external.source.directories": [
- "C:\\Users\\Bram\\AppData\\Roaming\\JetBrains\\Rider2023.3\\resharper-host\\DecompilerCache",
- "C:\\Users\\Bram\\AppData\\Roaming\\JetBrains\\Rider2023.3\\resharper-host\\SourcesCache",
- "C:\\Users\\Bram\\AppData\\Local\\Symbols\\src"
+ "keyToStringList": {
+ "rider.external.source.directories": [
+ "C:\\Users\\Bram\\AppData\\Roaming\\JetBrains\\Rider2023.3\\resharper-host\\DecompilerCache",
+ "C:\\Users\\Bram\\AppData\\Roaming\\JetBrains\\Rider2023.3\\resharper-host\\SourcesCache",
+ "C:\\Users\\Bram\\AppData\\Local\\Symbols\\src"
]
}
-}]]>
+}
@@ -175,7 +603,13 @@
-
+
+
+
+
+
+
+
@@ -193,7 +627,15 @@
1711960060059
-
+
+
+ 1712045841557
+
+
+
+ 1712045841557
+
+
@@ -204,7 +646,15 @@
-
+
+
+
+
+
+
+
+
+
diff --git a/Engine/structs.cpp b/Engine/structs.cpp
index 8891027..041d288 100644
--- a/Engine/structs.cpp
+++ b/Engine/structs.cpp
@@ -1,6 +1,8 @@
#include "base.h"
#include "structs.h"
+#include
+
//-----------------------------------------------------------------
// Window Constructors
//-----------------------------------------------------------------
@@ -52,6 +54,10 @@ Point2f operator/(float right, const Point2f& left) {
Point2f operator*(float right, const Point2f& left) {
return Point2f{ right * left.x, right * left.y };
}
+std::ostream& operator<<(std::ostream& os, const Point2f& p) {
+ os << "Point2f( " << p.x << ", " << p.y << " )" << std::endl;
+ return os;
+}
//-----------------------------------------------------------------
// Rectf Constructors
//-----------------------------------------------------------------
diff --git a/Engine/structs.h b/Engine/structs.h
index cd60f17..c71ee55 100644
--- a/Engine/structs.h
+++ b/Engine/structs.h
@@ -26,6 +26,7 @@ struct Point2f
Point2f operator*( const Point2f& other ) const;
Point2f operator/( float other ) const;
Point2f operator-( const Point2f& other ) const;
+
float x;
float y;
@@ -34,6 +35,8 @@ struct Point2f
Point2f operator/(float right, const Point2f& left);
Point2f operator*(float right, const Point2f& left);
+std::ostream& operator<<(std::ostream& os, const Point2f& p);
+
struct Rectf
{
Rectf( );
diff --git a/Engine/utils.cpp b/Engine/utils.cpp
index dcbbd8f..3a5483e 100644
--- a/Engine/utils.cpp
+++ b/Engine/utils.cpp
@@ -705,6 +705,17 @@ Point2f utils::GetMousePos() {
//TODO: make the screen size a global or something
return Point2f { float(x), float(500.f - y) };
}
+bool utils::IsMouseButtonDown(int button) {
+ const Uint32 pStates = SDL_GetMouseState(nullptr, nullptr);
+ if (pStates & SDL_BUTTON(button)) {
+ return true;
+ }
+ return false;
+}
+static Point2f ViewportSize{ 900.f, 500.f }; //TODO: somehow move this (Ask teacher)
+Point2f utils::GetViewport() {
+ return ViewportSize;
+}
bool utils::isMouseDown(int button) {
const Uint32 pStates = SDL_GetMouseState(nullptr, nullptr);
diff --git a/Engine/utils.h b/Engine/utils.h
index 9316bb2..8b10de0 100644
--- a/Engine/utils.h
+++ b/Engine/utils.h
@@ -112,5 +112,10 @@ namespace utils
bool isKeyUp(int keycode);
Point2f GetMousePos();
+ bool IsMouseButtonDown(int button);
+
+
+ Point2f GetViewport();
+
}
\ No newline at end of file
diff --git a/Game/Game.vcxproj b/Game/Game.vcxproj
index 6b2f98f..e7c7d7d 100644
--- a/Game/Game.vcxproj
+++ b/Game/Game.vcxproj
@@ -151,6 +151,7 @@
+
MultiThreadedDebugDll
EnableFastChecks
@@ -301,6 +302,8 @@
+
+
MultiThreadedDebugDll
EnableFastChecks
@@ -458,10 +461,13 @@
+
+
+
diff --git a/Game/GameManager.cpp b/Game/GameManager.cpp
new file mode 100644
index 0000000..8faed90
--- /dev/null
+++ b/Game/GameManager.cpp
@@ -0,0 +1 @@
+#include "GameManager.h"
diff --git a/Game/GameManager.h b/Game/GameManager.h
new file mode 100644
index 0000000..0a34524
--- /dev/null
+++ b/Game/GameManager.h
@@ -0,0 +1,12 @@
+#pragma once
+#include "Player.h"
+
+class GameManager
+{
+public:
+ float balance{ 0.0f };
+ float fuel{ 0.0f };
+
+private:
+ GameManager() = default;
+};
diff --git a/Game/Gui/Button.cpp b/Game/Gui/Button.cpp
index b079d40..4ab2924 100644
--- a/Game/Gui/Button.cpp
+++ b/Game/Gui/Button.cpp
@@ -1 +1,37 @@
#include "Button.h"
+
+#include
+
+#include "colors.h"
+#include "utils.h"
+Button::Button(const std::string& filePath, Point2f pos, Point2f size, TextureManager* manager): m_Position(pos), m_Size(size) {
+ m_Texture = manager->GetTexture(filePath);
+ if(size.x == 0 && size.y == 0) {
+ m_Size = Point2f{float(m_Texture->GetWidth()), float(m_Texture->GetHeight())};
+ }
+ std::cout << "Button created" << '\n';
+}
+Button::~Button() {
+ std::cout << "Button destroyed" << '\n';
+}
+void Button::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) {
+ Point2f mousePos = utils::GetMousePos();
+ Rectf buttonRect = Rectf(m_Position, m_Size);
+
+ this->m_IsHovered = utils::IsPointInRect(mousePos, buttonRect);
+ m_IsPressed = m_IsHovered && utils::IsMouseButtonDown(SDL_BUTTON_LEFT);
+
+ if(m_IsPressed) {
+ m_OnClick();
+ }
+}
+
+
+
diff --git a/Game/Gui/Button.h b/Game/Gui/Button.h
index 240a95e..a7a134c 100644
--- a/Game/Gui/Button.h
+++ b/Game/Gui/Button.h
@@ -1,13 +1,22 @@
#pragma once
+#include
+#include
+
#include "Texture.h"
+#include "../TextureManager.h"
class Button
{
public:
Button() = default;
- Button(const std::string& filePath, Point2f pos, Point2f size);
+ Button(const std::string& filePath, Point2f pos, Point2f size, TextureManager* manager);
+ ~Button();
void Draw() const;
void Update(float elapsedSec);
+
+ void SetOnClick(std::function onClick) {
+ m_OnClick = onClick;
+ }
private:
Texture* m_Texture{ nullptr };
@@ -16,4 +25,6 @@ private:
bool m_IsHovered{ false };
bool m_IsPressed{ false };
+
+ std::function m_OnClick{ []() { std::cout << "Button not implemented" << std::endl; } };
};
diff --git a/Game/Gui/Screen.cpp b/Game/Gui/Screen.cpp
index 6bbb512..38457a1 100644
--- a/Game/Gui/Screen.cpp
+++ b/Game/Gui/Screen.cpp
@@ -6,9 +6,16 @@ Screen::Screen(const std::string& filePath, Point2f pos, Point2f size,TextureMan
Screen::~Screen() {
}
void Screen::Update(float elapsedSecs) {
+ for(Button* b : m_Buttons) {
+ 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);
+
+ for(Button* b: m_Buttons) {
+ b->Draw();
+ }
}
diff --git a/Game/Gui/Screen.h b/Game/Gui/Screen.h
index 7f11fca..8c9d1a9 100644
--- a/Game/Gui/Screen.h
+++ b/Game/Gui/Screen.h
@@ -1,4 +1,7 @@
#pragma once
+#include
+
+#include "Button.h"
#include "structs.h"
#include "Texture.h"
#include "../TextureManager.h"
@@ -9,18 +12,17 @@ public:
Screen() = default;
Screen(const std::string& filePath, Point2f pos, Point2f size, TextureManager* manager);
- ~Screen();
+ virtual ~Screen();
- void setActive(bool active) { m_Active = active; }
- void toggleActive() { m_Active = !m_Active; }
+ void AddButton(Button* button) { m_Buttons.push_back(button); }
- void Update(float elapsedSecs);
- void Draw() const;
+ virtual void Update(float elapsedSecs);
+ virtual void Draw() const;
private:
Point2f m_Position;
Point2f m_Size;
Texture* m_Background{ nullptr };
- bool m_Active{ false };
+ std::vector