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
00021
00022
00023
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
00035 if(keystates[SDLK_SPACE])
00036 {
00037 CommandManager::instance()->execute(new JumpCommand(this,_xDirection));
00038
00039
00040
00041
00042 }
00043 if(!keystates[SDLK_SPACE])
00044
00045 CommandManager::instance()->execute(new JumpResetCommand(this));
00046
00047
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
00052 else if(keystates[SDLK_UP])
00053 CommandManager::instance()->execute(new AimCommand(this,UP));
00054
00055 else if(keystates[SDLK_DOWN] && _state == JUMPING)
00056 CommandManager::instance()->execute(new AimCommand(this,DOWN));
00057
00058
00059 if( keystates[ SDLK_RCTRL ] || keystates[ SDLK_LCTRL ] )
00060 {
00061 CommandManager::instance()->execute(new ShootCommand(this));
00062 }
00063
00064
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
00078
00079
00080
00081
00082
00083
00084
00085