home *** CD-ROM | disk | FTP | other *** search
/ Game.EXE 2002 April / Game.EXE_04_2002.iso / Alawar / Animation2D.cpp next >
Encoding:
C/C++ Source or Header  |  2002-03-02  |  2.0 KB  |  95 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. {
  10. }
  11.  
  12. Animation2D::~Animation2D()
  13. {
  14.     Sequences::unload( sequences );
  15. }
  16.  
  17. void Animation2D::render()
  18. {
  19.     sequences->render_frame( current_seq, current_fr, alpha ); 
  20. }
  21.  
  22. void Animation2D::start(unsigned seq, bool is_loop)
  23. {
  24.     current_seq = seq;
  25.     current_fr = 0;
  26.     time_ms = 0;
  27.     loop_current = is_loop;
  28.     finished = false;
  29. }
  30.  
  31. bool Animation2D::life_cycle(unsigned delta_time_ms)
  32. {
  33.     time_ms += delta_time_ms;
  34.     while( time_ms > sequences->get_duration( current_seq, current_fr ) )
  35.     {
  36.         time_ms -= sequences->get_duration( current_seq, current_fr );
  37.         ++current_fr;
  38.         if( current_fr >= sequences->get_frame_count( current_seq ) )
  39.         {
  40.             if( loop_current )
  41.             {
  42.                 current_fr = 0;
  43.             }
  44.             else
  45.             {
  46.                 // ╬±≥αφεΓΦ≥ⁿ±  φα ∩ε±δσΣφσ∞ ΩαΣ≡σ
  47.                 --current_fr;
  48.                 time_ms = 0;
  49.                 finished = true;
  50.             }
  51.         }
  52.     }
  53.     return true;
  54. }
  55.  
  56. bool Animation2D::is_finished()const
  57. {
  58.     return finished;
  59. }
  60.  
  61. void Animation2D::set_transparency(unsigned alpha)
  62. {
  63.     this->alpha = alpha;
  64. }
  65.  
  66. void Animation2D::render_frame(unsigned seq, unsigned fr, int alpha)const
  67. {
  68.     sequences->render_frame( seq, fr, alpha );
  69. }
  70.  
  71. unsigned Animation2D::get_frame_count(unsigned seq)const
  72. {
  73.     return sequences->get_frame_count( seq );
  74. }
  75. unsigned Animation2D::get_sequence_count()const
  76. {
  77.     return sequences->get_sequence_count();
  78. }
  79. unsigned Animation2D::get_height()const
  80. {
  81.     return sequences->get_height( current_seq, current_fr );
  82. }
  83. unsigned Animation2D::get_width()const
  84. {
  85.     return sequences->get_width( current_seq, current_fr );
  86. }
  87. unsigned Animation2D::get_height(unsigned seq, unsigned fr)const
  88. {
  89.     return sequences->get_height( seq, fr );
  90. }
  91. unsigned Animation2D::get_width(unsigned seq, unsigned fr )const
  92. {
  93.     return sequences->get_width( seq, fr );
  94. }
  95.