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
|
var app = app || {};
const DIRECTION_STATE = {
'up': {
next: 'right',
previous: 'left',
},
'right': {
next: 'down',
previous: 'up',
},
'down': {
next: 'left',
previous: 'right',
},
'left': {
next: 'up',
previous: 'down',
},
};
class Tank extends BaseGameObject {
constructor(color, type, sprite, size, position, direction) {
super(null, sprite, size, position);
this.color = color;
this.type = type;
this.direction = direction;
}
get x (){
return this.container.x;
}
get y (){
return this.container.y;
}
set x (value) {
this.container.x = value;
}
set y (value) {
this.container.y = value;
}
rotateLeft() {
this.direction = DIRECTION_STATE[this.direction].previous;
this.container.rotation -= 1.57079633;
}
rotateRight() {
this.direction = DIRECTION_STATE[this.direction].next;
this.container.rotation += 1.57079633;
}
}
|