-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEntityManager.js
More file actions
executable file
·73 lines (69 loc) · 1.7 KB
/
EntityManager.js
File metadata and controls
executable file
·73 lines (69 loc) · 1.7 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
/**
* EntityManager.js
* Fahid Jarmache
* Manages all the entities for the server and client.
*/
class EntityManager {
constructor() {
this.entities = new Map();
this.players = new Map();
}
/**
* tick
* Updates our entities based on the game clock and tick. ??
* TODO: Add speed factor?
*/
tick(gameClock, gameTick) {
}
/**
* addEntity
* Adds an entity.
*/
addEntity(entity) {
this.entities.set(entity.entityID, entity);
}
/**
* removeEntity
* Removes the entity with the given ID.
*/
removeEntity(entityID) {
//var entity = this.entities.get(entityID);
// entity.cleanup() ??
this.entities.remove(entity);
}
/**
* updateEntity
* This will be called by the client game to update entities received from the server.
* Entities will be lerped to their most up-to-date positions.
*/
updateEntity(entityID, newData) {
}
/**
*
*/
addPlayer(playerEntity) {
// TODO: check clientID against serverID (-1?)
this.addEntity(playerEntity);
this.players.set(playerEntity.clientID, playerEntity);
}
/**
* Removes a player's entity, and the player.
*/
removePlayer(clientID) {
var player = this.players.get(clientID);
if (!player) {
debug("::removePlayer entity not found with key " + clientID + ", ignoring");
return;
}
this.removeEntity(player.entityID);
this.players.delete(clientID);
}
/**
* getEntities
* Returns the entity map
*/
getEntities() {
return this.entities;
}
}
module.exports = EntityManager;