Wizard Engine
2D cross-platform game engine built around SDL2
 
Loading...
Searching...
No Matches
sprite.hpp
Go to the documentation of this file.
1/*
2 Wizard Engine
3 Copyright (C) 2023-2024 Zana Domán
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20*/
21
22#ifndef WIZARD_ENGINE_SPRITE_HPP
23#define WIZARD_ENGINE_SPRITE_HPP
24
31
32namespace wze {
38class sprite final : public renderable, public animatable, public component {
39 private:
40 float _x;
41 float _y;
42 float _z;
43 float _angle;
44 float _width;
45 float _height;
46 bool _spatial;
47 std::shared_ptr<wze::texture> _texture;
48 uint8_t _color_r;
49 uint8_t _color_g;
50 uint8_t _color_b;
51 uint8_t _color_a;
52 enum flip _flip;
53 bool _visible;
54 uint8_t _priority;
55 bool _animated;
56 float _x_offset;
57 float _y_offset;
58 float _angle_offset;
59 bool _attach_x;
60 bool _attach_y;
61 bool _attach_angle;
62 bool _x_angle_lock;
63 bool _y_angle_lock;
64
65 public:
72 [[nodiscard]] float x() const final;
73
80 void set_x(float x) final;
81
88 [[nodiscard]] float y() const final;
89
96 void set_y(float y) final;
97
105 [[nodiscard]] float z() const final;
106
114 void set_z(float z);
115
122 [[nodiscard]] float angle() const final;
123
130 void set_angle(float angle) final;
131
138 [[nodiscard]] float width() const final;
139
146 void set_width(float width);
147
154 [[nodiscard]] float height() const final;
155
162 void set_height(float height);
163
170 [[nodiscard]] bool spatial() const final;
171
178 void set_spatial(bool spatial);
179
186 [[nodiscard]] std::shared_ptr<wze::texture> const& texture() const final;
187
194 void set_texture(std::shared_ptr<wze::texture> const& texture) final;
195
202 [[nodiscard]] uint8_t color_r() const final;
203
210 void set_color_r(uint8_t color_r);
211
218 [[nodiscard]] uint8_t color_g() const final;
219
226 void set_color_g(uint8_t color_g);
227
234 [[nodiscard]] uint8_t color_b() const final;
235
242 void set_color_b(uint8_t color_b);
243
250 [[nodiscard]] uint8_t color_a() const final;
251
258 void set_color_a(uint8_t color_a);
259
266 [[nodiscard]] enum flip flip() const final;
267
274 void set_flip(enum flip flip);
275
282 [[nodiscard]] bool visible() const final;
283
290 void set_visible(bool visible);
291
298 [[nodiscard]] uint8_t priority() const final;
299
306 void set_priority(uint8_t priority);
307
314 [[nodiscard]] bool animated() const final;
315
322 void set_animated(bool animated);
323
330 [[nodiscard]] float x_offset() const final;
331
338 void set_x_offset(float x_offset);
339
346 [[nodiscard]] float y_offset() const final;
347
354 void set_y_offset(float y_offset);
355
362 [[nodiscard]] float angle_offset() const final;
363
370 void set_angle_offset(float angle_offset);
371
378 [[nodiscard]] bool attach_x() const final;
379
386 void set_attach_x(bool attach_x);
387
394 [[nodiscard]] bool attach_y() const final;
395
402 void set_attach_y(bool attach_y);
403
410 [[nodiscard]] bool attach_angle() const final;
411
418 void set_attach_angle(bool attach_angle);
419
426 [[nodiscard]] bool x_angle_lock() const final;
427
434 void set_x_angle_lock(bool x_angle_lock);
435
442 [[nodiscard]] bool y_angle_lock() const final;
443
450 void set_y_angle_lock(bool y_angle_lock);
451
481 explicit sprite(float x = 0, float y = 0, float z = 0, float angle = 0,
482 float width = 0, float height = 0, bool spatial = false,
483 std::shared_ptr<wze::texture> const& texture = {},
484 uint8_t color_r = std::numeric_limits<uint8_t>::max(),
485 uint8_t color_g = std::numeric_limits<uint8_t>::max(),
486 uint8_t color_b = std::numeric_limits<uint8_t>::max(),
487 uint8_t color_a = std::numeric_limits<uint8_t>::max(),
488 enum flip flip = FLIP_NONE, bool visible = true,
489 uint8_t priority = std::numeric_limits<uint8_t>::max() / 2,
490 bool animated = true, float x_offset = 0,
491 float y_offset = 0, float angle_offset = 0,
492 bool attach_x = true, bool attach_y = true,
493 bool attach_angle = true, bool x_angle_lock = true,
494 bool y_angle_lock = true);
495};
496} /* namespace wze */
497
498#endif /* WIZARD_ENGINE_SPRITE_HPP */
Animatable interface.
Image file in host memory.
Animatable interface.
bool animated() const final
Gets whether the object should be animated.
Definition sprite.cpp:147
void set_texture(std::shared_ptr< wze::texture > const &texture) final
Sets the wze::texture of the object.
Definition sprite.cpp:87
Interface to make an object composable.
Enumerations.
Export header of the Wizard Engine.
Wizard Engine.
flip
Flips.
Definition enums.hpp:37
Interface to make an object renderable.