Claypool

Courses

Publications

Students

Projects

Service

Downloads

Misc


Dragonfly: GameObject.h Source File
Dragonfly 2.2
A text-based game engine

GameObject.h

00001 ///
00002 /// The base game object.
00003 ///
00004 
00005 #ifndef __GAME_OBJECT_H__
00006 #define __GAME_OBJECT_H__
00007 
00008 #include "Box.h"                ///< Objects have a bounding box.
00009 #include "Event.h"              ///< Objects can handle events.
00010 #include "Object.h"             ///< Base object class.
00011 #include "Position.h"           ///< Objects need a location.
00012 #include "Sprite.h"             ///< Objects (often) have sprites.
00013 
00014 enum Solidness {
00015   HARD,                         ///< Objects cause collision and impede
00016   SOFT,                         ///< Objects cause collision, don't impede
00017   SPECTRAL                      ///< Objects don't cause collision
00018 };
00019 
00020 class GameObject : public Object {
00021 
00022  private:
00023   int altitude;                 ///< -MAX to MAX supported (lower drawn first).
00024   Solidness solidness;          ///< Solidness state of object.
00025 
00026  protected:
00027   float x_velocity;             ///< Horizontal speed in spaces per game step.
00028   float x_velocity_countdown;   ///< Countdown to horizontal movement.
00029   float y_velocity;             ///< Veritical speed in spaces per game step.
00030   float y_velocity_countdown;   ///< Countdown to vertical movement.
00031   
00032  public:
00033   GameObject(int on_level = -1);
00034   virtual ~GameObject();
00035 
00036   bool isSolid();               ///< True if hard or soft, else False
00037 
00038   /// Set object solidness, with checks for consistency.  
00039   /// Return 0 if ok, else -1.
00040   int setSolidness(Solidness new_solid);
00041 
00042   /// Return object altitude.
00043   Solidness getSolidness();
00044 
00045   // Set visibility of object.  Objects not visible are not drawn.
00046   // Return 0 if ok, else -1.
00047   int setVisibility(bool visible);
00048 
00049   // Set persistence of object. Persistent objects are active across all
00050   // levels.  Return 0 if ok, else -1.
00051   int setPersistence(bool persistent);
00052   
00053   /// Set object altitude, with checks for consistency.  
00054   /// Return 0 if ok, else -1.
00055   int setAltitude(int new_altitude);
00056 
00057   /// Return object altitude.
00058   int getAltitude();
00059 
00060   void setXVelocity(float new_x_velocity);
00061   float getXVelocity();
00062   void setYVelocity(float new_y_velocity);
00063   float getYVelocity();
00064 
00065   /// Perform 1 step of velocity in horizontal direction.
00066   /// Return horizontal distance moved this step.
00067   int getXVelocityStep();
00068 
00069   /// Perform 1 step of velocity in vertical direction.
00070   /// Return vertical distance moved this step.
00071   int getYVelocityStep();
00072 };
00073  
00074 #endif // __GAME_OBJECT_H__
 All Classes Functions Variables Friends