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
|
void ship::move()
{
bool up = false;
bool down = false;
bool left = false;
bool right = false;
if (keys [SDLK_LEFT])
{
left = true;
if (GetX()-speed >= - 30 )
SetX( GetX()-speed);
}
if (keys [SDLK_RIGHT])
{
right = true;
if (GetX()+speed <= RES_X - 70 )
SetX( GetX()+speed);
}
if (keys [SDLK_UP])
{
up = true;
if (GetY()-speed >= 0)
SetY( GetY()-speed);
}
if (keys [SDLK_DOWN])
{
down = true;
if (GetY()+speed <= RES_Y - 30)
SetY( GetY()+speed);
}
if (up)
currstate = d_up;
if (down)
currstate = d_down;
if (left)
currstate = d_left;
if (right)
currstate = d_right;
if (up && left)
currstate = d_up_left;
if (up && right)
currstate = d_up_right;
if (down && left)
currstate = d_down_left;
if (down && right)
currstate = d_down_right;
if (!up && !down && !left && !right)
currstate = d_straight;
}
void ship::weapon_management(SDL_Surface *bmp)
{
if (keys[SDLK_SPACE] && canshoot)
{
shoot();
canshoot = false;
}
if (!keys[SDLK_SPACE]) canshoot = true;
if ( ! ship_bullets.empty())
{
move_bullets();
remove_bullet();
draw_bullets(bmp);
}
} |
Partager