Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // A class representing any in-game object.
- // TODO: (?) add "drawIn(SomeKindOfGraphicsContext)" method.
- // TODO: (?) add "getCollisionMesh()" method.
- class Entity
- {
- public:
- // Apply a transformation (translation + rotation) in a 2D coordinatable.
- // TODO: (?) add "bool applyRotation = true" parameter.
- virtual void applyTransformIn(EntityCoordinatable2D * c2d) const = 0;
- // Apply a translation in a 2D coordinatable.
- // TODO: (?) deprecate, replace by "applyTransformIn(c2d, false)".
- virtual void applyTranslateIn(EntityCoordinatable2D * c2d) const = 0;
- // Get the current coordinate of this entity. Might be calculated if there
- // is a movement active.
- virtual const EntityCoordinate2D getCoordinate() const = 0;
- // Get the dimension of this entity.
- virtual EntityDimension2D getDimension() const = 0;
- // Get the current orientation of this entity. Might be calculated if there
- // is an angular motion active.
- virtual const EntityTheta1D getOrientation() const = 0;
- // Increment the time of this entity by milliseconds.
- virtual void incrementTime(unsigned int time) = 0;
- // Get whether this entity is solid and should be checked for collisions
- // with other entities non-solid entities.
- // TODO: (?) Deprecate. Replace by "getCollisionMesh()".
- virtual const bool isSolid() const = 0;
- // Draw this entity using the current OpenGL context. Transform is not
- // applied prior to drawing. Use "applyTransformIn(GLCoordinatable2D)" to
- // apply transform to the GL context prior to drawing the entity.
- // TODO: (?) Deprecate, replace by "drawIn(SomeKindOfGraphicsContext)".
- virtual void drawInGL() const = 0;
- // Deconstructor
- virtual ~Entity(){};
- };
- // A class representing a movable ingame object.
- class MovableEntity: public Entity
- {
- private:
- // The last known determined coordinate of this entity before the start of
- // any kind of applicable motion. Coordination is measured in points.
- EntityCoordinate2D coordinate;
- // The last known determined orientation of this entity before the start of
- // ant kind of applicable motion. Orientation is measured in radians.
- EntityTheta1D orientation;
- // The current velocity of the entity. The angle is relative to the angle
- // of the entity, which is relative to the world. Speed is measured in
- // points per second. Rotation is measured in radians per second.
- EntityVelocity2D velocity;
- // The current speed of the angular movement, in radians per second.
- EntityTheta1D angularSpeed;
- // The motion-duration of the current velocity and rotation in milliseconds.
- EntityTime motionDuration;
- private:
- // A method to apply the new coordinate and orientation based on the current
- // active motion (velocity and angular speed) and motion duration.
- // properties "coordinate" and "orientation" will be updated and property
- // "motionDuration" will be reset to 0.
- // This method doesn't affect the "velocity" and "angularSpeed" properties.
- void applyMotion();
- protected:
- // Construct a new entity based on a coordinate and an orientation.
- MovableEntity(EntityCoordinate2D coordinate = EntityCoordinate2D(0,0),
- EntityTheta1D orientation = EntityTheta1D(0));
- // Set the velocity of this entity. The actual velocity applied might be
- // differend due the max speed in the requested direction of this entity.
- void setVelocity(EntityVelocity2D velocity);
- // Set the angular speed of this entity. The actual speed applied might
- // be differend due the max angular speed of this entity.
- void setAngularSpeed(EntityTheta1D speed);
- // Get the maximum speed of this entity in a certain direction.
- virtual EntityCoordinate1D getMaxSpeedInDirection(EntityTheta1D theta) = 0;
- // Get the maxmimum angular speed of this entity.
- virtual EntityTheta1D getMaxAngularSpeed() = 0;
- public:
- // Get the current coordinate of this entity. Might be calculated if there
- // is a movement active.
- virtual const EntityCoordinate2D getCoordinate() const;
- // Get the current orientation of this entity. Might be calculated if there
- // is an angular motion active.
- virtual const EntityTheta1D getOrientation() const;
- // Increment the time of this entity by milliseconds.
- virtual void incrementTime(unsigned int time);
- // Get the speed of the angular motion of this entity.
- inline const EntityTheta1D getAngularSpeed() const
- {return this->angularSpeed;}
- // Get the velocity of this entity.
- inline const EntityVelocity2D getVelocity() const
- {return this->velocity;}
- // Apply a transformation (translation + rotation) in a 2D coordinatable.
- virtual void applyTransformIn(EntityCoordinatable2D * c2d) const;
- // Apply a translation in a 2D coordinatable.
- virtual void applyTranslateIn(EntityCoordinatable2D * c2d) const;
- // Deconstructor
- virtual ~MovableEntity(){};
- };
- // A class representing a "smart" movable entity which could control itself
- // based on controller input.
- // TODO: add methods to receive paths from a path-finder.
- class Unit: public MovableEntity
- {
- private:
- // The health of this unit.
- Health health;
- protected:
- // Increment (or Decrement) the health of this unit. Actual applied
- // increment might be differend due the maximum health limit of this unit.
- inline void incrementHealth(int increment)
- {this->setHealth(this->health+increment);}
- // Set the health of this unit. The actual health applied might be differend
- // due the maximum health limit of this unit.
- inline void setHealth(Health health)
- {this->health = between<Health>(health, 0, this->getMaxHealth());}
- public:
- // Get the max health of this unit.
- virtual Health getMaxHealth() const = 0;
- // Get the owner of this unit, or NULL if this unit is un-owned (neutral).
- // TODO: Create "Owner" class and update return-type.
- virtual void * getOwner() const = 0;
- // Get the health of this unit.
- inline Health getHealth()
- {return this->health;}
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement