mirror of
https://github.com/HowestDAE/dae16-VerhulstBram.git
synced 2026-02-04 09:29:20 +01:00
Reformat + Basic animation system
General fixes
This commit is contained in:
1
.idea/.idea.Motherload/.idea/.name
generated
Normal file
1
.idea/.idea.Motherload/.idea/.name
generated
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Motherload
|
||||||
Binary file not shown.
8
.idea/.idea.Motherload/.idea/indexLayout.xml
generated
Normal file
8
.idea/.idea.Motherload/.idea/indexLayout.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="UserContentModel">
|
||||||
|
<attachedFolders />
|
||||||
|
<explicitIncludes />
|
||||||
|
<explicitExcludes />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
6
.idea/.idea.Motherload/.idea/projectSettingsUpdater.xml
generated
Normal file
6
.idea/.idea.Motherload/.idea/projectSettingsUpdater.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="RiderProjectSettingsUpdater">
|
||||||
|
<option name="vcsConfiguration" value="2" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
63
.idea/.idea.Motherload/.idea/workspace.xml
generated
63
.idea/.idea.Motherload/.idea/workspace.xml
generated
@@ -1,5 +1,8 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
|
<component name="AnalysisUIOptions">
|
||||||
|
<option name="SCOPE_TYPE" value="4" />
|
||||||
|
</component>
|
||||||
<component name="AutoGeneratedRunConfigurationManager">
|
<component name="AutoGeneratedRunConfigurationManager">
|
||||||
<projectFile>Game/Game.vcxproj</projectFile>
|
<projectFile>Game/Game.vcxproj</projectFile>
|
||||||
</component>
|
</component>
|
||||||
@@ -9,16 +12,33 @@
|
|||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="26a0623a-44d5-441c-8048-32ff1dab3479" name="Changes" comment="">
|
<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/.name" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/Engine/utils.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/Engine/utils.cpp" 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 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.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$/Game/Game.vcxproj" beforeDir="false" afterPath="$PROJECT_DIR$/Game/Game.vcxproj" 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.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.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/Game/TextureManager.cpp" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/Game/WorldGridManager.h" beforeDir="false" afterPath="$PROJECT_DIR$/Game/WorldGridManager.h" 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.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/Game/WorldLevel.cpp" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/Game/WorldTile.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/Game/WorldTile.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.h" beforeDir="false" afterPath="$PROJECT_DIR$/Game/WorldTile.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$/Prog2Engine.sln" beforeDir="false" afterPath="$PROJECT_DIR$/Motherload.sln" 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>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
@@ -62,6 +82,10 @@
|
|||||||
<component name="MarkdownSettingsMigration">
|
<component name="MarkdownSettingsMigration">
|
||||||
<option name="stateVersion" value="1" />
|
<option name="stateVersion" value="1" />
|
||||||
</component>
|
</component>
|
||||||
|
<component name="MetaFilesCheckinStateConfiguration" checkMetaFiles="true" />
|
||||||
|
<component name="ProblemsViewState">
|
||||||
|
<option name="selectedTabId" value="CurrentFile" />
|
||||||
|
</component>
|
||||||
<component name="ProjectColorInfo">{
|
<component name="ProjectColorInfo">{
|
||||||
"customColor": "",
|
"customColor": "",
|
||||||
"associatedIndex": 1
|
"associatedIndex": 1
|
||||||
@@ -76,11 +100,13 @@
|
|||||||
"C++ Project.Game.executor": "Run",
|
"C++ Project.Game.executor": "Run",
|
||||||
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
||||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||||
|
"ignore.virus.scanning.warn.message": "true",
|
||||||
"node.js.detected.package.eslint": "true",
|
"node.js.detected.package.eslint": "true",
|
||||||
"node.js.detected.package.tslint": "true",
|
"node.js.detected.package.tslint": "true",
|
||||||
"node.js.selected.package.eslint": "(autodetect)",
|
"node.js.selected.package.eslint": "(autodetect)",
|
||||||
"node.js.selected.package.tslint": "(autodetect)",
|
"node.js.selected.package.tslint": "(autodetect)",
|
||||||
"nodejs_package_manager_path": "npm",
|
"nodejs_package_manager_path": "npm",
|
||||||
|
"settings.editor.selected.configurable": "CppClangTidyOptionsId",
|
||||||
"vue.rearranger.settings.migration": "true"
|
"vue.rearranger.settings.migration": "true"
|
||||||
},
|
},
|
||||||
"keyToStringList": {
|
"keyToStringList": {
|
||||||
@@ -156,14 +182,39 @@
|
|||||||
<workItem from="1711641119746" duration="813000" />
|
<workItem from="1711641119746" duration="813000" />
|
||||||
<workItem from="1711642495862" duration="258000" />
|
<workItem from="1711642495862" duration="258000" />
|
||||||
<workItem from="1711647566340" duration="378000" />
|
<workItem from="1711647566340" duration="378000" />
|
||||||
<workItem from="1711647993177" duration="357000" />
|
<workItem from="1711647993177" duration="454000" />
|
||||||
|
<workItem from="1711694346681" duration="157000" />
|
||||||
|
<workItem from="1711694523256" duration="228000" />
|
||||||
|
<workItem from="1711694778634" duration="924000" />
|
||||||
|
<workItem from="1711697604502" duration="2696000" />
|
||||||
|
<workItem from="1711706270506" duration="2205000" />
|
||||||
|
<workItem from="1711718669225" duration="530000" />
|
||||||
|
<workItem from="1711734864498" duration="5607000" />
|
||||||
|
<workItem from="1711819496854" duration="481000" />
|
||||||
|
<workItem from="1711959076645" duration="941000" />
|
||||||
</task>
|
</task>
|
||||||
|
<task id="LOCAL-00001" summary="Rework Tile detection system">
|
||||||
|
<option name="closed" value="true" />
|
||||||
|
<created>1711648418492</created>
|
||||||
|
<option name="number" value="00001" />
|
||||||
|
<option name="presentableId" value="LOCAL-00001" />
|
||||||
|
<option name="project" value="LOCAL" />
|
||||||
|
<updated>1711648418492</updated>
|
||||||
|
</task>
|
||||||
|
<option name="localTasksCounter" value="2" />
|
||||||
<servers />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
<component name="TypeScriptGeneratedFilesManager">
|
<component name="TypeScriptGeneratedFilesManager">
|
||||||
<option name="version" value="3" />
|
<option name="version" value="3" />
|
||||||
</component>
|
</component>
|
||||||
|
<component name="UnityCheckinConfiguration" checkUnsavedScenes="true" />
|
||||||
<component name="VcsManagerConfiguration">
|
<component name="VcsManagerConfiguration">
|
||||||
<option name="CLEAR_INITIAL_COMMIT_MESSAGE" value="true" />
|
<option name="CLEAR_INITIAL_COMMIT_MESSAGE" value="true" />
|
||||||
|
<MESSAGE value="Rework Tile detection system" />
|
||||||
|
<option name="LAST_COMMIT_MESSAGE" value="Rework Tile detection system" />
|
||||||
|
</component>
|
||||||
|
<component name="XSLT-Support.FileAssociations.UIState">
|
||||||
|
<expand />
|
||||||
|
<select />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
25
Game/Animations/Animation.cpp
Normal file
25
Game/Animations/Animation.cpp
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
#include "Animation.h"
|
||||||
|
Animation::Animation(Texture* pTexture, int frames, float frameDuration, Rectf srcRect): m_pTexture(pTexture), m_SrcRect(srcRect), m_Frames(frames) {
|
||||||
|
|
||||||
|
}
|
||||||
|
Animation::~Animation() {
|
||||||
|
}
|
||||||
|
void Animation::Update(float elapsedSec) {
|
||||||
|
if (m_isPlaying) {
|
||||||
|
m_FrameTimer -= elapsedSec;
|
||||||
|
if (m_FrameTimer <= 0.0f) {
|
||||||
|
m_FrameTimer = 0.1f;
|
||||||
|
++m_CurrentFrame;
|
||||||
|
if (m_CurrentFrame >= m_Frames) {
|
||||||
|
m_CurrentFrame = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void Animation::Draw(const Point2f& pos, float angle) const {
|
||||||
|
Rectf src = m_SrcRect;
|
||||||
|
src.left += m_CurrentFrame * src.width;
|
||||||
|
auto dst = Rectf { pos.x, pos.y, src.width, src.height };
|
||||||
|
|
||||||
|
m_pTexture->Draw(dst, src, m_isFlipped);
|
||||||
|
}
|
||||||
30
Game/Animations/Animation.h
Normal file
30
Game/Animations/Animation.h
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "Texture.h"
|
||||||
|
|
||||||
|
class Animation
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Animation(Texture* pTexture, int frames, float frameDuration, Rectf srcRect);
|
||||||
|
~Animation();
|
||||||
|
|
||||||
|
void Update(float elapsedSec);
|
||||||
|
void Draw(const Point2f& pos, float angle = 0.0f) const;
|
||||||
|
|
||||||
|
void SetPlaying(bool isPlaying) {
|
||||||
|
m_isPlaying = isPlaying;
|
||||||
|
}
|
||||||
|
void SetFlipped(bool isFlipped) {
|
||||||
|
m_isFlipped = isFlipped;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
Texture* m_pTexture;
|
||||||
|
Rectf m_SrcRect;
|
||||||
|
|
||||||
|
int m_Frames { 0 };
|
||||||
|
int m_CurrentFrame { 0 };
|
||||||
|
float m_FrameTimer { 0.0f };
|
||||||
|
|
||||||
|
bool m_isPlaying { true };
|
||||||
|
bool m_isFlipped { false };
|
||||||
|
};
|
||||||
@@ -14,14 +14,14 @@ void Camera::BeginRendering() const {
|
|||||||
glScalef(m_Scale, m_Scale, 1);
|
glScalef(m_Scale, m_Scale, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ReSharper disable once CppMemberFunctionMayBeStatic
|
||||||
void Camera::EndRendering() const {
|
void Camera::EndRendering() const {
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
Point2f Camera::TransformMouse(const Point2f& mousePos) const {
|
Point2f Camera::TransformMouse(const Point2f& mousePos) const {
|
||||||
//Mousepos is in screen coords, we need to transform it to world coords
|
|
||||||
Point2f worldPos = mousePos;
|
Point2f worldPos = mousePos;
|
||||||
worldPos.x = (worldPos.x + m_Position.x) / m_Scale;
|
worldPos.x = ( worldPos.x + m_Position.x ) / m_Scale;
|
||||||
worldPos.y = Viewport.height - worldPos.y + m_Position.y / m_Scale;
|
worldPos.y = Viewport.height - worldPos.y + m_Position.y / m_Scale;
|
||||||
return worldPos;
|
return worldPos;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,28 +5,42 @@ class Player;
|
|||||||
class Camera
|
class Camera
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Camera( );
|
Camera();
|
||||||
Camera( const Point2f& position, float scale = 1);
|
Camera(const Point2f& position, float scale = 1);
|
||||||
~Camera() = default;
|
~Camera() = default;
|
||||||
|
|
||||||
void SetPosition( const Point2f& position ) { m_Position = position; }
|
Camera(const Camera& other) = default;
|
||||||
void SetScale( const float scale ) { m_Scale = scale; }
|
Camera& operator=(const Camera& other) = default;
|
||||||
|
|
||||||
const Point2f& GetPosition( ) const { return m_Position; }
|
void SetPosition(const Point2f& position) {
|
||||||
float GetScale( ) const { return m_Scale; }
|
m_Position = position;
|
||||||
|
}
|
||||||
|
void SetScale(const float scale) {
|
||||||
|
m_Scale = scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Point2f& GetPosition() const {
|
||||||
|
return m_Position;
|
||||||
|
}
|
||||||
|
float GetScale() const {
|
||||||
|
return m_Scale;
|
||||||
|
}
|
||||||
|
|
||||||
void BeginRendering() const;
|
void BeginRendering() const;
|
||||||
void EndRendering() const;
|
void EndRendering() const;
|
||||||
|
|
||||||
void SetTrackingPlayer(Player* player) { m_FollowingPlayer = player; }
|
void SetTrackingPlayer(Player* player) {
|
||||||
|
m_FollowingPlayer = player;
|
||||||
|
}
|
||||||
|
|
||||||
Point2f TransformMouse (const Point2f& mousePos) const;
|
Point2f TransformMouse(const Point2f& mousePos) const;
|
||||||
Point2f TransformWorld (const Point2f& worldPos) const;
|
Point2f TransformWorld(const Point2f& worldPos) const;
|
||||||
Rectf Viewport = Rectf{ 0, 0, 846.f, 500.f };
|
Rectf Viewport = Rectf { 0, 0, 846.f, 500.f };
|
||||||
//TODO: Remove this and make it some static
|
//TODO: Remove this and make it some static
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Point2f m_Position;
|
Point2f m_Position;
|
||||||
float m_Scale;
|
float m_Scale;
|
||||||
Player* m_FollowingPlayer{ nullptr };
|
Player* m_FollowingPlayer { nullptr };
|
||||||
|
//TODO: Ask if the rule applies to the fact that the player is not managed by the camera
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
#include "pch.h"
|
#include "pch.h"
|
||||||
#include "Game.h"
|
#include "Game.h"
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
|
|
||||||
#include "colors.h"
|
#include "colors.h"
|
||||||
@@ -10,11 +9,10 @@
|
|||||||
#include "WorldLevel.h"
|
#include "WorldLevel.h"
|
||||||
|
|
||||||
|
|
||||||
Rectf Game::VIEWPORT{};
|
Rectf Game::VIEWPORT {};
|
||||||
|
|
||||||
Game::Game(const Window& window)
|
Game::Game(const Window& window)
|
||||||
: BaseGame { window }, m_Camera(Camera()), m_WorldLevel(WorldLevel(&m_Camera, GetViewPort()))
|
: BaseGame { window }, m_Camera(Camera()), m_WorldLevel(WorldLevel(&m_Camera, GetViewPort())) {
|
||||||
{
|
|
||||||
Initialize();
|
Initialize();
|
||||||
Game::VIEWPORT = GetViewPort(); //TODO: See if this can be removed
|
Game::VIEWPORT = GetViewPort(); //TODO: See if this can be removed
|
||||||
}
|
}
|
||||||
@@ -24,7 +22,7 @@ Game::~Game() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Game::Initialize() {
|
void Game::Initialize() {
|
||||||
m_Camera.SetPosition(Point2f{-GetViewPort().width / 2, -GetViewPort().height / 2});
|
m_Camera.SetPosition(Point2f { -GetViewPort().width / 2, -GetViewPort().height / 2 });
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::Cleanup() {
|
void Game::Cleanup() {
|
||||||
@@ -33,10 +31,11 @@ void Game::Cleanup() {
|
|||||||
void Game::Update(float elapsedSec) {
|
void Game::Update(float elapsedSec) {
|
||||||
const Uint8* pStates = SDL_GetKeyboardState(nullptr);
|
const Uint8* pStates = SDL_GetKeyboardState(nullptr);
|
||||||
|
|
||||||
if(m_IsRightMouseDown) {
|
if (m_IsRightMouseDown) {
|
||||||
Point2f newCameraPos = Point2f{m_MousePos.x + m_MouseOffset.x, m_MousePos.y + m_MouseOffset.y};
|
const Point2f newCameraPos = Point2f { m_MousePos.x + m_MouseOffset.x, m_MousePos.y + m_MouseOffset.y };
|
||||||
m_Camera.SetPosition(Point2f{-newCameraPos.x, -newCameraPos.y});
|
m_Camera.SetPosition(Point2f { -newCameraPos.x, -newCameraPos.y });
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
m_MouseOffset = m_Camera.GetPosition();
|
m_MouseOffset = m_Camera.GetPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,13 +56,13 @@ void Game::ProcessKeyUpEvent(const SDL_KeyboardEvent& e) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Game::ProcessMouseMotionEvent(const SDL_MouseMotionEvent& e) {
|
void Game::ProcessMouseMotionEvent(const SDL_MouseMotionEvent& e) {
|
||||||
m_MousePos = Point2f{float(e.x), float(e.y)};
|
m_MousePos = Point2f { float(e.x), float(e.y) };
|
||||||
m_WorldLevel.MouseMove(Point2f { float(e.x), float(e.y) });
|
m_WorldLevel.MouseMove(Point2f { float(e.x), float(e.y) });
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::ProcessMouseDownEvent(const SDL_MouseButtonEvent& e) {
|
void Game::ProcessMouseDownEvent(const SDL_MouseButtonEvent& e) {
|
||||||
m_IsRightMouseDown = e.button == SDL_BUTTON_RIGHT;
|
m_IsRightMouseDown = e.button == SDL_BUTTON_RIGHT;
|
||||||
m_MouseOffset = Point2f{-m_Camera.GetPosition().x - m_MousePos.x, -m_Camera.GetPosition().y - m_MousePos.y};
|
m_MouseOffset = Point2f { -m_Camera.GetPosition().x - m_MousePos.x, -m_Camera.GetPosition().y - m_MousePos.y };
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::ProcessMouseUpEvent(const SDL_MouseButtonEvent& e) {
|
void Game::ProcessMouseUpEvent(const SDL_MouseButtonEvent& e) {
|
||||||
|
|||||||
10
Game/Game.h
10
Game/Game.h
@@ -1,10 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "BaseGame.h"
|
#include "BaseGame.h"
|
||||||
#include "Camera.h"
|
#include "Camera.h"
|
||||||
#include "WorldLevel.h"
|
#include "WorldLevel.h"
|
||||||
#include "WorldTile.h"
|
|
||||||
|
|
||||||
class Game : public BaseGame
|
class Game : public BaseGame
|
||||||
{
|
{
|
||||||
@@ -15,7 +13,7 @@ public:
|
|||||||
Game(Game&& other) = delete;
|
Game(Game&& other) = delete;
|
||||||
Game& operator=(Game&& other) = delete;
|
Game& operator=(Game&& other) = delete;
|
||||||
// http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rh-override
|
// http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rh-override
|
||||||
~Game();
|
~Game() override;
|
||||||
|
|
||||||
void Update(float elapsedSec) override;
|
void Update(float elapsedSec) override;
|
||||||
void Draw() const override;
|
void Draw() const override;
|
||||||
@@ -40,8 +38,8 @@ private:
|
|||||||
Camera m_Camera;
|
Camera m_Camera;
|
||||||
WorldLevel m_WorldLevel;
|
WorldLevel m_WorldLevel;
|
||||||
|
|
||||||
Point2f m_MousePos{};
|
Point2f m_MousePos {};
|
||||||
Point2f m_MouseOffset{};
|
Point2f m_MouseOffset {};
|
||||||
bool m_IsRightMouseDown{};
|
bool m_IsRightMouseDown {};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
<RootNamespace>Game</RootNamespace>
|
<RootNamespace>Game</RootNamespace>
|
||||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props"/>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>true</UseDebugLibraries>
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
@@ -52,24 +52,24 @@
|
|||||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
<CharacterSet>Unicode</CharacterSet>
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props"/>
|
||||||
<ImportGroup Label="ExtensionSettings">
|
<ImportGroup Label="ExtensionSettings">
|
||||||
</ImportGroup>
|
</ImportGroup>
|
||||||
<ImportGroup Label="Shared">
|
<ImportGroup Label="Shared">
|
||||||
</ImportGroup>
|
</ImportGroup>
|
||||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform"/>
|
||||||
</ImportGroup>
|
</ImportGroup>
|
||||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform"/>
|
||||||
</ImportGroup>
|
</ImportGroup>
|
||||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform"/>
|
||||||
</ImportGroup>
|
</ImportGroup>
|
||||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform"/>
|
||||||
</ImportGroup>
|
</ImportGroup>
|
||||||
<PropertyGroup Label="UserMacros" />
|
<PropertyGroup Label="UserMacros"/>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
<IncludePath>C:\Users\Bram\Desktop\Programming 2\Exam\dae16-VerhulstBram\Engine\imgui;$(SolutionDir)\Libraries\SDLTtf\SDL2_ttf-2.20.2\include;$(SolutionDir)\Libraries\SDLMixer\SDL2_mixer-2.6.3\include;$(SolutionDir)\Libraries\SDLImage\SDL2_image-2.6.3\include;$(SolutionDir)\Libraries\SDLMain\SDL2-2.26.3\include;$(SolutionDir)\Engine;$(IncludePath)</IncludePath>
|
<IncludePath>C:\Users\Bram\Desktop\Programming 2\Exam\dae16-VerhulstBram\Engine\imgui;$(SolutionDir)\Libraries\SDLTtf\SDL2_ttf-2.20.2\include;$(SolutionDir)\Libraries\SDLMixer\SDL2_mixer-2.6.3\include;$(SolutionDir)\Libraries\SDLImage\SDL2_image-2.6.3\include;$(SolutionDir)\Libraries\SDLMain\SDL2-2.26.3\include;$(SolutionDir)\Engine;$(IncludePath)</IncludePath>
|
||||||
<LibraryPath>$(SolutionDir)\x64\Debug;$(SolutionDir)\Libraries\SDLTtf\SDL2_ttf-2.20.2\lib\x64;$(SolutionDir)\Libraries\SDLMixer\SDL2_mixer-2.6.3\lib\x64;$(SolutionDir)\Libraries\SDLImage\SDL2_image-2.6.3\lib\x64;$(SolutionDir)\Libraries\SDLMain\SDL2-2.26.3\lib\x64;$(LibraryPath)</LibraryPath>
|
<LibraryPath>$(SolutionDir)\x64\Debug;$(SolutionDir)\Libraries\SDLTtf\SDL2_ttf-2.20.2\lib\x64;$(SolutionDir)\Libraries\SDLMixer\SDL2_mixer-2.6.3\lib\x64;$(SolutionDir)\Libraries\SDLImage\SDL2_image-2.6.3\lib\x64;$(SolutionDir)\Libraries\SDLMain\SDL2-2.26.3\lib\x64;$(LibraryPath)</LibraryPath>
|
||||||
@@ -124,10 +124,11 @@
|
|||||||
</CustomBuildStep>
|
</CustomBuildStep>
|
||||||
<PostBuildEvent>
|
<PostBuildEvent>
|
||||||
<Command>xcopy "$(SolutionDir)Libraries\SDLMain\SDL2-2.26.3\lib\x64\*.dll" "$(TargetDir)" /y /d
|
<Command>xcopy "$(SolutionDir)Libraries\SDLMain\SDL2-2.26.3\lib\x64\*.dll" "$(TargetDir)" /y /d
|
||||||
xcopy "$(SolutionDir)Libraries\SDLImage\SDL2_image-2.6.3\lib\x64\*.dll" "$(TargetDir)" /y /d
|
xcopy "$(SolutionDir)Libraries\SDLImage\SDL2_image-2.6.3\lib\x64\*.dll" "$(TargetDir)" /y /d
|
||||||
xcopy "$(SolutionDir)Libraries\SDLMixer\SDL2_mixer-2.6.3\lib\x64\*.dll" "$(TargetDir)" /y /d
|
xcopy "$(SolutionDir)Libraries\SDLMixer\SDL2_mixer-2.6.3\lib\x64\*.dll" "$(TargetDir)" /y /d
|
||||||
xcopy "$(SolutionDir)Libraries\SDLTtf\SDL2_ttf-2.20.2\lib\x64\*.dll" "$(TargetDir)" /y /d
|
xcopy "$(SolutionDir)Libraries\SDLTtf\SDL2_ttf-2.20.2\lib\x64\*.dll" "$(TargetDir)" /y /d
|
||||||
xcopy "$(SolutionDir)Resources\*.*" "$(TargetDir)" /y /d /s</Command>
|
xcopy "$(SolutionDir)Resources\*.*" "$(TargetDir)" /y /d /s
|
||||||
|
</Command>
|
||||||
</PostBuildEvent>
|
</PostBuildEvent>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
@@ -147,9 +148,157 @@ xcopy "$(SolutionDir)Resources\*.*" "$(TargetDir)" /y /d /s</Command>
|
|||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="Camera.cpp" />
|
<ClCompile Include="Animations\Animation.cpp"/>
|
||||||
<ClCompile Include="Game.cpp" />
|
<ClCompile Include="Camera.cpp"/>
|
||||||
<ClCompile Include="WorldGridManager.cpp" />
|
<ClCompile Include="Game.cpp"/>
|
||||||
|
<ClCompile Include="GridSystem\WorldGridManager.cpp">
|
||||||
|
<RuntimeLibrary>MultiThreadedDebugDll</RuntimeLibrary>
|
||||||
|
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||||
|
<Optimization>Disabled</Optimization>
|
||||||
|
<SupportJustMyCode>true</SupportJustMyCode>
|
||||||
|
<AssemblerOutput>NoListing</AssemblerOutput>
|
||||||
|
<AssemblerListingLocation>x64\Debug\</AssemblerListingLocation>
|
||||||
|
<UndefineAllPreprocessorDefinitions>false</UndefineAllPreprocessorDefinitions>
|
||||||
|
<BrowseInformation>false</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>NotUsing</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\WorldTile.cpp">
|
||||||
|
<RuntimeLibrary>MultiThreadedDebugDll</RuntimeLibrary>
|
||||||
|
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||||
|
<Optimization>Disabled</Optimization>
|
||||||
|
<SupportJustMyCode>true</SupportJustMyCode>
|
||||||
|
<AssemblerOutput>NoListing</AssemblerOutput>
|
||||||
|
<AssemblerListingLocation>x64\Debug\</AssemblerListingLocation>
|
||||||
|
<UndefineAllPreprocessorDefinitions>false</UndefineAllPreprocessorDefinitions>
|
||||||
|
<BrowseInformation>false</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>NotUsing</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="Level.cpp">
|
<ClCompile Include="Level.cpp">
|
||||||
<RuntimeLibrary>MultiThreadedDebugDll</RuntimeLibrary>
|
<RuntimeLibrary>MultiThreadedDebugDll</RuntimeLibrary>
|
||||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||||
@@ -224,10 +373,10 @@ xcopy "$(SolutionDir)Resources\*.*" "$(TargetDir)" /y /d /s</Command>
|
|||||||
<SDLCheck>true</SDLCheck>
|
<SDLCheck>true</SDLCheck>
|
||||||
<LinkCompiled>true</LinkCompiled>
|
<LinkCompiled>true</LinkCompiled>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="main.cpp" />
|
<ClCompile Include="main.cpp"/>
|
||||||
<ClCompile Include="pch.cpp" />
|
<ClCompile Include="pch.cpp"/>
|
||||||
<ClCompile Include="Player.cpp" />
|
<ClCompile Include="Player.cpp"/>
|
||||||
<ClCompile Include="TextureManager.cpp" />
|
<ClCompile Include="TextureManager.cpp"/>
|
||||||
<ClCompile Include="WorldLevel.cpp">
|
<ClCompile Include="WorldLevel.cpp">
|
||||||
<RuntimeLibrary>MultiThreadedDebugDll</RuntimeLibrary>
|
<RuntimeLibrary>MultiThreadedDebugDll</RuntimeLibrary>
|
||||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||||
@@ -302,20 +451,20 @@ xcopy "$(SolutionDir)Resources\*.*" "$(TargetDir)" /y /d /s</Command>
|
|||||||
<SDLCheck>true</SDLCheck>
|
<SDLCheck>true</SDLCheck>
|
||||||
<LinkCompiled>true</LinkCompiled>
|
<LinkCompiled>true</LinkCompiled>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="WorldTile.cpp" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="Camera.h" />
|
<ClInclude Include="Animations\Animation.h"/>
|
||||||
<ClInclude Include="Game.h" />
|
<ClInclude Include="Camera.h"/>
|
||||||
<ClInclude Include="WorldGridManager.h" />
|
<ClInclude Include="Game.h"/>
|
||||||
<ClInclude Include="Level.h" />
|
<ClInclude Include="GridSystem\WorldGridManager.h"/>
|
||||||
<ClInclude Include="pch.h" />
|
<ClInclude Include="GridSystem\WorldTile.h"/>
|
||||||
<ClInclude Include="Player.h" />
|
<ClInclude Include="Level.h"/>
|
||||||
<ClInclude Include="TextureManager.h" />
|
<ClInclude Include="pch.h"/>
|
||||||
<ClInclude Include="WorldLevel.h" />
|
<ClInclude Include="Player.h"/>
|
||||||
<ClInclude Include="WorldTile.h" />
|
<ClInclude Include="TextureManager.h"/>
|
||||||
|
<ClInclude Include="WorldLevel.h"/>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets"/>
|
||||||
<ImportGroup Label="ExtensionTargets">
|
<ImportGroup Label="ExtensionTargets">
|
||||||
</ImportGroup>
|
</ImportGroup>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include "WorldGridManager.h"
|
#include "WorldGridManager.h"
|
||||||
WorldGridManager::WorldGridManager() {
|
WorldGridManager::WorldGridManager() {
|
||||||
for (size_t x { 0 }; x < WORLD_WIDTH; ++x) {
|
for (size_t x { 0 }; x < WORLD_WIDTH; ++x) {
|
||||||
for(size_t y { 0 }; y < WORLD_HEIGHT; ++y) {
|
for (size_t y { 0 }; y < WORLD_HEIGHT; ++y) {
|
||||||
m_worldTiles[x][y] = nullptr;
|
m_worldTiles[x][y] = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -10,13 +10,13 @@ WorldGridManager::WorldGridManager() {
|
|||||||
WorldGridManager::~WorldGridManager() {
|
WorldGridManager::~WorldGridManager() {
|
||||||
|
|
||||||
}
|
}
|
||||||
WorldTile* WorldGridManager::GetTileAtIndex(const int x, const int y) const {
|
WorldTile * WorldGridManager::GetTileAtIndex(const int x, const int y) const {
|
||||||
if (x < 0 || x >= WORLD_WIDTH || y < 0 || y >= WORLD_HEIGHT) {
|
if (x < 0 || x >= WORLD_WIDTH || y < 0 || y >= WORLD_HEIGHT) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return m_worldTiles[x][y];
|
return m_worldTiles[x][y];
|
||||||
}
|
}
|
||||||
WorldTile* WorldGridManager::GetTileAtWorldPos(const Point2f& pos) const {
|
WorldTile * WorldGridManager::GetTileAtWorldPos(const Point2f& pos) const {
|
||||||
int x = int(pos.x / TILE_WIDTH + WORLD_WIDTH / 2);
|
int x = int(pos.x / TILE_WIDTH + WORLD_WIDTH / 2);
|
||||||
int y = int(-pos.y / TILE_HEIGHT);
|
int y = int(-pos.y / TILE_HEIGHT);
|
||||||
if (x < 0 || x >= WORLD_WIDTH || y < 0 || y >= WORLD_HEIGHT) {
|
if (x < 0 || x >= WORLD_WIDTH || y < 0 || y >= WORLD_HEIGHT) {
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "structs.h"
|
#include "structs.h"
|
||||||
|
|
||||||
@@ -12,15 +11,16 @@ static const int TILE_HEIGHT = 50;
|
|||||||
|
|
||||||
class WorldTile;
|
class WorldTile;
|
||||||
|
|
||||||
struct surroundingTiles {
|
struct surroundingTiles
|
||||||
std::array<WorldTile*, 8> tiles;
|
{
|
||||||
|
std::array<WorldTile *, 8> tiles;
|
||||||
|
|
||||||
//Center of the surrounding tiles is 0, 0
|
//Center of the surrounding tiles is 0, 0
|
||||||
void SetTile(int x, int y, WorldTile* tile) {
|
void SetTile(int x, int y, WorldTile* tile) {
|
||||||
tiles[x + y * 3] = tile;
|
tiles[x + y * 3] = tile;
|
||||||
}
|
}
|
||||||
|
|
||||||
WorldTile* GetTile(int x, int y) {
|
WorldTile * GetTile(int x, int y) {
|
||||||
return tiles[x + y * 3];
|
return tiles[x + y * 3];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -31,14 +31,15 @@ public:
|
|||||||
WorldGridManager();
|
WorldGridManager();
|
||||||
~WorldGridManager();
|
~WorldGridManager();
|
||||||
|
|
||||||
WorldTile* GetTileAtIndex(const int x, const int y) const;
|
WorldGridManager(const WorldGridManager& other) = default;
|
||||||
WorldTile* GetTileAtWorldPos(const Point2f& pos) const;
|
|
||||||
|
WorldTile * GetTileAtIndex(const int x, const int y) const;
|
||||||
|
WorldTile * GetTileAtWorldPos(const Point2f& pos) const;
|
||||||
|
|
||||||
void SetTileAtIndex(const int x, const int y, WorldTile* tile);
|
void SetTileAtIndex(const int x, const int y, WorldTile* tile);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
std::array<std::array<WorldTile *, WORLD_WIDTH>, WORLD_HEIGHT> m_worldTiles;
|
||||||
std::array<std::array<WorldTile*, WORLD_WIDTH>, WORLD_HEIGHT> m_worldTiles;
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
@@ -1,8 +1,7 @@
|
|||||||
#include "pch.h"
|
#include "WorldTile.h"
|
||||||
#include "WorldTile.h"
|
|
||||||
|
|
||||||
#include "colors.h"
|
#include "colors.h"
|
||||||
#include "TextureManager.h"
|
#include "../TextureManager.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -17,12 +16,12 @@ WorldTile::~WorldTile() {
|
|||||||
void WorldTile::Draw() const {
|
void WorldTile::Draw() const {
|
||||||
if (*m_GroundTileType != Tiles::AIR) {
|
if (*m_GroundTileType != Tiles::AIR) {
|
||||||
m_pTexture->Draw(m_Position);
|
m_pTexture->Draw(m_Position);
|
||||||
if(m_Hightlight) {
|
if (m_Hightlight) {
|
||||||
utils::SetColor(Colors::GREEN);
|
utils::SetColor(Colors::GREEN);
|
||||||
utils::FillRect(m_Position, 50, 50);
|
utils::FillRect(m_Position, 50, 50);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Collision::TileCollisionRect WorldTile::GetCollisionRect() {
|
Collision::TileCollisionRect WorldTile::GetCollisionRect() {
|
||||||
return Collision::TileCollisionRect{ m_Position, GetSize(), (this)};
|
return Collision::TileCollisionRect { m_Position, GetSize(), ( this ) };
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "Collision.h"
|
#include "Collision.h"
|
||||||
#include "Texture.h"
|
#include "Texture.h"
|
||||||
#include "TextureManager.h"
|
#include "../TextureManager.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -13,21 +13,23 @@ enum class GroundTileTypes
|
|||||||
Iron
|
Iron
|
||||||
};
|
};
|
||||||
|
|
||||||
class GroundTileType {
|
class GroundTileType
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
GroundTileType(const std::string& filePath, GroundTileTypes type): m_filePath(filePath), m_type(type) {}
|
GroundTileType(const std::string& filePath, GroundTileTypes type): m_filePath(filePath), m_type(type) {
|
||||||
|
}
|
||||||
virtual ~GroundTileType() = default;
|
virtual ~GroundTileType() = default;
|
||||||
bool operator== ( const GroundTileType& rhs ) const {
|
bool operator==(const GroundTileType& rhs) const {
|
||||||
return m_type == rhs.m_type;
|
return m_type == rhs.m_type;
|
||||||
}
|
}
|
||||||
bool operator!= ( const GroundTileType& rhs) const {
|
bool operator!=(const GroundTileType& rhs) const {
|
||||||
return m_type != rhs.m_type;
|
return m_type != rhs.m_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool operator== (const GroundTileType* rhs) const {
|
virtual bool operator==(const GroundTileType* rhs) const {
|
||||||
return rhs->m_type == m_type;
|
return rhs->m_type == m_type;
|
||||||
}
|
}
|
||||||
virtual bool operator!= (const GroundTileType* rhs) const {
|
virtual bool operator!=(const GroundTileType* rhs) const {
|
||||||
return rhs->m_type != m_type;
|
return rhs->m_type != m_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,41 +40,45 @@ public:
|
|||||||
virtual GroundTileTypes getType() const {
|
virtual GroundTileTypes getType() const {
|
||||||
return m_type;
|
return m_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::string m_filePath;
|
std::string m_filePath;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GroundTileTypes m_type;
|
GroundTileTypes m_type;
|
||||||
};
|
};
|
||||||
|
|
||||||
class RandomGroundTile: public GroundTileType {
|
class RandomGroundTile : public GroundTileType
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
RandomGroundTile(const std::string& filePath, GroundTileTypes type, int maxRandom): GroundTileType(filePath, type), m_maxRandom(maxRandom) {
|
RandomGroundTile(const std::string& filePath, GroundTileTypes type, int maxRandom): GroundTileType(filePath, type), m_maxRandom(maxRandom) {
|
||||||
}
|
}
|
||||||
|
|
||||||
~RandomGroundTile() override = default;
|
~RandomGroundTile() override = default;
|
||||||
|
|
||||||
bool operator== (const GroundTileType* rhs) const override{
|
bool operator==(const GroundTileType* rhs) const override {
|
||||||
return rhs->getType() == this->getType();
|
return rhs->getType() == this->getType();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator!= (const GroundTileType* rhs) const override{
|
bool operator!=(const GroundTileType* rhs) const override {
|
||||||
return rhs->getType() != this->getType();
|
return rhs->getType() != this->getType();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string getPath() const override {
|
std::string getPath() const override {
|
||||||
int variant = utils::randRange(1, m_maxRandom);
|
int variant = utils::randRange(1, m_maxRandom);
|
||||||
std::string toReplace{ "[0]" };
|
std::string toReplace { "[0]" };
|
||||||
std::string replacement = std::to_string(utils::randRange(1, m_maxRandom));
|
std::string replacement = std::to_string(utils::randRange(1, m_maxRandom));
|
||||||
|
|
||||||
size_t found = m_filePath.find(toReplace);
|
size_t found = m_filePath.find(toReplace);
|
||||||
std::string newFilePath{ m_filePath };
|
std::string newFilePath { m_filePath };
|
||||||
|
|
||||||
if(found != std::string::npos) {
|
if (found != std::string::npos) {
|
||||||
newFilePath.replace(found, 3, replacement);
|
newFilePath.replace(found, 3, replacement);
|
||||||
}
|
}
|
||||||
|
|
||||||
return newFilePath;
|
return newFilePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_maxRandom;
|
int m_maxRandom;
|
||||||
};
|
};
|
||||||
@@ -84,7 +90,8 @@ namespace Tiles
|
|||||||
static GroundTileType* IRON = new GroundTileType("tiles/ores/Ore_Ironium.png", GroundTileTypes::Iron);
|
static GroundTileType* IRON = new GroundTileType("tiles/ores/Ore_Ironium.png", GroundTileTypes::Iron);
|
||||||
}
|
}
|
||||||
|
|
||||||
class WorldTile {
|
class WorldTile
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
WorldTile() = default;
|
WorldTile() = default;
|
||||||
WorldTile(const Point2f& position, GroundTileType* groundTileType, TextureManager* pTextureManager);
|
WorldTile(const Point2f& position, GroundTileType* groundTileType, TextureManager* pTextureManager);
|
||||||
@@ -92,18 +99,27 @@ public:
|
|||||||
|
|
||||||
void Draw() const;
|
void Draw() const;
|
||||||
|
|
||||||
Point2f GetPosition() const { return m_Position; }
|
Point2f GetPosition() const {
|
||||||
void SetPosition(const Point2f& position) { m_Position = position; }
|
return m_Position;
|
||||||
|
}
|
||||||
|
void SetPosition(const Point2f& position) {
|
||||||
|
m_Position = position;
|
||||||
|
}
|
||||||
|
|
||||||
Point2f GetSize() const { return Point2f{ 50, 50 }; }
|
Point2f GetSize() const {
|
||||||
|
return Point2f { 50, 50 };
|
||||||
|
}
|
||||||
|
|
||||||
GroundTileType* GetTileType() const { return m_GroundTileType; }
|
GroundTileType * GetTileType() const {
|
||||||
void SetTileType(GroundTileType* type) { m_GroundTileType = type; }
|
return m_GroundTileType;
|
||||||
|
}
|
||||||
|
void SetTileType(GroundTileType* type) {
|
||||||
|
m_GroundTileType = type;
|
||||||
|
}
|
||||||
|
|
||||||
Collision::TileCollisionRect GetCollisionRect();
|
Collision::TileCollisionRect GetCollisionRect();
|
||||||
|
|
||||||
bool m_Hightlight{ false };
|
bool m_Hightlight { false };
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Point2f m_Position;
|
Point2f m_Position;
|
||||||
@@ -8,6 +8,9 @@ public:
|
|||||||
Level(Camera* camera);
|
Level(Camera* camera);
|
||||||
virtual ~Level();
|
virtual ~Level();
|
||||||
|
|
||||||
|
Level(const Level& other) = default;
|
||||||
|
Level(Level&& other) = default;
|
||||||
|
|
||||||
virtual void Update(float elapsedSec) = 0;
|
virtual void Update(float elapsedSec) = 0;
|
||||||
virtual void Draw() const = 0;
|
virtual void Draw() const = 0;
|
||||||
virtual void MouseMove(const Point2f& mousePos) = 0;
|
virtual void MouseMove(const Point2f& mousePos) = 0;
|
||||||
|
|||||||
119
Game/Player.cpp
119
Game/Player.cpp
@@ -6,21 +6,34 @@
|
|||||||
#include "colors.h"
|
#include "colors.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "WorldLevel.h"
|
#include "WorldLevel.h"
|
||||||
|
#include "Animations/Animation.h"
|
||||||
|
|
||||||
Player::Player(const Point2f& Position) : m_Position(Position), m_Size(Point2f{40, 40}), m_Vel(Point2f{0,0}), m_Acc(Point2f{0,0}) {
|
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;
|
m_ContactMap[Collision::CollisionDirection::Top] = nullptr;
|
||||||
m_ContactMap[Collision::CollisionDirection::Bottom] = nullptr;
|
m_ContactMap[Collision::CollisionDirection::Bottom] = nullptr;
|
||||||
m_ContactMap[Collision::CollisionDirection::Left] = nullptr;
|
m_ContactMap[Collision::CollisionDirection::Left] = nullptr;
|
||||||
m_ContactMap[Collision::CollisionDirection::Right] = nullptr;
|
m_ContactMap[Collision::CollisionDirection::Right] = nullptr;
|
||||||
|
|
||||||
|
m_walkAnimation = new Animation(manager->GetTexture("animations/player/player_walk.png"), 8, 0.1f, Rectf { 0, 0, 70, 70 });
|
||||||
}
|
}
|
||||||
Collision::CollisionRect Player::GetCollisionRect() {
|
Collision::CollisionRect Player::GetCollisionRect() const {
|
||||||
Collision::CollisionRect rect = {m_Position, m_Size, m_Vel};
|
Collision::CollisionRect rect = { m_Position, m_Size, m_Vel };
|
||||||
return rect;
|
return rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::Draw() const {
|
void Player::Draw() const {
|
||||||
|
if (m_DrawCollisionRect) {
|
||||||
utils::SetColor(Colors::PINK);
|
utils::SetColor(Colors::PINK);
|
||||||
utils::DrawRect(Rectf{m_Position.x, m_Position.y, m_Size.x, m_Size.y});
|
utils::DrawRect(Rectf { m_Position.x, m_Position.y, m_Size.x, m_Size.y });
|
||||||
|
}
|
||||||
|
Point2f center = m_Position + m_Size / 2;
|
||||||
|
|
||||||
|
const int frameWidth = 70; //TODO: fix this
|
||||||
|
int halfFrameWidth = frameWidth / 2;
|
||||||
|
|
||||||
|
auto drawPos = Point2f { center.x - halfFrameWidth - 10, center.y - halfFrameWidth + 9 };
|
||||||
|
|
||||||
|
m_walkAnimation->Draw(drawPos, 0);
|
||||||
}
|
}
|
||||||
void Player::ProcessImGui() {
|
void Player::ProcessImGui() {
|
||||||
ImGui::Begin("Collision Info", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
|
ImGui::Begin("Collision Info", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
|
||||||
@@ -28,6 +41,7 @@ void Player::ProcessImGui() {
|
|||||||
ImGui::Text("Did just dig right: %s", m_DidJustDigRight ? "true" : "false");
|
ImGui::Text("Did just dig right: %s", m_DidJustDigRight ? "true" : "false");
|
||||||
bool test = !utils::isKeyDown(SDL_SCANCODE_H);
|
bool test = !utils::isKeyDown(SDL_SCANCODE_H);
|
||||||
ImGui::Text("Is Key Up H: %s", test ? "true" : "false");
|
ImGui::Text("Is Key Up H: %s", test ? "true" : "false");
|
||||||
|
ImGui::Checkbox("Draw Collision Rect", &m_DrawCollisionRect);
|
||||||
|
|
||||||
//ContactMap
|
//ContactMap
|
||||||
ImGui::Text("ContactMap:");
|
ImGui::Text("ContactMap:");
|
||||||
@@ -39,62 +53,58 @@ void Player::ProcessImGui() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Player::Update(float elapsedTime, WorldLevel& level) {
|
void Player::Update(float elapsedTime, WorldLevel& level) {
|
||||||
// m_Acc.y += m_Gravity.y;
|
|
||||||
// m_Vel.y = std::min(m_Vel.y, m_MaxSpeed);
|
|
||||||
//
|
|
||||||
// Point2f nextPos = m_Position + m_Vel * elapsedTime;
|
|
||||||
// //collision checking
|
|
||||||
|
|
||||||
m_Vel = Point2f{0, -100};
|
|
||||||
|
|
||||||
|
|
||||||
|
m_Vel = Point2f { 0, -100 };
|
||||||
|
|
||||||
//check for keys
|
//check for keys
|
||||||
if(utils::isKeyDown(SDL_SCANCODE_W)) {
|
if (utils::isKeyDown(SDL_SCANCODE_W)) {
|
||||||
m_Vel.y = 100;
|
m_Vel.y = 100;
|
||||||
m_Grounded = false;
|
m_Grounded = false;
|
||||||
}
|
}
|
||||||
if(utils::isKeyPressed(SDL_SCANCODE_S)) {
|
if (utils::isKeyPressed(SDL_SCANCODE_S)) {
|
||||||
m_Vel.y = -100;
|
m_Vel.y = -100;
|
||||||
if(m_Grounded) {
|
if (m_Grounded) {
|
||||||
if(m_ContactMap[Collision::CollisionDirection::Bottom] != nullptr) {
|
if (m_ContactMap[Collision::CollisionDirection::Bottom] != nullptr) {
|
||||||
m_ContactMap[Collision::CollisionDirection::Bottom]->SetTileType(Tiles::AIR);
|
m_ContactMap[Collision::CollisionDirection::Bottom]->SetTileType(Tiles::AIR);
|
||||||
WorldTile* tile = m_ContactMap[Collision::CollisionDirection::Bottom];
|
WorldTile* tile = m_ContactMap[Collision::CollisionDirection::Bottom];
|
||||||
//center of tile
|
//center of tile
|
||||||
Point2f tileCenter = tile->GetCollisionRect().getCollisionRect().pos + tile->GetCollisionRect().getCollisionRect().size / 2;
|
Point2f tileCenter = tile->GetCollisionRect().getCollisionRect().pos + tile->GetCollisionRect().getCollisionRect().size / 2;
|
||||||
m_Position = Point2f{tileCenter.x - m_Size.x / 2, tileCenter.y - m_Size.y / 2 + 5};
|
m_Position = Point2f { tileCenter.x - m_Size.x / 2, tileCenter.y - m_Size.y / 2 + 5 };
|
||||||
|
|
||||||
m_ContactMap[Collision::CollisionDirection::Bottom] = nullptr;
|
m_ContactMap[Collision::CollisionDirection::Bottom] = nullptr;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(utils::isKeyDown(SDL_SCANCODE_A)) {
|
if (utils::isKeyDown(SDL_SCANCODE_A)) {
|
||||||
|
m_walkAnimation->SetFlipped(false);
|
||||||
m_Vel.x = -100;
|
m_Vel.x = -100;
|
||||||
|
|
||||||
}
|
}
|
||||||
if(utils::isKeyDown(SDL_SCANCODE_D)) {
|
if (utils::isKeyDown(SDL_SCANCODE_D)) {
|
||||||
m_Vel.x = 100;
|
m_Vel.x = 100;
|
||||||
if(m_Grounded && !m_DidJustDigRight) {
|
m_walkAnimation->SetFlipped(true);
|
||||||
|
if (m_Grounded && !m_DidJustDigRight) {
|
||||||
//Check if the player doesnt come from digging a tile
|
//Check if the player doesnt come from digging a tile
|
||||||
if(m_ContactMap[Collision::CollisionDirection::Right] != nullptr) {
|
if (m_ContactMap[Collision::CollisionDirection::Right] != nullptr) {
|
||||||
m_ContactMap[Collision::CollisionDirection::Right]->SetTileType(Tiles::AIR);
|
m_ContactMap[Collision::CollisionDirection::Right]->SetTileType(Tiles::AIR);
|
||||||
WorldTile* tile = m_ContactMap[Collision::CollisionDirection::Right];
|
WorldTile* tile = m_ContactMap[Collision::CollisionDirection::Right];
|
||||||
//center of tile
|
//center of tile
|
||||||
Point2f tileCenter = tile->GetCollisionRect().getCollisionRect().pos + tile->GetCollisionRect().getCollisionRect().size / 2;
|
const Point2f tileCenter = tile->GetCollisionRect().getCollisionRect().pos + tile->GetCollisionRect().getCollisionRect().size / 2;
|
||||||
m_Position = Point2f{tileCenter.x - m_Size.x / 2, tileCenter.y - m_Size.y / 2 + 5};
|
m_Position = Point2f { tileCenter.x - m_Size.x / 2, tileCenter.y - m_Size.y / 2 + 5 };
|
||||||
|
|
||||||
m_ContactMap[Collision::CollisionDirection::Right] = nullptr;
|
m_ContactMap[Collision::CollisionDirection::Right] = nullptr;
|
||||||
m_DidJustDigRight = true;
|
m_DidJustDigRight = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(m_DidJustDigRight) {
|
if (m_DidJustDigRight) {
|
||||||
if(!utils::isKeyDown(SDL_SCANCODE_D)) {
|
if (!utils::isKeyDown(SDL_SCANCODE_D)) {
|
||||||
m_DidJustDigRight = false;
|
m_DidJustDigRight = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_walkAnimation->Update(elapsedTime);
|
||||||
|
|
||||||
|
|
||||||
m_ContactMap[Collision::CollisionDirection::Top] = nullptr;
|
m_ContactMap[Collision::CollisionDirection::Top] = nullptr;
|
||||||
m_ContactMap[Collision::CollisionDirection::Bottom] = nullptr;
|
m_ContactMap[Collision::CollisionDirection::Bottom] = nullptr;
|
||||||
m_ContactMap[Collision::CollisionDirection::Left] = nullptr;
|
m_ContactMap[Collision::CollisionDirection::Left] = nullptr;
|
||||||
@@ -105,46 +115,47 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
|
|||||||
float t = 0, min_t = INFINITY;
|
float t = 0, min_t = INFINITY;
|
||||||
Point2f intersectionPoint, normal;
|
Point2f intersectionPoint, normal;
|
||||||
|
|
||||||
std::vector<std::pair<int, float>> contactTimes{};
|
std::vector<std::pair<int, float>> contactTimes {};
|
||||||
|
|
||||||
WorldGridManager& gridManager = level.GetGridManager();
|
const WorldGridManager& gridManager = level.GetGridManager();
|
||||||
|
|
||||||
for (int x { 0 }; x < WORLD_WIDTH; ++x) {
|
for (int x { 0 }; x < WORLD_WIDTH; ++x) {
|
||||||
for(int y { 0 }; y < WORLD_HEIGHT; ++y) {
|
for (int y { 0 }; y < WORLD_HEIGHT; ++y) {
|
||||||
WorldTile* tile = gridManager.GetTileAtIndex(x,y);
|
WorldTile* tile = gridManager.GetTileAtIndex(x, y);
|
||||||
if(*tile->GetTileType() != Tiles::AIR) {
|
if (*tile->GetTileType() != Tiles::AIR) {
|
||||||
tile->m_Hightlight = false;
|
tile->m_Hightlight = false;
|
||||||
if(Collision::DynamicRectVsRect(this->GetCollisionRect(), elapsedTime, tile->GetCollisionRect().getCollisionRect(), intersectionPoint, normal, t)) {
|
if (Collision::DynamicRectVsRect(this->GetCollisionRect(), elapsedTime, tile->GetCollisionRect().getCollisionRect(), intersectionPoint, normal, t)) {
|
||||||
contactTimes.push_back(std::pair<int, float>{x + y * WORLD_WIDTH, t});
|
contactTimes.emplace_back(std::pair<int, float> { x + y * WORLD_WIDTH, t });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
return a.second < b.second;
|
||||||
});
|
});
|
||||||
|
|
||||||
for (std::pair<int, float> contact_time : contactTimes) {
|
for (std::pair<int, float> contact_time : contactTimes) {
|
||||||
int x = contact_time.first % WORLD_WIDTH;
|
int x = contact_time.first % WORLD_WIDTH;
|
||||||
int y = contact_time.first / WORLD_WIDTH;
|
int y = contact_time.first / WORLD_WIDTH;
|
||||||
WorldTile* world_tile = gridManager.GetTileAtIndex(x,y);
|
WorldTile* world_tile = gridManager.GetTileAtIndex(x, y);
|
||||||
|
|
||||||
const Point2f WorldTilePos = world_tile->GetCollisionRect().getCollisionRect().pos;
|
const Point2f WorldTilePos = world_tile->GetCollisionRect().getCollisionRect().pos;
|
||||||
const Point2f WorldTileSize = world_tile->GetCollisionRect().getCollisionRect().size;
|
const Point2f WorldTileSize = world_tile->GetCollisionRect().getCollisionRect().size;
|
||||||
|
|
||||||
if(WorldTilePos.y + WorldTileSize.y > m_Position.y) {
|
if (WorldTilePos.y + WorldTileSize.y > m_Position.y) {
|
||||||
if(WorldTilePos.x + WorldTileSize.x > m_Position.x) {
|
if (WorldTilePos.x + WorldTileSize.x > m_Position.x) {
|
||||||
if(WorldTilePos.y + WorldTileSize.y / 2 > m_Position.y && m_Position.y + m_Size.y / 2 > WorldTilePos.y) {
|
if (WorldTilePos.y + WorldTileSize.y / 2 > m_Position.y && m_Position.y + m_Size.y / 2 > WorldTilePos.y) {
|
||||||
//Right of player
|
//Right of player
|
||||||
m_ContactMap[Collision::CollisionDirection::Right] = world_tile;
|
m_ContactMap[Collision::CollisionDirection::Right] = world_tile;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(WorldTilePos.y + WorldTileSize.y > m_Position.y) {
|
if (WorldTilePos.y + WorldTileSize.y > m_Position.y) {
|
||||||
if(WorldTilePos.x < m_Position.x + m_Size.x) {
|
if (WorldTilePos.x < m_Position.x + m_Size.x) {
|
||||||
if(WorldTilePos.y + WorldTileSize.y / 2 > m_Position.y && m_Position.y + m_Size.y / 2 > WorldTilePos.y) {
|
if (WorldTilePos.y + WorldTileSize.y / 2 > m_Position.y && m_Position.y + m_Size.y / 2 > WorldTilePos.y) {
|
||||||
//Left of player
|
//Left of player
|
||||||
m_ContactMap[Collision::CollisionDirection::Left] = world_tile;
|
m_ContactMap[Collision::CollisionDirection::Left] = world_tile;
|
||||||
}
|
}
|
||||||
@@ -152,8 +163,8 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Below the player
|
//Below the player
|
||||||
if(WorldTilePos.y + WorldTileSize.y <= m_Position.y) {
|
if (WorldTilePos.y + WorldTileSize.y <= m_Position.y) {
|
||||||
if(WorldTilePos.x + WorldTileSize.x / 2 > m_Position.x && m_Position.x + m_Size.x / 2 > WorldTilePos.x) {
|
if (WorldTilePos.x + WorldTileSize.x / 2 > m_Position.x && m_Position.x + m_Size.x / 2 > WorldTilePos.x) {
|
||||||
m_ContactMap[Collision::CollisionDirection::Bottom] = world_tile;
|
m_ContactMap[Collision::CollisionDirection::Bottom] = world_tile;
|
||||||
m_Grounded = true;
|
m_Grounded = true;
|
||||||
world_tile->m_Hightlight = true;
|
world_tile->m_Hightlight = true;
|
||||||
@@ -164,6 +175,24 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
|
|||||||
Collision::ResolvePlayerVsRect(*this, elapsedTime, &rect);
|
Collision::ResolvePlayerVsRect(*this, elapsedTime, &rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_Position = m_Position + m_Vel * elapsedTime;
|
if (m_Vel.x != 0.0f) {
|
||||||
|
m_State = PlayerState::Walking;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
m_State = PlayerState::Idle;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (m_State) {
|
||||||
|
case PlayerState::Idle:
|
||||||
|
m_walkAnimation->SetPlaying(false);
|
||||||
|
break;
|
||||||
|
case PlayerState::Walking:
|
||||||
|
m_walkAnimation->SetPlaying(true);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
m_Position = m_Position + m_Vel * elapsedTime;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,24 +1,60 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "Collision.h"
|
#include "Collision.h"
|
||||||
|
#include "TextureManager.h"
|
||||||
|
#include "Animations/Animation.h"
|
||||||
|
|
||||||
class WorldLevel;
|
class WorldLevel;
|
||||||
|
|
||||||
|
enum class PlayerState
|
||||||
|
{
|
||||||
|
Idle,
|
||||||
|
Walking,
|
||||||
|
Digging,
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class PlayerDirection
|
||||||
|
{
|
||||||
|
Left,
|
||||||
|
Right,
|
||||||
|
Up,
|
||||||
|
Down,
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class DigDirection
|
||||||
|
{
|
||||||
|
Left,
|
||||||
|
Right,
|
||||||
|
Down
|
||||||
|
};
|
||||||
|
|
||||||
class Player
|
class Player
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
Player(const Point2f& Position, TextureManager* pTextureManager);
|
||||||
Player(const Point2f& Position);
|
Collision::CollisionRect GetCollisionRect() const;
|
||||||
Collision::CollisionRect GetCollisionRect();
|
|
||||||
void Update(float elapsedTime, WorldLevel& level);
|
void Update(float elapsedTime, WorldLevel& level);
|
||||||
void Draw() const;
|
void Draw() const;
|
||||||
|
|
||||||
void SetPosition(Point2f pos) { m_Position = pos; }
|
void SetPosition(Point2f pos) {
|
||||||
Point2f GetPosition() const { return m_Position; }
|
m_Position = pos;
|
||||||
|
}
|
||||||
|
Point2f GetPosition() const {
|
||||||
|
return m_Position;
|
||||||
|
}
|
||||||
|
|
||||||
void SetVelocity(Point2f vel) { m_Vel = vel; }
|
void SetVelocity(Point2f vel) {
|
||||||
Point2f GetVelocity() const { return m_Vel; }
|
m_Vel = vel;
|
||||||
|
}
|
||||||
|
Point2f GetVelocity() const {
|
||||||
|
return m_Vel;
|
||||||
|
}
|
||||||
|
|
||||||
auto GetContactMap(){ return m_ContactMap; }
|
auto GetContactMap() {
|
||||||
void SetContactMap(Collision::CollisionDirection dir, WorldTile* tile) { m_ContactMap[dir] = tile; }
|
return m_ContactMap;
|
||||||
|
}
|
||||||
|
void SetContactMap(Collision::CollisionDirection dir, WorldTile* tile) {
|
||||||
|
m_ContactMap[dir] = tile;
|
||||||
|
}
|
||||||
|
|
||||||
void ProcessImGui();
|
void ProcessImGui();
|
||||||
|
|
||||||
@@ -28,12 +64,20 @@ private:
|
|||||||
|
|
||||||
Point2f m_Vel;
|
Point2f m_Vel;
|
||||||
|
|
||||||
std::map<Collision::CollisionDirection, WorldTile*> m_ContactMap;
|
std::map<Collision::CollisionDirection, WorldTile *> m_ContactMap;
|
||||||
|
|
||||||
Point2f m_Acc;
|
Point2f m_Acc;
|
||||||
Point2f m_Gravity{ 0, -9.81f };
|
Point2f m_Gravity { 0, -9.81f };
|
||||||
|
|
||||||
bool m_Grounded{ false };
|
bool m_Grounded { false };
|
||||||
|
|
||||||
bool m_DidJustDigRight{ false };
|
bool m_DidJustDigRight { false };
|
||||||
|
Animation* m_walkAnimation;
|
||||||
|
|
||||||
|
PlayerState m_State { PlayerState::Idle };
|
||||||
|
PlayerDirection m_Direction { PlayerDirection::Right };
|
||||||
|
DigDirection m_DigDirection { DigDirection::Right };
|
||||||
|
|
||||||
|
//Testing
|
||||||
|
bool m_DrawCollisionRect { true };
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
#include "pch.h"
|
#include "pch.h"
|
||||||
#include "TextureManager.h"
|
#include "TextureManager.h"
|
||||||
TextureManager* TextureManager::m_pInstance = NULL;
|
TextureManager* TextureManager::m_pInstance = nullptr;
|
||||||
|
|
||||||
TextureManager* TextureManager::GetInstance() {
|
TextureManager * TextureManager::GetInstance() {
|
||||||
if (m_pInstance == nullptr) {
|
if (m_pInstance == nullptr) {
|
||||||
m_pInstance = new TextureManager();
|
m_pInstance = new TextureManager();
|
||||||
}
|
}
|
||||||
return m_pInstance;
|
return m_pInstance;
|
||||||
}
|
}
|
||||||
Texture* TextureManager::GetTexture(const std::string& name) {
|
Texture * TextureManager::GetTexture(const std::string& name) {
|
||||||
if (m_Textures.find(name) != m_Textures.end()) {
|
if (m_Textures.find(name) != m_Textures.end()) {
|
||||||
return m_Textures[name];
|
return m_Textures[name];
|
||||||
}
|
}
|
||||||
@@ -16,3 +16,6 @@ Texture* TextureManager::GetTexture(const std::string& name) {
|
|||||||
m_Textures[name] = pTexture;
|
m_Textures[name] = pTexture;
|
||||||
return pTexture;
|
return pTexture;
|
||||||
}
|
}
|
||||||
|
TextureManager::~TextureManager() {
|
||||||
|
//TODO: Loop over the m_Textures to delete them
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,15 +6,15 @@
|
|||||||
class TextureManager
|
class TextureManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TextureManager() = default;
|
static TextureManager * GetInstance();
|
||||||
|
Texture * GetTexture(const std::string& name);
|
||||||
|
|
||||||
static TextureManager* GetInstance();
|
|
||||||
|
|
||||||
Texture* GetTexture(const std::string& name);
|
|
||||||
|
|
||||||
static TextureManager* m_pInstance;
|
|
||||||
private:
|
private:
|
||||||
std::map<std::string, Texture*> m_Textures{};
|
TextureManager() = default;
|
||||||
|
~TextureManager();
|
||||||
|
static TextureManager* m_pInstance;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::map<std::string, Texture *> m_Textures {};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -11,20 +11,18 @@
|
|||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
|
|
||||||
WorldLevel::WorldLevel(Camera* camera, Rectf viewport):
|
WorldLevel::WorldLevel(Camera* camera, Rectf viewport): Level(camera),
|
||||||
Level(camera),
|
|
||||||
m_gridManager(WorldGridManager()),
|
m_gridManager(WorldGridManager()),
|
||||||
m_player(Player { Point2f { 0, 100 } }),
|
m_player(Player { Point2f { 0, 100 }, TextureManager::GetInstance() }),
|
||||||
m_mousePos { 0, 0 },
|
m_mousePos { 0, 0 },
|
||||||
m_viewport(viewport)
|
m_viewport(viewport) {
|
||||||
{
|
|
||||||
// The grid is 34 x 50 big, the top center is 0,0 in world coords
|
// The grid is 34 x 50 big, the top center is 0,0 in world coords
|
||||||
for (size_t x { 0 }; x < WORLD_WIDTH; ++x) {
|
for (size_t x { 0 }; x < WORLD_WIDTH; ++x) {
|
||||||
for (size_t y { 0 }; y < WORLD_HEIGHT; ++y) {
|
for (size_t y { 0 }; y < WORLD_HEIGHT; ++y) {
|
||||||
int actualX = x - WORLD_WIDTH / 2;
|
int actualX = x - WORLD_WIDTH / 2;
|
||||||
Point2f pos = Point2f{ float(actualX * TILE_WIDTH), -float(y * TILE_HEIGHT) - TILE_HEIGHT};
|
auto pos = Point2f { float(actualX * TILE_WIDTH), -float(y * TILE_HEIGHT) - TILE_HEIGHT };
|
||||||
GroundTileType* type = Tiles::AIR;
|
GroundTileType* type = Tiles::AIR;
|
||||||
switch(utils::randRange(0,2)) {
|
switch (utils::randRange(0, 2)) {
|
||||||
case 0:
|
case 0:
|
||||||
type = Tiles::DIRT;
|
type = Tiles::DIRT;
|
||||||
break;
|
break;
|
||||||
@@ -38,8 +36,7 @@ WorldLevel::WorldLevel(Camera* camera, Rectf viewport):
|
|||||||
std::cout << "??" << std::endl;
|
std::cout << "??" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_gridManager.SetTileAtIndex(x, y, new WorldTile { pos, type, TextureManager::GetInstance() });
|
||||||
m_gridManager.SetTileAtIndex(x,y, new WorldTile{ pos, type, TextureManager::GetInstance() });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (size_t x { 0 }; x < WORLD_WIDTH; ++x) {
|
for (size_t x { 0 }; x < WORLD_WIDTH; ++x) {
|
||||||
@@ -53,22 +50,22 @@ WorldLevel::~WorldLevel() {
|
|||||||
void WorldLevel::Update(float elapsedSec) {
|
void WorldLevel::Update(float elapsedSec) {
|
||||||
int mouseX, mouseY;
|
int mouseX, mouseY;
|
||||||
SDL_GetMouseState(&mouseX, &mouseY);
|
SDL_GetMouseState(&mouseX, &mouseY);
|
||||||
m_mousePos = Point2f{ float(mouseX), float(mouseY) };
|
m_mousePos = Point2f { float(mouseX), float(mouseY) };
|
||||||
m_mousePos = m_pCamera->TransformMouse(m_mousePos);
|
m_mousePos = m_pCamera->TransformMouse(m_mousePos);
|
||||||
//m_player.Update(elapsedSec, *this);
|
//m_player.Update(elapsedSec, *this);
|
||||||
|
|
||||||
|
|
||||||
WorldTile* selectedTile{ nullptr };
|
WorldTile* selectedTile { nullptr };
|
||||||
|
|
||||||
for (size_t x { 0 }; x < WORLD_WIDTH; ++x) {
|
for (size_t x { 0 }; x < WORLD_WIDTH; ++x) {
|
||||||
for (size_t y { 0 }; y < WORLD_HEIGHT; ++y) {
|
for (size_t y { 0 }; y < WORLD_HEIGHT; ++y) {
|
||||||
if(m_gridManager.GetTileAtIndex(x,y)->GetCollisionRect().Contains(m_mousePos)) {
|
if (m_gridManager.GetTileAtIndex(x, y)->GetCollisionRect().Contains(m_mousePos)) {
|
||||||
selectedTile = m_gridManager.GetTileAtIndex(x,y);
|
selectedTile = m_gridManager.GetTileAtIndex(x, y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(selectedTile != nullptr) {
|
if (selectedTile != nullptr) {
|
||||||
if(utils::isMouseDown(SDL_BUTTON_LEFT)) {
|
if (utils::isMouseDown(SDL_BUTTON_LEFT)) {
|
||||||
selectedTile->SetTileType(Tiles::AIR);
|
selectedTile->SetTileType(Tiles::AIR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -76,7 +73,7 @@ void WorldLevel::Update(float elapsedSec) {
|
|||||||
m_player.Update(elapsedSec, *this);
|
m_player.Update(elapsedSec, *this);
|
||||||
|
|
||||||
WorldTile* t = m_gridManager.GetTileAtWorldPos(m_mousePos);
|
WorldTile* t = m_gridManager.GetTileAtWorldPos(m_mousePos);
|
||||||
if(t != nullptr) {
|
if (t != nullptr) {
|
||||||
t->SetTileType(Tiles::AIR);
|
t->SetTileType(Tiles::AIR);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,15 +97,15 @@ void WorldLevel::Draw() const {
|
|||||||
|
|
||||||
for (size_t x { 0 }; x < WORLD_WIDTH; ++x) {
|
for (size_t x { 0 }; x < WORLD_WIDTH; ++x) {
|
||||||
for (size_t y { 0 }; y < WORLD_HEIGHT; ++y) {
|
for (size_t y { 0 }; y < WORLD_HEIGHT; ++y) {
|
||||||
m_gridManager.GetTileAtIndex(x,y)->Draw();
|
m_gridManager.GetTileAtIndex(x, y)->Draw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//loop over worldtiles
|
//loop over worldtiles
|
||||||
for (int x { 0 }; x < WORLD_WIDTH; ++x) {
|
for (int x { 0 }; x < WORLD_WIDTH; ++x) {
|
||||||
for (int y { 0 }; y < WORLD_HEIGHT; ++y) {
|
for (int y { 0 }; y < WORLD_HEIGHT; ++y) {
|
||||||
if(*m_gridManager.GetTileAtIndex(x,y)->GetTileType() != Tiles::AIR) {
|
if (*m_gridManager.GetTileAtIndex(x, y)->GetTileType() != Tiles::AIR) {
|
||||||
Collision::CollisionRect rect = m_gridManager.GetTileAtIndex(x,y)->GetCollisionRect().getCollisionRect();
|
Collision::CollisionRect rect = m_gridManager.GetTileAtIndex(x, y)->GetCollisionRect().getCollisionRect();
|
||||||
utils::SetColor(Colors::GREEN);
|
utils::SetColor(Colors::GREEN);
|
||||||
utils::DrawRect(rect.pos, rect.size.x, rect.size.y);
|
utils::DrawRect(rect.pos, rect.size.x, rect.size.y);
|
||||||
}
|
}
|
||||||
@@ -134,16 +131,17 @@ void WorldLevel::ProcessImGui() {
|
|||||||
if (ImGui::MenuItem("Camera Info")) {
|
if (ImGui::MenuItem("Camera Info")) {
|
||||||
m_ShowCameraWindow = !m_ShowCameraWindow;
|
m_ShowCameraWindow = !m_ShowCameraWindow;
|
||||||
}
|
}
|
||||||
if(ImGui::MenuItem("Player Info")) {
|
if (ImGui::MenuItem("Player Info")) {
|
||||||
m_ShowPlayerInfo = !m_ShowPlayerInfo;
|
m_ShowPlayerInfo = !m_ShowPlayerInfo;
|
||||||
}
|
}
|
||||||
ImGui::EndMenu();
|
ImGui::EndMenu();
|
||||||
}
|
}
|
||||||
if(ImGui::BeginMenu(std::to_string(utils::isKeyPressed(SDL_SCANCODE_S)).c_str())){}
|
if (ImGui::BeginMenu(std::to_string(utils::isKeyPressed(SDL_SCANCODE_S)).c_str())) {
|
||||||
|
}
|
||||||
ImGui::EndMainMenuBar();
|
ImGui::EndMainMenuBar();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(m_ShowTextureManagerWindow) {
|
if (m_ShowTextureManagerWindow) {
|
||||||
ImGui::Begin("Texture Manager", &m_ShowTextureManagerWindow, ImGuiWindowFlags_AlwaysAutoResize);
|
ImGui::Begin("Texture Manager", &m_ShowTextureManagerWindow, ImGuiWindowFlags_AlwaysAutoResize);
|
||||||
ImGui::Text("Texture loading Count:");
|
ImGui::Text("Texture loading Count:");
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
@@ -151,17 +149,17 @@ void WorldLevel::ProcessImGui() {
|
|||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(m_ShowCameraWindow) {
|
if (m_ShowCameraWindow) {
|
||||||
ImGui::Begin("Camera", &m_ShowCameraWindow, ImGuiWindowFlags_AlwaysAutoResize);
|
ImGui::Begin("Camera", &m_ShowCameraWindow, ImGuiWindowFlags_AlwaysAutoResize);
|
||||||
ImGui::Text("Camera Position: (%f, %f)", m_pCamera->GetPosition().x, m_pCamera->GetPosition().y);
|
ImGui::Text("Camera Position: (%f, %f)", m_pCamera->GetPosition().x, m_pCamera->GetPosition().y);
|
||||||
ImGui::Text("Is Right Mouse Down: %s", utils::isMouseDown(0) ? "true" : "false");
|
ImGui::Text("Is Right Mouse Down: %s", utils::isMouseDown(0) ? "true" : "false");
|
||||||
if(ImGui::Button("Reset Camera")) {
|
if (ImGui::Button("Reset Camera")) {
|
||||||
m_pCamera->SetPosition(Point2f{-m_viewport.width / 2, -m_viewport.height / 2});
|
m_pCamera->SetPosition(Point2f { -m_viewport.width / 2, -m_viewport.height / 2 });
|
||||||
}
|
}
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(m_ShowPlayerInfo) {
|
if (m_ShowPlayerInfo) {
|
||||||
ImGui::Begin("Player Info", &m_ShowPlayerInfo, ImGuiWindowFlags_AlwaysAutoResize);
|
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 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 Velocity: (%f, %f)", m_player.GetVelocity().x, m_player.GetVelocity().y);
|
||||||
|
|||||||
@@ -1,43 +1,42 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "Level.h"
|
|
||||||
#include "Texture.h"
|
|
||||||
#include "WorldLevel.h"
|
|
||||||
#include "WorldTile.h"
|
|
||||||
#include <array>
|
|
||||||
|
|
||||||
#include "Collision.h"
|
#include "Collision.h"
|
||||||
|
#include "Level.h"
|
||||||
#include "Player.h"
|
#include "Player.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "WorldGridManager.h"
|
#include "WorldLevel.h"
|
||||||
|
#include "GridSystem/WorldGridManager.h"
|
||||||
|
|
||||||
|
|
||||||
class WorldLevel : public Level {
|
class WorldLevel : public Level
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
WorldLevel(Camera* camera, Rectf viewport);
|
WorldLevel(Camera* camera, Rectf viewport);
|
||||||
~WorldLevel() override;
|
~WorldLevel() override;
|
||||||
|
|
||||||
|
WorldLevel(const WorldLevel& other) = default;
|
||||||
|
WorldLevel(WorldLevel&& other) = default;
|
||||||
|
|
||||||
void Update(float elapsedSec) override;
|
void Update(float elapsedSec) override;
|
||||||
void Draw() const override;
|
void Draw() const override;
|
||||||
|
|
||||||
void MouseMove(const Point2f& mousePos) override;
|
void MouseMove(const Point2f& mousePos) override;
|
||||||
void ProcessImGui() override;
|
void ProcessImGui() override;
|
||||||
|
|
||||||
WorldGridManager& GetGridManager() { return m_gridManager; }
|
WorldGridManager& GetGridManager() {
|
||||||
|
return m_gridManager;
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<Collision::CollisionRect> m_Rects;
|
std::vector<Collision::CollisionRect> m_Rects;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
WorldGridManager m_gridManager {};
|
||||||
|
|
||||||
WorldGridManager m_gridManager{};
|
|
||||||
Player m_player;
|
Player m_player;
|
||||||
Point2f m_mousePos{};
|
Point2f m_mousePos {};
|
||||||
|
|
||||||
Rectf m_viewport;
|
Rectf m_viewport;
|
||||||
|
|
||||||
// ImGui Vars
|
// ImGui Vars
|
||||||
bool m_ShowTextureManagerWindow{ false };
|
bool m_ShowTextureManagerWindow { false };
|
||||||
bool m_ShowCameraWindow{ false };
|
bool m_ShowCameraWindow { false };
|
||||||
bool m_ShowPlayerInfo{ true };
|
bool m_ShowPlayerInfo { true };
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -6,13 +6,12 @@
|
|||||||
void StartHeapControl();
|
void StartHeapControl();
|
||||||
void DumpMemoryLeaks();
|
void DumpMemoryLeaks();
|
||||||
|
|
||||||
int SDL_main(int argv, char** args)
|
int SDL_main(int argv, char** args) {
|
||||||
{
|
|
||||||
srand(static_cast<unsigned int>(time(nullptr)));
|
srand(static_cast<unsigned int>(time(nullptr)));
|
||||||
|
|
||||||
StartHeapControl();
|
StartHeapControl();
|
||||||
|
|
||||||
Game* pGame { new Game { Window { "Motherload - Verhulst, Bram - 1DAEGD16E", 846.f, 500.f } } };
|
auto pGame { new Game { Window { "Motherload - Verhulst, Bram - 1DAEGD16E", 846.f, 500.f } } };
|
||||||
pGame->Run();
|
pGame->Run();
|
||||||
delete pGame;
|
delete pGame;
|
||||||
|
|
||||||
|
|||||||
BIN
Resources/animations/player/player_walk.png
Normal file
BIN
Resources/animations/player/player_walk.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 16 KiB |
Reference in New Issue
Block a user