home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2009 February / maximum-cd-2009-02.iso / DiscContents / SMC_1.6_win32.exe / src / video / animation.h < prev    next >
Encoding:
C/C++ Source or Header  |  2008-07-01  |  11.9 KB  |  383 lines

  1. /***************************************************************************
  2.  * animation.h  -  header for the corresponding cpp file
  3.  *
  4.  * Copyright (C) 2003 - 2008 Florian Richter
  5.  ***************************************************************************/
  6. /*
  7.    This program is free software; you can redistribute it and/or modify
  8.    it under the terms of the GNU General Public License as published by
  9.    the Free Software Foundation; either version 3 of the License, or
  10.    (at your option) any later version.
  11.    
  12.    You should have received a copy of the GNU General Public License
  13.    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  14. */
  15.  
  16. #ifndef SMC_ANIMATION_H
  17. #define SMC_ANIMATION_H
  18.  
  19. #include "../objects/movingsprite.h"
  20. #include "../objects/objectsprite.h"
  21. #include "../core/obj_manager.h"
  22.  
  23. /* *** *** *** *** *** *** *** Animation definitions *** *** *** *** *** *** *** *** *** *** */
  24.  
  25. enum AnimationEffect
  26. {
  27.     ANIM_UNDEFINED,
  28.     BLINKING_POINTS,
  29.     FIRE_EXPLOSION,
  30.     PARTICLE_EXPLOSION,
  31. };
  32.  
  33. /* *** *** *** *** *** *** *** Particle blending definitions *** *** *** *** *** *** *** *** *** *** */
  34.  
  35. enum BlendingMode
  36. {
  37.     BLEND_NONE,
  38.     BLEND_ADD,
  39.     BLEND_DRIVE
  40.     // todo : more
  41. };
  42.  
  43. /* *** *** *** *** *** *** *** Base Animation class *** *** *** *** *** *** *** *** *** *** */
  44.  
  45. class cAnimation : public cImageObjectSprite
  46. {
  47. public:
  48.     cAnimation( float x = 0, float y = 0 );
  49.     virtual ~cAnimation( void );
  50.  
  51.     // initialize animation
  52.     virtual void Init_Anim( void );
  53.     // update animation
  54.     virtual void Update( void );
  55.     // draw animation
  56.     virtual void Draw( cSurfaceRequest *request = NULL );
  57.  
  58.     // ignore onground check
  59.     virtual void Check_on_Ground( void ) {};
  60.  
  61.     // Set time to live for Objects in seconds
  62.     void Set_Time_to_Live( float time, float time_rand = 0 );
  63.     /* Set speed of fading out ( 0.01 - 100 )
  64.     * the lower the longer it takes
  65.     * Note : only useful for non particle animation Objects
  66.     */
  67.     void Set_Fading_Speed( float speed );
  68.     // set z position
  69.     virtual void Set_Pos_Z( float pos, float pos_rand = 0 );
  70.  
  71.     // Z random position
  72.     float posz_rand;
  73.     // fading out speed
  74.     float fading_speed;
  75.     // object time to live
  76.     float time_to_live, time_to_live_rand;
  77.     // animation type
  78.     AnimationEffect animtype;
  79. };
  80.  
  81. /* *** *** *** *** *** *** *** *** Blinking points *** *** *** *** *** *** *** *** *** */
  82.  
  83. class cAnimation_Goldpiece : public cAnimation
  84. {
  85. public:
  86.     cAnimation_Goldpiece( float posx, float posy, float height = 40, float width = 20 );
  87.     virtual ~cAnimation_Goldpiece( void );
  88.  
  89.     // update
  90.     virtual void Update( void );
  91.     // draw
  92.     virtual void Draw( cSurfaceRequest *request = NULL );
  93.  
  94.     typedef vector<cSprite *> BlinkPointList;
  95.     BlinkPointList objects;
  96.     
  97. };
  98.  
  99. /* *** *** *** *** *** *** *** Fireball Animation *** *** *** *** *** *** *** *** *** *** */
  100.  
  101. class cAnimation_Fireball_Item : public cImageObjectSprite
  102. {
  103. public:
  104.     cAnimation_Fireball_Item( void )
  105.     : cImageObjectSprite()
  106.     {
  107.         counter = 0;
  108.     }
  109.  
  110.     virtual ~cAnimation_Fireball_Item( void ) {}
  111.  
  112.     // lifetime
  113.     float counter;
  114. };
  115.  
  116. class cAnimation_Fireball : public cAnimation
  117. {
  118. public:
  119.     cAnimation_Fireball( float posx, float posy, unsigned int power = 5 );
  120.     virtual ~cAnimation_Fireball( void );
  121.  
  122.     // initialize animation
  123.     virtual void Init_Anim( void );
  124.     // update
  125.     virtual void Update( void );
  126.     // draw
  127.     virtual void Draw( cSurfaceRequest *request = NULL );
  128.  
  129.     typedef vector<cAnimation_Fireball_Item *> FireAnimList;
  130.     FireAnimList objects;
  131. };
  132.  
  133. /* *** *** *** *** *** *** *** Particle Emitter *** *** *** *** *** *** *** *** *** *** */
  134.  
  135. class cParticle_Emitter;
  136.  
  137. // Particle Item
  138. class cParticle : public cMovingSprite
  139. {
  140. public:
  141.     cParticle( void );
  142.     virtual ~cParticle( void );
  143.  
  144.     // update
  145.     virtual void Update( void );
  146.     // draw
  147.     virtual void Draw( cParticle_Emitter *origin );
  148.  
  149.     // ignore onground check
  150.     virtual void Check_on_Ground( void ) {};
  151.  
  152.     // set gravity
  153.     void Set_Gravity( float x, float y );
  154.  
  155.     // time to live
  156.     float time_to_live;
  157.     // constant rotation
  158.     float const_rotx, const_roty, const_rotz;
  159.     // particle gravity
  160.     float gravity_x, gravity_y;
  161.  
  162.     // fading position value
  163.     float fade_pos;
  164. };
  165.  
  166. // Particle Emitter
  167. class cParticle_Emitter : public cAnimation
  168. {
  169. public:
  170.     // constructor
  171.     cParticle_Emitter( void );
  172.     // create from stream
  173.     cParticle_Emitter( CEGUI::XMLAttributes &attributes );
  174.     // destructor
  175.     virtual ~cParticle_Emitter( void );
  176.  
  177.     // create from stream
  178.     virtual void Create_from_Stream( CEGUI::XMLAttributes &attributes );
  179.     // save to stream
  180.     virtual void Save_to_Stream( ofstream &file );
  181.  
  182.     // Init
  183.     virtual void Init( void );
  184.     // copy
  185.     virtual cParticle_Emitter *Copy( void );
  186.     // initialize animation
  187.     virtual void Init_Anim( void );
  188.     // Emit Particles
  189.     virtual void Emit( void );
  190.     // Clear Particles and Animation data
  191.     virtual void Clear( void );
  192.  
  193.     // Update given settings
  194.     virtual void Update( void );
  195.     // Draw everything
  196.     virtual void Draw( cSurfaceRequest *request = NULL );
  197.  
  198.     // if update is valid for the current state
  199.     virtual bool Is_Update_Valid( void );
  200.     // if draw is valid for the current state and position
  201.     virtual bool Is_Draw_Valid( void );
  202.  
  203.     // ignore onground check
  204.     virtual void Check_on_Ground( void ) {};
  205.  
  206.     // Set the Emitter rect
  207.     void Set_Emitter_Rect( float x, float y, float w = 0, float h = 0 );
  208.     void Set_Emitter_Rect( GL_rect r );
  209.     /* Set time to live for the Emitter in seconds
  210.      * set -1 for infinite
  211.     */
  212.     void Set_Emitter_Time_to_Live( float time );
  213.     // Set time between Iterations
  214.     void Set_Emitter_Iteration_Interval( float time );
  215.     // Set Particle Count/Quota
  216.     void Set_Quota( unsigned int size );
  217.     // Set speed ( 0 - 100 )
  218.     void Set_Speed( float vel_base, float vel_random = 2 );
  219.     // Set start rotation z uses start direction
  220.     void Set_Start_Rot_Z_Uses_Direction( bool enable );
  221.     // Set x constant rotation
  222.     void Set_Const_Rotation_X( float rot, float rot_random = 0 );
  223.     // Set y constant rotation
  224.     void Set_Const_Rotation_Y( float rot, float rot_random = 0 );
  225.     // Set z constant rotation
  226.     void Set_Const_Rotation_Z( float rot, float rot_random = 0 );
  227.     /* Set direction range ( 0 - 360 )
  228.      * 0 : Right, 90 Down, 180 Left, 270 Up
  229.     */
  230.     void Set_Direction_Range( float start, float range = 0 );
  231.     // Set image scale ( 0.01 - 100 )
  232.     virtual void Set_Scale( float nscale, float scale_random = 0 );
  233.     // Set horizontal gravity
  234.     void Set_Horizontal_Gravity( float start, float random = 0 );
  235.     // Set vertical gravity
  236.     void Set_Vertical_Gravity( float start, float random = 0 );
  237.     // Set the Color
  238.     virtual void Set_Color( Color col, Color col_rand = Color( static_cast<Uint8>(0) ) );
  239.     // Set fading type
  240.     void Set_Fading_Size( bool enable );
  241.     void Set_Fading_Alpha( bool enable );
  242.     void Set_Fading_Color( bool enable );
  243.     // Set blending mode
  244.     virtual void Set_Blending( BlendingMode mode );
  245.     // Set image
  246.     virtual void Set_Image( GL_Surface *img );
  247.     // Set the file name
  248.     virtual void Set_Filename( string str_filename );
  249.  
  250.     // editor activation
  251.     virtual void Editor_Activate( void );
  252.     // position z base key up event
  253.     bool Editor_Pos_Z_Base_Key( const CEGUI::EventArgs &event );
  254.     // position z rand key up event
  255.     bool Editor_Pos_Z_Rand_Key( const CEGUI::EventArgs &event );
  256.     // editor filename key up event
  257.     bool Editor_Filename_Key( const CEGUI::EventArgs &event );
  258.     // emitter width key up event
  259.     bool Editor_Emitter_Width_Key( const CEGUI::EventArgs &event );
  260.     // emitter height key up event
  261.     bool Editor_Emitter_Height_Key( const CEGUI::EventArgs &event );
  262.     // emitter time to live key up event
  263.     bool Editor_Emitter_Time_To_Live_Key( const CEGUI::EventArgs &event );
  264.     // emitter interval key up event
  265.     bool Editor_Emitter_Interval_Key( const CEGUI::EventArgs &event );
  266.     // quota key up event
  267.     bool Editor_Quota_Key( const CEGUI::EventArgs &event );
  268.     // ttl base key up event
  269.     bool Editor_Ttl_Base_Key( const CEGUI::EventArgs &event );
  270.     // ttl rand key up event
  271.     bool Editor_Ttl_Rand_Key( const CEGUI::EventArgs &event );
  272.     // velocity base key up event
  273.     bool Editor_Velocity_Base_Key( const CEGUI::EventArgs &event );
  274.     // velocity rand key up event
  275.     bool Editor_Velocity_Rand_Key( const CEGUI::EventArgs &event );
  276.     // start rotation x base key up event
  277.     bool Editor_Rotation_X_Base_Key( const CEGUI::EventArgs &event );
  278.     // start rotation y base key up event
  279.     bool Editor_Rotation_Y_Base_Key( const CEGUI::EventArgs &event );
  280.     // start rotation z base key up event
  281.     bool Editor_Rotation_Z_Base_Key( const CEGUI::EventArgs &event );
  282.     // start rotation z uses start direction event
  283.     bool Editor_Start_Rot_Z_Uses_Direction_Changed( const CEGUI::EventArgs &event );
  284.     // constant rotation x base key up event
  285.     bool Editor_Const_Rotation_X_Base_Key( const CEGUI::EventArgs &event );
  286.     // constant rotation x rand key up event
  287.     bool Editor_Const_Rotation_X_Rand_Key( const CEGUI::EventArgs &event );
  288.     // constant rotation y base key up event
  289.     bool Editor_Const_Rotation_Y_Base_Key( const CEGUI::EventArgs &event );
  290.     // constant rotation y rand key up event
  291.     bool Editor_Const_Rotation_Y_Rand_Key( const CEGUI::EventArgs &event );
  292.     // constant rotation z base key up event
  293.     bool Editor_Const_Rotation_Z_Base_Key( const CEGUI::EventArgs &event );
  294.     // constant rotation z rand key up event
  295.     bool Editor_Const_Rotation_Z_Rand_Key( const CEGUI::EventArgs &event );
  296.     // direction base key up event
  297.     bool Editor_Direction_Base_Key( const CEGUI::EventArgs &event );
  298.     // direction rand key up event
  299.     bool Editor_Direction_Rand_Key( const CEGUI::EventArgs &event );
  300.     // scale base key up event
  301.     bool Editor_Scale_Base_Key( const CEGUI::EventArgs &event );
  302.     // scale rand key up event
  303.     bool Editor_Scale_Rand_Key( const CEGUI::EventArgs &event );
  304.     // horizontal gravity base key up event
  305.     bool Editor_Horizontal_Gravity_Base_Key( const CEGUI::EventArgs &event );
  306.     // horizontal gravity rand key up event
  307.     bool Editor_Horizontal_Gravity_Rand_Key( const CEGUI::EventArgs &event );
  308.     // vertical gravity base key up event
  309.     bool Editor_Vertical_Gravity_Base_Key( const CEGUI::EventArgs &event );
  310.     // vertical gravity rand key up event
  311.     bool Editor_Vertical_Gravity_Rand_Key( const CEGUI::EventArgs &event );
  312.     // todo : start rotation x/y/z rand, color, color_rand
  313.  
  314.     // Particle items
  315.     typedef vector<cParticle *> ParticleList;
  316.     ParticleList objects;
  317.  
  318.     // filename of the particle
  319.     string filename;
  320.     // emitter time to live
  321.     float emitter_time_to_live;
  322.     // emitter iteration interval
  323.     float emitter_iteration_interval;
  324.     // emitter object quota
  325.     unsigned int emitter_quota;
  326.  
  327.     // velocity
  328.     float vel, vel_rand;
  329.     // start rotation z uses start direction
  330.     bool start_rot_z_uses_direction;
  331.     // constant rotation
  332.     float const_rotx, const_roty, const_rotz;
  333.     // constant rotation random modifier
  334.     float const_rotx_rand, const_roty_rand, const_rotz_rand;
  335.     // direction range
  336.     float angle_start, angle_range;
  337.     // size scaling
  338.     float size_scale, size_scale_rand;
  339.     // gravity
  340.     float gravity_x, gravity_x_rand;
  341.     float gravity_y, gravity_y_rand;
  342.     // color random
  343.     Color color_rand;
  344.     // fading types todo : dest-color
  345.     bool fade_size, fade_alpha, fade_color;
  346.     // blending mode
  347.     BlendingMode blending;
  348.  
  349. private:
  350.     // time alive
  351.     float emitter_living_time;
  352.     // emit counter
  353.     float emit_counter;
  354. };
  355.  
  356. /* *** *** *** *** *** *** *** Animation Manager *** *** *** *** *** *** *** *** *** *** */
  357.  
  358. class cAnimation_Manager : public cObject_Manager<cAnimation>
  359. {
  360. public:
  361.     cAnimation_Manager( void );
  362.     virtual ~cAnimation_Manager( void );
  363.  
  364.     // Add an animation object with the given settings
  365.     virtual void Add( cAnimation *animation );
  366.  
  367.     // Update the objects
  368.     void Update( void );
  369.     // Draw the objects
  370.     void Draw( void );
  371.  
  372.     typedef vector<cAnimation *> AnimationList;
  373. };
  374.  
  375. /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
  376.  
  377. // The Animation Manager
  378. extern cAnimation_Manager *pAnimation_Manager;
  379.  
  380. /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
  381.  
  382. #endif
  383.