PGE Engine
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros Pages
npc_animator.h
1 /*
2  * Platformer Game Engine by Wohlstand, a free platform for game making
3  * Copyright (c) 2014-2015 Vitaly Novichkov <admin@wohlnet.ru>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef NPC_ANIMATOR_H
20 #define NPC_ANIMATOR_H
21 
22 #include <QList>
23 #include <QString>
24 
25 #include <SDL2/SDL_timer.h>
26 #include <utility>
27 
28 #include <common_features/sizef.h>
29 #include <data_configs/obj_npc.h>
30 
31 typedef std::pair<double, double > AniPos;
32 
34 {
35 public:
37  AdvNpcAnimator(PGE_Texture &sprite, obj_npc &config);
38  void construct(PGE_Texture &sprite, obj_npc &config);
39  ~AdvNpcAnimator();
40 
41  AniPos image(int dir, int frame=-1);
42  AniPos wholeImage();
43 
44  enum CustomAnimationAlgorithms
45  {
46  ANI_DefaultSequence=0,
47  ANI_FrameJump=1,
48  ANI_CustomSequence=2
49  };
50 
51  void setSequenceL(QList<int> _frames);
52  void setSequenceR(QList<int> _frames);
53  void setSequence(QList<int> _frames);
54 
55  void setFrameL(int y);
56  void setFrameR(int y);
57 
58  int frameSpeed();
59  void setFrameSpeed(int ms);
60  void setBidirectional(bool bid);
61  void setDirectedSequence(bool dd);
62  void setOnceMode(bool en);
63  bool animationFinished();
64  PGE_SizeF sizeOfFrame();
65 
66  void start();
67  void stop();
68 
69  void manualTick(int ticks);
70 
71 private:
72  bool isValid;
73  void nextFrame();
74  obj_npc setup;
75 
76  PGE_Texture mainImage;
77 
78  QList<AniPos> frames;
79 
80  int manual_ticks;
81  bool onceMode;
82  bool _animationFinished;
83 
84  bool isEnabled;
85  SDL_TimerID timer_id;
86 
87  void createAnimationFrames();
88 
89  bool animated;
90 
91  int _frameSpeed;
92  int frameStyle;
93 
94  bool aniBiDirect;
95  int frameStep;
96 
97  bool customAnimate;
98  int customAniAlg; //custom animation algorythm 0 - forward, 1 - frameJump
99  int custom_frameFL;//first left
100  int custom_frameEL;//end left / jump step
101  int custom_frameFR;//first right
102  int custom_frameER;//enf right / jump step
103 
104  bool frameSequance;
105 
106  QList<int> frames_listL; //Current frame srquence
107  QList<int> frames_listR; //Current frame srquence
108 
109  int framesQ;
110  double frameSize; // size of one frame
111  double frameWidth; // sprite width
112  double frameHeight; //sprite height
113 
114  //Animation alhorithm
115  bool aniDirectL;
116  bool aniDirectR;
117 
118  int CurrentFrameL;
119  int CurrentFrameR;
120 
121  int frameCurrentL;
122  int frameCurrentR;
123 
124  int frameFirstL;
125  int frameLastL;
126 
127  int frameFirstR;
128  int frameLastR;
129 
130 };
131 
132 #endif // NPC_ANIMATOR_H
Definition: pge_texture.h:32
Definition: sizef.h:23
Definition: npc_animator.h:33
Definition: obj_npc.h:34