summary refs log tree commit diff stats
path: root/src/sprite.h
blob: e0cff0ccf048373fec36b3aa38bbf7cae41eb8a8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#ifndef SPRITE_H_70503825
#define SPRITE_H_70503825

#include <deque>
#include <map>
#include <string_view>
#include <vector>
#include "direction.h"
#include "renderer.h"
#include "vector.h"
#include "step_type.h"

enum class SpriteLayer {
  Normal,
  Above
};

struct SpriteFrame {
  SDL_Rect srcRect;
  vec2i center;
  vec2i size;
};

struct Animation {
  bool looping = true;
  std::vector<int> frameIndices;
};

enum class CharacterState {
  Still,
  Walking,
  Crouching,
  Running
};

struct Movement {
  vec2i pos;
  Direction dir;
};

class Sprite {
public:

  std::string alias;
  bool persistent = false;

  // Transform
  vec2i loc { 0, 0 };
  SpriteLayer layer = SpriteLayer::Normal;
  bool collidable = false;
  bool solid = false;
  vec2i collisionOffset;
  vec2i collisionSize;
  std::string interactionScript;
  std::string walkthroughScript;
  std::string enclosureZone;

  // Animation
  bool isAnimated = false;
  std::string spritesheet;
  Direction dir = Direction::down;
  std::string animationName = "still";
  int animationId = 0;
  int animationFrame = 0;
  std::vector<SpriteFrame> frames;
  std::vector<Animation> animations;
  std::map<std::string, std::map<Direction, int>> nameDirToAnim;
  bool animFinished = false;
  bool hasShadow = false;

  // Character
  bool orientable = false;
  std::vector<int> followers;
  std::deque<Movement> trail;
  CharacterState characterState = CharacterState::Still;
  StepType stepType = StepType::none;
  int runningSfxChannel = -1;

  // Input
  bool controllable = false;
  bool player = false;

  // Behaviour
  bool wander = false;
};

#endif /* end of include guard: SPRITE_H_70503825 */