-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentityItem.js
More file actions
31 lines (30 loc) · 904 Bytes
/
entityItem.js
File metadata and controls
31 lines (30 loc) · 904 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
function EntityItem(item,x,y,z,dx){
Entity.call(this,x,y,z);
this.item = item;
this.initY = y;
this.dx = dx;
this.bb = [-16,32,-16,32];
level.entities.push(this);
}
EntityItem.prototype.render = function(xoff,yoff){
context.drawImage(this.item.image, this.x-xoff, this.y-yoff,16,16);
};
EntityItem.prototype.tick = function(){
//if(this.getTileUnder()==AIR&&this.z>0)this.z--;
this.ticks++;
if(this.ticks<30){
this.y=Easing.easeOutBounce(this.ticks,this.initY,50,30);
this.x+=this.dx;
this.dx-=0.02;
}else if(this.ticks%20<10){
this.y+=0.1;
}else{
this.y-=0.1;
}
if(this.ticks>1000)level.entities.splice(level.entities.indexOf(this), 1);
};
EntityItem.prototype.getTileUnder = Entity.prototype.getTileUnder;
EntityItem.prototype.interact = function(){
if(player.inventory.addItem(this.item))
level.entities.splice(level.entities.indexOf(this), 1);
};