Bomberman Multiplayer
Authoritative multiplayer networking layer for Bomberman.
Loading...
Searching...
No Matches
Object.h
1#ifndef _BOMBERMAN_ENTITIES_OBJECT_H_
2#define _BOMBERMAN_ENTITIES_OBJECT_H_
3
4#include <SDL.h>
5#include <memory>
6
7namespace bomberman
8{
13 class Object
14 {
15 public:
21 Object(SDL_Renderer* renderer);
26 virtual ~Object();
33 void setSize(const int width, const int height);
40 void setPosition(const int x, const int y);
47 void setPositionF(const float x, const float y);
56 void setClip(const int width, const int height, const int x, const int y);
62 void attachToCamera(bool isAttached = true);
66 void setVisible(bool isVisible);
70 [[nodiscard]]
71 bool isVisible() const;
77 int getWidth() const;
83 int getHeight() const;
89 int getPositionX() const;
95 int getPositionY() const;
101 float getPositionXF() const;
107 float getPositionYF() const;
113 const SDL_Rect& getRect() const;
119 SDL_FRect getRectF() const;
125 void setFlip(SDL_RendererFlip flip);
129 void setColorMod(Uint8 r, Uint8 g, Uint8 b);
135 virtual void update(const unsigned int delta);
141 void draw(const SDL_Rect& camera) const;
142
143 protected:
144 SDL_Renderer* renderer = nullptr; // SDL2 renderer
145 std::shared_ptr<SDL_Texture> texture = nullptr; // SDL2 texture
146 SDL_Rect rect; // size and position of texture on the screen
147 SDL_Rect clip; // what part of texture to draw on the screen
148 SDL_RendererFlip flipping = SDL_FLIP_NONE; // flip of texture
149 float positionX = 0.0f; // precise position X
150 float positionY = 0.0f; // precise position Y
151 Uint8 colorModR = 0xFF; // texture color modulation R
152 Uint8 colorModG = 0xFF; // texture color modulation G
153 Uint8 colorModB = 0xFF; // texture color modulation B
154
155 private:
156 bool isAttachedToCamera = true; // follow to camera
157 bool visible = true; // draw object when true
158 };
159} // namespace bomberman
160
161#endif // _BOMBERMAN_ENTITIES_OBJECT_H_
Base class for objects.
Definition Object.h:14
int getPositionX() const
Get the Position X of object (integer)
Definition Object.cpp:69
bool isVisible() const
Returns whether this object is currently drawable.
Definition Object.cpp:54
virtual void update(const unsigned int delta)
Update object.
Definition Object.cpp:116
void attachToCamera(bool isAttached=true)
Attach object to camera movement.
Definition Object.cpp:44
SDL_FRect getRectF() const
Get Rect of object (float position)
Definition Object.cpp:94
void setPosition(const int x, const int y)
Set the Position of object (integer)
Definition Object.cpp:23
float getPositionYF() const
Get the Position Y of object (float)
Definition Object.cpp:84
void setVisible(bool isVisible)
Toggle whether this object should currently be drawn.
Definition Object.cpp:49
virtual ~Object()
Destroy the object.
Definition Object.cpp:15
float getPositionXF() const
Get the Position X of object (float)
Definition Object.cpp:79
void setColorMod(Uint8 r, Uint8 g, Uint8 b)
Set texture color modulation applied during draw.
Definition Object.cpp:109
const SDL_Rect & getRect() const
Get Rect of object.
Definition Object.cpp:89
void setSize(const int width, const int height)
Set the Size of object.
Definition Object.cpp:17
int getPositionY() const
Get the Position Y of object (integer)
Definition Object.cpp:74
int getWidth() const
Get the Width of object.
Definition Object.cpp:59
int getHeight() const
Get the Height of object.
Definition Object.cpp:64
void setFlip(SDL_RendererFlip flip)
Set the Flip object.
Definition Object.cpp:104
void setClip(const int width, const int height, const int x, const int y)
Set the Clip of source texture.
Definition Object.cpp:36
void draw(const SDL_Rect &camera) const
Draw object on the screen.
Definition Object.cpp:118
void setPositionF(const float x, const float y)
Set the Position of object (float/sub-pixel)
Definition Object.cpp:28