summary refs log tree commit diff stats
path: root/src/sprite.h
blob: 82ea90cc19558cc45bf80a494488ac2ab11e8892 (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
#ifndef SPRITE_H_70503825
#define SPRITE_H_70503825

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

class Sprite {
public:

  Sprite(std::string_view filename, Renderer& renderer);

  int getTextureId() const {
    return textureId_;
  }

  const vec2i& loc() const { return loc_; }

  vec2i& loc() { return loc_; }

  const vec2i& size() const { return size_; }

  vec2i& size() { return size_; }

  int getFrame() const { return animations_[curAnim_][curFrame_]; }

  void setDirection(Direction dir);

  Direction getDirection() const { return curDir_; }

  void setState(std::string state);

  void tickAnim();

private:

  void updateAnimation();

  int textureId_;
  vec2i loc_ { 0, 0 };
  vec2i size_;
  Direction curDir_ = Direction::down;
  std::string state_;
  int curAnim_ = 0;
  int curFrame_ = 0;
  std::vector<std::vector<int>> animations_;
  std::map<std::string, std::map<Direction, int>> stateDirToAnim_;
};

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