diff options
author | Stijn Buys <ingar@osirion.org> | 2007-10-28 09:19:35 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2007-10-28 09:19:35 +0000 |
commit | 09789179cd77ce2f626fffbc94a90ec8784b76df (patch) | |
tree | ea265dc9b338fc9673d55f7db0623fe4b2aa5824 /src/game/ship.cc | |
parent | 795ec263875665e530458c7d95a1fb0242d55f8f (diff) |
game::Ship interface changes
Diffstat (limited to 'src/game/ship.cc')
-rw-r--r-- | src/game/ship.cc | 73 |
1 files changed, 30 insertions, 43 deletions
diff --git a/src/game/ship.cc b/src/game/ship.cc index f0c40c4..049283f 100644 --- a/src/game/ship.cc +++ b/src/game/ship.cc @@ -11,21 +11,22 @@ // C++ headers #include <iostream> +using common::degrees360f; +using common::degrees180f; + namespace game { Ship::Ship() { speed = 0; - yaw = 0; - yaw_offset = 0; + yaw_current = 0; + yaw_target = yaw_current; - thrust = 0; + thrust_current = 0; // ship specs acceleration = 1.5f; - max_speed = 4.0f; - - max_yaw_offset = 45.0f; + speed_max = 4.0f; yaw_speed = 4.0f; } @@ -33,56 +34,42 @@ Ship::~Ship() { } +void Ship::set_yaw(float y) +{ + 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; +} + void Ship::update(float elapsed) { // update yaw + float yaw_offset = degrees180f(yaw_target - yaw_current); float d = yaw_speed * elapsed * yaw_offset; - yaw_offset -= d; - yaw +=d; + yaw_current = degrees360f(yaw_current + d); // update thrust - if (speed < thrust * max_speed) { + if (speed < thrust_current * speed_max) { speed += acceleration * elapsed; - if (speed > thrust * max_speed) { - speed = thrust * max_speed; + if (speed > thrust_current * speed_max) { + speed = thrust_current * speed_max; } - } else if(speed > thrust * max_speed) { + } else if(speed > thrust_current * speed_max) { 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; + location.x += cosf(yaw_current * M_PI / 180) * speed * elapsed; + location.z -= sinf(yaw_current * M_PI / 180) * speed * elapsed; } } // namespace game |