PGE Engine
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros Pages
lvl_player.h
1 /*
2  * Platformer Game Engine by Wohlstand, a free platform for game making
3  * Copyright (c) 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 LVL_PLAYER_H
20 #define LVL_PLAYER_H
21 
22 #include "lvl_camera.h"
23 #include "lvl_warp.h"
24 #include "lvl_npc.h"
25 
26 #include "lvl_base_object.h"
27 #include <controls/controllable_object.h>
28 #include <data_configs/obj_player.h>
29 #include <common_features/matrix_animator.h>
31 #include <common_features/event_queue.h>
32 
33 #include <QHash>
34 #include <QVector>
35 
36 class LVL_Section;
37 class LVL_Block;
38 
39 class LVL_Player :
40  public PGE_Phys_Object,
41  public ControllableObject
42 {
43  public:
44  LVL_Player();
45  virtual ~LVL_Player();
46  void setCharacter(int CharacterID, int _stateID);
47  void setCharacterSafe(int CharacterID, int _stateID);
48  private:
49  bool _doSafeSwitchCharacter;
50  public:
51  void setPlayerPointInfo(PlayerPoint pt);
52  void init();
53  void update(float ticks);
54  void updateCamera();
55 
56  void refreshEnvironmentState();
57 
58  void updateCollisions();
59  void solveCollision(PGE_Phys_Object *collided);
61  float _heightDelta; //Delta of changing height. Need to protect going through block on character switching
62 
63  /*****************NPC's and blocks******************/
64  typedef QHash<int, PGE_Phys_Object*> PlayerColliders;
65  QHash<int, PGE_Phys_Object*> collided_top;
66  QHash<int, PGE_Phys_Object*> collided_left;
67  QHash<int, PGE_Phys_Object*> collided_right;
68  QHash<int, PGE_Phys_Object*> collided_bottom;
69  QHash<int, PGE_Phys_Object*> collided_center;
70  LVL_Npc * collided_talkable_npc;
71  bool _stucked;
72  /***************************************************/
73 
74  int playerID;
75  obj_player setup;
76  PlayerPoint data;
78 
79  void teleport(float x, float y);
80  void exitFromLevel(QString levelFile, int targetWarp, long wX=-1, long wY=-1);
81 
82  QHash<int, obj_player_state > states;
83  int characterID;
84  int stateID;
85  obj_player_state state_cur;
86 
87 
88  enum kill_npc_reasons
89  {
90  NPC_Unknown=-1,
91  NPC_Stomped=0,
92  NPC_Kicked,
93  NPC_Taked_Coin,
94  NPC_Taked_Powerup
95  };
96 
97  void kill_npc(LVL_Npc*target, kill_npc_reasons reason);
98  //QQueue<LVL_Npc*> npc_queue;
99 
100  /*******************Environmept*********************/
101  QHash<int, obj_player_physics > physics;
102  QHash<int, int > environments_map;
103 
104  obj_player_physics physics_cur;
105  int environment;
106  int last_environment;
107  /*******************Environmept*********************/
108 
109  /*******************Motion*************************/
110  bool isRunning();
111  bool _isRunning;
112 
113  int direction();
114  int _direction;
115  /*******************Motion*************************/
116 
117  /*******************Life and Death*****************/
118  bool isAlive;
119  enum deathReason
120  {
121  DEAD_fall=0,
122  DEAD_burn,
123  DEAD_killed
124  };
125  void kill(deathReason reason=DEAD_killed);
126  void unregister();
127 
128  bool doKill;
129  deathReason kill_reason;
130 
131  int health;
132  bool invincible;
133  float invincible_delay;
134  bool blink_screen;
135  bool blink_screen_state;
136  bool doHarm;
137  int doHarm_damage;
138  void harm(int _damage=1);
139  void setInvincible(bool state, float delay, bool enableScreenBlink=false);
140  /*******************Life and Death*****************/
141 
143 
144  /********************Jumps***************************/
145  bool JumpPressed;
146  bool onGround();
147  bool _onGround;
148  bool on_slippery_surface;
149  QHash<intptr_t, PGE_Phys_Object* > foot_contacts_map;
150  QHash<intptr_t, PGE_Phys_Object* > foot_sl_contacts_map;
151  float jumpTime;
152  float jumpVelocity;
153  /********************Jumps***************************/
154 
155  /********************Bump***************************/
156  bool bumpDown;
157  bool bumpUp;
159  float bumpJumpVelocity;
161  void bump(bool _up=false, double bounceSpeed=0.0, int timeToJump=0);
162  inline void bumpf(bool _up, float bounceSpeed=0.0f, int timeToJump=0)
163  {
164  bump(_up, (double)bounceSpeed, timeToJump);
165  }
166  /********************Bump***************************/
167 
168  /********************Climbing***************************/
169  QHash<intptr_t, PGE_Phys_Object* > climbable_map;
170  bool climbing;
171  double climbableHeight;
172  /********************Climbing***************************/
173 
174  /*******************Warps*********************/
175  bool contactedWithWarp;
176  LVL_Warp * contactedWarp;
177  bool wasEntered;
178  int wasEnteredTimeout;
179  bool isWarping;
180 
181  int warpDirectO;
182  float warpPipeOffset;
183  float warpFrameW;
184  float warpFrameH;
185 
186  EventQueue<LVL_Player > event_queue;
187  void processWarpChecking();
188  void WarpTo(float x, float y, int warpType, int warpDirection=1);
189  void WarpTo(LevelDoor warp);
190  /*******************Warps*********************/\
191 
192  /******************floating*******************/
193  bool floating_allow;
194  bool floating_isworks;
195  float floating_timer;
196  float floating_maxtime;
198  /******************floating*******************/
199 
200  /******************Attack*******************/
201  /*This feature will provide teporary ability to break any nearest blocks*/
202  enum AttackDirection
203  {
204  Attack_Forward=0,
205  Attack_Up,
206  Attack_Down
207  };
208  bool attack_enabled;
209  bool attack_pressed;
210  void attack(AttackDirection _dir);
211  /******************Attack*******************/
212 
213  /************************************************
214  __
215  /` ,\__
216  | ).-'
217  / .--'
218  / /
219  , _.==''` \
220  .'( _.=' |
221  { `` _.=' |
222  { \` ; /
223  `. `'=..' .='
224  `=._ .='
225  duck '-`\\`__
226  `-._{
227  ************************************************/
228  bool duck_allow;
229  bool ducking;
230  void setDuck(bool duck);
231 private:
232  void _collideUnduck();
233  /******************Duck*************************/
235 public:
236  void render(double camX, double camY);
237  MatrixAnimator animator;
238  int frameW;
239  int frameH;
240  bool locked();
241  void setLocked(bool lock);
242  bool isExiting;
243  int _exiting_swimTimer;
244 
245  /********************Lua Stuff*******************
246  .-""""-
247  F .-'
248  F J
249  I I
250  L `.
251  L `-._,
252  `-.__.-'
253  ***********************************************/
254  virtual void lua_onLoop(){}
255  bool isLuaPlayer;
256  /********************Lua Stuff******************/
257 
258  bool isInited();
259 
260 private:
261  bool _no_render;
262  bool isLocked;
263  bool _isInited;
264  void refreshAnimation();
265 };
266 
267 #endif // LVL_PLAYER_H
bool forceCollideCenter
collide with invizible blocks at center
Definition: lvl_player.h:60
Definition: lvl_camera.h:36
void update(float ticks)
Definition: lvl_player_update.cpp:27
Provides controller input interface for a physical objects (for example, playable characters) ...
Definition: controllable_object.h:30
QHash< intptr_t, PGE_Phys_Object * > foot_contacts_map
staying on ground surfaces
Definition: lvl_player.h:149
Level specific Warp entry structure. Defines preferences of each Warp entry.
Definition: lvl_filedata.h:231
Definition: obj_player.h:103
Definition: obj_player.h:31
QHash< intptr_t, PGE_Phys_Object * > foot_sl_contacts_map
Slipery surfaces.
Definition: lvl_player.h:150
float bumpVelocity
down velocity
Definition: lvl_player.h:158
bool floating_start_type
true= sin(time), false= cos(time)
Definition: lvl_player.h:197
Definition: lvl_section.h:34
Definition: lvl_player.h:39
LVL_Player()
Definition: lvl_player.cpp:22
Definition: lvl_block.h:31
PGE_LevelCamera * camera
Connected camera.
Definition: lvl_player.h:77
Definition: lvl_npc.h:21
void setCharacter(int CharacterID, int _stateID)
Definition: lvl_player_setup.cpp:48
PGE File Library.
float gscale_Backup
BackUP of last gravity scale.
Definition: lvl_player.h:142
void WarpTo(float x, float y, int warpType, int warpDirection=1)
Definition: lvl_player_warps_and_teleports.cpp:139
int bumpJumpTime
Up jump velocity.
Definition: lvl_player.h:160
Definition: obj_player.h:75
Definition: matrix_animator.h:40
The PGE_Phys_Object class.
Definition: lvl_base_object.h:51
Level specific Player spawn point entry definition structure.
Definition: lvl_filedata.h:76
Definition: lvl_warp.h:25