Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Engine/Board.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "Board.h"

Board::Board(int in_width, int in_height)
:
width(in_width),
height(in_height)
{
}

void Board::DrawCell(const Vei2& gridPos, Graphics& gfx, Color c)
{
gfx.DrawRectDim(gridPos * cellSize, cellSize, cellSize, c);
}
17 changes: 17 additions & 0 deletions Engine/Board.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once

#include "Graphics.h"
#include "Vei2.h"
#include "Colors.h"

class Board
{
public:
Board(int in_width, int in_height);
void DrawCell(const Vei2& gridPos, Graphics& gfx, Color c);
private:
Color c;
static constexpr int cellSize = 15;
int width;
int height;
};
16 changes: 11 additions & 5 deletions Engine/Engine.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,32 @@
<PropertyGroup Label="Globals">
<ProjectGuid>{FFCA512B-49FC-4FC8-8A73-C4F87D322FF2}</ProjectGuid>
<RootNamespace>Engine</RootNamespace>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
Expand Down Expand Up @@ -136,6 +136,7 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="Board.h" />
<ClInclude Include="ChiliException.h" />
<ClInclude Include="ChiliWin.h" />
<ClInclude Include="Colors.h" />
Expand All @@ -146,11 +147,14 @@
<ClInclude Include="Keyboard.h" />
<ClInclude Include="MainWindow.h" />
<ClInclude Include="Mouse.h" />
<ClInclude Include="Player.h" />
<ClInclude Include="Resource.h" />
<ClInclude Include="Sound.h" />
<ClInclude Include="SoundEffect.h" />
<ClInclude Include="Vei2.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="Board.cpp" />
<ClCompile Include="COMInitializer.cpp" />
<ClCompile Include="DXErr.cpp" />
<ClCompile Include="Game.cpp" />
Expand All @@ -159,7 +163,9 @@
<ClCompile Include="Main.cpp" />
<ClCompile Include="MainWindow.cpp" />
<ClCompile Include="Mouse.cpp" />
<ClCompile Include="Player.cpp" />
<ClCompile Include="Sound.cpp" />
<ClCompile Include="Vei2.cpp" />
</ItemGroup>
<ItemGroup>
<FxCompile Include="FramebufferPS.hlsl">
Expand Down
18 changes: 18 additions & 0 deletions Engine/Engine.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@
<ClInclude Include="COMInitializer.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Board.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Vei2.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Player.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="DXErr.cpp">
Expand Down Expand Up @@ -86,6 +95,15 @@
<ClCompile Include="COMInitializer.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Board.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Vei2.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Player.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<FxCompile Include="FramebufferPS.hlsl">
Expand Down
14 changes: 14 additions & 0 deletions Engine/FrameTimer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "FrameTimer.h"

FrameTimer::FrameTimer()
{
last = std::chrono::steady_clock::now();
}

float FrameTimer::GetDeltaTime()
{
std::chrono::steady_clock::time_point current = std::chrono::steady_clock::now();
std::chrono::duration<float> deltaTime = current - last;
last = current;
return deltaTime.count();
}
12 changes: 12 additions & 0 deletions Engine/FrameTimer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

#include <chrono>

class FrameTimer
{
public:
FrameTimer();
float GetDeltaTime();
private:
std::chrono::steady_clock::time_point last;
};
31 changes: 29 additions & 2 deletions Engine/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
Game::Game( MainWindow& wnd )
:
wnd( wnd ),
gfx( wnd )
gfx( wnd ),
brd(20, 20),
player({2, 1})
{
}

Expand All @@ -38,8 +40,33 @@ void Game::Go()

void Game::UpdateModel()
{
if (wnd.kbd.KeyIsPressed(VK_RIGHT) && !rightPressed)
{
rightPressed = true;
playerDelta_Loc = { 1, 0 };
player.MoveBy(playerDelta_Loc);
}
if (wnd.kbd.KeyIsPressed(VK_LEFT) && !leftPressed)
{
leftPressed = true;
playerDelta_Loc = { -1, 0 };
player.MoveBy(playerDelta_Loc);
}
if (wnd.kbd.KeyIsPressed(VK_DOWN) && !downPressed)
{
downPressed = true;
playerDelta_Loc = { 0, 1 };
player.MoveBy(playerDelta_Loc);
}
if (wnd.kbd.KeyIsPressed(VK_UP) && !upPressed)
{
upPressed = true;
playerDelta_Loc = { 0, -1 };
player.MoveBy(playerDelta_Loc);
}
}

void Game::ComposeFrame()
{
}
player.Draw(brd, gfx, Colors::Green);
}
16 changes: 10 additions & 6 deletions Engine/Game.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
#include "Keyboard.h"
#include "Mouse.h"
#include "Graphics.h"
#include "Board.h"
#include "Vei2.h"
#include "Player.h"

class Game
{
Expand All @@ -34,13 +37,14 @@ class Game
private:
void ComposeFrame();
void UpdateModel();
/********************************/
/* User Functions */
/********************************/
private:
MainWindow& wnd;
Graphics gfx;
/********************************/
/* User Variables */
/********************************/
Board brd;
Player player;
Vei2 playerDelta_Loc = { 0, 0 };
bool rightPressed = false;
bool leftPressed = false;
bool upPressed = false;
bool downPressed = false;
};
11 changes: 11 additions & 0 deletions Engine/Graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,17 @@ void Graphics::PutPixel( int x,int y,Color c )
pSysBuffer[Graphics::ScreenWidth * y + x] = c;
}

void Graphics::DrawRectDim(Vei2 pos, int width, int height, Color c)
{
for (int y0 = pos.y; y0 < pos.y + height; y0++)
{
for (int x0 = pos.x; x0 < pos.x + width; x0++)
{
PutPixel(x0, y0, c);
}
}
}


//////////////////////////////////////////////////
// Graphics Exception
Expand Down
2 changes: 2 additions & 0 deletions Engine/Graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <wrl.h>
#include "ChiliException.h"
#include "Colors.h"
#include "Vei2.h"

class Graphics
{
Expand Down Expand Up @@ -57,6 +58,7 @@ class Graphics
PutPixel( x,y,{ unsigned char( r ),unsigned char( g ),unsigned char( b ) } );
}
void PutPixel( int x,int y,Color c );
void DrawRectDim(Vei2 pos, int width, int height, Color c);
~Graphics();
private:
Microsoft::WRL::ComPtr<IDXGISwapChain> pSwapChain;
Expand Down
16 changes: 16 additions & 0 deletions Engine/Player.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include "Player.h"

Player::Player(const Vei2& in_pos)
{
pos = in_pos;
}

void Player::Draw(Board& brd, Graphics& gfx, Color c) const
{
brd.DrawCell(pos, gfx, c);
}

void Player::MoveBy(const Vei2& delta_loc)
{
pos += delta_loc;
}
16 changes: 16 additions & 0 deletions Engine/Player.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

#include "Vei2.h"
#include "Board.h"
#include "Colors.h"

class Player
{
public:
Player(const Vei2& in_pos);
void Draw(Board& brd, Graphics& gfx, Color c) const;
void MoveBy(const Vei2& delta_loc);
private:
Vei2 pos;
Color c;
};
20 changes: 20 additions & 0 deletions Engine/Vei2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "Vei2.h"

Vei2::Vei2(int x, int y)
:
x(x),
y(y)
{
}

Vei2& Vei2::operator+=(const Vei2& rhs)
{
x += rhs.x;
y += rhs.y;
return *this;
}

const Vei2 Vei2::operator*(int val) const
{
return Vei2(x * val, y * val);
}
13 changes: 13 additions & 0 deletions Engine/Vei2.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

class Vei2
{
public:
Vei2() = default;
Vei2(int x, int y);
Vei2& operator += (const Vei2& rhs);
const Vei2 operator * (int val) const;
public:
int x;
int y;
};