TazGraph Project v0.1.0
Loading...
Searching...
No Matches
MovingAnimation.h
1#pragma once
2
3#include "Animation.h"
4#include <vector>
5#include <glm/glm.hpp>
6#include <stdexcept>
7
8class MovingAnimation : public Animation //todo moving animation can be moving sprite with of without transform
9{
10public:
11 // have a vector for the positions
12 // when given only dx and dy then add that to the same vector as first element
13 // sprite will check bool if it is about continious
14 std::vector<glm::vec2> positions; // Stores the positions for the animation
15 std::vector<int> zIndices; // zIndex for each position
16 std::vector<int> rotations;
17
19 {
20
21 }
22 // ix,iy is initial position (destX, destY), f is total frames to move, s is the speed to move frames, type as in animation, dx,dy distance to move
23 MovingAnimation(int ix, int iy, int f, float s, const std::string _type, int dx, int dy, int _reps = 0) : Animation(ix, iy, f, s, _type) // Animation frames look the next number of frames from the index
24 {
25 positions.clear();
26 zIndices.clear();
27 rotations.clear();
28
29 glm::vec2 distanceXY(dx, dy);
30 positions.push_back(distanceXY);
31 zIndices.push_back(0);
32 rotations.push_back(0);
33
34 reps = _reps;
35 }
36
37 MovingAnimation(int ix, int iy, int f, float s, const animType _type, int dx, int dy, int _reps = 0) : Animation(ix, iy, f, s, _type) // Animation frames look the next number of frames from the index
38 {
39 positions.clear();
40 zIndices.clear();
41 rotations.clear();
42
43 glm::vec2 distanceXY(dx, dy);
44 positions.push_back(distanceXY);
45 zIndices.push_back(0);
46 rotations.push_back(0);
47
48 reps = _reps;
49 }
50
52 int ix, int iy, int f, float s, const std::string _type, const std::vector<glm::vec2>& _positions, const std::vector<int>& _zIndices, const std::vector<int>& _rotations, int _reps = 0) // Animation frames look the next number of frames from the index
53 {
54 positions.clear();
55 zIndices.clear();
56 rotations.clear();
57
58 positions = _positions;
59 zIndices = _zIndices;
60 rotations = _rotations;
61
62 Animation(ix, iy, positions.size(), s, _type);
63
64 reps = _reps;
65 validateVectors();
66 }
67
69 int ix, int iy, size_t f, float s, const animType _type, const std::vector<glm::vec2>& _positions, const std::vector<int>& _zIndices, const std::vector<int>& _rotations, int _reps = 0) // Animation frames look the next number of frames from the index
70 {
71 positions.clear();
72 zIndices.clear();
73 rotations.clear();
74
75 positions = _positions;
76 zIndices = _zIndices;
77 rotations = _rotations;
78
79 Animation(ix, iy, positions.size(), s, _type);
80
81 reps = _reps;
82 validateVectors();
83 }
84
85private:
86 void validateVectors() const {
87 // Ensure all vectors are of the same length to prevent indexing errors
88 if (positions.size() != zIndices.size() || positions.size() != rotations.size()) {
89 throw std::invalid_argument("All vectors (positions, zIndices, rotations) must have the same length.");
90 }
91 }
92};
Definition MovingAnimation.h:9
Definition Animation.h:6