diff --git a/Engine/Board.cpp b/Engine/Board.cpp new file mode 100644 index 00000000..9b69a8c0 --- /dev/null +++ b/Engine/Board.cpp @@ -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); +} \ No newline at end of file diff --git a/Engine/Board.h b/Engine/Board.h new file mode 100644 index 00000000..a62ee1c6 --- /dev/null +++ b/Engine/Board.h @@ -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; +}; \ No newline at end of file diff --git a/Engine/Engine.vcxproj b/Engine/Engine.vcxproj index c6e66c51..f1dfa506 100644 --- a/Engine/Engine.vcxproj +++ b/Engine/Engine.vcxproj @@ -21,32 +21,32 @@ {FFCA512B-49FC-4FC8-8A73-C4F87D322FF2} Engine - 8.1 + 10.0 Application true - v140 + v143 Unicode Application false - v140 + v143 true Unicode Application true - v140 + v143 Unicode Application false - v140 + v143 true Unicode @@ -136,6 +136,7 @@ + @@ -146,11 +147,14 @@ + + + @@ -159,7 +163,9 @@ + + diff --git a/Engine/Engine.vcxproj.filters b/Engine/Engine.vcxproj.filters index 2026aaba..8ceaf89c 100644 --- a/Engine/Engine.vcxproj.filters +++ b/Engine/Engine.vcxproj.filters @@ -57,6 +57,15 @@ Header Files + + Header Files + + + Header Files + + + Header Files + @@ -86,6 +95,15 @@ Source Files + + Source Files + + + Source Files + + + Source Files + diff --git a/Engine/FrameTimer.cpp b/Engine/FrameTimer.cpp new file mode 100644 index 00000000..3538f006 --- /dev/null +++ b/Engine/FrameTimer.cpp @@ -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 deltaTime = current - last; + last = current; + return deltaTime.count(); +} \ No newline at end of file diff --git a/Engine/FrameTimer.h b/Engine/FrameTimer.h new file mode 100644 index 00000000..7ef79edb --- /dev/null +++ b/Engine/FrameTimer.h @@ -0,0 +1,12 @@ +#pragma once + +#include + +class FrameTimer +{ +public: + FrameTimer(); + float GetDeltaTime(); +private: + std::chrono::steady_clock::time_point last; +}; \ No newline at end of file diff --git a/Engine/Game.cpp b/Engine/Game.cpp index dbdb5218..fe61de65 100644 --- a/Engine/Game.cpp +++ b/Engine/Game.cpp @@ -24,7 +24,9 @@ Game::Game( MainWindow& wnd ) : wnd( wnd ), - gfx( wnd ) + gfx( wnd ), + brd(20, 20), + player({2, 1}) { } @@ -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); +} \ No newline at end of file diff --git a/Engine/Game.h b/Engine/Game.h index 1702e223..3ab397a0 100644 --- a/Engine/Game.h +++ b/Engine/Game.h @@ -23,6 +23,9 @@ #include "Keyboard.h" #include "Mouse.h" #include "Graphics.h" +#include "Board.h" +#include "Vei2.h" +#include "Player.h" class Game { @@ -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; }; \ No newline at end of file diff --git a/Engine/Graphics.cpp b/Engine/Graphics.cpp index bdff4ebf..7d8421ce 100644 --- a/Engine/Graphics.cpp +++ b/Engine/Graphics.cpp @@ -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 diff --git a/Engine/Graphics.h b/Engine/Graphics.h index 9a44e3fe..7818ab23 100644 --- a/Engine/Graphics.h +++ b/Engine/Graphics.h @@ -24,6 +24,7 @@ #include #include "ChiliException.h" #include "Colors.h" +#include "Vei2.h" class Graphics { @@ -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 pSwapChain; diff --git a/Engine/Player.cpp b/Engine/Player.cpp new file mode 100644 index 00000000..d0916d38 --- /dev/null +++ b/Engine/Player.cpp @@ -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; +} \ No newline at end of file diff --git a/Engine/Player.h b/Engine/Player.h new file mode 100644 index 00000000..31682e2c --- /dev/null +++ b/Engine/Player.h @@ -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; +}; \ No newline at end of file diff --git a/Engine/Vei2.cpp b/Engine/Vei2.cpp new file mode 100644 index 00000000..965b6184 --- /dev/null +++ b/Engine/Vei2.cpp @@ -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); +} \ No newline at end of file diff --git a/Engine/Vei2.h b/Engine/Vei2.h new file mode 100644 index 00000000..36d73c58 --- /dev/null +++ b/Engine/Vei2.h @@ -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; +}; \ No newline at end of file