Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Buttons = class()
- function Buttons:init(x,y,txt,funct,Mode,l,h)
- self.x = x
- self.y = y
- fontSize(30)
- font("AmericanTypewriter-Bold")
- self.txt = txt
- self.Sl,self.Sh = textSize(self.txt)
- self.funct = funct
- self.l=l or self.Sl+20
- self.h=h or self.Sh+20
- self.mode=Mode
- self.colour=color(0, 0, 0, 255)
- end
- function Buttons:draw()
- pushStyle()
- fontSize(30)
- font("AmericanTypewriter-Bold")
- fill(self.colour)
- if self.mode then
- text(self.txt,self.x+self.l/2,self.y+self.h/2)
- else
- text(self.txt,self.x,self.y)
- end
- popStyle()
- end
- function Buttons:touched(touch)
- if self.mode then
- self.tx=touch.x-self.l/2
- self.ty=touch.y-self.h/2
- else
- self.tx = touch.x
- self.ty = touch.y
- end
- if self.tx<=self.x + self.l/2 and self.tx>=self.x - self.l/2 and
- self.ty>=self.y - self.h/2 and self.ty<=self.y + self.h/2 then
- if touch.state==BEGAN then
- self.colour=color(255, 255, 255, 255)
- self.press=true
- elseif touch.state == ENDED and self.press then
- self.colour=color(0, 0, 0, 255)
- self.funct()
- sound(SOUND_PICKUP, 49238)
- end
- else
- self.colour=color(0, 0, 0, 255)
- end
- if touch.state==ENDED then
- self.colour=color(0, 0, 0, 255)
- self.press=false
- end
- end
- function exitButtoninit()
- exits = Buttons(WIDTH/2-350,HEIGHT/2-500,"EXIT",close,true)
- reestart = Buttons(WIDTH/2+200,HEIGHT/2-500,"RESTART",restart,true)
- nextPAGE = Buttons(WIDTH/2+2,HEIGHT/2-470,"NEXTPAGE",playNEXTPAGE)
- end
- function exitButtondraw()
- exits:draw()
- reestart:draw()
- nextPAGE:draw()
- end
- function exitButtontouch(touch)
- exits:touched(touch)
- reestart:touched(touch)
- nextPAGE:touched(touch)
- end
- function playNEXTPAGEinit()
- BACK = Buttons(WIDTH/2+2,HEIGHT/2-470,"BACK",back)
- end
- function playNEXTPAGEdraw()
- sprite("Planet Cute:Water Block",WIDTH/2,HEIGHT/2,WIDTH*2,HEIGHT*4)
- fontSize(70)
- text("PAGE 2",400,530)
- BACK:draw()
- end
- function playNEXTPAGEtouch(touch)
- BACK:touched(touch)
- end
- function playNEXTPAGE()
- ChangeState("playNEXTPAGE",playNEXTPAGEinit)
- end
- function back()
- ChangeState("back",exitButtoninit)
- end
- function home()
- ChangeState("home",exitButtoninit)
- end
- function ChangeState(State,funct)
- for k,v in pairs(PhysicsBodies) do
- v:destroy()
- v=nil
- end
- PhysicsBodies={}
- funct()
- GameState=State
- end
- --MAIN
- displayMode(FULLSCREEN_NO_BUTTONS)
- function setup()
- PhysicsBodies={}
- GameState = "home"
- exitButtoninit()
- end
- function draw()
- background(255,255,255,255)
- if GameState == "home" then
- exitButtondraw()
- elseif GameState == "playNEXTPAGE" then
- playNEXTPAGEdraw()
- elseif GameState == "back" then
- exitButtondraw()
- end
- end
- function touched(touch)
- if GameState == "home" then
- exitButtontouch(touch)
- elseif GameState == "playNEXTPAGE" then
- playNEXTPAGEtouch(touch)
- elseif GameState == "back" then
- exitButtontouch(touch)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement