Advertisement
Guest User

StoreScene

a guest
Jan 8th, 2016
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.64 KB | None | 0 0
  1. StoreScene = class()
  2.  
  3. local homeButton
  4. local buyButtonForSkips
  5. local buyButtonForBackgrounds
  6. local backgroundPreviewRed
  7. local backgroundPreviewGreen
  8. local backgroundPreviewBlue
  9.  
  10. function StoreScene:init()
  11.     -- you can accept and set parameters here
  12.     homeButton = Button("Dropbox:homeButton", vec2(WIDTH/2-400, HEIGHT/2+325))
  13.     buyButtonForSkips = Button("Dropbox:storeBuyButton", vec2(WIDTH/2+350, HEIGHT/2+150))
  14.     buyButtonForBackgrounds = Button("Dropbox:storeBuyButton", vec2(WIDTH/2+350, HEIGHT/2))
  15.     backgroundPreviewRed = Button("Dropbox:storeBackgroundPreviewRed", vec2(WIDTH/2-75, HEIGHT/2))
  16.     backgroundPreviewGreen = Button("Dropbox:storeBackgroundPreviewGreen", vec2(WIDTH/2, HEIGHT/2))
  17.     backgroundPreviewBlue = Button("Dropbox:storeBackgroundPreviewBlue", vec2(WIDTH/2+75, HEIGHT/2))
  18.    
  19.     homeButton.draggable = false
  20.     buyButtonForSkips.draggable = false
  21.     buyButtonForBackgrounds.draggable = false
  22.     backgroundPreviewRed.draggable = false
  23.     backgroundPreviewGreen.draggable = false
  24.     backgroundPreviewBlue.draggable = false
  25. end
  26.  
  27. function StoreScene:draw()
  28.     -- Codea does not automatically call this method
  29.     background(0, 0, 0, 255)
  30.     homeButton:draw()
  31.     buyButtonForSkips:draw()
  32.     buyButtonForBackgrounds:draw()
  33.     backgroundPreviewRed:draw()
  34.     backgroundPreviewGreen:draw()
  35.     backgroundPreviewBlue:draw()
  36.    
  37.     fill(255, 255, 255, 255)
  38.     fontSize(60)
  39.     text("Store", WIDTH/2, HEIGHT/2+300)
  40.     fontSize(55)
  41.     text("Skips", WIDTH/2-300, HEIGHT/2+150)
  42.     text("15", WIDTH/2+190, HEIGHT/2+150) -- cost for skips
  43.     sprite("Dropbox:candyForCurrency", WIDTH/2+260, HEIGHT/2+155, 75, 75)
  44.     text("Backgrounds", WIDTH/2-300, HEIGHT/2)
  45.     text("10", WIDTH/2+190, HEIGHT/2) -- cost for backgrounds
  46.     sprite("Dropbox:candyForCurrency", WIDTH/2+260, HEIGHT/2+5, 75, 75)
  47.    
  48.     --amount of candy in basket in top right of screen
  49.     text(math.floor(amountOfCandyInBasket), WIDTH/2+300, HEIGHT/2+325)
  50.     sprite("Dropbox:candyForCurrency", WIDTH/2+400, HEIGHT/2+325, 75, 75)
  51. end
  52.  
  53. function StoreScene:touched(touch)
  54.     -- Codea does not automatically call this method
  55.     homeButton:touched(touch)
  56.     buyButtonForSkips:touched(touch)
  57.     buyButtonForBackgrounds:touched(touch)
  58.     backgroundPreviewRed:touched(touch)
  59.     backgroundPreviewGreen:touched(touch)
  60.     backgroundPreviewBlue:touched(touch)
  61.    
  62.     if(homeButton.selected == true) then
  63.         sound(SOUND_HIT, 1851, 0.50)
  64.         Scene.Change("mainmenu")
  65.     elseif(buyButtonForSkips.selected == true) then
  66.         sound(SOUND_HIT, 1851, 0.50)
  67.         if(amountOfCandyInBasket >= 15) then
  68.             amountOfCandyInBasket = amountOfCandyInBasket - 15
  69.             amountOfSkips = amountOfSkips + 1
  70.             saveLocalData("candy", amountOfCandyInBasket)
  71.         else
  72.             alert("Not enough candy!", "Can't buy item")
  73.         end
  74.     elseif(buyButtonForBackgrounds.selected == true) then
  75.         if(amountOfCandyInBasket >= 10) then
  76.             amountOfCandyInBasket = amountOfCandyInBasket - 10
  77.             saveLocalData("candy", amountOfCandyInBasket)
  78.             -- need to make a variable for background in the main game
  79.         else
  80.             alert("Not enough candy!", "Can't buy item")
  81.         end
  82.     elseif(backgroundPreviewRed.selected == true) then
  83.         backgroundPreview = "red"
  84.         Scene.Change("backgrounds")
  85.     elseif(backgroundPreviewGreen.selected == true) then
  86.         backgroundPreview = "green"
  87.         Scene.Change("backgrounds")
  88.     elseif(backgroundPreviewBlue.selected == true) then
  89.         backgroundPreview = "blue"
  90.         Scene.Change("backgrounds")
  91.     end
  92. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement