00001 #ifndef __OBJECT_H 00002 #define __OBJECT_H 00003 00004 #define MISSILE_FIRE_BREAK 2000 00005 #define PLAYER_MISSILE_FIRE_BREAK 500 00006 #define MAX_GUNS 5 /* maximum # of guns attached to game obj */ 00007 00008 /* 00009 * FLAGS 00010 */ 00011 00012 /* Object Component Flags (integrated components in use) */ 00013 00014 #define OBJCOMP_IMM (1<<0) // immunity 00015 #define OBJCOMP_HP (1<<1) // hit points 00016 #define OBJCOMP_VIS (1<<2) // visualization 00017 #define OBJCOMP_PHYS (1<<3) // physics 00018 #define OBJCOMP_PATH (1<<4) // pathing 00019 00020 /* Physics Flags */ 00021 00022 #define PHYS_VEL_ZERO (1<<0) // velocity zeroing 00023 #define PHYS_VEL_DAMPEN (1<<1) // velocity dampening (NOT IMPLMNTD) 00024 #define PHYS_ACC_ZERO (1<<2) // acceleration zeroing 00025 #define PHYS_ACC_DAMPEN (1<<3) // acceleartion dampening (NOT IMPLMNTD) 00026 #define PHYS_GRAV (1<<4) // gravity applied 00027 #define PHYS_TILE_REPEL (1<<5) // repelled from tiles 00028 #define PHYS_TILE_BOUNCE (1<<6) // bounces off tiles 00029 #define PHYS_DRIVE_FACE (1<<7) // drives facing module 00030 00031 /* Pathing Flags */ 00032 00033 #define PATH_REV (1<<0) // going reverse? 00034 #define PATH_ACC_SPEED (1<<1) // auto-accept speed recommendations 00035 #define PATH_LEVEL_REL (1<<2) // path relative level (off: relative pt) 00036 00037 /* Simple Events - events without parameters */ 00038 00039 #define EVT_DIED 0 // obj dies (command as well) 00040 #define EVT_OFFSCRN 1 // obj offscreen 00041 #define EVT_ACTION 2 // time to perform action 00042 #define EVT_CALCDEST 3 // time to calculate destination 00043 #define EVT_MOVEOK 4 // movement was okay, no tile collisions 00044 #define EVT_IMM_ON 5 // immunity on (command as well) 00045 #define EVT_IMM_OFF 6 // immunity off 00046 #define EVT_ANIMEND 7 // animation reached its end 00047 #define EVT_BOUNCE 8 // obj bounced off of something 00048 #define EVT_CHGFACE 9 // obj facing a different direction 00049 #define EVT_FIRST 10 // object constructed, first event. 00050 00051 class Object 00052 { 00053 private: 00054 ObjectInfo *objectinfo; 00055 Animation **animations; 00056 int cur_anim; 00057 int weakness_time_countdown; 00058 int cyclic; 00059 Object* object_bay; 00060 Vector2D pos; 00061 Vector2D dst; 00062 /* Destination Calculated Bit 00063 * 00064 * When an object shadows another object, it needs to know the 00065 * other objects destination. But, we only want to calculate it 00066 * once, so we keep track of whether the destination has been 00067 * calculated or not. 00068 */ 00069 bool dst_calculated; 00070 int comps; 00071 bool died; 00072 GameTimer *game_timer; 00073 ScoreManager *score_manager; 00074 Input *input; 00075 /* this will be dropped this if acces to tile pos from obj will be better */ 00076 Tile *lastcollided; 00077 int phys_flags; 00078 int phys_facing_offset; 00079 Vector2D phys_pos; 00080 Vector2D phys_vel; 00081 Vector2D phys_acc; 00082 Vector2D phys_dst; 00083 /* 00084 * EXTERNAL COMPONENTS 00085 * 00086 */ 00087 /* --- Behaviour --- */ 00088 BehaviourInterface *behaviour; 00089 /* --- Guns --- */ 00090 GunInterface **gun; 00091 /* --- Facing --- */ 00092 FacingInterface *facing; 00093 /* public, but only meant to be changed by Path. */ 00094 /* --- Pathing Variables --- */ 00095 int path_flags; 00096 Path *path_cur; 00097 float path_dist; 00098 Object *path_shdw; 00099 Path *path_backup; 00100 int imm_countdown; 00101 int hp_cur; 00102 bool hp_tiledmg; 00103 public: 00104 /* 00105 * GAME SIMULATION METHODS 00106 * 00107 * METHODS THAT ARE CALLED FROM THE GAME SIMULATION 00108 */ 00109 Object( Vector2D _pos, ObjectInfo *_objectinfo, GameTimer *_timer, 00110 ScoreManager *score_manager, Input *_input ); 00111 ~Object(); 00112 /* --- Notification --- */ 00113 /* "x1S" means "called x1 per cycle while onscreen" */ 00114 void OffScreen(); 00115 void CycleStarts(); 00116 void Action(); 00117 void CalcDestination(); 00118 void Draw( Display *display, int xoffset ); 00119 void MoveOK(); 00120 void CollisionDetected( Tile* ); 00121 void React (Object * o); 00122 /* --- Introspection --- */ 00123 int IsPlayer(); 00124 bool Died() { return died; } 00125 int FlagStatus( int flagpos ); 00126 int GetWidth(); 00127 int GetHeight(); 00128 int GetHealthState(); 00129 int GetNMissiles(); 00130 /* --- Access -- */ 00131 Vector2D GetPosition() { return pos; } 00132 int GetTileX() { return pos.GetTileX(); } 00133 int GetTileY() { return pos.GetTileY(); } 00134 void GetCoords(float *x, float *y) { pos.GetCoords(x,y); } 00135 Vector2D* GetVelocity(); 00136 Vector2D* GetAcceleration(); 00137 Vector2D* GetDestination(); 00138 Animation* GetAnimation(); 00139 ObjectInfo* GetObjectInfo(); 00140 ObjectCell *RemoveObjectCell( ObjectCell *objcell ); 00141 /* --- Interaction --- */ 00142 Object* ObjectBayDetach(); 00143 void Nudge( Vector2D dpos ); 00144 /* --- Pathing Interaction --- */ 00145 void PathRecommendsSpeed( float ); 00146 void PathSignals( int ); 00147 /* --- Bus Messages --- */ 00148 void Dies() {} // will be used later. 00149 /* public, !!BUT!! 00150 * 00151 * for use ONLY by: 00152 * * Object code 00153 * * External components - ex: Behaviour, Gun code 00154 * 00155 * 00156 * INTEGRATED COMPONENTS 00157 * 00158 * Respect Encapsulation! 00159 */ 00160 /* --- Immunity --- */ 00161 void imm_Init(); 00162 bool imm_Status(); 00163 void imm_Event( int ); 00164 /* --- HP --- */ 00165 void hp_Init( bool tiles_damage ); 00166 int hp_Cur(); 00167 void hp_ModifyHealth( int m ); 00168 void hp_Event( int ); 00169 void hp_HitTile( Tile* ); 00170 void hp_HitObj( Object* ); 00171 /* --- Visualization --- */ 00172 void vis_Init(); 00173 void vis_Event( int ); 00174 /* --- Physics --- */ 00175 void phys_Init( int flags ); 00176 void phys_Action(); 00177 void phys_Event( int ); 00178 void phys_HitTile( Tile* ); 00179 void phys_HitObj( Object* ); 00180 /* --- Pathing --- */ 00181 void path_Event( int ); 00182 // --- The Bus --- // 00183 /* NEVER consider bus messages as arriving to components 00184 * in a particular order. If you need a particular order, 00185 * use multiple bus messages and call them in sequence. 00186 */ 00187 void bus_Event( int ); 00188 void bus_HitTile( Tile* ); 00189 void bus_HitObj( Object* ); 00190 void bus_PathSig( int ); 00191 /* For object preservation across levels (ie, the Player) */ 00192 ObjectMemento* CreateMemento(); 00193 void RestoreFromMemento( ObjectMemento* ); 00194 Vector2D GetEdgePoint( int dir ); 00195 /* Object Bay 00196 * 00197 * The Object Bay is a place for Objects to place *new* Objects for the Level 00198 * to pick up and put into the master object list. 00199 * For example, Objects that fire missiles put the missiles into the object 00200 * bay, and the Level picks them up and places them into its list of all 00201 * objects. 00202 */ 00203 void ObjectBayAttach( Object* ); 00204 Input *GetInput(); 00205 int GetTime(); 00206 GameTimer *GetGameTimer(); 00207 ScoreManager *GetScoreManager(); 00208 }; 00209 00210 #endif // __OBJECT_H