Added inventory support

This commit is contained in:
simon
2018-01-20 12:48:51 -05:00
parent 352bfef375
commit c9a28327a9
4 changed files with 125 additions and 30 deletions

View File

@@ -110,6 +110,8 @@ class Cubot extends GameObject {
heldItem: ItemType;
energy: number;
inventory: Phaser.Group;
private hologram: Phaser.Text;
/**
@@ -202,6 +204,9 @@ class Cubot extends GameObject {
this.energy = json.energy;
this.direction = json.direction;
//Update Inventory
this.createInventory([json.heldItem]);
this.heldItem = json.heldItem;
//Update color
this.tint = this.getTint();
@@ -379,6 +384,40 @@ class Cubot extends GameObject {
}
this.addChild(username);
}
public createInventory(items: number[]): void {
//Remove old inventory
if(this.inventory != undefined) {
this.inventory.destroy();
}
let inventory = mar.game.make.group();
switch (items.length) {
case 0:
this.inventory = inventory;
this.addChild(inventory);
break;
case 1:
if (items[0] !== 0) {
let shadow = mar.game.make.sprite(0, 0, "sheet", "inventory/inv1x1");
shadow.anchor.set(0.5, 0.1);
shadow.alpha = 0.5;
let item = mar.game.make.sprite(0, 0, "sheet", "inventory/item");
item.anchor.set(0.5, 0.1);
item.tint = Util.itemColor(items[0]);
inventory.addChild(shadow);
inventory.addChild(item);
}
this.inventory = inventory;
this.addChild(inventory);
break;
}
}
}
class HarvesterNPC extends Cubot {