Basic screen system

This commit is contained in:
Bram Verhulst
2024-04-02 10:17:20 +02:00
parent 0f9bb76973
commit df9e2f0b64
15 changed files with 404 additions and 410 deletions

View File

@@ -11,34 +11,21 @@
</component>
<component name="ChangeListManager">
<list default="true" id="26a0623a-44d5-441c-8048-32ff1dab3479" name="Changes" comment="">
<change afterPath="$PROJECT_DIR$/.idea/.idea.Motherload/.idea/.name" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/.idea.Motherload/.idea/indexLayout.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/.idea.Motherload/.idea/projectSettingsUpdater.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/Assets/Player/PlayerWalk.aseprite" afterDir="false" />
<change afterPath="$PROJECT_DIR$/Game/Animations/Animation.cpp" afterDir="false" />
<change afterPath="$PROJECT_DIR$/Game/Animations/Animation.h" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/.idea.Motherload/.idea/copilot/chatSessions/blobs/version" beforeDir="false" />
<change afterPath="$PROJECT_DIR$/Game/Gui/Button.cpp" afterDir="false" />
<change afterPath="$PROJECT_DIR$/Game/Gui/Button.h" afterDir="false" />
<change afterPath="$PROJECT_DIR$/Game/Gui/Screen.cpp" afterDir="false" />
<change afterPath="$PROJECT_DIR$/Game/Gui/Screen.h" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/.idea.Motherload/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.Motherload/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/PlayerWalk.aseprite" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/Game/Camera.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/Game/Camera.cpp" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Game/Camera.h" beforeDir="false" afterPath="$PROJECT_DIR$/Game/Camera.h" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Game/Game.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/Game/Game.cpp" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Game/Game.h" beforeDir="false" afterPath="$PROJECT_DIR$/Game/Game.h" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Engine/Collision.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/Engine/Collision.cpp" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Engine/structs.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/Engine/structs.cpp" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Engine/structs.h" beforeDir="false" afterPath="$PROJECT_DIR$/Engine/structs.h" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Engine/utils.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/Engine/utils.cpp" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Engine/utils.h" beforeDir="false" afterPath="$PROJECT_DIR$/Engine/utils.h" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Game/Game.vcxproj" beforeDir="false" afterPath="$PROJECT_DIR$/Game/Game.vcxproj" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Game/Level.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/Game/Level.cpp" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Game/Level.h" beforeDir="false" afterPath="$PROJECT_DIR$/Game/Level.h" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Game/Player.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/Game/Player.cpp" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Game/Player.h" beforeDir="false" afterPath="$PROJECT_DIR$/Game/Player.h" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Game/TextureManager.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/Game/TextureManager.cpp" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Game/TextureManager.h" beforeDir="false" afterPath="$PROJECT_DIR$/Game/TextureManager.h" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Game/WorldGridManager.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/Game/GridSystem/WorldGridManager.cpp" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Game/WorldGridManager.h" beforeDir="false" afterPath="$PROJECT_DIR$/Game/GridSystem/WorldGridManager.h" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Game/WorldLevel.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/Game/WorldLevel.cpp" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Game/WorldLevel.h" beforeDir="false" afterPath="$PROJECT_DIR$/Game/WorldLevel.h" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Game/WorldTile.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/Game/GridSystem/WorldTile.cpp" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Game/WorldTile.h" beforeDir="false" afterPath="$PROJECT_DIR$/Game/GridSystem/WorldTile.h" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Game/main.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/Game/main.cpp" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Game/pch.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/Game/pch.cpp" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -72,12 +59,6 @@
<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" />
</component>
<component name="MarkdownSettingsMigration">
<option name="stateVersion" value="1" />
@@ -95,28 +76,28 @@
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent">{
&quot;keyToString&quot;: {
&quot;C++ Project.Game.executor&quot;: &quot;Run&quot;,
&quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;,
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
&quot;ignore.virus.scanning.warn.message&quot;: &quot;true&quot;,
&quot;node.js.detected.package.eslint&quot;: &quot;true&quot;,
&quot;node.js.detected.package.tslint&quot;: &quot;true&quot;,
&quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;,
&quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;,
&quot;nodejs_package_manager_path&quot;: &quot;npm&quot;,
&quot;settings.editor.selected.configurable&quot;: &quot;CppClangTidyOptionsId&quot;,
&quot;vue.rearranger.settings.migration&quot;: &quot;true&quot;
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"C++ Project.Game.executor": "Run",
"RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"ignore.virus.scanning.warn.message": "true",
"node.js.detected.package.eslint": "true",
"node.js.detected.package.tslint": "true",
"node.js.selected.package.eslint": "(autodetect)",
"node.js.selected.package.tslint": "(autodetect)",
"nodejs_package_manager_path": "npm",
"settings.editor.selected.configurable": "CppClangTidyOptionsId",
"vue.rearranger.settings.migration": "true"
},
&quot;keyToStringList&quot;: {
&quot;rider.external.source.directories&quot;: [
&quot;C:\\Users\\Bram\\AppData\\Roaming\\JetBrains\\Rider2023.3\\resharper-host\\DecompilerCache&quot;,
&quot;C:\\Users\\Bram\\AppData\\Roaming\\JetBrains\\Rider2023.3\\resharper-host\\SourcesCache&quot;,
&quot;C:\\Users\\Bram\\AppData\\Local\\Symbols\\src&quot;
"keyToStringList": {
"rider.external.source.directories": [
"C:\\Users\\Bram\\AppData\\Roaming\\JetBrains\\Rider2023.3\\resharper-host\\DecompilerCache",
"C:\\Users\\Bram\\AppData\\Roaming\\JetBrains\\Rider2023.3\\resharper-host\\SourcesCache",
"C:\\Users\\Bram\\AppData\\Local\\Symbols\\src"
]
}
}</component>
}]]></component>
<component name="RunManager">
<configuration name="Game" type="CppProject" factoryName="C++ Project">
<configuration_1>
@@ -191,7 +172,10 @@
<workItem from="1711718669225" duration="530000" />
<workItem from="1711734864498" duration="5607000" />
<workItem from="1711819496854" duration="481000" />
<workItem from="1711959076645" duration="941000" />
<workItem from="1711959076645" duration="5786000" />
<workItem from="1711987750989" duration="660000" />
<workItem from="1711988744393" duration="1555000" />
<workItem from="1712008689540" duration="3701000" />
</task>
<task id="LOCAL-00001" summary="Rework Tile detection system">
<option name="closed" value="true" />
@@ -201,7 +185,15 @@
<option name="project" value="LOCAL" />
<updated>1711648418492</updated>
</task>
<option name="localTasksCounter" value="2" />
<task id="LOCAL-00002" summary="Reformat + Basic animation system&#10;General fixes">
<option name="closed" value="true" />
<created>1711960060059</created>
<option name="number" value="00002" />
<option name="presentableId" value="LOCAL-00002" />
<option name="project" value="LOCAL" />
<updated>1711960060059</updated>
</task>
<option name="localTasksCounter" value="3" />
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
@@ -211,7 +203,8 @@
<component name="VcsManagerConfiguration">
<option name="CLEAR_INITIAL_COMMIT_MESSAGE" value="true" />
<MESSAGE value="Rework Tile detection system" />
<option name="LAST_COMMIT_MESSAGE" value="Rework Tile detection system" />
<MESSAGE value="Reformat + Basic animation system&#10;General fixes" />
<option name="LAST_COMMIT_MESSAGE" value="Reformat + Basic animation system&#10;General fixes" />
</component>
<component name="XSLT-Support.FileAssociations.UIState">
<expand />

View File

@@ -2,7 +2,7 @@
#include "utils.h"
#include "../Game/Player.h"
#include "../Game/WorldTile.h"
#include "../Game/GridSystem/WorldTile.h"
namespace Collision
{

View File

@@ -65,6 +65,7 @@ Rectf::Rectf(float left, float bottom, float width, float height)
, width { width }
, height { height } {
}
Rectf::Rectf(Point2f pos, Point2f size): left(pos.x), bottom(pos.y), width(size.x), height(size.y) {}
// Rectf::Rectf(int left, int bottom, int width, int height) : left { (float)left }, bottom { (float)bottom }, width { (float)width }, height { (float)height } {
// }

View File

@@ -38,6 +38,7 @@ struct Rectf
{
Rectf( );
explicit Rectf( float left, float bottom, float width, float height );
Rectf(Point2f pos, Point2f size);
//explicit Rectf( int left, int bottom, int width, int height ); //Stupid fix for it giving an error (same as Point2f)
Point2f BottomLeft() const { return Point2f{ left, bottom }; }

File diff suppressed because it is too large Load Diff

View File

@@ -111,4 +111,6 @@ namespace utils
bool isMouseDown(int button);
bool isKeyUp(int keycode);
Point2f GetMousePos();
}

View File

@@ -299,6 +299,8 @@
<SDLCheck>true</SDLCheck>
<LinkCompiled>true</LinkCompiled>
</ClCompile>
<ClCompile Include="Gui\Button.cpp" />
<ClCompile Include="Gui\Screen.cpp" />
<ClCompile Include="Level.cpp">
<RuntimeLibrary>MultiThreadedDebugDll</RuntimeLibrary>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
@@ -458,6 +460,8 @@
<ClInclude Include="Game.h"/>
<ClInclude Include="GridSystem\WorldGridManager.h"/>
<ClInclude Include="GridSystem\WorldTile.h"/>
<ClInclude Include="Gui\Button.h" />
<ClInclude Include="Gui\Screen.h" />
<ClInclude Include="Level.h"/>
<ClInclude Include="pch.h"/>
<ClInclude Include="Player.h"/>

1
Game/Gui/Button.cpp Normal file
View File

@@ -0,0 +1 @@
#include "Button.h"

19
Game/Gui/Button.h Normal file
View File

@@ -0,0 +1,19 @@
#pragma once
#include "Texture.h"
class Button
{
public:
Button() = default;
Button(const std::string& filePath, Point2f pos, Point2f size);
void Draw() const;
void Update(float elapsedSec);
private:
Texture* m_Texture{ nullptr };
Point2f m_Position;
Point2f m_Size;
bool m_IsHovered{ false };
bool m_IsPressed{ false };
};

14
Game/Gui/Screen.cpp Normal file
View File

@@ -0,0 +1,14 @@
#include "Screen.h"
Screen::Screen(const std::string& filePath, Point2f pos, Point2f size,TextureManager* manager): m_Position(pos), m_Size(size)
{
m_Background = manager->GetTexture(filePath);
}
Screen::~Screen() {
}
void Screen::Update(float 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);
}

26
Game/Gui/Screen.h Normal file
View File

@@ -0,0 +1,26 @@
#pragma once
#include "structs.h"
#include "Texture.h"
#include "../TextureManager.h"
class Screen
{
public:
Screen() = default;
Screen(const std::string& filePath, Point2f pos, Point2f size, TextureManager* manager);
~Screen();
void setActive(bool active) { m_Active = active; }
void toggleActive() { m_Active = !m_Active; }
void Update(float elapsedSecs);
void Draw() const;
private:
Point2f m_Position;
Point2f m_Size;
Texture* m_Background{ nullptr };
bool m_Active{ false };
};

View File

@@ -7,6 +7,7 @@
#include "utils.h"
#include "WorldLevel.h"
#include "Animations/Animation.h"
#include "GridSystem/WorldTile.h"
Player::Player(const Point2f& Position, TextureManager* manager) : m_Position(Position), m_Size(Point2f { 40, 40 }), m_Vel(Point2f { 0, 0 }), m_Acc(Point2f { 0, 0 }) {
m_ContactMap[Collision::CollisionDirection::Top] = nullptr;
@@ -39,7 +40,7 @@ void Player::ProcessImGui() {
ImGui::Begin("Collision Info", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
ImGui::Text("is Grounded: %s", m_Grounded ? "true" : "false");
ImGui::Text("Did just dig right: %s", m_DidJustDigRight ? "true" : "false");
bool test = !utils::isKeyDown(SDL_SCANCODE_H);
bool test = !utils::isKeyPressed(SDL_SCANCODE_H);
ImGui::Text("Is Key Up H: %s", test ? "true" : "false");
ImGui::Checkbox("Draw Collision Rect", &m_DrawCollisionRect);

View File

@@ -9,8 +9,10 @@
#include "Collision.h"
#include "colors.h"
#include "utils.h"
#include "GridSystem/WorldTile.h"
class GroundTileType;
WorldLevel::WorldLevel(Camera* camera, Rectf viewport): Level(camera),
m_gridManager(WorldGridManager()),
m_player(Player { Point2f { 0, 100 }, TextureManager::GetInstance() }),
@@ -33,7 +35,7 @@ WorldLevel::WorldLevel(Camera* camera, Rectf viewport): Level(camera),
//AIR
break;
default:
std::cout << "??" << std::endl;
std::cout << "??" << '\n';
}
m_gridManager.SetTileAtIndex(x, y, new WorldTile { pos, type, TextureManager::GetInstance() });
@@ -42,6 +44,8 @@ WorldLevel::WorldLevel(Camera* camera, Rectf viewport): Level(camera),
for (size_t x { 0 }; x < WORLD_WIDTH; ++x) {
m_gridManager.GetTileAtIndex(x, 0)->SetTileType(Tiles::AIR);
}
Point2f screenCenterPos = Point2f { m_viewport.width / 2 - 492 / 2, m_viewport.height / 2 - 396 / 2 };
m_screen = Screen{ "gui/fuel/background.png", screenCenterPos, Point2f { 492, 396 }, TextureManager::GetInstance() };
}
WorldLevel::~WorldLevel() {
//delete m_pTextTexture;
@@ -117,6 +121,10 @@ void WorldLevel::Draw() const {
m_player.Draw();
m_pCamera->EndRendering();
utils::FillRect(utils::GetMousePos(), 10, 10);
m_screen.Draw();
}
void WorldLevel::MouseMove(const Point2f& mousePos) {
m_mousePos = mousePos;

View File

@@ -3,8 +3,8 @@
#include "Level.h"
#include "Player.h"
#include "utils.h"
#include "WorldLevel.h"
#include "GridSystem/WorldGridManager.h"
#include "Gui/Screen.h"
class WorldLevel : public Level
@@ -35,6 +35,8 @@ private:
Rectf m_viewport;
Screen m_screen;
// ImGui Vars
bool m_ShowTextureManagerWindow { false };
bool m_ShowCameraWindow { false };

View File

@@ -11,7 +11,7 @@ int SDL_main(int argv, char** args) {
StartHeapControl();
auto pGame { new Game { Window { "Motherload - Verhulst, Bram - 1DAEGD16E", 846.f, 500.f } } };
auto pGame { new Game { Window { "Motherload - Verhulst, Bram - 1DAEGD16E", 900.f, 500.f } } };
pGame->Run();
delete pGame;