diff --git a/.gitignore b/.gitignore index 426d76d..191b7e4 100644 --- a/.gitignore +++ b/.gitignore @@ -396,3 +396,7 @@ FodyWeavers.xsd # JetBrains Rider *.sln.iml + +# Game Project specifics -> do not ignore: +!**/Libraries/**/x86/ +!**/Libraries/**/x64/ diff --git a/.idea/.idea.Prog2Engine/.idea/.gitignore b/.idea/.idea.Prog2Engine/.idea/.gitignore index 8249ff7..0d12fee 100644 --- a/.idea/.idea.Prog2Engine/.idea/.gitignore +++ b/.idea/.idea.Prog2Engine/.idea/.gitignore @@ -11,3 +11,5 @@ # Datasource local storage ignored files /dataSources/ /dataSources.local.xml +# GitHub Copilot persisted chat sessions +/copilot/chatSessions diff --git a/Engine/structs.cpp b/Engine/structs.cpp index cbfcca9..a910871 100644 --- a/Engine/structs.cpp +++ b/Engine/structs.cpp @@ -4,94 +4,87 @@ //----------------------------------------------------------------- // Window Constructors //----------------------------------------------------------------- -Window::Window( const std::string& title , float width , float height , bool isVSyncOn ) - :title{ title } - ,width{ width } - ,height{ height } - ,isVSyncOn{ isVSyncOn } -{ +Window::Window(const std::string& title, float width, float height, bool isVSyncOn) + : title { title } + , width { width } + , height { height } + , isVSyncOn { isVSyncOn } { } //----------------------------------------------------------------- // Point2f Constructors //----------------------------------------------------------------- -Point2f::Point2f( ) - :Point2f{ 0.0f, 0.0f } -{ +Point2f::Point2f() + : Point2f { 0.0f, 0.0f } { } -Point2f::Point2f( float x, float y ) - :x{ x }, y{ y } -{ +Point2f::Point2f(float x, float y) + : x { x }, y { y } { } +// Point2f::Point2f(int x, int y) +// : x { (float)x }, y { (float)y } { +// } + //----------------------------------------------------------------- // Rectf Constructors //----------------------------------------------------------------- -Rectf::Rectf( ) - :Rectf{ 0.0f, 0.0f, 0.0f, 0.0f } -{ +Rectf::Rectf() + : Rectf { 0.0f, 0.0f, 0.0f, 0.0f } { } -Rectf::Rectf( float left, float bottom, float width, float height ) - :left{ left } - ,bottom{ bottom } - ,width{ width } - ,height{ height } -{ +Rectf::Rectf(float left, float bottom, float width, float height) + : left { left } + , bottom { bottom } + , width { width } + , height { height } { } +// Rectf::Rectf(int left, int bottom, int width, int height) : left { (float)left }, bottom { (float)bottom }, width { (float)width }, height { (float)height } { +// } //----------------------------------------------------------------- // Color4f Constructors //----------------------------------------------------------------- -Color4f::Color4f( ) - :Color4f{ 0.0f, 0.0f, 0.0f, 1.0f } -{ +Color4f::Color4f() + : Color4f { 0.0f, 0.0f, 0.0f, 1.0f } { } -Color4f::Color4f( float r, float g, float b, float a ) - :r{ r } - ,g{ g } - ,b{ b } - ,a{ a } -{ +Color4f::Color4f(float r, float g, float b, float a) + : r { r } + , g { g } + , b { b } + , a { a } { } //----------------------------------------------------------------- // Circlef Constructors //----------------------------------------------------------------- -Circlef::Circlef( ) - :Circlef{ 0.0f, 0.0f, 0.0f } -{ +Circlef::Circlef() + : Circlef { 0.0f, 0.0f, 0.0f } { } -Circlef::Circlef( float centerX, float centerY, float radius ) - :Circlef{ Point2f{ centerX, centerY }, radius } -{ +Circlef::Circlef(float centerX, float centerY, float radius) + : Circlef { Point2f { centerX, centerY }, radius } { } -Circlef::Circlef( const Point2f& center, float radius ) - :center{ center } - ,radius{ radius } -{ +Circlef::Circlef(const Point2f& center, float radius) + : center { center } + , radius { radius } { } //----------------------------------------------------------------- // Ellipsef Constructors //----------------------------------------------------------------- -Ellipsef::Ellipsef( ) - :Ellipsef{ 0.0f, 0.0f, 0.0f, 0.0f } -{ +Ellipsef::Ellipsef() + : Ellipsef { 0.0f, 0.0f, 0.0f, 0.0f } { } -Ellipsef::Ellipsef( const Point2f& center, float radiusX, float radiusY ) - : center{ center } - , radiusX{ radiusX } - , radiusY{ radiusY } -{ +Ellipsef::Ellipsef(const Point2f& center, float radiusX, float radiusY) + : center { center } + , radiusX { radiusX } + , radiusY { radiusY } { } -Ellipsef::Ellipsef( float centerX, float centerY, float radiusX, float radiusY ) - : Ellipsef{ Point2f{ centerX, centerY }, radiusX, radiusY } -{ +Ellipsef::Ellipsef(float centerX, float centerY, float radiusX, float radiusY) + : Ellipsef { Point2f { centerX, centerY }, radiusX, radiusY } { } diff --git a/Engine/structs.h b/Engine/structs.h index 247c777..b885c0b 100644 --- a/Engine/structs.h +++ b/Engine/structs.h @@ -16,6 +16,7 @@ struct Point2f { Point2f( ); explicit Point2f( float x, float y ); + //Point2f(int x, int y); //Stupid fix for it giving an error float x; float y; @@ -27,6 +28,7 @@ struct Rectf { Rectf( ); explicit Rectf( float left, float bottom, float width, float height ); + //explicit Rectf( int left, int bottom, int width, int height ); //Stupid fix for it giving an error (same as Point2f) float left; float bottom; diff --git a/Game/Camera.cpp b/Game/Camera.cpp new file mode 100644 index 0000000..b350b29 --- /dev/null +++ b/Game/Camera.cpp @@ -0,0 +1,2 @@ +#include "pch.h" +#include "Camera.h" diff --git a/Game/Camera.h b/Game/Camera.h new file mode 100644 index 0000000..7f10a0e --- /dev/null +++ b/Game/Camera.h @@ -0,0 +1,10 @@ +#pragma once + +class Camera +{ +public: + +private: + + +}; diff --git a/Game/Game.cpp b/Game/Game.cpp index e18b62e..1584c47 100644 --- a/Game/Game.cpp +++ b/Game/Game.cpp @@ -1,8 +1,11 @@ #include "pch.h" #include "Game.h" +#include "utils.h" + Game::Game(const Window& window) - : BaseGame { window } { + : BaseGame { window } +{ Initialize(); } @@ -11,27 +14,34 @@ Game::~Game() { } void Game::Initialize() { - + m_WorldLevel = WorldLevel(); } void Game::Cleanup() { } void Game::Update(float elapsedSec) { - // Check keyboard state - //const Uint8 *pStates = SDL_GetKeyboardState( nullptr ); - //if ( pStates[SDL_SCANCODE_RIGHT] ) - //{ - // std::cout << "Right arrow key is down\n"; - //} - //if ( pStates[SDL_SCANCODE_LEFT] && pStates[SDL_SCANCODE_UP]) - //{ - // std::cout << "Left and up arrow keys are down\n"; - //} + const Uint8 *pStates = SDL_GetKeyboardState( nullptr ); + if ( pStates[SDL_SCANCODE_RIGHT] ) { + m_CameraOffset.x += 100 * elapsedSec; + } + if ( pStates[SDL_SCANCODE_LEFT] ) { + m_CameraOffset.x -= 100 * elapsedSec; + } + + } void Game::Draw() const { ClearBackground(); + glPushMatrix(); + { + glTranslatef(m_CameraOffset.x , m_CameraOffset.y, 0); + m_WorldLevel.Draw(); + utils::SetColor(Color4f{1.0f, 0.0f, 0.0f, 1.0f}); + utils::FillEllipse(0,0,20,20); + } + glPopMatrix(); } void Game::ProcessKeyDownEvent(const SDL_KeyboardEvent& e) { diff --git a/Game/Game.h b/Game/Game.h index 30dbb0e..24109f3 100644 --- a/Game/Game.h +++ b/Game/Game.h @@ -1,5 +1,9 @@ #pragma once +#include + #include "BaseGame.h" +#include "WorldLevel.h" +#include "WorldTile.h" class Game : public BaseGame { @@ -27,4 +31,8 @@ private: void Initialize(); void Cleanup(); void ClearBackground() const; + + + Point2f m_CameraOffset{0, 0}; + WorldLevel m_WorldLevel; }; diff --git a/Game/Game.vcxproj b/Game/Game.vcxproj index c558494..fce32a7 100644 --- a/Game/Game.vcxproj +++ b/Game/Game.vcxproj @@ -147,13 +147,21 @@ xcopy "$(SolutionDir)Resources\*.*" "$(TargetDir)" /y /d /s + + + + + + + + diff --git a/Game/Level.cpp b/Game/Level.cpp new file mode 100644 index 0000000..fcc8b14 --- /dev/null +++ b/Game/Level.cpp @@ -0,0 +1,10 @@ +#include "pch.h" +#include "Level.h" +Level::Level() { +} +Level::~Level() { +} +void Level::Update(float elapsedSec) { +} +void Level::Draw() const { +} diff --git a/Game/Level.h b/Game/Level.h new file mode 100644 index 0000000..0aa6f70 --- /dev/null +++ b/Game/Level.h @@ -0,0 +1,16 @@ +#pragma once + +class Level +{ +public: + Level(); + ~Level(); + + + virtual void Update(float elapsedSec); + virtual void Draw() const; + +private: + + +}; diff --git a/Game/WorldLevel.cpp b/Game/WorldLevel.cpp new file mode 100644 index 0000000..c0b872d --- /dev/null +++ b/Game/WorldLevel.cpp @@ -0,0 +1,25 @@ +#include "pch.h" +#include "WorldLevel.h" + +#include "utils.h" + +WorldLevel::WorldLevel() { + for (int i{ 0 }; i < 10; ++i) { + for (int j{ 0 }; j < 10; ++j) { + m_WorldTiles[i][j] = WorldTile{ Point2f{ (float)i * 50, (float)j * 50 }, GroundTileTypes::Dirt }; + } + } +} +WorldLevel::~WorldLevel() { +} +void WorldLevel::Update(float elapsedSec) { +} +void WorldLevel::Draw() const { + for (int i{ 0 }; i < 10; ++i) { + for (int j{ 0 }; j < 10; ++j) { + utils::SetColor(Color4f{ 0.5f, 0.5f, 0.5f, 1.0f }); + utils::FillRect(m_WorldTiles[i][j].GetPosition().x, m_WorldTiles[i][j].GetPosition().y, 50, 50); + } + } + +} diff --git a/Game/WorldLevel.h b/Game/WorldLevel.h new file mode 100644 index 0000000..62760b5 --- /dev/null +++ b/Game/WorldLevel.h @@ -0,0 +1,17 @@ +#pragma once +#include "Level.h" +#include "WorldTile.h" + +class WorldLevel : public Level { +public: + WorldLevel(); + ~WorldLevel(); + + void Update(float elapsedSec) override; + void Draw() const override; + +private: + WorldTile m_WorldTiles[10][10]; + + +}; diff --git a/Game/WorldTile.cpp b/Game/WorldTile.cpp new file mode 100644 index 0000000..56e4733 --- /dev/null +++ b/Game/WorldTile.cpp @@ -0,0 +1,14 @@ +#include "pch.h" +#include "WorldTile.h" + +#include "utils.h" +WorldTile::WorldTile() { +} +WorldTile::WorldTile(const Point2f& position, GroundTileTypes groundTileType) : m_Position { position }, m_GroundTileType { groundTileType } { +} +void WorldTile::Draw() const { + if (m_GroundTileType != GroundTileTypes::Air) { + utils::SetColor(Color4f{ 0.5f, 0.5f, 0.5f, 1.0f}); + utils::FillRect(m_Position.x, m_Position.y, 50, 50); + } +} diff --git a/Game/WorldTile.h b/Game/WorldTile.h new file mode 100644 index 0000000..50eb0b5 --- /dev/null +++ b/Game/WorldTile.h @@ -0,0 +1,25 @@ +#pragma once + +enum class GroundTileTypes +{ + Air, + Dirt, +}; + +class WorldTile { +public: + WorldTile(); + WorldTile(const Point2f& position, GroundTileTypes groundTileType); + + void Draw() const; + + Point2f GetPosition() const { return m_Position; } + void SetPosition(const Point2f& position) { m_Position = position; } + + +private: + Point2f m_Position; + GroundTileTypes m_GroundTileType; + + +};