forked from ec-idds/hackathon-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsprite.js
More file actions
33 lines (30 loc) · 768 Bytes
/
sprite.js
File metadata and controls
33 lines (30 loc) · 768 Bytes
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
class Sprite {
constructor (image, x, y, w, h, controllable) {
this.image = image;
this.x = x;
this.y = y;
this.w = w;
this.h = h;
if(controllable === undefined){
this.controllable = false;
} else {
this.controllable = controllable;
}
}
draw () {
image(this.image, this.x, this.y, this.w, this.h);
}
keyIsPressed (keyCode) {
if(this.controllable != true) return
if(keyCode == LEFT_ARROW){
this.x--;
} else if (keyCode == RIGHT_ARROW){
this.x++;
}
if (keyCode == UP_ARROW){
this.y--;
} else if (keyCode == DOWN_ARROW){
this.y++;
}
}
}