Advertisement
10100

candy.lua

Jan 25th, 2014
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.63 KB | None | 0 0
  1. --PROJECT CANDYLAND SAGA
  2. --MAIN.LUA
  3. --CANDY.LUA
  4.  
  5. local class = require 'middleclass'
  6.  
  7. Candy = class('Candy')
  8.  
  9. function Candy:initialize(x, y, PLAYER)
  10.     self.active = true
  11.     self.x = x
  12.     self.y = y
  13.     self.h2 = 40
  14.     self.h = 40
  15.     self.vel = 2.5
  16.     if PLAYER.lessRainbows then
  17.         rN = math.random(1, 14)
  18.     else
  19.         rN = math.random(1, 9)
  20.     end
  21.     self.id = rN
  22.     if rN == 1 or rN == 10 then
  23.         self.img = love.graphics.newImage("/art/yaycandies/size1/lollipop_blue.png")
  24.     elseif rN == 2 or rN == 11 then
  25.         self.img = love.graphics.newImage("/art/yaycandies/size1/lollipop_green.png")
  26.     elseif rN == 3 or rN == 12 then
  27.         self.img = love.graphics.newImage("/art/yaycandies/size1/lollipop_yellow.png")
  28.     elseif rN == 4 or rN == 13 then
  29.         self.img = love.graphics.newImage("/art/yaycandies/size1/lollipop_red.png")
  30.     elseif rN == 5 or rN == 14 then
  31.         self.img = love.graphics.newImage("/art/yaycandies/size1/lollipop_teal.png")
  32.     elseif rN == 6 then
  33.         self.img = love.graphics.newImage("/art/yaycandies/size1/lollipop_purple.png")
  34.     elseif rN == 7 then
  35.         self.img = love.graphics.newImage("/art/yaycandies/size1/lollipop_orange.png")
  36.     elseif rN == 8 then
  37.         self.img = love.graphics.newImage("/art/yaycandies/size1/lollipop_pink.png")
  38.     elseif rN == 9 then
  39.         self.img = love.graphics.newImage("/art/yaycandies/size1/lollipop_rainbow.png")
  40.     end
  41. end
  42.  
  43. function Candy:update(dt, PLAYER)
  44.     if self.active then
  45.         self.y = self.y + self.vel
  46.         if self.y > love.window.getHeight() then
  47.             self.y = 0
  48.             if self.id == 9 then
  49.                 PLAYER.lifes = PLAYER.lifes - 1
  50.             end
  51.         end
  52.     end
  53. end
  54.  
  55. function Candy:draw()
  56.     love.graphics.draw(self.img, self.x, self.y)
  57. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement