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>2007-10-20 10:02:51 +0000
committerStijn Buys <ingar@osirion.org>2007-10-20 10:02:51 +0000
commit3866f2b33313d891347f454537843befd295b78f (patch)
treeba748f4bf021605cc8e1488e7e14a4085f81a9ae /src/game
Initial import.
Diffstat (limited to 'src/game')
-rw-r--r--src/game/Makefile.am9
-rw-r--r--src/game/game.cc31
-rw-r--r--src/game/game.h33
-rw-r--r--src/game/player.h20
-rw-r--r--src/game/sector.h26
-rw-r--r--src/game/ship.cc85
-rw-r--r--src/game/ship.h54
-rw-r--r--src/game/star.cc17
-rw-r--r--src/game/star.h29
-rw-r--r--src/game/world.h24
10 files changed, 328 insertions, 0 deletions
diff --git a/src/game/Makefile.am b/src/game/Makefile.am
new file mode 100644
index 0000000..754c168
--- /dev/null
+++ b/src/game/Makefile.am
@@ -0,0 +1,9 @@
+
+METASOURCES = AUTO
+libgame_la_LDFLAGS = -avoid-version
+noinst_LTLIBRARIES = libgame.la
+
+libgame_la_SOURCES = game.cc game.h ship.cc ship.h player.h world.h star.cc \
+ star.h sector.h
+INCLUDES = -I$(top_srcdir)/src
+noinst_HEADERS = world.h sector.h
diff --git a/src/game/game.cc b/src/game/game.cc
new file mode 100644
index 0000000..dfa5fe5
--- /dev/null
+++ b/src/game/game.cc
@@ -0,0 +1,31 @@
+/* game.cc
+ This file is part of the Osirion project
+*/
+
+// project headers
+#include "ship.h"
+#include "star.h"
+
+namespace game {
+
+Ship ship;
+Star star;
+bool initialized = false;
+
+void init()
+{
+ star.location = Vector3f(256.0f, 0.0f, 256.0f);
+ initialized = true;
+}
+
+void shutdown()
+{
+ initialized = false;
+}
+
+void update(float elapsed)
+{
+ ship.update(elapsed);
+}
+
+}; // namespace game
diff --git a/src/game/game.h b/src/game/game.h
new file mode 100644
index 0000000..7c1cc0c
--- /dev/null
+++ b/src/game/game.h
@@ -0,0 +1,33 @@
+/* game.h
+ This file is part of the Osirion project
+*/
+
+#ifndef __INCLUDED_GAME_H__
+#define __INCLUDED_GAME_H__
+
+// project headers
+#include "ship.h"
+#include "star.h"
+
+namespace game
+{
+ /// initialize the game
+ void init();
+
+ /// shutdown the game
+ void shutdown();
+
+ /// update the game state
+ void update(float elapsed);
+
+ /// the only ship in the game
+ extern Ship ship;
+
+ /// the only star in the game
+ extern Star star;
+
+ /// true while the game is running
+ extern bool initialized;
+};
+
+#endif // __INCLUDED_GAME_H__
diff --git a/src/game/player.h b/src/game/player.h
new file mode 100644
index 0000000..4c75206
--- /dev/null
+++ b/src/game/player.h
@@ -0,0 +1,20 @@
+/* player.h
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
+*/
+
+#ifndef __INCLUDED_PLAyER_H__
+#define __INCLUDED_PLAyER_H__
+
+#include <string>
+
+/// A player in the game
+class Player {
+public:
+ Player();
+ ~Player();
+
+ std::string name;
+};
+
+#endif // __INCLUDED_PLAyER_H__
diff --git a/src/game/sector.h b/src/game/sector.h
new file mode 100644
index 0000000..10f548c
--- /dev/null
+++ b/src/game/sector.h
@@ -0,0 +1,26 @@
+/* sector.h
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
+*/
+
+#ifndef __INCLUDED_SECTOR_H__
+#define __INCLUDED_SECTOR_H__
+
+#include <string>
+
+namespace game
+{
+class Sector {
+public:
+ Sector();
+ ~Sector();
+
+ /// tag used in configuration files, e.g. "terran"
+ std::string tag;
+ /// name to display, e.g. "Terran System"
+ std::string name;
+};
+
+} // namespace game
+
+#endif // __INCLUDED_SECTOR_H__
diff --git a/src/game/ship.cc b/src/game/ship.cc
new file mode 100644
index 0000000..a24be0d
--- /dev/null
+++ b/src/game/ship.cc
@@ -0,0 +1,85 @@
+/* ship.cc
+ This file is part of the Osirion project
+*/
+
+// C++ headers
+#include <iostream>
+
+// project headers
+#include "common/functions.h"
+#include "common/osirion.h"
+
+#include "ship.h"
+
+Ship::Ship()
+{
+ speed = 0;
+ yaw = 0;
+ yaw_offset = 0;
+
+ thrust = 0;
+
+ // ship specs
+ acceleration = 6 * GAMESCALE;
+ max_speed = 16.0f * GAMESCALE;
+
+ max_yaw_offset = 45;
+ yaw_speed = 4;
+}
+
+Ship::~Ship()
+{
+}
+
+void Ship::update(float elapsed)
+{
+ // update yaw
+ float d = yaw_speed * elapsed * yaw_offset;
+ yaw_offset -= d;
+ yaw +=d;
+
+ // update thrust
+ if (speed < thrust * max_speed) {
+ speed += acceleration * elapsed;
+ if (speed > thrust * max_speed) {
+ speed = thrust * max_speed;
+ }
+ } else if(speed > thrust * max_speed) {
+ 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;
+}
+
diff --git a/src/game/ship.h b/src/game/ship.h
new file mode 100644
index 0000000..d6a00ba
--- /dev/null
+++ b/src/game/ship.h
@@ -0,0 +1,54 @@
+/* ship.h
+ This file is part of the Osirion project
+*/
+
+#ifndef __INCLUDED_SHIP_H__
+#define __INCLUDED_SHIP_H__
+
+// project headers
+#include "common/vector3f.h"
+
+class Ship
+{
+public:
+ Ship();
+ ~Ship();
+
+ /// update the ship state
+ void update(float elapsed);
+
+ /// location of the ship in space
+ Vector3f location;
+ /// speed vector in units/second
+ float speed;
+
+ /// turn left, increase yaw_offset
+ void turn_left();
+ /// turn right, decrease yaw_offset
+ void turn_right();
+ /// yaw, angle in the x/z plane
+ float yaw;
+
+ /// increase thrust
+ void thrust_increase();
+ /// decrease thrust
+ void thrust_decrease();
+ /// forward thruster in % [0-1]
+ float thrust;
+
+ /* -- Ship SPECS --*/
+ /// acceleration
+ float acceleration;
+ /// maximum speed
+ float max_speed;
+ /// maximum yaw_offset
+ float max_yaw_offset;
+ /// yaw turn speed
+ float yaw_speed;
+
+private:
+ float yaw_offset;
+};
+
+#endif // __INCLUDED_SHIP_H__
+
diff --git a/src/game/star.cc b/src/game/star.cc
new file mode 100644
index 0000000..6aa82ac
--- /dev/null
+++ b/src/game/star.cc
@@ -0,0 +1,17 @@
+/* star.h
+ 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 "star.h"
+
+Star::Star() :
+ location(0,0,0),
+ color(1,1,1,1)
+{
+ radius = 48;
+}
+
+Star::~Star()
+{
+}
diff --git a/src/game/star.h b/src/game/star.h
new file mode 100644
index 0000000..ef33ad5
--- /dev/null
+++ b/src/game/star.h
@@ -0,0 +1,29 @@
+/* star.h
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
+*/
+
+#ifndef __INCLUDED_STAR_H__
+#define __INCLUDED_STAR_H__
+
+// C++ headers
+#include <string>
+
+// project headers
+#include "common/vector3f.h"
+#include "common/color.h"
+
+/// A star, that shines so bright
+class Star {
+public:
+ Star();
+ ~Star();
+
+ Vector3f location;
+ Color color;
+ float radius;
+
+ std::string name;
+};
+
+#endif // __INCLUDED_STAR_H__
diff --git a/src/game/world.h b/src/game/world.h
new file mode 100644
index 0000000..8cbc232
--- /dev/null
+++ b/src/game/world.h
@@ -0,0 +1,24 @@
+/* world.h
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
+*/
+
+#ifndef __INCLUDED_WORLD_H__
+#define __INCLUDED_WORLD_H__
+
+#include <string>
+
+namespace game
+{
+
+/// The game world
+namespace World {
+ /// load the intial game world into memory
+ void init();
+ /// unload the game world
+ void shutdown();
+};
+
+} // namespace game
+
+#endif // __INCLUDED_WORLD_H__