C:/Documents and Settings/mtauraso/Desktop/proj3/projectX/Player.cpp

Go to the documentation of this file.
00001 #include "Player.h"
00002 #include "List.h"
00003 #include "Command.h"
00004 #include "CommandManager.h"
00005 #include "glfuncs.h"
00006 #include "Control.h"
00007 #include "Screen.h"
00008 
00009 Player::Player(List * playerInfo, int x, int y)
00010 :Person(playerInfo,x,y)
00011 {
00012         _depth = 2;
00013         _type = PLAYER;
00014 }
00015 
00016 void Player::control()
00017 {
00018         Uint8 *keystates = SDL_GetKeyState( NULL );
00019 
00020         //SAVE DEMO BUTTON
00021         //if(keystates[SDLK_s])
00022         //{
00023         //      CommandManager::instance()->saveRecording("scripts/newDemo.txt");
00024         //}
00025         if(keystates[SDLK_LEFT])
00026         {
00027                 CommandManager::instance()->execute(new MoveCommand(this,LEFT));
00028         }
00029         if(keystates[SDLK_RIGHT])
00030         {
00031                 CommandManager::instance()->execute(new MoveCommand(this,RIGHT));
00032         }
00033 
00034         // Jumping
00035         if(keystates[SDLK_SPACE])
00036         {
00037                 CommandManager::instance()->execute(new JumpCommand(this,_xDirection));
00038         
00039                 //Keep the jump key state around so you can't jump by just holding the key
00040                 
00041                 //CommandManager::instance()->execute(new PlaySoundCommand("beat.wav"));
00042         }
00043         if(!keystates[SDLK_SPACE])
00044                 //Reset the jump keystate as soon as we poll and see that the key is no longer held.
00045                 CommandManager::instance()->execute(new JumpResetCommand(this));
00046         
00047         //if neither or both are pressed shoot to the side
00048         if(((!keystates[SDLK_UP])&&(!keystates[SDLK_DOWN]))||((keystates[SDLK_UP])&&(keystates[SDLK_DOWN]))
00049                                                                || (_state != JUMPING && keystates[SDLK_DOWN]))
00050                 CommandManager::instance()->execute(new AimCommand(this,MIDDLE));
00051         //if up only, shoot up
00052         else if(keystates[SDLK_UP])
00053                 CommandManager::instance()->execute(new AimCommand(this,UP));
00054         //if down only, shoot down
00055         else if(keystates[SDLK_DOWN] && _state == JUMPING)
00056                 CommandManager::instance()->execute(new AimCommand(this,DOWN));
00057 
00058         // Shooting
00059         if( keystates[ SDLK_RCTRL ] || keystates[ SDLK_LCTRL ] )
00060         {
00061                 CommandManager::instance()->execute(new ShootCommand(this));
00062         }
00063 
00064         // Crouching
00065         if( _crouching && !keystates[ SDLK_DOWN ] )
00066         {
00067                 CommandManager::instance()->execute( new CrouchCommand( this, false ) );
00068         }
00069         if( keystates[ SDLK_DOWN ] && !_crouching )
00070         {
00071                 CommandManager::instance()->execute( new CrouchCommand( this, true ) );
00072         }
00073 }
00077 /*void Player::die()
00078 {
00079         Person::die();
00080         /*
00081         Control::detachController( this );
00082         if( this == Screen::instance()->getFollowObj() )
00083                 Screen::instance()->registerFollowObj( NULL );
00084         */
00085 /*}*/

Generated on Sat Apr 22 15:05:20 2006 for ProjectX by  doxygen 1.4.6-NO