Inventory System for Level Actors
* Added an inventory system for actors as a replacement to the arbitrary key/value data store. Colored keys now add themselves to the player's inventory, and colored doors check the inventory. * Inventory is a map[string]int between doodad filenames (red-key.doodad) and quantity (0 for key items/unlimited qty). * API methods to add and remove inventory. * Items HUD appears in Play Mode in lower-left corner showing doodad sprites of all the items in the Player's inventory.
This commit is contained in:
parent
e86ae6144e
commit
4ba3e18e18
|
@ -1,6 +1,7 @@
|
|||
|
||||
function main() {
|
||||
var color = Self.Doodad.Tag("color");
|
||||
var keyname = "key-" + color + ".doodad";
|
||||
|
||||
// Layers in the doodad image.
|
||||
var layer = {
|
||||
|
@ -34,8 +35,9 @@ function main() {
|
|||
return;
|
||||
}
|
||||
|
||||
var data = e.Actor.GetData("key:" + color);
|
||||
if (data === "") {
|
||||
// Do they have our key?
|
||||
var hasKey = e.Actor.HasItem(keyname) >= 0;
|
||||
if (!hasKey) {
|
||||
// Door is locked.
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -2,7 +2,9 @@ function main() {
|
|||
var color = Self.Doodad.Tag("color");
|
||||
|
||||
Events.OnCollide(function(e) {
|
||||
e.Actor.SetData("key:" + color, "true");
|
||||
if (e.Settled) {
|
||||
e.Actor.AddItem(Self.Doodad.Filename, 0);
|
||||
Self.Destroy();
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user