Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/game
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-02-13 00:40:59 +0000
committerStijn Buys <ingar@osirion.org>2008-02-13 00:40:59 +0000
commit1f95c377b2abfaa454b1f2298af10956d95ad941 (patch)
tree2715cf49a8de16921775eff0dc1ac0ceace145b2 /src/game
parent468ab7f566ee493b8c7ff6a95763d99ed2ccc200 (diff)
split client from game module
Diffstat (limited to 'src/game')
-rw-r--r--src/game/game.cc50
-rw-r--r--src/game/game.h6
-rw-r--r--src/game/ship.cc55
-rw-r--r--src/game/ship.h31
4 files changed, 66 insertions, 76 deletions
diff --git a/src/game/game.cc b/src/game/game.cc
index 51bb565..25f8926 100644
--- a/src/game/game.cc
+++ b/src/game/game.cc
@@ -4,20 +4,28 @@
the terms of the GNU General Public License version 2
*/
-// project headers
+#include <vector>
+
#include "game/game.h"
#include "game/sector.h"
#include "game/ship.h"
#include "game/star.h"
-#include "filesystem/filesystem.h"
+#include "core/entity.h"
#include "sys/sys.h"
-
-// C++ headers
-#include <vector>
+#include "math/mathlib.h"
+#include "filesystem/filesystem.h"
namespace game
{
+Game::Game()
+{
+}
+
+Game::~Game()
+{
+}
+
bool Game::init()
{
using math::Vector3f;
@@ -102,11 +110,6 @@ bool Game::init()
star->location = Vector3f(256.0f, 0.0f, 256.0f);
star->label = "star: Sabishi Hoshi";
-
- ship = new Ship();
- ship->location = Vector3f(0,0,0);
- ship->label = "ship: Micron Vector";
-
core::Entity *cube = new core::Entity(core::entity::Solid & core::entity::Static);
cube->core_shape = core::entity::Cube;
cube->core_color = Color(0.0f, 0.8f, 0.0f);
@@ -151,7 +154,7 @@ void Game::shutdown()
void Game::frame(float seconds)
{
- ship->update(seconds);
+
}
void Game::event_join(core::Player *player)
@@ -160,8 +163,27 @@ void Game::event_join(core::Player *player)
return;
ship = new Ship();
- ship->location = Vector3f(0,0,0);
- ship->label = "ship: Micron Vector";
+ ship->location = math::Vector3f(0,0,0);
+ ship->label = "ship: <"+player->name+"> Micron Vector";
+ ship->owner = player;
+
+ player->controled = ship;
+
+ con_print << player->name << " joins" << std::endl;
}
-}; // namespace game
+void Game::event_leave(core::Player *player)
+{
+ if (!player)
+ return;
+
+ con_print << player->name << " leaves" << std::endl;
+
+ if (player->controled) {
+ // player only has one ship for now
+ core::entity::remove(player->controled->id);
+ }
+}
+
+} // namespace game
+
diff --git a/src/game/game.h b/src/game/game.h
index abe0c0d..9c993fe 100644
--- a/src/game/game.h
+++ b/src/game/game.h
@@ -26,6 +26,9 @@ namespace game
class Game : public core::GameInterface {
public:
+ Game();
+ ~Game();
+
/// initialize the game
bool init();
/// shutdown the game
@@ -36,6 +39,9 @@ public:
/// a player joins the game
void event_join(core::Player *player);
+ /// a player leaves the game
+ void event_leave(core::Player *player);
+
/// sectors in space
std::vector<Sector*> sectors;
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
diff --git a/src/game/ship.h b/src/game/ship.h
index e919f38..d108223 100644
--- a/src/game/ship.h
+++ b/src/game/ship.h
@@ -13,43 +13,22 @@
namespace game {
-class Ship : public core::Entity
+class Ship : public core::EntityControlable
{
public:
Ship();
~Ship();
/// update the ship state
- void update(float elapsed);
-
- /// speed vector in units/second
- float speed;
-
- /// return the current yaw angle
- inline float yaw() const { return yaw_current; }
- /// set the target yaw angle
- void set_yaw(float y);
-
- /// return the current thruster power
- inline float thrust() const { return thrust_current; }
- /// set thruster power
- void set_thrust(float t);
+ void frame(float seconds);
/* -- Ship SPECS --*/
/// acceleration
float acceleration;
/// maximum speed
- float speed_max;
- /// yaw turn speed
- float yaw_speed;
-private:
- /// current yaw, angle in XZ plane, 0-360
- float yaw_current;
- /// target yaw angle, angle in XYplane, 0-360
- float yaw_target;
-
- /// current thruster power in % [0-1]
- float thrust_current;
+ float max_speed;
+ /// turn speed in rotations per second
+ float turn_speed;
};
} // namespace game