-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCollectable.js
35 lines (28 loc) · 876 Bytes
/
Collectable.js
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
'use strict';
class Collectable extends Entity {
constructor(x, y) {
super(x, y, tilesize);
this.collected = false;
this.idleFrames = new Keyframes([
utils.makeRect( 0, 0),
utils.makeRect(tilesize, 0)
], random(90, 110));
this.idleFrames.start();
this.dir = random([-1, 1]);
}
draw(camera) {
if (!this.collected) {
this.idleFrames.update();
let dx = this.position.x;
let dy = this.position.y;
let cf = this.idleFrames.getCurrent();
push();
if (this.dir === -1) {
scale(-1, 1);
dx = (dx * -1) - tilesize;
}
image(assets.getImage("pollen"), floor(dx), dy, tilesize, tilesize, cf.x, cf.y, tilesize, tilesize);
pop();
}
}
}