Advertisement
Hendrix000007

Untitled

Jan 26th, 2012
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.19 KB | None | 0 0
  1. ----------------------
  2. --STAMINA.LUA CLASS
  3. ---------------------
  4. local _M = {}
  5. local screen =
  6. {
  7.     left = display.screenOriginX,
  8.     top = display.screenOriginY,
  9.     right = display.contentWidth - display.screenOriginX,
  10.     bottom = display.contentHeight - display.screenOriginY
  11. };
  12.  
  13. staminaGroup = display.newGroup()
  14. staminaGroup.x = screen.left; staminaGroup.y = screen.top +10
  15.  
  16. _M.lives = 2
  17.    
  18. _M.staminaInit = {}
  19.     for i = 1, 4 do
  20.         _M.staminaInit[i] = display.newImage("staminaEmpty.png", 25 + (i * 25), 25)
  21.             staminaGroup:insert(_M.staminaInit[i])
  22.     end
  23.    
  24. _M.staminaLives = {}
  25.     for i = 1, _M.lives do
  26.         _M.staminaLives[i] = display.newImage("staminaFull.png", 25 + (i * 25), 25)
  27.             staminaGroup:insert(_M.staminaLives[i])
  28.     end
  29.    
  30.    
  31. function _M:life(addOrSub) --use add or sub as args
  32.     if _M.lives > 0 then
  33.         if addOrSub == "add" then
  34.             if _M.lives < 4 then
  35.                 _M.lives = _M.lives + 1
  36.                 return _M.lives
  37.             end
  38.         elseif addOrSub == "sub" then
  39.             _M.lives = _M.lives - 1
  40.             return addOrSub
  41.         end
  42.     else
  43.         print("ure dead man!")
  44.     end
  45. end
  46.  
  47.  
  48. return _M
  49.  
  50. -----------------------
  51. -- IN MAIN.LUA FILE
  52. -----------------------
  53. local stamina = require ("stamina")
  54. stamina:life("sub")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement