-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDroppedItem.js
31 lines (25 loc) · 876 Bytes
/
DroppedItem.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
function DroppedItem(type, item, destination) {
powerupjs.SpriteGameObject.call(this, sprites.carry_items[type], 1, 0, ID.layer_objects);
this.type = 'dropped_item';
this.sprite_type = type
this.item_type = typeof item !== "undefined" ? item : 'item';
this.destination = destination
this.time = 0
}
DroppedItem.prototype = Object.create(powerupjs.SpriteGameObject.prototype);
DroppedItem.prototype.update = function(delta) {
powerupjs.SpriteGameObject.prototype.update.call(this, delta);
this.time += 270
if (this.velocity.y === 0 && this.velocity.x === 0) {
this.position.y += Math.sin(this.time) * 1.4; // Add bobbing effect
}
if (this.destination !== undefined) {
if (this.position.y < this.destination.y) {
this.velocity.y = 100 // Falling effect
}
else {
this.velocity.y = 0;
this.velocity.x = 0;
}
}
}