1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
|
void Player::Handle_Event(SDL_Event Event, vector<Shot> *shots)
{
Set_CenterPosition();
if (Event.type == SDL_KEYDOWN)
{
switch(Event.key.keysym.sym)
{
case SDLK_UP:
Velocity.Y = -PLANE_SPEED;
break;
case SDLK_DOWN:
Velocity.Y = PLANE_SPEED;
break;
case SDLK_LEFT:
Velocity.X = -PLANE_SPEED;
break;
case SDLK_RIGHT:
Velocity.X = PLANE_SPEED;
break;
/*
case SDLK_PAGEUP:
Velocity.X = -PLANE_SPEED;
Velocity.Y = -PLANE_SPEED;
break;
case SDLK_PAGEDOWN:
Velocity.X = PLANE_SPEED;
Velocity.Y = -PLANE_SPEED;
break;
*/
case SDLK_SPACE:
if ( Clip.y == MOVING_HORIZONTALLY )
{
if (Clip.x == STRAIGHT_AHEAD)
{
Shot newshot( Player_Shot, CenterPosition.X - 2, CenterPosition.Y - Clip.h/2 - 10, 0, -SHOT_SPEED );
shots->push_back(newshot);
}
else if (Clip.x == MOVING_LEFT)
{
Shot newshot( Player_Shot, CenterPosition.X - Clip.w/2 - 10, CenterPosition.Y - 5, -SHOT_SPEED, 0 );
shots->push_back(newshot);
}
else if (Clip.x == MOVING_RIGHT)
{
Shot newshot( Player_Shot, CenterPosition.X + Clip.w/2 - 10, CenterPosition.Y - 5, SHOT_SPEED, 0 );
shots->push_back(newshot);
}
}
else if ( Clip.y == MOVING_FORWARD )
{
if ( Clip.x == STRAIGHT_AHEAD )
{
Shot newshot( Player_Shot, CenterPosition.X - 2, CenterPosition.Y - Clip.h/2 - 10, 0, -SHOT_SPEED );
shots->push_back(newshot);
}
else if ( Clip.x == MOVING_LEFT )
{
Shot newshot( Player_Shot, CenterPosition.X - Clip.w/2, CenterPosition.Y - Clip.h/2, -SHOT_SPEED, -SHOT_SPEED );
shots->push_back(newshot);
}
}
else if (Clip.y == MOVING_BACKWARD)
{
if ( Clip.x == STRAIGHT_AHEAD )
{
Shot newshot( Player_Shot, CenterPosition.X - 2, CenterPosition.Y + Clip.h/2, 0, SHOT_SPEED );
shots->push_back(newshot);
}
}
//cout<<shots->size()<<" end"<<endl;
break;
}
}
else if (Event.type == SDL_KEYUP)
{
switch(Event.key.keysym.sym)
{
case SDLK_UP:
case SDLK_DOWN:
Velocity.Y = 0;
break;
case SDLK_LEFT:
case SDLK_RIGHT:
Velocity.X = 0;
break;
case SDLK_SPACE:
break;
}
}
}
|