Sandbox 1
Sandbox game that emulates different material physics
Loading...
Searching...
No Matches
classes.hpp
Go to the documentation of this file.
1
13#ifndef CLASSES_H
14#define CLASSES_H
15
16#include <SDL3/SDL_video.h>
17#include <SDL3/SDL_init.h>
18#include <SDL3/SDL_render.h>
19#include <SDL3_ttf/SDL_ttf.h>
20
21#include <cstdint>
22#include <map>
23#include <utility>
24
25
29enum PixelType : uint8_t {
30 SAND
31 ,WATER
32};
33
34
39struct Vector2 {
40 int x;
41 int y;
42
50 if ((x != v.x) || (y != v.y)) {
51 return true;
52 }
53 else {
54 return false;
55 }
56 };
57};
58
59
63struct Pixel {
64 SDL_Color color;
66};
67
68
73typedef std::map<std::pair<int, int>, Pixel> PixelMap;
74
84class World {
85 static World* instance;
86 SDL_Window* window;
87 SDL_Renderer* renderer;
88 TTF_TextEngine* text_renderer;
89 SDL_Texture* texture;
90 TTF_Font* font;
93 SDL_Color bg_color;
94
99 World();
100
113 bool checkIfCanMove(Vector2 pos, PixelMap *new_pixel_map);
114
205 void recalcWorld();
206
210 void addPixel();
211
212public:
213 bool mouse_is_down = false;
215
216 ~World();
217
219 World(const World& obj) = delete;
220
228 static World* getIstance() {
229 if (instance == nullptr) {
230 instance = new World();
231 }
232 return instance;
233 }
234
238 void clearWorld();
239
246 SDL_AppResult initWorld();
247
274 SDL_AppResult redrawWorld();
275};
276
277#endif // CLASSES_H
SDL_Texture * texture
SDL texture.
Definition classes.hpp:89
TTF_TextEngine * text_renderer
TTF engine what is tied to World::renderer to easly render text.
Definition classes.hpp:88
SDL_Window * window
SDL window.
Definition classes.hpp:86
bool checkIfCanMove(Vector2 pos, PixelMap *new_pixel_map)
Checks if position on the screen is avalible for movement.
Definition classes.cpp:137
PixelMap pixel_map
PixelMap what contains all phical object pixels.
Definition classes.hpp:92
SDL_AppResult redrawWorld()
Redraws pixels on the screen, calls recalcWorld() and addPixel().
Definition classes.cpp:213
SDL_AppResult initWorld()
Function what defines World::window, World::texture and World::font.
Definition classes.cpp:63
void clearWorld()
Complitely clears pixel_map.
Definition classes.cpp:58
TTF_Font * font
Fonts that are used for the text on the screen.
Definition classes.hpp:90
PixelType selected_pixel_type
Currently selected PixelType, used in addPixel().
Definition classes.hpp:214
void addPixel()
Adds new pixel to pixel_map in a radius of BRUSH_SPREAD.
Definition classes.cpp:110
void recalcWorld()
Recalculates position of each pixel in pixel_map according to their physic behavior.
Definition classes.cpp:147
static World * getIstance()
Function what returns the worlds instance. If it's nullptr inwokes World().
Definition classes.hpp:228
World(const World &obj)=delete
Remove copy constructor.
Vector2 window_size
Window width and height in pixels devided by PIXEL_SIZE.
Definition classes.hpp:91
bool mouse_is_down
Stores current state of the mouse button, used in redrawWorld() to detect then addPixel() should be i...
Definition classes.hpp:213
static World * instance
Poiner to the one existing instance of the world.
Definition classes.hpp:85
SDL_Color bg_color
Background color of the screen.
Definition classes.hpp:93
SDL_Renderer * renderer
SDL renderer.
Definition classes.hpp:87
World()
Class constructor, here we define World::bg_color and World::selected_pixel_type.
Definition classes.cpp:47
PixelType
Enum that represents pixel type as a physical object.
Definition classes.hpp:29
std::map< std::pair< int, int >, Pixel > PixelMap
Map with key being std::pair<int, int> that represents pixel position in 2D space on the screen,...
Definition classes.hpp:73
Enum that represents pixel type as a physical object.
Definition classes.hpp:63
PixelType type
PixelType.
Definition classes.hpp:65
SDL_Color color
Color of the pixel.
Definition classes.hpp:64
Struct what represends objects position in 2D space.
Definition classes.hpp:39
int y
Y coordinate.
Definition classes.hpp:41
int x
X coordinate.
Definition classes.hpp:40
bool operator!=(Vector2 v)
Compares Vector2's.
Definition classes.hpp:49