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>2008-10-18 17:58:45 +0000
committerStijn Buys <ingar@osirion.org>2008-10-18 17:58:45 +0000
commit35613f0860a2d8cb643ca8de006de08503e48e53 (patch)
tree8a5436de643e818e68a82df2e5cb2df2145f5062 /src/game/example/spectator.cc
parentdb287e4a5133125bb6f25ba21ea97c47b19ac67f (diff)
example module
Diffstat (limited to 'src/game/example/spectator.cc')
-rw-r--r--src/game/example/spectator.cc65
1 files changed, 65 insertions, 0 deletions
diff --git a/src/game/example/spectator.cc b/src/game/example/spectator.cc
new file mode 100644
index 0000000..7b3a165
--- /dev/null
+++ b/src/game/example/spectator.cc
@@ -0,0 +1,65 @@
+/*
+ base/spectator.cc
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
+*/
+
+#include "example/spectator.h"
+
+namespace example {
+
+core::Cvar *Spectator::g_spectatorspeed = 0;
+core::Cvar *Spectator::g_spectatorrotation = 0;
+
+Spectator::Spectator(core::Player *owner) : core::EntityControlable(owner)
+{
+ // default properties
+ entity_shape = core::Entity::Diamond;
+ entity_radius = 0.25f;
+
+ // the spectator gets player color
+ entity_color.assign(owner->color());
+ entity_color_second.assign(owner->color_second());
+
+ // set dirty flag
+ set_dirty();
+}
+
+Spectator::~Spectator()
+{
+}
+
+void Spectator::frame(float elapsed)
+{
+ // only update if necessary
+ if (!entity_speed && ! target_thrust && !target_direction && !target_pitch && !target_roll)
+ return;
+
+ // assign thrust value from input
+ entity_thrust = target_thrust;
+
+ // rotate according to input
+ float rotation = g_spectatorrotation->value() * elapsed;
+ entity_axis.change_direction(target_direction * rotation);
+ entity_axis.change_pitch(target_pitch * rotation);
+ entity_axis.change_roll(target_roll * rotation);
+
+ // assign speed from thruster
+ float maxspeed = g_spectatorspeed->value();
+ entity_speed = entity_thrust * maxspeed;
+
+ // assign new location
+ if (entity_speed)
+ entity_location += entity_axis.forward() * entity_speed * elapsed;
+
+ if (target_afterburner)
+ entity_location += entity_axis.forward() * maxspeed * target_afterburner * elapsed;
+
+ if (target_strafe)
+ entity_location += entity_axis.left() * maxspeed * target_strafe * elapsed;
+
+ // set dirty flag
+ set_dirty();
+}
+
+}