-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug-entity-test.js
More file actions
90 lines (75 loc) · 2.06 KB
/
debug-entity-test.js
File metadata and controls
90 lines (75 loc) · 2.06 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Quick test to verify entity creation
console.log('Testing entity creation...');
// Mock canvas for EntityManager
const mockCanvas = {
width: 800,
height: 600
};
// Mock Vector2
class Vector2 {
constructor(x = 0, y = 0) {
this.x = x;
this.y = y;
}
static zero() {
return new Vector2(0, 0);
}
add(other) {
return new Vector2(this.x + other.x, this.y + other.y);
}
multiply(scalar) {
return new Vector2(this.x * scalar, this.y * scalar);
}
}
// Simple EntityManager test
class SimpleEntityManager {
constructor(canvas) {
this.entities = [];
this.canvas = canvas;
}
addEntity(entity) {
this.entities.push(entity);
console.log(`Added entity: ${entity.type}, total entities: ${this.entities.length}`);
}
getAllEntities() {
return [...this.entities];
}
getEntityCount() {
return this.entities.length;
}
}
// Test entity creation
const entityManager = new SimpleEntityManager(mockCanvas);
// Test ship creation (like in Game.init())
const playerShip = {
position: new Vector2(320, 240),
velocity: Vector2.zero(),
size: new Vector2(20, 20),
rotation: 0,
color: "#00ff00",
type: "ship",
playerId: "player",
trail: []
};
entityManager.addEntity(playerShip);
// Test asteroid creation (like in Game.init())
for (let i = 0; i < 4; i++) {
const asteroid = {
position: new Vector2(100 + i * 150, 100 + i * 100),
velocity: new Vector2(50, 30),
size: new Vector2(30, 30),
rotation: 0,
color: "#ffffff",
type: "asteroid",
age: 0
};
entityManager.addEntity(asteroid);
}
// Verify results
console.log(`Final entity count: ${entityManager.getEntityCount()}`);
console.log('Entities:', entityManager.getAllEntities().map(e => ({ type: e.type, playerId: e.playerId })));
if (entityManager.getEntityCount() === 5) {
console.log('✅ Entity creation test PASSED');
} else {
console.log('❌ Entity creation test FAILED');
}