-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClientCell.js
More file actions
50 lines (39 loc) · 1.02 KB
/
ClientCell.js
File metadata and controls
50 lines (39 loc) · 1.02 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
import PositionedObject from '../common/PositionedObject';
import ClientGameObject from './ClientGameObject';
class ClientCell extends PositionedObject {
constructor(cfg) {
super();
const { cellWidth, cellHeight } = cfg.world;
Object.assign(
this,
{
cfg,
objects: [],
x: cellWidth * cfg.cellCol,
y: cellWidth * cfg.cellRow,
width: cellWidth,
height: cellHeight,
},
cfg,
);
this.initGameObjects();
}
initGameObjects() {
const { cellCfg } = this;
this.objects = cellCfg[0].map((objCfg) => new ClientGameObject({ cell: this, objCfg }));
}
render(time) {
const { objects } = this;
objects.map((obj) => obj.render(time));
}
addGameObject(objToAdd) {
this.objects.push(objToAdd);
}
removeGameObject(objToRemove) {
this.objects = this.objects.filter((obj) => obj !== objToRemove);
}
findObjectsByType(type) {
return this.objects.filter((obj) => obj.type === type);
}
}
export default ClientCell;