Skip to content

Commit

Permalink
Added score on server side, 1 s = 1 point. Part of #10.
Browse files Browse the repository at this point in the history
  • Loading branch information
Reicher committed Feb 3, 2017
1 parent 2f59766 commit aa1fcd6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
7 changes: 6 additions & 1 deletion client/src/states/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default class extends Phaser.State {
init(connection, id) {
this.connection = connection;
this.playerId = id;
this.score = 0

// Client pixels per server meter
this.gameScale = 32
Expand Down Expand Up @@ -55,14 +56,18 @@ export default class extends Phaser.State {
this.game.add.existing(newEntity)
clientEntity = newEntity

if (serverEntity.id == this.playerId)
if (serverEntity.id == this.playerId){
this.game.camera.follow(this.entities[this.playerId])
this.score = serverEntity.score
}
}
clientEntity.x = serverEntity.x * this.gameScale;
clientEntity.y = serverEntity.y * this.gameScale;
//clientEntity.body.velocity.x = serverEntity.vx
//clientEntity.body.velocity.y = serverEntity.vy
clientEntity.angle = serverEntity.r

console.log(clientEntity.score)
}
}

Expand Down
7 changes: 5 additions & 2 deletions server/src/triangulum/system/OutputSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "triangulum/component/ClientInfo.h"
#include "triangulum/component/DynamicBody.h"
#include "triangulum/component/Graphics.h"
#include "triangulum/component/Score.h"
#include "triangulum/network/ConnectionManager.h"

using namespace entityx;
Expand All @@ -23,8 +24,8 @@ void OutputSystem::update(EntityManager& entities,
{
auto object_list = nlohmann::json::array();

entities.each<Graphics, DynamicBody>(
[&object_list](Entity entity, Graphics& graphics, DynamicBody& body) {
entities.each<Graphics, DynamicBody, Score>(
[&object_list](Entity entity, Graphics& graphics, DynamicBody& body, Score score) {

nlohmann::json object;

Expand All @@ -46,6 +47,8 @@ void OutputSystem::update(EntityManager& entities,

object["vr"] = 0;

object["score"] = (int)score.score;

object_list.push_back(object);

});
Expand Down
12 changes: 7 additions & 5 deletions server/src/triangulum/system/SimulationSystem.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#include "triangulum/system/SimulationSystem.h"
//#include "triangulum/component/Score.h"
#include "triangulum/component/Score.h"
#include "triangulum/component/Input.h"

using namespace entityx;

namespace triangulum {
namespace system {

using namespace component;

SimulationSystem::SimulationSystem(b2World& world)
: m_world(world)
, m_velocityIterations(8) // how strongly to correct velocity
Expand All @@ -20,10 +22,10 @@ void SimulationSystem::update(EntityManager& entities,
TimeDelta dt)
{
// Why wont this work, is this update fucked up because of this is a listener as well?
/* entities.each<Score>(
[](Entity entity, Score& score) {
score.score += dt;
});*/
entities.each<Score>(
[&dt](Entity entity, Score& score) {
score.score += dt;
});

m_world.Step(dt, m_velocityIterations, m_positionIterations);
}
Expand Down

0 comments on commit aa1fcd6

Please sign in to comment.