Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2007-10-20 10:02:51 +0000
committerStijn Buys <ingar@osirion.org>2007-10-20 10:02:51 +0000
commit3866f2b33313d891347f454537843befd295b78f (patch)
treeba748f4bf021605cc8e1488e7e14a4085f81a9ae /src/game/ship.cc
Initial import.
Diffstat (limited to 'src/game/ship.cc')
-rw-r--r--src/game/ship.cc85
1 files changed, 85 insertions, 0 deletions
diff --git a/src/game/ship.cc b/src/game/ship.cc
new file mode 100644
index 0000000..a24be0d
--- /dev/null
+++ b/src/game/ship.cc
@@ -0,0 +1,85 @@
+/* ship.cc
+ This file is part of the Osirion project
+*/
+
+// C++ headers
+#include <iostream>
+
+// project headers
+#include "common/functions.h"
+#include "common/osirion.h"
+
+#include "ship.h"
+
+Ship::Ship()
+{
+ speed = 0;
+ yaw = 0;
+ yaw_offset = 0;
+
+ thrust = 0;
+
+ // ship specs
+ acceleration = 6 * GAMESCALE;
+ max_speed = 16.0f * GAMESCALE;
+
+ max_yaw_offset = 45;
+ yaw_speed = 4;
+}
+
+Ship::~Ship()
+{
+}
+
+void Ship::update(float elapsed)
+{
+ // update yaw
+ float d = yaw_speed * elapsed * yaw_offset;
+ yaw_offset -= d;
+ yaw +=d;
+
+ // update thrust
+ if (speed < thrust * max_speed) {
+ speed += acceleration * elapsed;
+ if (speed > thrust * max_speed) {
+ speed = thrust * max_speed;
+ }
+ } else if(speed > thrust * max_speed) {
+ speed -= acceleration * elapsed;
+ if (speed < 0) speed = 0;
+ }
+
+ // location TODO avoid sin/cos calculations
+ location.x += cosf(yaw * M_PI / 180) * speed * elapsed;
+ location.z -= sinf(yaw * M_PI / 180) * speed * elapsed;
+}
+
+
+void Ship::thrust_increase()
+{
+ thrust += 0.05;
+ if (thrust > 1) thrust = 1;
+}
+
+void Ship::thrust_decrease()
+{
+ thrust -= 0.08;
+ if (thrust < 0) thrust = 0;
+}
+
+void Ship::turn_left()
+{
+ //yaw = degreesf(yaw + 2);
+ yaw_offset += 2;
+ if (yaw_offset > max_yaw_offset)
+ yaw_offset = max_yaw_offset;
+}
+
+void Ship::turn_right()
+{
+ //yaw = degreesf(yaw - 2);
+ yaw_offset -= 2;
+ if (yaw_offset < -max_yaw_offset)
+ yaw_offset = - max_yaw_offset;
+}
+