The Game Engine  1
WorldObject.cpp
Go to the documentation of this file.
1 #include "WorldObject.h"
2 #include "fns.h"
3 #include <limits>
4 
5  WorldObject::WorldObject(std::string name, Point2D pos, int z ):
6  mName(name),
7  mPos(pos),
8  mAcceleration(),
9  mVelocity(),
10  mMaxVelocity(),
11  mMaxSpeed(0),
12  ZOrder(z),
13  mVisible(true),
14  mTransparency(1),
15  mAngle(0),
16  mScale(1),
17  mLastUpdate(0),
18  mLastDraw(0),
19  mUnused(true),
20  mBehavior(NULL)
21  {
22  setVelocity(0,0);
23  }
24 
26 
28  if(mUnused) return;
29  //is speed != 0
30  if(getMaxSpeedSquared()){
31  //do acceleration
33  if(abs(mMaxSpeed) >= numeric_limits<double>::epsilon()){//to handle when the max velocity is 0 but max speed is > 0 to minimize ops per loop
35  mMaxSpeed=0;
36  }
38  //do velocity
39  mPos += mVelocity;
40  }
41 }
42 
44  if ( mBehavior )
45  mBehavior();
46 }
47 
48 void WorldObject::drawCollisions(vector<CollisionObject*> &vec, const Point2D& pos) {
49  for(unsigned int i=0; i < vec.size(); i++) {
50  vec[i]->draw(pos);
51  }
52 }
53 
55  return abs(mMaxSpeed) < numeric_limits<double>::epsilon() ? mMaxSpeed : mMaxVelocity.length();
56 }
57 
60  return abs(mMaxSpeed) < numeric_limits<double>::epsilon() ? mMaxVelocity.lengthSquared() : mMaxSpeed*mMaxSpeed;
61 }
62 
66 
68 }
69