summary refs log tree commit diff stats
path: root/src/sprite.h
blob: 5e8003bec7572025a71996909dc518912156b453 (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
#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 setWalking(bool walking);

  void tickAnim();

private:

  void updateAnimation();

  int textureId_;
  vec2i loc_ { 0, 0 };
  vec2i size_;
  Direction curDir_ = Direction::down;
  bool isWalking_ = false;
  int curAnim_ = 0;
  int curFrame_ = 0;
  std::vector<std::vector<int>> animations_;
  std::map<Direction, int> stillAnims_;
  std::map<Direction, int> walkingAnims_;
};

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