Line data Source code
1 : #ifndef rendersystem_hpp
2 : #define rendersystem_hpp
3 :
4 : #include <stdint.h>
5 :
6 : #include "entity.h"
7 : #include "system.h"
8 : #include "termbox.h"
9 : #include "util.h"
10 :
11 : enum class RenderLayer {
12 : Ground,
13 : GroundCover,
14 : Particles,
15 : MobBelow,
16 : Mob,
17 : MobAbove,
18 : };
19 :
20 2618 : class Sprite : public Component {
21 : public:
22 : vec2i position{0, 0};
23 : RenderLayer renderLayer{RenderLayer::Ground};
24 :
25 : // Colour
26 : uint16_t fg = TB_WHITE;
27 : uint16_t bg = TB_BLACK;
28 :
29 : // Animation
30 : std::string frames{};
31 : bool animated = false;
32 : int frame = 0;
33 : int frameRate = 1;
34 : int frameCounter = 0;
35 :
36 : // Effects
37 : int flashTimer = 0;
38 :
39 5 : Sprite() = default;
40 497 : Sprite(std::string frames, bool animated, int frameRate, uint16_t fg, uint16_t bg,
41 : vec2i position, RenderLayer layer)
42 497 : : frames(frames), position(position), animated(animated), frameRate(frameRate), fg(fg),
43 497 : bg(bg), renderLayer(layer) {
44 497 : if (animated) {
45 369 : frame = randInt(0, 1);
46 369 : frameCounter = randInt(0, frameRate);
47 : }
48 497 : }
49 : };
50 :
51 : class Game;
52 5 : class RenderSystem : public System {
53 : public:
54 : RenderSystem(Game& game);
55 : void update() final;
56 0 : void handleEvent(const EvAny&) final {}
57 :
58 : void render();
59 :
60 : protected:
61 : void renderGround();
62 : void renderOcean();
63 :
64 : protected:
65 : Game& game_;
66 : int32_t tick_ = 0;
67 : Array2D<int32_t> randomArray2D_;
68 : };
69 :
70 : #endif /* rendersystem_hpp */
|