mirror of
https://github.com/HowestDAE/dae16-VerhulstBram.git
synced 2026-02-04 07:59:19 +01:00
Update Gitignore and Basic Camera / Level Implementation
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -396,3 +396,7 @@ FodyWeavers.xsd
|
|||||||
|
|
||||||
# JetBrains Rider
|
# JetBrains Rider
|
||||||
*.sln.iml
|
*.sln.iml
|
||||||
|
|
||||||
|
# Game Project specifics -> do not ignore:
|
||||||
|
!**/Libraries/**/x86/
|
||||||
|
!**/Libraries/**/x64/
|
||||||
|
|||||||
2
.idea/.idea.Prog2Engine/.idea/.gitignore
generated
vendored
2
.idea/.idea.Prog2Engine/.idea/.gitignore
generated
vendored
@@ -11,3 +11,5 @@
|
|||||||
# Datasource local storage ignored files
|
# Datasource local storage ignored files
|
||||||
/dataSources/
|
/dataSources/
|
||||||
/dataSources.local.xml
|
/dataSources.local.xml
|
||||||
|
# GitHub Copilot persisted chat sessions
|
||||||
|
/copilot/chatSessions
|
||||||
|
|||||||
@@ -4,94 +4,87 @@
|
|||||||
//-----------------------------------------------------------------
|
//-----------------------------------------------------------------
|
||||||
// Window Constructors
|
// Window Constructors
|
||||||
//-----------------------------------------------------------------
|
//-----------------------------------------------------------------
|
||||||
Window::Window( const std::string& title , float width , float height , bool isVSyncOn )
|
Window::Window(const std::string& title, float width, float height, bool isVSyncOn)
|
||||||
:title{ title }
|
: title { title }
|
||||||
,width{ width }
|
, width { width }
|
||||||
,height{ height }
|
, height { height }
|
||||||
,isVSyncOn{ isVSyncOn }
|
, isVSyncOn { isVSyncOn } {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------
|
//-----------------------------------------------------------------
|
||||||
// Point2f Constructors
|
// Point2f Constructors
|
||||||
//-----------------------------------------------------------------
|
//-----------------------------------------------------------------
|
||||||
Point2f::Point2f( )
|
Point2f::Point2f()
|
||||||
:Point2f{ 0.0f, 0.0f }
|
: Point2f { 0.0f, 0.0f } {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
Point2f::Point2f( float x, float y )
|
Point2f::Point2f(float x, float y)
|
||||||
:x{ x }, y{ y }
|
: x { x }, y { y } {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Point2f::Point2f(int x, int y)
|
||||||
|
// : x { (float)x }, y { (float)y } {
|
||||||
|
// }
|
||||||
|
|
||||||
//-----------------------------------------------------------------
|
//-----------------------------------------------------------------
|
||||||
// Rectf Constructors
|
// Rectf Constructors
|
||||||
//-----------------------------------------------------------------
|
//-----------------------------------------------------------------
|
||||||
Rectf::Rectf( )
|
Rectf::Rectf()
|
||||||
:Rectf{ 0.0f, 0.0f, 0.0f, 0.0f }
|
: Rectf { 0.0f, 0.0f, 0.0f, 0.0f } {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Rectf::Rectf( float left, float bottom, float width, float height )
|
Rectf::Rectf(float left, float bottom, float width, float height)
|
||||||
:left{ left }
|
: left { left }
|
||||||
,bottom{ bottom }
|
, bottom { bottom }
|
||||||
,width{ width }
|
, width { width }
|
||||||
,height{ height }
|
, 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 Constructors
|
||||||
//-----------------------------------------------------------------
|
//-----------------------------------------------------------------
|
||||||
Color4f::Color4f( )
|
Color4f::Color4f()
|
||||||
:Color4f{ 0.0f, 0.0f, 0.0f, 1.0f }
|
: Color4f { 0.0f, 0.0f, 0.0f, 1.0f } {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Color4f::Color4f( float r, float g, float b, float a )
|
Color4f::Color4f(float r, float g, float b, float a)
|
||||||
:r{ r }
|
: r { r }
|
||||||
,g{ g }
|
, g { g }
|
||||||
,b{ b }
|
, b { b }
|
||||||
,a{ a }
|
, a { a } {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------
|
//-----------------------------------------------------------------
|
||||||
// Circlef Constructors
|
// Circlef Constructors
|
||||||
//-----------------------------------------------------------------
|
//-----------------------------------------------------------------
|
||||||
Circlef::Circlef( )
|
Circlef::Circlef()
|
||||||
:Circlef{ 0.0f, 0.0f, 0.0f }
|
: Circlef { 0.0f, 0.0f, 0.0f } {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Circlef::Circlef( float centerX, float centerY, float radius )
|
Circlef::Circlef(float centerX, float centerY, float radius)
|
||||||
:Circlef{ Point2f{ centerX, centerY }, radius }
|
: Circlef { Point2f { centerX, centerY }, radius } {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Circlef::Circlef( const Point2f& center, float radius )
|
Circlef::Circlef(const Point2f& center, float radius)
|
||||||
:center{ center }
|
: center { center }
|
||||||
,radius{ radius }
|
, radius { radius } {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------
|
//-----------------------------------------------------------------
|
||||||
// Ellipsef Constructors
|
// Ellipsef Constructors
|
||||||
//-----------------------------------------------------------------
|
//-----------------------------------------------------------------
|
||||||
Ellipsef::Ellipsef( )
|
Ellipsef::Ellipsef()
|
||||||
:Ellipsef{ 0.0f, 0.0f, 0.0f, 0.0f }
|
: Ellipsef { 0.0f, 0.0f, 0.0f, 0.0f } {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Ellipsef::Ellipsef( const Point2f& center, float radiusX, float radiusY )
|
Ellipsef::Ellipsef(const Point2f& center, float radiusX, float radiusY)
|
||||||
: center{ center }
|
: center { center }
|
||||||
, radiusX{ radiusX }
|
, radiusX { radiusX }
|
||||||
, radiusY{ radiusY }
|
, radiusY { radiusY } {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ellipsef::Ellipsef( float centerX, float centerY, float radiusX, float radiusY )
|
Ellipsef::Ellipsef(float centerX, float centerY, float radiusX, float radiusY)
|
||||||
: Ellipsef{ Point2f{ centerX, centerY }, radiusX, radiusY }
|
: Ellipsef { Point2f { centerX, centerY }, radiusX, radiusY } {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ struct Point2f
|
|||||||
{
|
{
|
||||||
Point2f( );
|
Point2f( );
|
||||||
explicit Point2f( float x, float y );
|
explicit Point2f( float x, float y );
|
||||||
|
//Point2f(int x, int y); //Stupid fix for it giving an error
|
||||||
|
|
||||||
float x;
|
float x;
|
||||||
float y;
|
float y;
|
||||||
@@ -27,6 +28,7 @@ struct Rectf
|
|||||||
{
|
{
|
||||||
Rectf( );
|
Rectf( );
|
||||||
explicit Rectf( float left, float bottom, float width, float height );
|
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 left;
|
||||||
float bottom;
|
float bottom;
|
||||||
|
|||||||
2
Game/Camera.cpp
Normal file
2
Game/Camera.cpp
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
#include "pch.h"
|
||||||
|
#include "Camera.h"
|
||||||
10
Game/Camera.h
Normal file
10
Game/Camera.h
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
class Camera
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
@@ -1,8 +1,11 @@
|
|||||||
#include "pch.h"
|
#include "pch.h"
|
||||||
#include "Game.h"
|
#include "Game.h"
|
||||||
|
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
Game::Game(const Window& window)
|
Game::Game(const Window& window)
|
||||||
: BaseGame { window } {
|
: BaseGame { window }
|
||||||
|
{
|
||||||
Initialize();
|
Initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -11,27 +14,34 @@ Game::~Game() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Game::Initialize() {
|
void Game::Initialize() {
|
||||||
|
m_WorldLevel = WorldLevel();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::Cleanup() {
|
void Game::Cleanup() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::Update(float elapsedSec) {
|
void Game::Update(float elapsedSec) {
|
||||||
// Check keyboard state
|
const Uint8 *pStates = SDL_GetKeyboardState( nullptr );
|
||||||
//const Uint8 *pStates = SDL_GetKeyboardState( nullptr );
|
if ( pStates[SDL_SCANCODE_RIGHT] ) {
|
||||||
//if ( pStates[SDL_SCANCODE_RIGHT] )
|
m_CameraOffset.x += 100 * elapsedSec;
|
||||||
//{
|
}
|
||||||
// std::cout << "Right arrow key is down\n";
|
if ( pStates[SDL_SCANCODE_LEFT] ) {
|
||||||
//}
|
m_CameraOffset.x -= 100 * elapsedSec;
|
||||||
//if ( pStates[SDL_SCANCODE_LEFT] && pStates[SDL_SCANCODE_UP])
|
}
|
||||||
//{
|
|
||||||
// std::cout << "Left and up arrow keys are down\n";
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::Draw() const {
|
void Game::Draw() const {
|
||||||
ClearBackground();
|
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) {
|
void Game::ProcessKeyDownEvent(const SDL_KeyboardEvent& e) {
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "BaseGame.h"
|
#include "BaseGame.h"
|
||||||
|
#include "WorldLevel.h"
|
||||||
|
#include "WorldTile.h"
|
||||||
|
|
||||||
class Game : public BaseGame
|
class Game : public BaseGame
|
||||||
{
|
{
|
||||||
@@ -27,4 +31,8 @@ private:
|
|||||||
void Initialize();
|
void Initialize();
|
||||||
void Cleanup();
|
void Cleanup();
|
||||||
void ClearBackground() const;
|
void ClearBackground() const;
|
||||||
|
|
||||||
|
|
||||||
|
Point2f m_CameraOffset{0, 0};
|
||||||
|
WorldLevel m_WorldLevel;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -147,13 +147,21 @@ xcopy "$(SolutionDir)Resources\*.*" "$(TargetDir)" /y /d /s</Command>
|
|||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ClCompile Include="Camera.cpp" />
|
||||||
<ClCompile Include="Game.cpp" />
|
<ClCompile Include="Game.cpp" />
|
||||||
|
<ClCompile Include="Level.cpp" />
|
||||||
<ClCompile Include="main.cpp" />
|
<ClCompile Include="main.cpp" />
|
||||||
<ClCompile Include="pch.cpp" />
|
<ClCompile Include="pch.cpp" />
|
||||||
|
<ClCompile Include="WorldLevel.cpp" />
|
||||||
|
<ClCompile Include="WorldTile.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ClInclude Include="Camera.h" />
|
||||||
<ClInclude Include="Game.h" />
|
<ClInclude Include="Game.h" />
|
||||||
|
<ClInclude Include="Level.h" />
|
||||||
<ClInclude Include="pch.h" />
|
<ClInclude Include="pch.h" />
|
||||||
|
<ClInclude Include="WorldLevel.h" />
|
||||||
|
<ClInclude Include="WorldTile.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
<ImportGroup Label="ExtensionTargets">
|
<ImportGroup Label="ExtensionTargets">
|
||||||
|
|||||||
10
Game/Level.cpp
Normal file
10
Game/Level.cpp
Normal 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
16
Game/Level.h
Normal 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
25
Game/WorldLevel.cpp
Normal 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
17
Game/WorldLevel.h
Normal 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
14
Game/WorldTile.cpp
Normal 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
25
Game/WorldTile.h
Normal 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;
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user