From 3010473314505bd948c687ac644b7d87ef03298d Mon Sep 17 00:00:00 2001 From: Simponic Date: Tue, 30 Jun 2020 20:10:29 -0600 Subject: Updated file structure and changed indents to spaces --- src/ship.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/ship.cpp (limited to 'src/ship.cpp') diff --git a/src/ship.cpp b/src/ship.cpp new file mode 100644 index 0000000..2eaa852 --- /dev/null +++ b/src/ship.cpp @@ -0,0 +1,36 @@ +#include "ship.h" +#include "bullet.h" + +#include + +#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 ); +} -- cgit v1.2.3-70-g09d2