--- a/src/proto2/Application.cc Tue Nov 18 19:42:01 2008 +0000
+++ b/src/proto2/Application.cc Tue Nov 18 19:59:43 2008 +0000
@@ -78,9 +78,9 @@
}
}
- // check for valid combinations of arugments
- if (!(arg_server xor !arg_connect.empty()))
- throw ArgumentError("must supply *exactly* one of --server/--client");
+ // check for invalid combinations of arugments
+ if (arg_server and !arg_connect.empty())
+ throw ArgumentError("cannot be both server and client");
}
public:
@@ -102,15 +102,16 @@
if (arg_graphics)
engine.setupGraphics();
- // setup either network server or client
+ // setup either network server, client or singleplayer
if (arg_server) {
engine.setupNetworkServer(arg_port);
} else if (!arg_connect.empty()) {
engine.setupNetworkClient(arg_connect, arg_port);
- } else
- assert(false);
+ } else {
+ engine.setupSinglePlayer();
+ }
// run the main loop
engine.run();
--- a/src/proto2/Engine.cc Tue Nov 18 19:42:01 2008 +0000
+++ b/src/proto2/Engine.cc Tue Nov 18 19:59:43 2008 +0000
@@ -2,6 +2,7 @@
#include "Engine.hh"
#include "NetworkServer.hh"
#include "NetworkClient.hh"
+#include "SinglePlayer.hh"
#include <iostream>
@@ -28,7 +29,10 @@
}
void Engine::setupSinglePlayer (void) {
- LocalPlayer* lp = new LocalPlayer(Vector(400, 300), true);
+ // create player directly
+ LocalPlayer* lp = new SinglePlayer();
+
+ // add to gamestate
game_state.newLocalPlayer(lp);
}
--- a/src/proto2/Engine.hh Tue Nov 18 19:42:01 2008 +0000
+++ b/src/proto2/Engine.hh Tue Nov 18 19:59:43 2008 +0000
@@ -37,8 +37,7 @@
// setting up both of these will lead to odd behaviour :)
void setupNetworkServer (const std::string &listen_port);
void setupNetworkClient (const std::string &connect_host, const std::string &connect_port);
-
- void setupSinglePlayer(void);
+ void setupSinglePlayer (void);
// run the main loop
void run (void);
--- a/src/proto2/GameState.cc Tue Nov 18 19:42:01 2008 +0000
+++ b/src/proto2/GameState.cc Tue Nov 18 19:59:43 2008 +0000
@@ -6,16 +6,16 @@
// handle up/down/left/right
if (input & INPUT_MOVE_UP)
- dy -= 3;
+ dy -= PLAYER_MOVE_FORCE;
if (input & INPUT_MOVE_DOWN)
- dy += 3;
+ dy += PLAYER_MOVE_FORCE;
if (input & INPUT_MOVE_LEFT)
- dx -= 3;
+ dx -= PLAYER_MOVE_FORCE;
if (input & INPUT_MOVE_RIGHT)
- dx += 3;
+ dx += PLAYER_MOVE_FORCE;
// apply force
applyForce(Vector(dx, dy));
--- a/src/proto2/GameState.hh Tue Nov 18 19:42:01 2008 +0000
+++ b/src/proto2/GameState.hh Tue Nov 18 19:59:43 2008 +0000
@@ -7,7 +7,7 @@
#include <list>
#include <stdexcept>
-const uint16_t PLAYER_MASS = 8035;
+const uint16_t PLAYER_MASS = 100;
const uint16_t PLAYER_DIM_W = 10;
const uint16_t PLAYER_DIM_H = 10;
const uint16_t MAP_DIM_W = 800;
@@ -63,12 +63,14 @@
throw std::logic_error("newLocalPlayer called even though we already have a local player");
player_list.push_back(player);
+ addObject(player);
local_player = player;
}
void newRemotePlayer (RemotePlayer *player) {
player_list.push_back(player);
+ addObject(player);
}
void removePlayer (Player *player) {
--- a/src/proto2/Graphics.cc Tue Nov 18 19:42:01 2008 +0000
+++ b/src/proto2/Graphics.cc Tue Nov 18 19:59:43 2008 +0000
@@ -17,7 +17,7 @@
void Graphics::check_input (void) {
LocalPlayer *player;
- PlayerInput_Move input_move;
+ PlayerInput_Move input_move = 0;
// stop on escape
if (keyboard.get_keycode(CL_KEY_ESCAPE)) {
--- a/src/proto2/Graphics.hh Tue Nov 18 19:42:01 2008 +0000
+++ b/src/proto2/Graphics.hh Tue Nov 18 19:59:43 2008 +0000
@@ -11,8 +11,8 @@
#include <ClanLib/gl.h>
#include <ClanLib/display.h>
-#define GRAPHICS_WINDOW_TITLE "Kisna Glista"
-#define GRAPHICS_UPDATE_INTERVAL_MS 100
+const std::string GRAPHICS_WINDOW_TITLE = "Kisna Glista";
+const uint16_t GRAPHICS_UPDATE_INTERVAL_MS = 100;
class Graphics {
private:
--- a/src/proto2/Input.hh Tue Nov 18 19:42:01 2008 +0000
+++ b/src/proto2/Input.hh Tue Nov 18 19:59:43 2008 +0000
@@ -1,6 +1,8 @@
#ifndef INPUT_HH
#define INPUT_HH
+const uint16_t PLAYER_MOVE_FORCE = 5;
+
enum {
INPUT_MOVE_UP = 0x01,
INPUT_MOVE_DOWN = 0x02,
--- a/src/proto2/Physics.cc Tue Nov 18 19:42:01 2008 +0000
+++ b/src/proto2/Physics.cc Tue Nov 18 19:59:43 2008 +0000
@@ -1,9 +1,10 @@
+
+#include "Physics.hh"
+#include "Engine.hh"
+
#include <algorithm>
#include <functional>
-#include "Physics.hh"
-
-
PhysicsWorld::PhysicsWorld (Vector dimensions)
: tick_timer(PHYSICS_TICK_MS), dimensions(dimensions) {
@@ -16,6 +17,8 @@
}
void PhysicsWorld::tick () {
+ Engine::log(DEBUG, "physics.apply_force") << "*tick*";
+
for(std::vector<PhysicsObject*>::iterator i = objects.begin(); i != objects.end(); i++) {
(*i)->tick();
}
@@ -28,11 +31,13 @@
void PhysicsObject::updatePosition () {
// Calculate gravity's influence on the velocity vector
- this->velocity += (GRAVITY_FORCE / this->mass) * PHYSICS_TICK_MS * 1000;
+ this->velocity += (GRAVITY_FORCE / this->mass) * PHYSICS_TICK_MS;
- Vector newPosition = position + velocity * PHYSICS_TICK_MS * 1000;
+ Vector newPosition = position + velocity * PHYSICS_TICK_MS;
//TODO Handle the object as a square or a polygon
+
+ Engine::log(DEBUG, "physics.update_position") << "position" << newPosition;
if(newPosition.x < 0 || (newPosition.x > PHYSICS_WORLD_WIDTH)
|| (newPosition.y < 0) || (newPosition.y >= PHYSICS_WORLD_HEIGHT)) {
@@ -46,8 +51,12 @@
}
void PhysicsObject::applyForce (Vector force) {
- this->velocity += force / mass * PHYSICS_TICK_MS * 1000; // The last factor denotes the time.
+ Vector oldVelocity = velocity;
+
+ this->velocity += (force * PHYSICS_TICK_MS) / mass; // The last factor denotes the time.
// It should be scaled somehow.
+
+ Engine::log(DEBUG, "physics.apply_force") << "force=" << force << ", velocity " << oldVelocity << " -> " << velocity;
}
void PhysicsObject::updatePhysics (Vector position, Vector velocity, Vector force) {
--- a/src/proto2/Physics.hh Tue Nov 18 19:42:01 2008 +0000
+++ b/src/proto2/Physics.hh Tue Nov 18 19:59:43 2008 +0000
@@ -8,7 +8,7 @@
const uint16_t PHYSICS_TICK_MS = 50;
const uint16_t PHYSICS_WORLD_WIDTH = 800;
const uint16_t PHYSICS_WORLD_HEIGHT = 600;
-const Vector GRAVITY_FORCE(0,-1);
+const Vector GRAVITY_FORCE(0, -5);
// forward-declare
class PhysicsObject;
--- a/src/proto2/Vector.hh Tue Nov 18 19:42:01 2008 +0000
+++ b/src/proto2/Vector.hh Tue Nov 18 19:59:43 2008 +0000
@@ -71,6 +71,6 @@
return s<<"("<<v.x<<", "<<v.y<<")";
}
-typedef _Vector<uint32_t> Vector;
+typedef _Vector<int32_t> Vector;
#endif