The Game Engine  1
WorldObject.h
Go to the documentation of this file.
1 #ifndef __WORLDOBJECT_H__
2 #define __WORLDOBJECT_H__
3 #include "fns.h"
4 #include "CollisionObject.h"
5 
6 // predeclared for build
7 class CollisionObject;
8 
20 {
21 public:
22  WorldObject(std::string name, Point2D pos = Point2D(), int z = 0);
23 
34  };
35 
39  virtual void draw() = 0;
40 
44  virtual void drawCollisions();
45 
49  void drawCollisions(vector<CollisionObject*>& vec, const Point2D& pos);
50 
55  virtual void update();
56 
60  virtual void runBehavior();
61 
65  void setPosition(double x, double y) {mPos.x = x; mPos.y = y;}
66 
70  void setPosition(Point2D pos) { mPos = pos; }
71 
75  void setBasePosition(double x, double y) {Point2D bPos = getBasePos(); mPos.x = x - bPos.x; mPos.y = y - bPos.y;}
76 
80  void setBasePosition(Point2D pos) {Point2D bPos = getBasePos(); mPos.x = pos.x - bPos.x; mPos.y = pos.y - bPos.y;}
81 
85  void setCenterPosition(double x, double y) {Point2D cPos = getCenterPos(); mPos.x = x - cPos.x; mPos.y = y - cPos.y;}
86 
90  void setCenterPosition(Point2D pos) {Point2D cPos = getCenterPos(); mPos.x = pos.x - cPos.x; mPos.y = pos.y - cPos.y;}
91 
97  void move(double dx=0.0, double dy=0.0){mPos.x+=dx; mPos.y+=dy;}
98 
103  virtual void move(Point2D direction) { mPos += direction; }
104 
109  virtual void moveTowards(Point2D direction);
110 
114  Point2D getPosition() { return mPos; }
115 
120  void setTransparency(float f) { mTransparency = f>1?1:f<0?0:f;}
121 
125  float getTransparency() {return mTransparency;}
126 
131  void setAngle(float a) { mAngle = a; while(a>360)a-=360;}
132 
136  float getAngle() {return mAngle;}
137 
142  void setVelocity(Point2D vel) {
143  mVelocity = vel;
144  if(mMaxVelocity < vel){
145  setMaxVelocity(vel);
146  }
147  }
148 
154  void setVelocity(double xVel, double yVel) {
155  mVelocity.x = xVel;
156  mVelocity.y = yVel;
157  if(mMaxVelocity < mVelocity){
159  }
160  }
161 
166 
171  void setMaxVelocity(Point2D vel) { mMaxVelocity = vel; }
172 
178  void setMaxVelocity(double vel, Point2D dir) {
179  mMaxVelocity = dir.unitVec();
180  mMaxVelocity *= vel;
181  }
182 
187  void setMaxSpeed(double vel) {
188  if(abs(mMaxVelocity.lengthSquared()) < numeric_limits<double>::epsilon()){//if the velocity is 0
189  mMaxSpeed = vel;
190  }
191  else{
193  }
194  }
195 
200 
204  double getMaxSpeed();
205 
209  double getMaxSpeedSquared();
210 
215  void setAcceleration(Point2D accel) { mAcceleration = accel; }
216 
221 
222  void setZOrder(int i) { ZOrder=i; }
223  int getZOrder() { return ZOrder; }
224 
228  std::string getName() { return mName; }
229 
233  bool operator<(WorldObject &rhs) { return ZOrder == rhs.getZOrder() ? getBasePos().y < rhs.getBasePos().y : ZOrder < rhs.getZOrder(); }
234 
238  virtual Point2D getBasePos() = 0;
239 
243  virtual Point2D getCenterPos() = 0;
244 
248  virtual WorldObjectType getType() = 0;
249 
250 protected:
252  std::string mName;
260  double mMaxSpeed;
264  bool mVisible;
268  float mAngle;
270  float mScale;
272  int ZOrder;
276  long mLastDraw;
278  bool mUnused;
281 };
282 #endif