Advertisement
eliasdaler

chest.lua

May 2nd, 2015
1,692
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.37 KB | None | 0 0
  1. chest = {
  2.     init = function(this)
  3.         setScriptState(this, "ChestClosedState")
  4.         disableComponent(this, "InteractionComponent")
  5.     end,
  6.     GraphicsComponent = {
  7.         filename = "res/images/chest.png",
  8.         animated = true,
  9.         defaultAnimation = "closed",
  10.         z = 0,
  11.         animations = {
  12.             closed = {
  13.                 frame = {0, 0, 16, 16},
  14.                 numOfFrames = 1,
  15.                 frameTime = 0,
  16.                 looped = false
  17.             },
  18.             opened = {
  19.                 frame = {16, 0, 16, 16},
  20.                 numOfFrames = 1,
  21.                 frameTime = 0,
  22.                 looped = false              
  23.             }
  24.         }
  25.     },
  26.     CollisionComponent = {
  27.         type = "Solid",
  28.         boundingBox = { 0, 0, 16, 16 }
  29.     },
  30.     InteractionComponent = {
  31.         type = "Open",
  32.         interactionRect = { -8, 16, 32, 16 },
  33.         interact = function (this, second)
  34.             if(getScriptState(this) == "ChestClosedState") then
  35.                 setInteractionType(this, "None")
  36.                 setScriptState(this, "ChestOpeningState")    
  37.             end
  38.         end
  39.     },
  40.     InventoryComponent = {
  41.     },
  42.     NpcComponent = {
  43.         textFile = "chest.lua",
  44.         talks = {
  45.             {
  46.                 {
  47.                     text = "got_item",
  48.                     endFunc = function() -- gets called when player closes "got item" window
  49.                         setState(playerEntity, "IdleState")
  50.                         hideOverlaySprite() -- hides item which appears from the chest
  51.                     end
  52.                 }
  53.             },
  54.         }
  55.     },
  56.     ScriptStateMachineComponent = {
  57.         states = {
  58.             ChestClosedState = {
  59.                 enter = function(self, this)
  60.                     setAnimation(this, "closed")
  61.                 end,
  62.             },
  63.             ChestOpeningState = {
  64.                 enter = function(self, this)
  65.                     setAnimation(this, "opened")
  66.                     playSound("res/sounds/chest_open.wav")
  67.                     openChest(this)
  68.                     setScriptState(this, "ChestOpenedState")
  69.                 end,
  70.             },
  71.             ChestOpenedState = {
  72.                 enter = function(self, this)
  73.                     setAnimation(this, "opened")
  74.                 end
  75.             }
  76.         }
  77.     }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement