summaryrefslogtreecommitdiff
path: root/ship.cpp
blob: 2eaa852f74eaad9c900cf5caa6326d179d31e2a9 (plain)
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
#include "ship.h"
#include "bullet.h"

#include <cmath>

#define M_PI 3.14159265
// Put your ship methods here

// Apply thrust to ship
void Ship :: thrust ( const bool isUp )
{
   float thrust = THRUST_AMOUNT * ( isUp ? 1 : -1 );
   fuel -= 3;
   if ( fuel >= 0 )
   {
        velocity.addDx ( thrust * ( -cos ( M_PI / 180 * angle ) ) );
        velocity.addDy ( thrust * ( sin ( M_PI / 180 * angle ) ) );
   }
   else
   {
       fuel = 0; // In the case of negative fuel
   }
}

// Rotate ship
void Ship :: rotate ( const bool isRight )
{
   angle += ROTATE_AMOUNT * ( isRight ? -1 : 1 );
   fuel -= 1;
}

// Draw ship
void Ship :: draw ( ) const
{
   drawShip ( getPoint() , -(angle - 90) , isThrusting );
}