Advertisement
Guest User

Untitled

a guest
Oct 29th, 2010
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.32 KB | None | 0 0
  1. // A class representing any in-game object.
  2. // TODO: (?) add "drawIn(SomeKindOfGraphicsContext)" method.
  3. // TODO: (?) add "getCollisionMesh()" method.
  4. class Entity
  5. {    
  6. public:
  7.    
  8.     // Apply a transformation (translation + rotation) in a 2D coordinatable.
  9.     // TODO: (?) add "bool applyRotation = true" parameter.
  10.     virtual void applyTransformIn(EntityCoordinatable2D * c2d) const = 0;
  11.    
  12.     // Apply a translation in a 2D coordinatable.
  13.     // TODO: (?) deprecate, replace by "applyTransformIn(c2d, false)".
  14.     virtual void applyTranslateIn(EntityCoordinatable2D * c2d) const = 0;
  15.    
  16.     // Get the current coordinate of this entity. Might be calculated if there
  17.     // is a movement active.
  18.     virtual const EntityCoordinate2D getCoordinate() const = 0;
  19.    
  20.     // Get the dimension of this entity.
  21.     virtual EntityDimension2D getDimension() const = 0;
  22.    
  23.     // Get the current orientation of this entity. Might be calculated if there
  24.     // is an angular motion active.
  25.     virtual const EntityTheta1D getOrientation() const = 0;
  26.    
  27.     // Increment the time of this entity by milliseconds.
  28.     virtual void incrementTime(unsigned int time) = 0;
  29.    
  30.     // Get whether this entity is solid and should be checked for collisions
  31.     // with other entities non-solid entities.
  32.     // TODO: (?) Deprecate. Replace by "getCollisionMesh()".
  33.     virtual const bool isSolid() const = 0;
  34.    
  35.     // Draw this entity using the current OpenGL context. Transform is not
  36.     // applied prior to drawing. Use "applyTransformIn(GLCoordinatable2D)" to
  37.     // apply transform to the GL context prior to drawing the entity.
  38.     // TODO: (?) Deprecate, replace by "drawIn(SomeKindOfGraphicsContext)".
  39.     virtual void drawInGL() const = 0;
  40.    
  41.     // Deconstructor
  42.     virtual ~Entity(){};
  43. };
  44.  
  45. // A class representing a movable ingame object.
  46. class MovableEntity: public Entity
  47. {
  48. private:
  49.    
  50.     // The last known determined coordinate of this entity before the start of
  51.     // any kind of applicable motion. Coordination is measured in points.
  52.     EntityCoordinate2D coordinate;
  53.    
  54.     // The last known determined orientation of this entity before the start of
  55.     // ant kind of applicable motion. Orientation is measured in radians.
  56.     EntityTheta1D orientation;
  57.    
  58.     // The current velocity of the entity. The angle is relative to the angle
  59.     // of the entity, which is relative to the world. Speed is measured in
  60.     // points per second. Rotation is measured in radians per second.
  61.     EntityVelocity2D velocity;
  62.    
  63.     // The current speed of the angular movement, in radians per second.
  64.     EntityTheta1D angularSpeed;
  65.    
  66.     // The motion-duration of the current velocity and rotation in milliseconds.
  67.     EntityTime motionDuration;
  68.    
  69. private:
  70.    
  71.     // A method to apply the new coordinate and orientation based on the current
  72.     // active motion (velocity and angular speed) and motion duration.
  73.     // properties "coordinate" and "orientation" will be updated and property
  74.     // "motionDuration" will be reset to 0.
  75.     // This method doesn't affect the "velocity" and "angularSpeed" properties.
  76.     void applyMotion();
  77.    
  78. protected:
  79.    
  80.     // Construct a new entity based on a coordinate and an orientation.
  81.     MovableEntity(EntityCoordinate2D coordinate = EntityCoordinate2D(0,0),
  82.                   EntityTheta1D orientation = EntityTheta1D(0));
  83.    
  84.     // Set the velocity of this entity. The actual velocity applied might be
  85.     // differend due the max speed in the requested direction of this entity.
  86.     void setVelocity(EntityVelocity2D velocity);
  87.    
  88.     // Set the angular speed of this entity. The actual speed applied might
  89.     // be differend due the max angular speed of this entity.
  90.     void setAngularSpeed(EntityTheta1D speed);
  91.    
  92.     // Get the maximum speed of this entity in a certain direction.
  93.     virtual EntityCoordinate1D getMaxSpeedInDirection(EntityTheta1D theta) = 0;
  94.    
  95.     // Get the maxmimum angular speed of this entity.
  96.     virtual EntityTheta1D getMaxAngularSpeed() = 0;
  97.    
  98. public:
  99.    
  100.     // Get the current coordinate of this entity. Might be calculated if there
  101.     // is a movement active.
  102.     virtual const EntityCoordinate2D getCoordinate() const;
  103.    
  104.     // Get the current orientation of this entity. Might be calculated if there
  105.     // is an angular motion active.
  106.     virtual const EntityTheta1D getOrientation() const;
  107.    
  108.     // Increment the time of this entity by milliseconds.
  109.     virtual void incrementTime(unsigned int time);
  110.    
  111.     // Get the speed of the angular motion of this entity.
  112.     inline const EntityTheta1D getAngularSpeed() const
  113.     {return this->angularSpeed;}
  114.    
  115.     // Get the velocity of this entity.
  116.     inline const EntityVelocity2D getVelocity() const
  117.     {return this->velocity;}
  118.    
  119.     // Apply a transformation (translation + rotation) in a 2D coordinatable.
  120.     virtual void applyTransformIn(EntityCoordinatable2D * c2d) const;
  121.    
  122.     // Apply a translation in a 2D coordinatable.
  123.     virtual void applyTranslateIn(EntityCoordinatable2D * c2d) const;
  124.    
  125.     // Deconstructor
  126.     virtual ~MovableEntity(){};
  127. };
  128.  
  129.  
  130. // A class representing a "smart" movable entity which could control itself
  131. // based on controller input.
  132. // TODO: add methods to receive paths from a path-finder.
  133. class Unit: public MovableEntity
  134. {
  135. private:
  136.    
  137.     // The health of this unit.
  138.     Health health;
  139.  
  140. protected:
  141.    
  142.     // Increment (or Decrement) the health of this unit. Actual applied
  143.     // increment might be differend due the maximum health limit of this unit.
  144.     inline void incrementHealth(int increment)
  145.     {this->setHealth(this->health+increment);}
  146.    
  147.     // Set the health of this unit. The actual health applied might be differend
  148.     // due the maximum health limit of this unit.
  149.     inline void setHealth(Health health)
  150.     {this->health = between<Health>(health, 0, this->getMaxHealth());}
  151.  
  152. public:
  153.    
  154.     // Get the max health of this unit.
  155.     virtual Health getMaxHealth() const = 0;
  156.    
  157.     // Get the owner of this unit, or NULL if this unit is un-owned (neutral).
  158.     // TODO: Create "Owner" class and update return-type.
  159.     virtual void * getOwner() const = 0;
  160.    
  161.     // Get the health of this unit.
  162.     inline Health getHealth()
  163.     {return this->health;}
  164. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement