Advertisement
Wazt

"Collect" all the items and win.

Jul 9th, 2015
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.78 KB | None | 0 0
  1. collected = {} --what items were collected by player y, per player
  2. coords = {{x = 500, y = 325},{x = 100, y = 325},{x = 200, y = 325},{x = 300, y = 325},{x = 400, y = 325}} --coords for each item/ground//whatever
  3. size = 10 --in pixels, the item hitbox is 2*size by 2*size
  4.  
  5. function eventNewPlayer(name)
  6.     tfm.exec.bindKeyboard(name,32,true,true)
  7.     ui.addTextArea(0,"",name,5,27,nil,nil,0x32464F,0x32464F,0.9,false)
  8. end
  9.  
  10. function eventKeyboard(name,key,up,x,y)
  11.     if (key == 32) and (#collected[name] ~= #coords) then
  12.         for i=1,#coords do
  13.             local exists = false
  14.             for _,ob in pairs(collected[name]) do
  15.                 if ob == i then
  16.                     exists = true
  17.                 end
  18.             end
  19.             if exists == false then
  20.                 if (tfm.get.room.playerList[name].x >= coords[i].x - size) and (tfm.get.room.playerList[name].x <= coords[i].x +size) and (tfm.get.room.playerList[name].y >= coords[i].y - size) and (tfm.get.room.playerList[name].y <= coords[i].y + size) then
  21.                     ui.updateTextArea(0,"Item " ..i.. " collected",name)
  22.                     table.insert(collected[name], i)
  23.                     if #collected[name] == #coords then
  24.                         ui.updateTextArea(0,"You have collected all the items!", name)
  25.                         tfm.exec.giveCheese(name)
  26.                         tfm.exec.playerVictory(name)
  27.                     end
  28.                 end
  29.             end
  30.         end
  31.     end
  32. end
  33.  
  34. function eventMouse(name, x, y)
  35.     tfm.exec.movePlayer(name, x, y, false, -1, -1, false)
  36. end
  37.  
  38. function eventNewGame()
  39.     for name,player in pairs(tfm.get.room.playerList) do
  40.         collected[name] = {}
  41.         ui.updateTextArea(0,"",name)
  42.     end
  43.     for i=1,#coords do
  44.         tfm.exec.addPhysicObject(i, coords[i].x, coords[i].y, {type=4, width=20, height=20, foreground=false, miceCollision=false, dynamic=false})
  45.     end
  46. end
  47.  
  48. tfm.exec.disableAutoShaman(true)
  49. tfm.exec.newGame("@0")
  50. for name,player in pairs(tfm.get.room.playerList) do
  51.     eventNewPlayer(name)
  52. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement