From 78b9b2436c59529865c1c17a7c20e320f8d6f695 Mon Sep 17 00:00:00 2001 From: /jedi/ Date: Wed, 28 Sep 2016 05:52:23 +0200 Subject: [PATCH] stuff to test --- game/game.cpp | 4 ++-- game/state/state.cpp | 26 ++++++++++++++++++++++++++ game/state/state.hpp | 4 ++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/game/game.cpp b/game/game.cpp index 0389e72..181b8ff 100644 --- a/game/game.cpp +++ b/game/game.cpp @@ -15,12 +15,11 @@ Game::Game() m_state = new game::State(); m_state->init(); - m_state->addPlayer(); } bool Game::cycle(float dt) { -#if 1 +#if 0 // XXX the following is just testing code to do things static float total = 0.0; @@ -34,6 +33,7 @@ bool Game::cycle(float dt) // m_state->players[0]->addCommand(new game::ShootCommand(a)); // } //} + m_state->addPlayer(); acc += dt; total += dt; diff --git a/game/state/state.cpp b/game/state/state.cpp index 63ef686..ae366da 100644 --- a/game/state/state.cpp +++ b/game/state/state.cpp @@ -18,6 +18,8 @@ #include "util.hpp" +using namespace std; + namespace game { void State::init() { @@ -76,6 +78,30 @@ namespace game { void State::quitPlayer(int playerId) { (void) playerId; + cout << playerId << " quit" << endl; + } + + void State::clear(int playerId) + { + cout << playerId << " clear" << endl; + } + + void State::setName(int playerId, std::string name) + { + // discard if not unique + for (const Player *other : players) { + if (name == other->name) { + std::cout << "name '" << name << "' already given to player #" << other->id << std::endl; + return; + } + } + + playerForId(playerId)->name = name; + } + + void State::setSpeed(int playerId, double speed) + { + playerForId(playerId)->speed = speed; } void State::advancePlayerShipSpawns(float dt) diff --git a/game/state/state.hpp b/game/state/state.hpp index 40c71f6..c57a849 100644 --- a/game/state/state.hpp +++ b/game/state/state.hpp @@ -2,6 +2,7 @@ #include #include +#include #include @@ -51,6 +52,9 @@ namespace game { // The upper layer (network/renderer) calling these three functions // should keep id's unique and give one (network) input an id. int addPlayer(); + void clear(int playerId); + void setName(int playerId, std::string name); + void setSpeed(int playerId, double speed); void quitPlayer(int playerId); void commandForPlayer(int playerId, Command *cmd);