PGE Engine
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros Pages
lvl_base_object.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 BASE_OBJECT_H
20 #define BASE_OBJECT_H
21 
22 #include <common_features/rectf.h>
23 #include <common_features/pointf.h>
24 #include <common_features/pge_texture.h>
25 
26 #include <QVector>
27 #ifdef __APPLE__
28 #include <tgmath.h>
29 #endif
30 
32 {
33  float min_vel_x;
34  float min_vel_y;
35  float max_vel_x;
36  float max_vel_y;
37  float decelerate_x;
38  float grd_dec_x;
39  float decelerate_y;
40  float gravityScale;
41  float gravityAccel;
43 };
44 
45 class LVL_Section;
46 class LVL_Block;
52 {
53 public:
55  virtual ~PGE_Phys_Object();
56  virtual double posX();
57  virtual double posY();
58  double posCenterX();
59  double posCenterY();
60  double width();
61  double height();
62 
63  double top();
64  void setTop(double tp);
65  double bottom();
66  void setBottom(double btm);
67  double left();
68  void setLeft(double lf);
69  double right();
70  void setRight(double rt);
71 
72  void setSize(float w, float h);
73  void setWidth(float w);
74  void setHeight(float h);
75 
76  virtual void setPos(double x, double y);
77  void setPosX(double x);
78  void setPosY(double y);
79  void setCenterPos(double x, double y);
80  void setCenterX(double x);
81  void setCenterY(double y);
82 
83  double speedX();
84  double speedY();
85  double speedXsum();
86  double speedYsum();
87  void setSpeed(double x, double y);
88  void setSpeedX(double x);
89  void setSpeedY(double y);
90  void setDecelX(double x);
91  void applyAccel(double x, double y);
92 
93  double gravityScale();
94  void setGravityScale(double scl);
95  float gravityAccel();
96  void setGravityAccel(float acl);
97 
98  void _syncPosition();
99  void _syncPositionAndSize();
100  void _syncSection();
101  void renderDebug(float _camX, float _camY);
102 
103  void iterateStep(float ticks);
104  virtual void updateCollisions();
105  virtual void solveCollision(PGE_Phys_Object *collided);
106  double colliding_xSpeed;
107  double colliding_ySpeed;
108 
109  bool collided_slope;
110  float collided_slope_angle_ratio;
111  bool collided_slope_celling;
112  float collided_slope_angle_ratio_celling;
113 
114  enum Slopes{
115  SLOPE_LEFT=-1,
116  SLOPE_RIGHT=1
117  };
118 
119  PGE_Phys_Object *nearestBlock(QVector<PGE_Phys_Object *> &blocks);
120  PGE_Phys_Object *nearestBlockY(QVector<PGE_Phys_Object *> &blocks);
121  bool isWall(QVector<PGE_Phys_Object *> &blocks);
122  bool isFloor(QVector<PGE_Phys_Object *> &blocks, bool *isCliff=0);
123 
124  static const float _smbxTickTime;
125  static float SMBXTicksToTime(float ticks);
126 
129  double _accelX;
130  double _accelY;
131 
132  double _velocityX;
133  double _velocityY;
134 
137 
138  double _velocityX_add;
139  double _velocityY_add;
140 
141  double _posX;
142  double _posY;
143 
144  double _width;
145  double _height;
146  double _width_half;
147  double _height_half;
148 
149  double _realWidth;
150  double _realHeight;
151 
152  void setParentSection(LVL_Section* sct);
153  LVL_Section* sct();
154  LVL_Section *_parentSection;
155 
156  int type;
157 
158  enum CollisionType{
159  COLLISION_NONE = 0,
160  COLLISION_ANY = 1,
161  COLLISION_TOP = 2,
162  COLLISION_BOTTOM = 3
163  };
164 
165  int collide_player;
166  int collide_npc;
167 
168  bool slippery_surface;
169  bool isRectangle;
170 
171  PGE_Texture texture;
172  GLuint texId;
173  virtual GLdouble zIndex();
174  GLdouble z_index;
175 
176  /**************************Layer member****************************/
177  virtual void show();
178  virtual void hide();
179  virtual bool isVisible();
180  bool _is_visible;
181  /******************************************************************/
182 
183 public:
184 
185  enum types
186  {
187  LVLUnknown=0,
188  LVLBlock,
189  LVLBGO,
190  LVLNPC,
191  LVLPlayer,
192  LVLEffect,
193  LVLWarp,
194  LVLSpecial,
195  LVLPhysEnv
196  };
197 
198  virtual void update();
199  virtual void update(float ticks);
200  virtual void render(double x, double y);
201 
202  bool isPaused();
203  void setPaused(bool p);
204 private:
205  bool _paused;
206 
207 };
208 
209 
210 
211 bool operator< (const PGE_Phys_Object& lhs, const PGE_Phys_Object& rhs);
212 bool operator> (const PGE_Phys_Object& lhs, const PGE_Phys_Object& rhs);
213 
214 #endif // BASE_OBJECT_H
double posCenterX()
Centered Position X.
Definition: lvl_base_object.cpp:92
double posCenterY()
Centered Position Y.
Definition: lvl_base_object.cpp:97
Definition: pge_texture.h:32
double _width
Synchronized with R-Tree Width.
Definition: lvl_base_object.h:144
double _velocityX_prev
X speed before last itertion step (pixels per 1/65 of second)
Definition: lvl_base_object.h:135
double _velocityY_add
additional Y acceleration
Definition: lvl_base_object.h:139
double _velocityY_prev
Y speed before last itertion step (pixels per 1/65 of second)
Definition: lvl_base_object.h:136
virtual double posX()
Position X.
Definition: lvl_base_object.cpp:82
double _posY
Synchronized with R-Tree position.
Definition: lvl_base_object.h:142
float decelerate_y
Deceleration of Y velocity in each second.
Definition: lvl_base_object.h:39
double _width_half
Half of width.
Definition: lvl_base_object.h:146
double _velocityX_add
additional X acceleration
Definition: lvl_base_object.h:138
double _realWidth
Width prepared to synchronize with R-Tree.
Definition: lvl_base_object.h:149
float max_vel_x
Max allowed X velocity.
Definition: lvl_base_object.h:35
PGE_RectF posRect
Real body geometry and position.
Definition: lvl_base_object.h:128
PGE_Phys_Object_Phys phys_setup
Settings of physics.
Definition: lvl_base_object.h:127
float gravityAccel
Item gravity acceleration.
Definition: lvl_base_object.h:41
float grd_dec_x
Soft deceleration if max X speed limit exited.
Definition: lvl_base_object.h:38
float gravityScale
Item specific gravity scaling.
Definition: lvl_base_object.h:40
double _velocityY
current Y speed (pixels per 1/65 of second)
Definition: lvl_base_object.h:133
double _posX
Synchronized with R-Tree position.
Definition: lvl_base_object.h:141
double _height
Synchronized with R-Tree Height.
Definition: lvl_base_object.h:145
Definition: lvl_section.h:34
double _realHeight
Height prepared to synchronize with R-Tree.
Definition: lvl_base_object.h:150
Definition: lvl_block.h:31
Definition: rectf.h:26
float max_vel_y
Max allowed Y velocity.
Definition: lvl_base_object.h:36
virtual double posY()
Position Y.
Definition: lvl_base_object.cpp:87
double _accelX
Delta of X velocity in a second.
Definition: lvl_base_object.h:129
double _velocityX
current X speed (pixels per 1/65 of second)
Definition: lvl_base_object.h:132
float decelerate_x
Deceleration of X velocity in each second.
Definition: lvl_base_object.h:37
double _accelY
Delta of Y velocity in a second.
Definition: lvl_base_object.h:130
float min_vel_y
Min allowed Y velocity.
Definition: lvl_base_object.h:34
The PGE_Phys_Object class.
Definition: lvl_base_object.h:51
float min_vel_x
Min allowed X velocity.
Definition: lvl_base_object.h:33
double _height_half
Half of height.
Definition: lvl_base_object.h:147
Definition: lvl_base_object.h:31