animate.h

Go to the documentation of this file.
00001 
00007 /*
00008 Copyright (C) 2000  Jeffrey S. Freedman
00009 
00010 This program is free software; you can redistribute it and/or
00011 modify it under the terms of the GNU General Public License
00012 as published by the Free Software Foundation; either version 2
00013 of the License, or (at your option) any later version.
00014 
00015 This program is distributed in the hope that it will be useful,
00016 but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 GNU General Public License for more details.
00019 
00020 You should have received a copy of the GNU General Public License
00021 along with this program; if not, write to the Free Software
00022 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00023 */
00024 
00025 #ifndef INCL_ANIMATE
00026 #define INCL_ANIMATE  1
00027 
00028 #include "iregobjs.h"
00029 
00030 /*
00031  *  An animator:
00032  */
00033 class Animator : public Time_sensitive, public Game_singletons
00034   {
00035 protected:
00036   Game_object *obj;   // Object we're controlling.
00037   unsigned char deltax, deltay; // If wiggling, deltas from
00038           //   original position.
00039   bool animating;     // 1 if animation turned on.
00040   int sfxnum;     // Sound effects #, or -1 if none.
00041   void start_animation();
00042 public:
00043   Animator(Game_object *o, int snum = -1) 
00044     : obj(o), deltax(0), deltay(0), animating(false), sfxnum(snum)
00045     {  }
00046   static Animator *create(Game_object *ob);
00047   ~Animator();
00048   void want_animation()   // Want animation on.
00049     {
00050     if (!animating)
00051       start_animation();
00052     }
00053   int get_deltax()
00054     { return deltax; }
00055   int get_deltay()
00056     { return deltay; }
00057   virtual int get_framenum();
00058   };
00059 
00060 /*
00061  *  Animate by going through frames.
00062  */
00063 class Frame_animator : public Animator
00064   {
00065   unsigned char first_frame;  // First frame of animation.
00066   unsigned char frames;   // # of frames.
00067   unsigned int created;   // Time created
00068   unsigned int delay;   // Rate of animation
00069   unsigned short last_shape;  // To check if we need to re init
00070   unsigned short last_frame;  // To check if we need to re init
00071   enum        // Type of animation
00072   {
00073     FA_LOOPING = 0,
00074     FA_SUNDIAL = 1,
00075     FA_ENERGY_FIELD = 2
00076   } type;
00077   void Initialize();
00078 public:
00079   Frame_animator(Game_object *o);
00080   virtual int get_framenum();
00081           // For Time_sensitive:
00082   virtual void handle_event(unsigned long time, long udata);
00083   };
00084 
00085 /*
00086  *  Just play SFX.
00087  */
00088 class Sfx_animator : public Animator
00089   {
00090 public:
00091   Sfx_animator(Game_object *o);
00092           // For Time_sensitive:
00093   virtual void handle_event(unsigned long time, long udata);
00094   };
00095 
00096 /*
00097  *  Animate by going through frames, but only do the lower frames once.
00098  */
00099 class Field_frame_animator : public Animator
00100   {
00101   unsigned char frames;   // # of frames.
00102   unsigned char recycle;    // # of frame to recycle at.
00103   bool activated;     // Time to check for damage.
00104 public:
00105   friend class Field_object;
00106   Field_frame_animator(Game_object *o, int rcy);
00107           // For Time_sensitive:
00108   virtual void handle_event(unsigned long time, long udata);
00109   };
00110 
00111 /*
00112  *  Animate by wiggling.
00113  */
00114 class Wiggle_animator : public Animator
00115   {
00116 public:
00117   Wiggle_animator(Game_object *o) : Animator(o)
00118     {  }
00119           // For Time_sensitive:
00120   virtual void handle_event(unsigned long time, long udata);
00121   };
00122 
00123 /*
00124  *  An object that cycles through its frames, or wiggles if just one
00125  *  frame.  The base class is for those in U7chunks.
00126  */
00127 class Animated_object : public Terrain_game_object
00128   {
00129   Animator *animator;   // Controls animation.
00130 public:
00131   Animated_object(int shapenum, int framenum, unsigned int tilex, 
00132          unsigned int tiley, unsigned int lft = 0);
00133   virtual ~Animated_object();
00134           // Render.
00135   virtual void paint();
00136           // +++++Needed on this one:
00137           // Get coord. where this was placed.
00138   virtual Tile_coord get_original_tile_coord() const
00139     { return get_tile() + 
00140       Tile_coord(-animator->get_deltax(), 
00141            -animator->get_deltay(), 0); }
00142   };
00143 
00144 /*
00145  *  An object that cycles through its frames, or wiggles if just one
00146  *  frame.  This is the IREG version.
00147  */
00148 class Animated_ireg_object : public Ireg_game_object
00149   {
00150   Animator *animator;   // Controls animation.
00151 public:
00152   Animated_ireg_object(int shapenum, int framenum, unsigned int tilex, 
00153          unsigned int tiley, unsigned int lft = 0);
00154   virtual ~Animated_ireg_object();
00155           // Render.
00156   virtual void paint();
00157           // Get coord. where this was placed.
00158   virtual Tile_coord get_original_tile_coord() const
00159     { return get_tile() + 
00160       Tile_coord(-animator->get_deltax(), 
00161            -animator->get_deltay(), 0); }
00162 
00163         // Write out to IREG file.
00164   virtual void write_ireg(DataSource* out);
00165   };
00166 
00167 /*
00168  *  An object that cycles through its frames, or wiggles if just one
00169  *  frame.  This is the IFIX version.
00170  */
00171 class Animated_ifix_object : public Ifix_game_object
00172   {
00173   Animator *animator;   // Controls animation.
00174 public:
00175   Animated_ifix_object(unsigned char *ifix);
00176   Animated_ifix_object(int shapenum, int framenum, unsigned int tilex, 
00177          unsigned int tiley, unsigned int lft = 0);
00178   virtual ~Animated_ifix_object();
00179           // Render.
00180   virtual void paint();
00181           // Get coord. where this was placed.
00182   virtual Tile_coord get_original_tile_coord() const
00183     { return get_tile() + 
00184       Tile_coord(-animator->get_deltax(), 
00185            -animator->get_deltay(), 0); }
00186 
00187   virtual void write_ifix(DataSource* ifix);
00188 
00189   };
00190 #endif
00191 
00192 

Generated on Mon Jul 9 14:42:48 2007 for ExultEngine by  doxygen 1.5.1