Advertisement
luismiasas

Untitled

Sep 1st, 2013
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.66 KB | None | 0 0
  1. Buttons = class()
  2.  
  3.  
  4.  
  5. function Buttons:init(x,y,txt,funct,Mode,l,h)
  6.  
  7. self.x = x
  8.  
  9. self.y = y
  10.  
  11. fontSize(30)
  12.  
  13. font("AmericanTypewriter-Bold")
  14.  
  15. self.txt = txt
  16.  
  17. self.Sl,self.Sh = textSize(self.txt)
  18.  
  19. self.funct = funct
  20.  
  21. self.l=l or self.Sl+20
  22.  
  23. self.h=h or self.Sh+20
  24.  
  25. self.mode=Mode
  26.  
  27. self.colour=color(0, 0, 0, 255)
  28.  
  29. end
  30.  
  31.  
  32.  
  33. function Buttons:draw()
  34.  
  35. pushStyle()
  36.  
  37. fontSize(30)
  38.  
  39. font("AmericanTypewriter-Bold")
  40.  
  41. fill(self.colour)
  42.  
  43. if self.mode then
  44.  
  45. text(self.txt,self.x+self.l/2,self.y+self.h/2)
  46.  
  47. else
  48.  
  49. text(self.txt,self.x,self.y)
  50.  
  51. end
  52.  
  53. popStyle()
  54.  
  55. end
  56.  
  57.  
  58.  
  59. function Buttons:touched(touch)
  60.  
  61. if self.mode then
  62.  
  63. self.tx=touch.x-self.l/2
  64.  
  65. self.ty=touch.y-self.h/2
  66.  
  67. else
  68.  
  69. self.tx = touch.x
  70.  
  71. self.ty = touch.y
  72.  
  73. end
  74.  
  75. if self.tx<=self.x + self.l/2 and self.tx>=self.x - self.l/2 and
  76.  
  77. self.ty>=self.y - self.h/2 and self.ty<=self.y + self.h/2 then
  78.  
  79. if touch.state==BEGAN then
  80.  
  81. self.colour=color(255, 255, 255, 255)
  82.  
  83. self.press=true
  84.  
  85. elseif touch.state == ENDED and self.press then
  86.  
  87. self.colour=color(0, 0, 0, 255)
  88.  
  89. self.funct()
  90.  
  91. sound(SOUND_PICKUP, 49238)
  92.  
  93. end
  94.  
  95. else
  96.  
  97. self.colour=color(0, 0, 0, 255)
  98.  
  99. end
  100.  
  101. if touch.state==ENDED then
  102.  
  103. self.colour=color(0, 0, 0, 255)
  104.  
  105. self.press=false
  106.  
  107. end
  108.  
  109. end
  110.  
  111.  
  112.  
  113. function exitButtoninit()
  114.  
  115. exits = Buttons(WIDTH/2-350,HEIGHT/2-500,"EXIT",close,true)
  116. reestart = Buttons(WIDTH/2+200,HEIGHT/2-500,"RESTART",restart,true)
  117. nextPAGE = Buttons(WIDTH/2+2,HEIGHT/2-470,"NEXTPAGE",playNEXTPAGE)
  118.  
  119. end
  120.  
  121. function exitButtondraw()
  122.  
  123. exits:draw()
  124. reestart:draw()
  125. nextPAGE:draw()
  126.  
  127. end
  128.  
  129. function exitButtontouch(touch)
  130.  
  131. exits:touched(touch)
  132. reestart:touched(touch)
  133. nextPAGE:touched(touch)
  134. end
  135.  
  136. function playNEXTPAGEinit()
  137. BACK = Buttons(WIDTH/2+2,HEIGHT/2-470,"BACK",back)
  138.  
  139. end
  140.  
  141. function playNEXTPAGEdraw()
  142.  
  143. sprite("Planet Cute:Water Block",WIDTH/2,HEIGHT/2,WIDTH*2,HEIGHT*4)
  144. fontSize(70)
  145. text("PAGE 2",400,530)
  146. BACK:draw()
  147. end
  148.  
  149. function playNEXTPAGEtouch(touch)
  150.  
  151. BACK:touched(touch)
  152. end
  153.  
  154. function playNEXTPAGE()
  155. ChangeState("playNEXTPAGE",playNEXTPAGEinit)
  156. end
  157.  
  158. function back()
  159. ChangeState("back",exitButtoninit)
  160. end
  161.  
  162. function home()
  163.  
  164. ChangeState("home",exitButtoninit)
  165.  
  166. end
  167.  
  168. function ChangeState(State,funct)
  169. for k,v in pairs(PhysicsBodies) do
  170. v:destroy()
  171. v=nil
  172. end
  173. PhysicsBodies={}
  174. funct()
  175. GameState=State
  176. end
  177.  
  178.  
  179. --MAIN
  180. displayMode(FULLSCREEN_NO_BUTTONS)
  181.  
  182. function setup()
  183. PhysicsBodies={}
  184. GameState = "home"
  185. exitButtoninit()
  186. end
  187. function draw()
  188. background(255,255,255,255)
  189. if GameState == "home" then
  190. exitButtondraw()
  191. elseif GameState == "playNEXTPAGE" then
  192. playNEXTPAGEdraw()
  193. elseif GameState == "back" then
  194. exitButtondraw()
  195. end
  196. end
  197.  
  198. function touched(touch)
  199. if GameState == "home" then
  200. exitButtontouch(touch)
  201.  
  202. elseif GameState == "playNEXTPAGE" then
  203. playNEXTPAGEtouch(touch)
  204. elseif GameState == "back" then
  205. exitButtontouch(touch)
  206.  
  207. end
  208. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement