Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local love = require "love"
- local constants = require "constants"
- local Button = {}
- Button.__index = Button
- function Button.new(shape, x, y, width, height, func, text)
- local self = setmetatable({}, Button)
- self.shape = shape
- self.x = x
- self.y = y
- self.width = width
- self.height = height
- self.func = func or function () end
- self.text = text or ''
- if self.shape == "circle" then
- self.x_min = self.x - self.width
- self.x_max = self.x + self.width
- self.y_min = self.y - self.width
- self.y_max = self.y + self.width
- else
- self.x_min = self.x
- self.x_max = self.x + self.width
- self.y_min = self.y
- self.y_max = self.y + self.height
- end
- return self
- end
- function Button:clicked(mouse_x, mouse_y)
- if mouse_x > self.x_min and
- mouse_x < self.x_max and
- mouse_y > self.y_min and
- mouse_y < self.y_max then
- self.func()
- end
- end
- function Button:draw()
- if self.func_con then
- love.graphics.setColor(255,255,255)
- else
- love.graphics.setColor(200,200,200)
- end
- if self.shape == "circle" then
- love.graphics.circle ("fill", self.x, self.y, self.height)
- else
- love.graphics.rectangle ("fill", self.x, self.y, self.width, self.height)
- end
- love.graphics.setColor(0,0,0)
- if self.shape == "circle" then
- love.graphics.printf (self.text, self.x_min, self.y-7.5, self.width*2, "center")
- else
- love.graphics.printf (self.text, self.x_min, (self.y_max + self.y_min)/2-7.5, self.width, "center")
- end
- end
- local Resource = {}
- Resource.__index = Resource
- function Resource.new(startvalue, isshown)
- self.startvalue = startvalue
- self.isshown = isshown
- self.currvalue = self.startvalue
- return self
- end
- function Resource:add(value)
- self.currvalue = self.currvalue + value
- end
- local Soul = {}
- Soul.__index = Soul
- function Soul.new(Name, Price, PRate, PValue)
- local self = setmetatable({}, Soul)
- self.name = Name
- self.ascensionlvl = 1
- self.lvl = 1
- self.price = price
- self.pRate = PRate
- self.PValue = PValue
- return self
- end
- function Soul:buy()
- if self.lvl + 1 <= 100 then
- self.lvl = self.lvl + 1
- self.price = self.price * (1.01)
- end
- end
- --ignore these, they have been replaced with the appropriate values for simplicity's sake
- function Soul:getLvlCap()
- return getLvlCap[self.ascensionlvl]
- end
- function Soul:getPriceUp()
- return getPriceUp[self.lvl]
- end
- local x_size, y_size = love.graphics.getDimensions()
- local x_mid = x_size/2
- local y_mid = y_size/2
- local coins = 0
- function addcoins()
- coins = coins + 1
- end
- function love.load()
- bigButton = Button.new("circle", x_mid, y_mid, 100, 100, addcoins, "button :D")
- wheat = Soul.new(wheat, 100, 100, 100)
- wheat.button = Button.new("rectangle", 0, 15, 100, 30, wheat:buy, 100)
- end
- function love.update()
- end
- function love.mousepressed(x, y)
- bigButton:clicked(x, y)
- wheat.button:clicked(x,y)
- end
- function love.draw()
- bigButton:draw()
- wheat.button:draw()
- love.graphics.setColor(255,255,255)
- love.graphics.print(coins,0,0)
- love.graphics.print(wheat.lvl,0,45)
- end
Advertisement
Add Comment
Please, Sign In to add comment