mirror of
https://github.com/HowestDAE/dae16-VerhulstBram.git
synced 2026-02-04 08:09:19 +01:00
Basic screen system
This commit is contained in:
@@ -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
1
Game/Gui/Button.cpp
Normal file
@@ -0,0 +1 @@
|
||||
#include "Button.h"
|
||||
19
Game/Gui/Button.h
Normal file
19
Game/Gui/Button.h
Normal 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
14
Game/Gui/Screen.cpp
Normal 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
26
Game/Gui/Screen.h
Normal 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 };
|
||||
};
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 };
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user