home *** CD-ROM | disk | FTP | other *** search
/ Game.EXE 2002 May / Game.EXE_05_2002.iso / Alawar / Lib / 2D / Animation2D.cpp next >
Encoding:
C/C++ Source or Header  |  2002-04-03  |  2.1 KB  |  103 lines

  1. #include "Animation2D.h"
  2. #include "Sequences.h"
  3.  
  4. Animation2D::Animation2D(Scene2D * scene, int layer, const String & name )
  5. :    Object2D( scene, layer ),
  6.     sequences( Sequences::load( name, scene ) ),
  7.     finished( true ),
  8.     alpha( 255 ),
  9.     current_seq( 0 ),
  10.     current_fr( 0 ),
  11.     time( 0 )
  12. {}
  13.  
  14. Animation2D::~Animation2D()
  15. {
  16.     Sequences::unload( sequences );
  17. }
  18.  
  19. void Animation2D::render()
  20. {
  21.     sequences->render_frame( current_seq, current_fr, alpha ); 
  22. }
  23.  
  24. void Animation2D::start(int seq, bool is_loop)
  25. {
  26.     if( seq < 0 )
  27.         seq = 0;
  28.     if( seq >= sequences->get_sequence_count() )
  29.         seq = sequences->get_sequence_count() - 1;
  30.     current_seq = seq;
  31.     current_fr = 0;
  32.     time = 0;
  33.     loop_current = is_loop;
  34.     finished = false;
  35. }
  36.  
  37. bool Animation2D::life_cycle(float delta_time)
  38. {
  39.     time += delta_time;
  40.     while( time > sequences->get_duration( current_seq, current_fr ) )
  41.     {
  42.         time -= sequences->get_duration( current_seq, current_fr );
  43.         ++current_fr;
  44.         if( current_fr >= sequences->get_frame_count( current_seq ) )
  45.         {
  46.             if( loop_current )
  47.             {
  48.                 current_fr = 0;
  49.             }
  50.             else
  51.             {
  52.                 // ╬±≥αφεΓΦ≥ⁿ±  φα ∩ε±δσΣφσ∞ ΩαΣ≡σ
  53.                 --current_fr;
  54.                 time = 0;
  55.                 finished = true;
  56.             }
  57.         }
  58.     }
  59.     return true;
  60. }
  61.  
  62. bool Animation2D::is_finished()const
  63. {
  64.     return finished;
  65. }
  66.  
  67. void Animation2D::set_transparency(int alpha)
  68. {
  69.     if( alpha < 0   ) alpha = 0;
  70.     if( alpha > 255 ) alpha = 255;
  71.     this->alpha = alpha;
  72. }
  73.  
  74. void Animation2D::render_frame(int seq, int fr, int alpha)const
  75. {
  76.     sequences->render_frame( seq, fr, alpha );
  77. }
  78.  
  79. int Animation2D::get_frame_count(int seq)const
  80. {
  81.     return sequences->get_frame_count( seq );
  82. }
  83. int Animation2D::get_sequence_count()const
  84. {
  85.     return sequences->get_sequence_count();
  86. }
  87. int Animation2D::get_height()const
  88. {
  89.     return sequences->get_height( current_seq, current_fr );
  90. }
  91. int Animation2D::get_width()const
  92. {
  93.     return sequences->get_width( current_seq, current_fr );
  94. }
  95. int Animation2D::get_height(int seq, int fr)const
  96. {
  97.     return sequences->get_height( seq, fr );
  98. }
  99. int Animation2D::get_width(int seq, int fr )const
  100. {
  101.     return sequences->get_width( seq, fr );
  102. }
  103.