remove example rendering

This commit is contained in:
Eero Holmala 2023-04-24 16:33:31 +03:00
parent 4e1b5e0dea
commit b9806c9334
7 changed files with 104 additions and 58 deletions

View File

@ -3,6 +3,48 @@
"xstring": "cpp",
"xutility": "cpp",
"map": "cpp",
"vector": "cpp"
"vector": "cpp",
"algorithm": "cpp",
"atomic": "cpp",
"bit": "cpp",
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"compare": "cpp",
"concepts": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"exception": "cpp",
"initializer_list": "cpp",
"ios": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"iterator": "cpp",
"limits": "cpp",
"memory": "cpp",
"new": "cpp",
"ostream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"typeinfo": "cpp",
"utility": "cpp",
"xfacet": "cpp",
"xiosbase": "cpp",
"xlocale": "cpp",
"xlocinfo": "cpp",
"xlocnum": "cpp",
"xmemory": "cpp",
"xstddef": "cpp",
"xtr1common": "cpp",
"xtree": "cpp"
}
}

View File

@ -16,7 +16,7 @@ App::App(int width, int height) :
m_WindowHeight, m_WindowHeight, 0);
// Initialize grid. Look at this transposed.
auto pair = std::pair<SDL_Rect, TEXTURE>();
std::pair<SDL_Rect, TEXTURE> pair = std::pair<SDL_Rect, TEXTURE>();
pair.second = WALL;
m_Grid = {
{ pair, pair, pair, pair, pair },
@ -26,8 +26,9 @@ App::App(int width, int height) :
{ pair, pair, pair, pair, pair }
};
m_Grid[0][0].second = NONE;
// m_Grid[0][0].second = NONE;
m_Board = std::make_shared<Board>();
// triggers the program that controls
// your graphics hardware and sets flags
@ -51,25 +52,6 @@ App::App(int width, int height) :
SDL_FreeSurface(symbol_x_surface);
SDL_FreeSurface(symbol_o_surface);
// let us control our image position
// so that we can move it with our keyboard.
SDL_Rect dest;
SDL_Rect dest2;
// connects our texture with dest to control position
SDL_QueryTexture(m_Textures[TTT::WALL], NULL, NULL, &dest.w, &dest.h);
SDL_QueryTexture(m_Textures[TTT::SYMBOL_O], NULL, NULL, &dest2.w, &dest2.h);
// adjust height and width of our image box.
// dest.w /= 6;
// dest.h /= 6;
// sets initial x-position of object
dest.x = (m_WindowWidth - dest.w) / 2;
dest2.x = (m_WindowWidth - dest2.w) / 2;
// sets initial y-position of object
dest.y = (m_WindowHeight - dest.h) / 2;
dest2.y = (m_WindowHeight - dest2.h) / 2;
DrawGrid();
// speed of box
@ -105,46 +87,21 @@ App::App(int width, int height) :
break;
case SDL_SCANCODE_W:
case SDL_SCANCODE_UP:
dest.y -= speed / 30;
break;
case SDL_SCANCODE_A:
case SDL_SCANCODE_LEFT:
dest.x -= speed / 30;
break;
case SDL_SCANCODE_S:
case SDL_SCANCODE_DOWN:
dest.y += speed / 30;
break;
case SDL_SCANCODE_D:
case SDL_SCANCODE_RIGHT:
dest.x += speed / 30;
break;
default:
break;
}
}
}
// right boundary
if (dest.x + dest.w > 1000)
dest.x = 1000 - dest.w;
// left boundary
if (dest.x < 0)
dest.x = 0;
// bottom boundary
if (dest.y + dest.h > 1000)
dest.y = 1000 - dest.h;
// upper boundary
if (dest.y < 0)
dest.y = 0;
// clears the screen
SDL_RenderClear(m_Renderer);
SDL_RenderCopy(m_Renderer, m_Textures[TTT::WALL], NULL, &dest);
SDL_RenderCopy(m_Renderer, m_Textures[TTT::SYMBOL_O], NULL, &dest2);
GridRenderCopy();
// triggers the double buffers
@ -181,9 +138,8 @@ void App::DrawGrid()
// m_Grid[i][j].first.x = (m_WindowWidth - m_Grid[i][j].first.w) / 2;
// m_Grid[i][j].first.y = (m_WindowHeight - m_Grid[i][j].first.h) / 2;
m_Grid[i][j].first.w = CELL_WIDTH;
m_Grid[i][j].first.h = CELL_HEIGHT;
m_Grid[i][j].first.w = CELL_WIDTH/8;
m_Grid[i][j].first.h = CELL_HEIGHT/8;
m_Grid[i][j].first.x = m_Grid[i][j].first.w * i;
m_Grid[i][j].first.y = m_Grid[i][j].first.h * j;
}

View File

@ -7,17 +7,14 @@
#include <map>
#include <vector>
#include <memory>
#include "Typedef.hh"
#include "Board.hh"
namespace TTT
{
enum TEXTURE {
NONE,
WALL,
SYMBOL_X,
SYMBOL_O
};
class App
{
private:
@ -31,6 +28,7 @@ private:
SDL_Surface* m_Surface;
std::map<TEXTURE,SDL_Texture*> m_Textures;
std::vector<std::vector<std::pair<SDL_Rect, TEXTURE>>> m_Grid;
std::shared_ptr<Board> m_Board;
public:
App(int width, int height);

18
TTT/Board.cpp Normal file
View File

@ -0,0 +1,18 @@
#include "Board.hh"
namespace TTT
{
Board::Board()
{
m_Grid = {
{},
};
}
Board::~Board()
{
}
} // namespace TTT

19
TTT/Board.hh Normal file
View File

@ -0,0 +1,19 @@
#pragma once
#include <vector>
#include "Typedef.hh"
namespace TTT
{
class Board
{
private:
std::vector<std::vector<TEXTURE>> m_Grid;
public:
Board();
~Board();
};
} // namespace TTT

View File

@ -5,7 +5,7 @@ find_package(SDL2 CONFIG REQUIRED)
find_package(SDL2_image CONFIG REQUIRED)
find_package(sdl2-gfx CONFIG REQUIRED)
add_executable(Tic-Tac-Toe main.cpp App.cpp App.hh)
add_executable(Tic-Tac-Toe main.cpp App.cpp App.hh Board.cpp Board.hh Typedef.hh)
target_link_libraries(Tic-Tac-Toe
PRIVATE

13
TTT/Typedef.hh Normal file
View File

@ -0,0 +1,13 @@
#pragma once
namespace TTT
{
enum TEXTURE {
NONE,
WALL,
SYMBOL_X,
SYMBOL_O
};
} // namespace TTT