Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/game/ship.cc')
-rw-r--r--src/game/ship.cc55
1 files changed, 19 insertions, 36 deletions
diff --git a/src/game/ship.cc b/src/game/ship.cc
index d6333cd..baa97f1 100644
--- a/src/game/ship.cc
+++ b/src/game/ship.cc
@@ -17,62 +17,45 @@ using math::degrees180f;
namespace game {
-Ship::Ship() : core::Entity(0)
+Ship::Ship() : core::EntityControlable(0)
{
type = ship_enttype;
- speed = 0;
- yaw_current = 0;
- yaw_target = yaw_current;
-
- thrust_current = 0;
-
// ship specs
acceleration = 1.5f;
- speed_max = 4.0f;
- yaw_speed = 4.0f;
+ max_speed = 4.0f;
+ turn_speed = 0.5f;
}
Ship::~Ship()
{
}
-void Ship::set_yaw(float y)
+void Ship::frame(float seconds)
{
- yaw_target = degrees360f(y);
-}
-void Ship::set_thrust(float t)
-{
- if (t < 0)
- thrust_current = 0;
- else if (t > 1)
- thrust_current = 1;
- else
- thrust_current = t;
-}
+ if (target_thrust < 0) target_thrust = 0.0f;
+ else if(target_thrust > 1) target_thrust = 1.0f;
-void Ship::update(float elapsed)
-{
- // update yaw
- float yaw_offset = degrees180f(yaw_target - yaw_current);
- float d = yaw_speed * elapsed * yaw_offset;
- yaw_current = degrees360f(yaw_current + d);
+ // update direction
+ float direction_offset = degrees180f(target_direction - direction);
+ float d = turn_speed * seconds * direction_offset;
+ direction = degrees360f(direction + d);
- // update thrust
- if (speed < thrust_current * speed_max) {
- speed += acceleration * elapsed;
- if (speed > thrust_current * speed_max) {
- speed = thrust_current * speed_max;
+ // update speed
+ if (speed < target_thrust * max_speed) {
+ speed += acceleration * seconds;
+ if (speed > target_thrust * max_speed) {
+ speed = target_thrust * max_speed;
}
- } else if(speed > thrust_current * speed_max) {
- speed -= acceleration * elapsed;
+ } else if(speed > target_thrust * max_speed) {
+ speed -= acceleration * seconds;
if (speed < 0) speed = 0;
}
// location TODO avoid sin/cos calculations
- location.x += cosf(yaw_current * M_PI / 180) * speed * elapsed;
- location.z -= sinf(yaw_current * M_PI / 180) * speed * elapsed;
+ location.x += cosf(direction * M_PI / 180) * speed * seconds;
+ location.z -= sinf(direction * M_PI / 180) * speed * seconds;
}
} // namespace game