-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-minimal-server.js
More file actions
67 lines (58 loc) · 1.75 KB
/
test-minimal-server.js
File metadata and controls
67 lines (58 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Minimal server test to debug trader movement
var p2 = require('p2');
var Trader = require('./server/Trader.js');
// Set up minimal globals
global.game = {
world: null,
systemManager: {
getSystem: function(systemId) {
return {
planets: [
{ x: 100, y: 100, name: 'Test Planet' }
],
starGates: []
};
}
},
server: {
debugMode: true
}
};
// Create world
var world = new p2.World({
gravity: [0, 0]
});
world.defaultContactMaterial.friction = 0;
global.game.world = world;
// Create a trader
console.log('Creating trader...');
var trader = new Trader(500, 500);
trader.currentSystem = 'sol';
console.log('Trader created:', {
id: trader.id,
position: [trader.getX(), trader.getY()],
damping: trader.rigidBody.damping,
mass: trader.rigidBody.mass
});
// Add trader to world
world.addBody(trader.rigidBody);
console.log('Trader added to world. Bodies in world:', world.bodies.length);
// Simulate a few ticks
console.log('\nSimulating 10 ticks...');
for (let i = 0; i < 10; i++) {
// Update AI
trader.updateAI();
// Step world
world.step(1/25);
// Log state
var velocity = trader.rigidBody.velocity;
var speed = Math.sqrt(velocity[0]**2 + velocity[1]**2);
console.log(`Tick ${i+1}: pos=[${trader.getX().toFixed(0)}, ${trader.getY().toFixed(0)}], speed=${speed.toFixed(2)}, thrust=${trader.isThrusting}`);
}
// Check final state
console.log('\nFinal trader state:', {
state: trader.state,
target: trader.targetPlanet?.name,
position: [trader.getX(), trader.getY()],
velocity: [...trader.rigidBody.velocity]
});