From 444106377d1049b7774e471cffbd123a2cbb75b2 Mon Sep 17 00:00:00 2001 From: Thomas Cole Date: Fri, 19 Feb 2021 10:28:08 -0500 Subject: [PATCH] Initial commit of code --- src/colors.lua | 17 +++++++++++++++++ src/lib/button.lua | 33 +++++++++++++++++++++++++++++++++ src/lib/upgrade.lua | 36 ++++++++++++++++++++++++++++++++++++ src/lib/util.lua | 9 +++++++++ src/main.lua | 40 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 135 insertions(+) create mode 100644 src/colors.lua create mode 100644 src/lib/button.lua create mode 100644 src/lib/upgrade.lua create mode 100644 src/lib/util.lua create mode 100644 src/main.lua diff --git a/src/colors.lua b/src/colors.lua new file mode 100644 index 0000000..f3fb13b --- /dev/null +++ b/src/colors.lua @@ -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; \ No newline at end of file diff --git a/src/lib/button.lua b/src/lib/button.lua new file mode 100644 index 0000000..b155702 --- /dev/null +++ b/src/lib/button.lua @@ -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 \ No newline at end of file diff --git a/src/lib/upgrade.lua b/src/lib/upgrade.lua new file mode 100644 index 0000000..bbce2f7 --- /dev/null +++ b/src/lib/upgrade.lua @@ -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 \ No newline at end of file diff --git a/src/lib/util.lua b/src/lib/util.lua new file mode 100644 index 0000000..0a8156f --- /dev/null +++ b/src/lib/util.lua @@ -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 \ No newline at end of file diff --git a/src/main.lua b/src/main.lua new file mode 100644 index 0000000..d7a3867 --- /dev/null +++ b/src/main.lua @@ -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 \ No newline at end of file