home *** CD-ROM | disk | FTP | other *** search
- #include "Pacman.h"
- #include "Level.h"
- #include <winuser.rh>
-
- Pacman::Pacman( Scene2D * scene )
- : Creature( 0 ),
- anim( scene, 1, "data/pacman" ),
- life( 3 ),
- score( 0 ),
- state( DEAD )
- {
- speed = 2; //∩ε ΦΣσσ ²≥ε Γ±σ Φτ ΦφΦ°ΩΦ
- }
-
- void Pacman::put_on_level( Level * level )
- {
- this->level = level;
- change_state( CREATING );
- }
-
- void Pacman::change_state( state_enum new_state )
- {
- // switch( state ) // ╧εΩΦφ≤≥ⁿ ∩≡σΣ√Σ≤∙σσ ±ε±≥ε φΦσ
- // {}
- state = new_state;
- switch( state ) // ╟αΘ≥Φ Γ φεΓεσ ±ε±≥ε φΦσ
- {
- case CREATING:
- level->move( this, "pacman_start" );
- anim.start( 5, false );
- anim.move( get_position().get_x()-anim.get_width()/2, get_position().get_y()-anim.get_height()/2 );
- break;
- case LIVING:
- next_direction = Direction::STAND;
- change_direction( Direction::STAND );
- break;
- case DYING:
- anim.start( 4, false );
- break;
- case DEAD:
- break;
- }
- }
-
- void Pacman::change_direction( Direction dir )
- {
- if ( curr_direction != dir )
- {
- switch( dir.get_dir() )
- {
- case Direction::RIGHT:
- anim.start(0,true);
- break;
- case Direction::LEFT:
- anim.start(2,true);
- break;
- case Direction::UP:
- anim.start(1,true);
- break;
- case Direction::DOWN:
- anim.start(3,true);
- break;
- }
- }
- curr_direction = dir;
- }
-
- void Pacman::key_up(int scan_code)
- {
- }
-
- void Pacman::key_down(int scan_code)
- {
- if ( state == LIVING )
- switch( scan_code )
- {
- case VK_UP:
- next_direction = Direction::UP;
- break;
- case VK_DOWN:
- next_direction = Direction::DOWN;
- break;
- case VK_LEFT:
- next_direction = Direction::LEFT;
- break;
- case VK_RIGHT:
- next_direction = Direction::RIGHT;
- break;
- }
- if( curr_direction.is_opposed( next_direction ) )
- {
- change_direction( next_direction );
- pos.swap_dst();
- }
- }
-
- int Pacman::get_life()const
- {
- return life;
- }
-
- int Pacman::get_score()const
- {
- return score;
- }
-
- bool Pacman::is_alive()const
- {
- return state != DEAD;
- }
-
- void Pacman::process_death(const Creature * cre)
- {}
-
- bool Pacman::is_solid()const
- {
- return state == LIVING;
- }
-
- void Pacman::process_collision(const Creature * cre)
- {
- if ( cre->get_name() == "Dot" )
- {
- ++score;
- return;
- }
- if ( cre->get_name() == "PowerDot" )
- {
- score += 50;
- internal_score_multiplier = 0;
- return;
- }
- if ( cre->get_name() == "Cat" )
- {
- score += ++internal_score_multiplier*200;
- return;
- }
- if ( cre->get_name() == "Cherry" )
- {
- ++life;
- score += 1000;
- return;
- }
- if( cre->get_name() == "Monster" )
- {
- --life;
- change_state( DYING );
- }
- }
-
- float Pacman::get_size()const
- {
- return anim.get_width(0,0);
- }
-
- String Pacman::get_name()const
- {
- return "Pacman";
- }
-
- void Pacman::life_cycle(float delta_time)
- {
- anim.move( get_position().get_x()-anim.get_width()/2, get_position().get_y()-anim.get_height()/2 );
- anim.life_cycle( delta_time );
- switch( state )
- {
- case CREATING:
- if( anim.is_finished() )
- change_state( LIVING );
- break;
- case LIVING:
- if ( pos.go_to( speed * delta_time ) )
- {
- if( level->next_direction( this, next_direction ) )
- {
- change_direction( next_direction );
- }
- else
- if( level->next_direction( this, curr_direction ) )
- {
- change_direction( curr_direction );
- }
- }
- break;
- case DYING:
- if( anim.is_finished() )
- if( life > 0 )
- change_state( CREATING );
- else
- change_state( DEAD );
- break;
- case DEAD:
- // :(
- break;
- }
- }
-