GomaGames / Spawn-RPG

RPG version of SpawnHero2
MIT License
0 stars 0 forks source link

Give Kelli new function definitions #41

Open kellishouts opened 8 years ago

theRemix commented 8 years ago

new functions that weren't in Spawn Hero 2

every Spawn method (pretty much ALL the code) must be wrapped inside this new function

Spawn.game = function(){
  // your game here
}

inside of there, you can run any Spawn.something() function

Spawn.hero(x, y);
Spawn. interactableSprite(x:Int, y:Int, graphic:String);
Spawn.collectableSprite(x:Int, y:Int, graphic:String);
Spawn.object(x:Int, y:Int, ?skin:String);
Spawn.message(message:String);

everything that you spawn returns that thing! and you can call .despawn() on anything despawnable

so

var myObject = Spawn.object(x:Int, y:Int, ?skin:String);
myObject.despawn();

Despawnables

Interactable Sprites

you can define what happens when you interact with anything interactable using the interact property of the object.

var sign = Spawn.interactableSprite(10, 10, 'assets/images/sign.png');
sign.interact = function(){
  Spawn.message("this sign has words");
}

interactables can talk

var person = Spawn.interactableSprite(10, 10, 'assets/images/person.png');
person.interact = function(){
  person.talk("hello coder!");
}

you can give anything in your inventory (collectables) to anything interactable only if you have that item in your inventory!

var person = Spawn.interactableSprite(10, 10, 'assets/images/person.png');
person.interact = function(){
  player.giveItem(someCollectableItem, person);
  person.talk("thank you!");
}

you can check if that interactable has an item that you gave

var bucket = Spawn.interactableSprite(10, 10, 'assets/images/bucket.png');
bucket.interact = function(){
  player.giveItem(someCollectableItem, bucket);
  if( bucket.hasItem(otherCollectableItem) ){
    Spawn.message("you have all the items!");
  }
}
theRemix commented 8 years ago

also hero has the hasItem() function

theRemix commented 8 years ago

also hero has the giveItem(item, receiver); where receiver is any interactable object

theRemix commented 8 years ago

i just added player.die() which can happen anytime, and happens whenever life goes down to 0