Update Gitignore and Basic Camera / Level Implementation

This commit is contained in:
2024-03-08 12:27:04 +01:00
parent 3dcfc744d5
commit 9dbfef5e78
15 changed files with 209 additions and 63 deletions

2
Game/Camera.cpp Normal file
View File

@@ -0,0 +1,2 @@
#include "pch.h"
#include "Camera.h"

10
Game/Camera.h Normal file
View File

@@ -0,0 +1,10 @@
#pragma once
class Camera
{
public:
private:
};

View File

@@ -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) {

View File

@@ -1,5 +1,9 @@
#pragma once
#include <vector>
#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;
};

View File

@@ -147,13 +147,21 @@ xcopy "$(SolutionDir)Resources\*.*" "$(TargetDir)" /y /d /s</Command>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="Camera.cpp" />
<ClCompile Include="Game.cpp" />
<ClCompile Include="Level.cpp" />
<ClCompile Include="main.cpp" />
<ClCompile Include="pch.cpp" />
<ClCompile Include="WorldLevel.cpp" />
<ClCompile Include="WorldTile.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="Camera.h" />
<ClInclude Include="Game.h" />
<ClInclude Include="Level.h" />
<ClInclude Include="pch.h" />
<ClInclude Include="WorldLevel.h" />
<ClInclude Include="WorldTile.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">

10
Game/Level.cpp Normal file
View File

@@ -0,0 +1,10 @@
#include "pch.h"
#include "Level.h"
Level::Level() {
}
Level::~Level() {
}
void Level::Update(float elapsedSec) {
}
void Level::Draw() const {
}

16
Game/Level.h Normal file
View File

@@ -0,0 +1,16 @@
#pragma once
class Level
{
public:
Level();
~Level();
virtual void Update(float elapsedSec);
virtual void Draw() const;
private:
};

25
Game/WorldLevel.cpp Normal file
View File

@@ -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);
}
}
}

17
Game/WorldLevel.h Normal file
View File

@@ -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];
};

14
Game/WorldTile.cpp Normal file
View File

@@ -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);
}
}

25
Game/WorldTile.h Normal file
View File

@@ -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;
};