Skip to content

Commit 4bcd8c1

Browse files
Keith BannisterKeith Bannister
Keith Bannister
authored and
Keith Bannister
committed
Clamp speed
1 parent 74c5e7c commit 4bcd8c1

File tree

2 files changed

+46
-6
lines changed

2 files changed

+46
-6
lines changed

ecosystem.config.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
module.exports = {
2+
apps: [{
3+
name: 'rockethedz',
4+
script: 'bin/www',
5+
watch: true,
6+
env: {
7+
"NODE_ENV": "development",
8+
"TURN_SERVER":"freya.bannister.id.au",
9+
},
10+
env_production: {
11+
"NODE_ENV": "production",
12+
"TURN_SERVER":"freya.bannister.id.au",
13+
}
14+
}],
15+
16+
deploy: {
17+
production: {
18+
user: 'keith',
19+
host: 'freya',
20+
ref: 'origin/master',
21+
repo: '[email protected]:strocode/hedz.git',
22+
path: '/home/keith/RocketHedz/',
23+
'pre-deploy-local': '',
24+
'post-deploy': 'npm install && npm run build && pwd && pushd public/game && npm install && popd && pm2 reload ecosystem.config.js --env production',
25+
'pre-setup': ''
26+
}
27+
}
28+
};

rockethedz_game_server/js/game.js

+18-6
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const config = {
2121
debug: {
2222
showBody: true,
2323
showStaticBody: true
24-
}
24+
},
2525
}
2626
},
2727
scene: {
@@ -160,6 +160,16 @@ function wrap(p) {
160160
}
161161
}
162162

163+
function clampVelocity(p, maxSpeed)
164+
{
165+
let v = p.body.velocity;
166+
let speed = Math.sqrt(v.x*v.x + v.y*v.y);
167+
if (speed > maxSpeed) {
168+
p.setVelocity(v.x*maxSpeed/speed, v.y*maxSpeed/speed);
169+
}
170+
171+
}
172+
163173
function update() {
164174
const self = this;
165175
const players = self.players;
@@ -170,10 +180,11 @@ function update() {
170180
let torque=5.0;
171181
if (input.left) {
172182
//playerPhysics.setAngularVelocity(-0.3/4);
173-
playerPhysics.body.torque = -torque;
174-
} else if (input.right) {
183+
playerPhysics.body.torque += -torque;
184+
}
185+
if (input.right) {
175186
//playerPhysics.setAngularVelocity(0.3/4);
176-
playerPhysics.body.torque = torque ;
187+
playerPhysics.body.torque += torque ;
177188

178189
} else {
179190
//playerPhysics.setAngularVelocity(0);
@@ -188,7 +199,8 @@ function update() {
188199
//player.setAcceleration(0);
189200
}
190201

191-
wrap(playerPhysics);
202+
wrap(playerPhysics); // enable wrap plugin didn't work for me
203+
clampVelocity(playerPhysics, 10);
192204

193205
players[player.playerId].x = playerPhysics.x;
194206
players[player.playerId].y = playerPhysics.y;
@@ -221,7 +233,7 @@ function addPlayer(self, playerInfo) {
221233

222234
// player.setDrag(100);
223235
// player.setAngularDrag(100);
224-
// player.setMaxVelocity(200);
236+
//player.setMaxVelocity(200);
225237

226238
console.log('Player collision filter', player.body.collisionFilter, 'star collision', self.star.body.collisionFilter, 'options', options);
227239

0 commit comments

Comments
 (0)