diff options
Diffstat (limited to 'src/game')
-rw-r--r-- | src/game/game.cc | 7 | ||||
-rw-r--r-- | src/game/ship.cc | 26 |
2 files changed, 22 insertions, 11 deletions
diff --git a/src/game/game.cc b/src/game/game.cc index 88718b4..07327d9 100644 --- a/src/game/game.cc +++ b/src/game/game.cc @@ -128,6 +128,8 @@ void Game::init() Star *star = 0; core::Entity *entity = 0; + float direction; + while (worldini.getline()) { if (worldini.got_key()) { if (worldini.section().compare("star") == 0) { @@ -163,9 +165,10 @@ void Game::init() continue; else if (worldini.got_key_string("model", entity->entity_modelname)) continue; - else if (worldini.got_key_angle("direction", entity->entity_direction)) + else if (worldini.got_key_angle("direction", direction)) { + entity->axis().change_direction(direction); continue; - else if (worldini.got_key_angle("radius", entity->entity_radius)) + } else if (worldini.got_key_angle("radius", entity->entity_radius)) continue; else if (worldini.got_key_vector3f("location", entity->entity_location)) continue; diff --git a/src/game/ship.cc b/src/game/ship.cc index 7c3d21d..af10525 100644 --- a/src/game/ship.cc +++ b/src/game/ship.cc @@ -37,9 +37,9 @@ void Ship::frame(float seconds) { // update thrust entity_thrust = target_thrust; - if (entity_thrust < 0) + if (entity_thrust < 0.0f) entity_thrust = 0.0f; - else if(entity_thrust > 1) + else if(entity_thrust > 1.0f) entity_thrust = 1.0f; // update direction @@ -48,9 +48,19 @@ void Ship::frame(float seconds) else if (target_direction < -1.0f) target_direction = -1.0f; - // turnspeed is rotations per second - float direction_offset = 360.0f * ship_shipmodel->turnspeed() * seconds * target_direction; - entity_direction = degrees360f(entity_direction + direction_offset); + float direction_offset = ship_shipmodel->turnspeed() * seconds * target_direction; + if (direction_offset) + entity_axis.change_direction(360.0f * direction_offset); + + // update pitch + if (target_pitch > 1.0f) + target_pitch = 1.0f; + else if (target_pitch < -1.0f) + target_pitch = -1.0f; + + float pitch_offset = ship_shipmodel->turnspeed() * seconds * target_pitch; + if (pitch_offset) + entity_axis.change_pitch(360.0f * pitch_offset); // update speed if (entity_speed < entity_thrust * ship_shipmodel->maxspeed()) { @@ -60,12 +70,10 @@ void Ship::frame(float seconds) } } else if(entity_speed > entity_thrust * ship_shipmodel->maxspeed()) { entity_speed -= ship_shipmodel->acceleration() * seconds; - if (entity_speed < 0) entity_speed = 0; + if (entity_speed < 0.0f) entity_speed = 0.0f; } - // location TODO avoid sin/cos calculations - entity_location.x += cosf(entity_direction * M_PI / 180) * entity_speed * seconds; - entity_location.y += sinf(entity_direction * M_PI / 180) * entity_speed * seconds; + entity_location += entity_axis.forward() * entity_speed * seconds; entity_dirty = true; } |