Initial commit of code
This commit is contained in:
parent
77c4c619c2
commit
444106377d
17
src/colors.lua
Normal file
17
src/colors.lua
Normal file
@ -0,0 +1,17 @@
|
||||
local colors = {}
|
||||
|
||||
colors["trueblue"] = "#0466c8ff"
|
||||
colors["background"] = "#7d8597ff"
|
||||
|
||||
return colors
|
||||
|
||||
--true-blue: #0466c8ff;
|
||||
--usafa-blue: #0353a4ff;
|
||||
--dark-cornflower-blue: #023e7dff;
|
||||
--oxford-blue: #002855ff;
|
||||
--oxford-blue-2: #001845ff;
|
||||
--oxford-blue-3: #001233ff;
|
||||
--independence: #33415cff;
|
||||
--black-coral: #5c677dff;
|
||||
--roman-silver: #7d8597ff;
|
||||
--manatee: #979dacff;
|
33
src/lib/button.lua
Normal file
33
src/lib/button.lua
Normal file
@ -0,0 +1,33 @@
|
||||
Button = {}
|
||||
|
||||
function Button:new(x,y,h,w,c)
|
||||
o = o or {}
|
||||
setmetatable(o,self)
|
||||
self.__index = self
|
||||
self.xPos = x or 0
|
||||
self.yPos = y or 0
|
||||
self.height = h or 0
|
||||
self.width = w or 0
|
||||
self.color = c or {1,1,1}
|
||||
return o
|
||||
end
|
||||
|
||||
function Button:draw()
|
||||
local r,g,b,a = love.graphics.getColor()
|
||||
|
||||
love.graphics.setColor(self.color)
|
||||
love.graphics.rectangle("fill", self.xPos, self.yPos, self.height, self.width)
|
||||
love.graphics.setColor(r,g,b)
|
||||
end
|
||||
|
||||
function Button:isButtonClicked(x,y)
|
||||
--if in x bounds
|
||||
if(x >= self.xPos and x <= (self.xPos + self.width)) then
|
||||
--if in y bounds
|
||||
if(y >= self.yPos and y <= (self.yPos + self.height)) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
36
src/lib/upgrade.lua
Normal file
36
src/lib/upgrade.lua
Normal file
@ -0,0 +1,36 @@
|
||||
Upgrade = { coolDown = 1, cost = 0, value = 0}
|
||||
|
||||
function Upgrade:new(coolDown, cost, value)
|
||||
o={}
|
||||
setmetatable(o,self)
|
||||
self.__index = self
|
||||
self.coolDown = coolDown
|
||||
self.cost = cost
|
||||
self.value = value
|
||||
|
||||
self.coolDownRemaining = coolDown
|
||||
self.countPurchased = 0
|
||||
return o
|
||||
end
|
||||
|
||||
function Upgrade:update(dt)
|
||||
if(self.coolDownRemaining <= 0) then
|
||||
self.coolDownRemaining = self.coolDown
|
||||
return true
|
||||
else
|
||||
self.coolDownRemaining = self.coolDownRemaining - dt
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
function Upgrade:getValueToAdd()
|
||||
return self.value
|
||||
end
|
||||
|
||||
function Upgrade:purchaseUpgrade()
|
||||
self.countPurchased = self.countPurchased + 1
|
||||
end
|
||||
|
||||
function Upgrade:getCountPurchased()
|
||||
return self.countPurchased
|
||||
end
|
9
src/lib/util.lua
Normal file
9
src/lib/util.lua
Normal file
@ -0,0 +1,9 @@
|
||||
local util = {}
|
||||
|
||||
function util.hexToLoveColor(hex)
|
||||
hex = hex:gsub("#","")
|
||||
return {tonumber("0x"..hex:sub(1,2))/255, tonumber("0x"..hex:sub(3,4))/255, tonumber("0x"..hex:sub(5,6))/255}
|
||||
end
|
||||
|
||||
|
||||
return util
|
40
src/main.lua
Normal file
40
src/main.lua
Normal file
@ -0,0 +1,40 @@
|
||||
util = require('lib/util')
|
||||
colors = require('colors')
|
||||
|
||||
require('lib/button')
|
||||
require('lib/upgrade')
|
||||
|
||||
function love.load()
|
||||
love.graphics.setBackgroundColor(util.hexToLoveColor(colors.background))
|
||||
width,height = love.graphics.getDimensions()
|
||||
|
||||
b = Button:new((width/2)-(200/2),height*.8,200,100,util.hexToLoveColor(colors.trueblue))
|
||||
Button:new(0,height*.5,50,50,{1,0,0})
|
||||
print(Button.__index)
|
||||
|
||||
print(b)
|
||||
|
||||
testUpgrade = Upgrade:new(1,0,1)
|
||||
|
||||
count = 0
|
||||
end
|
||||
|
||||
function love.update(dt)
|
||||
if(testUpgrade:update(dt) and testUpgrade:getCountPurchased() > 0) then
|
||||
count = count + testUpgrade:getValueToAdd()
|
||||
end
|
||||
end
|
||||
|
||||
function love.draw(dt)
|
||||
|
||||
b:draw()
|
||||
|
||||
love.graphics.printf(count, (width/2)-((width*.2)/2), height*.2, width*.2, "center")
|
||||
|
||||
end
|
||||
|
||||
function love.mousepressed(x,y,button,istouch)
|
||||
if(b:isButtonClicked(x,y)) then
|
||||
count = count + 1
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user