Created
May 4, 2013 17:12
-
-
Save prophetgoddess/5518115 to your computer and use it in GitHub Desktop.
source code for my new game
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require("Jumper") | |
require("loveframes") | |
cron = require("cron") | |
require("32log") | |
require("randomlua") | |
tilex = 0 | |
tiley = 0 | |
tilesize = 30 | |
gridsizex = 100 | |
gridsizey = 100 | |
completed = true | |
researching = 0 | |
value = 0 | |
researchingTech = nil | |
function love.load() | |
background = love.graphics.newImage("sprites/maintile.png") | |
starterBuilding = love.graphics.newImage("sprites/starterBuilding.png") | |
contentMenuImg = love.graphics.newImage("GUI/contentMenuImg.png") | |
menuBackground = love.graphics.newImage("GUI/buildMenu.png") | |
foodProductionName = "Food Production Building" | |
resourceProcessingName = "Resource Processing" | |
startportName = "Starport" | |
manufactoryName = "Manufactory" | |
touristCenterName = "Tourist Center" | |
mineName = "Mine" | |
libraryName = "Library" | |
hospitalName = "Hospital" | |
locked = ("GUI/locked.png") | |
buildMenu = 0 | |
researchMenu = 0 | |
manageMenu = 0 | |
stats = 0 | |
buildMenuCreated = 0 | |
researchMenuCreated = 0 | |
manageMenuCreated = 0 | |
statsMenuCreated = 0 | |
startPositionX = 50 | |
startPositionY = 50 | |
buildMenuButton = loveframes.Create("button") | |
buildMenuButton:SetPos(0, 0) | |
buildMenuButton:SetText("Build Menu") | |
buildMenuButton.OnClick = function(object) | |
buildMenu = 1 | |
end | |
researchMenuButton = loveframes.Create("button") | |
researchMenuButton:SetPos(100, 0) | |
researchMenuButton:SetText("Research Menu") | |
researchMenuButton.OnClick = function(object) | |
researchMenu = 1 | |
end | |
manageMenuButton = loveframes.Create("button") | |
manageMenuButton:SetPos(200, 0) | |
manageMenuButton:SetText("Manage Colony") | |
manageMenuButton.OnClick = function(object) | |
manageMenu = 1 | |
end | |
statsMenuButton = loveframes.Create("button") | |
statsMenuButton:SetPos(300, 0) | |
statsMenuButton:SetText("Stats") | |
statsMenuButton.OnClick = function(object) | |
stats = 1 | |
end | |
money = 10000 | |
resources = 500 | |
population = 20 | |
size = 1 | |
printedMoney = tostring(money) | |
printedResources = tostring(resources) | |
printedPopulation = tostring(population) | |
printedSize = tostring(size) | |
class "uraniumMining" { | |
max = 100; | |
researching = 0; | |
researched = 0; | |
unlocked = 1; | |
} | |
uraniumMiningInst = uraniumMining:new() | |
class "fasterMining" { | |
max = 100; | |
researching = 0; | |
researched = 0; | |
unlocked = 1; | |
} | |
fasterMiningInst = fasterMining:new() | |
class "advancedFoodProduction" { | |
max = 100; | |
researching = 0; | |
researched = 0; | |
unlocked = 1; | |
} | |
advancedFoodProductionInst = advancedFoodProduction:new() | |
class "enhancedResourceProcessing" { | |
max = 100; | |
researching = 0; | |
researched = 0; | |
unlocked = 1; | |
} | |
enhancedResourceProcessingInst = enhancedResourceProcessing:new() | |
class "rareEarthMining" { | |
max = 150; | |
researching = 0; | |
researched = 0; | |
unlocked = 0; | |
} | |
rareEarthMiningInst = rareEarthMining:new() | |
end | |
function love.update(dt) | |
cron.update(dt) | |
loveframes.update(dt) | |
end | |
function love.mousepressed(x, y, button) | |
loveframes.mousepressed(x, y, button) | |
end | |
function love.draw() | |
love.graphics.draw(starterBuilding, 600, 300) | |
loveframes.draw() | |
if buildMenu > 0 and buildMenuCreated < 1 then | |
buildMenuFrame = loveframes.Create("frame") | |
buildMenuFrame:SetSize(800,600) | |
buildMenuFrame:Center() | |
buildMenuFrame:SetName("Build Menu") | |
buildMenuFrame:SetDraggable(true) | |
buildMenuFrame.OnClose = function(object) | |
buildMenu = 0 | |
buildMenuCreated = 0 | |
end | |
foodProductionIcon = loveframes.Create("imagebutton") | |
foodProductionIcon:SetImage("GUI/foodProductionIcon.png") | |
foodProductionIcon:SetText("") | |
foodProductionIcon:SetParent(buildMenuFrame) | |
foodProductionIcon:SetPos(startPositionX, startPositionY) | |
resourceProcessingIcon = loveframes.Create("imagebutton") | |
resourceProcessingIcon:SetImage("GUI/resourceProcessingIcon.png") | |
resourceProcessingIcon:SetText("") | |
resourceProcessingIcon:SetParent(buildMenuFrame) | |
resourceProcessingIcon:SetPos(startPositionX + 100, startPositionY) | |
starportIcon = loveframes.Create("imagebutton") | |
starportIcon:SetImage("GUI/starportIcon.png") | |
starportIcon:SetText("") | |
starportIcon:SetParent(buildMenuFrame) | |
starportIcon:SetPos(startPositionX + 190, startPositionY) | |
manufactoryIcon = loveframes.Create("imagebutton") | |
manufactoryIcon:SetImage("GUI/manufactoryIcon.png") | |
manufactoryIcon:SetParent(buildMenuFrame) | |
manufactoryIcon:SetPos(startPositionX + 280, startPositionY) | |
manufactoryIcon:SetText("") | |
touristCenterIcon = loveframes.Create("imagebutton") | |
touristCenterIcon:SetImage("GUI/touristCenterIcon.png") | |
touristCenterIcon:SetParent(buildMenuFrame) | |
touristCenterIcon:SetPos(startPositionX + 370, startPositionY) | |
touristCenterIcon:SetText("") | |
mineIcon = loveframes.Create("imagebutton") | |
mineIcon:SetImage("GUI/mineIcon.png") | |
mineIcon:SetParent(buildMenuFrame) | |
mineIcon:SetText("") | |
mineIcon:SetPos(startPositionX + 460, startPositionY) | |
libraryIcon = loveframes.Create("imagebutton") | |
libraryIcon:SetImage("GUI/libraryIcon.png") | |
libraryIcon:SetParent(buildMenuFrame) | |
libraryIcon:SetText("") | |
libraryIcon:SetPos(startPositionX + 550, startPositionX) | |
hospitalIcon = loveframes.Create("imagebutton") | |
hospitalIcon:SetImage("GUI/hospitalIcon.png") | |
hospitalIcon:SetParent(buildMenuFrame) | |
hospitalIcon:SetText("") | |
hospitalIcon:SetPos(startPositionX + 640, startPositionY) | |
buildMenuCreated = 1 | |
end | |
if researchMenu > 0 and researchMenuCreated < 1 then | |
labelFont = love.graphics.newFont(10) | |
researchMenuFrame = loveframes.Create("frame") | |
researchMenuFrame:SetSize(800, 600) | |
researchMenuFrame:Center() | |
researchMenuFrame:SetName("Research Menu") | |
researchMenuFrame:SetDraggable(true) | |
researchMenuFrame.OnClose = function(object) | |
researchMenu = 0 | |
researchMenuCreated = 0 | |
end | |
uraniumMiningIcon = loveframes.Create("imagebutton") | |
uraniumMiningIcon:SetImage("GUI/uraniumtechicon.png") | |
uraniumMiningIcon:SetParent(researchMenuFrame) | |
uraniumMiningIcon:SetText("") | |
uraniumMiningIcon:SetPos(startPositionX + 10, startPositionY) | |
uraniumMiningIcon.OnClick = function (object) | |
if uraniumMiningInst.researching < 1 and uraniumMiningInst.researched < 1 and researchingTech == nil then | |
uraniumMiningInst.researching = 1 | |
research(uraniumMiningInst) | |
uraniumMiningIcon:SetImage("GUI/researchicon.png") | |
end | |
end | |
uraniumTechLabel = loveframes.Create("text") | |
uraniumTechLabel:SetParent(researchMenuFrame) | |
uraniumTechLabel:SetPos(startPositionX + 5, startPositionY + 68) | |
uraniumTechLabel:SetFont(labelFont) | |
uraniumTechLabel:SetText("Uranium Mining") | |
if uraniumMiningInst.researching > 0 then | |
uraniumMiningIcon:SetImage("GUI/researchicon.png") | |
end | |
fasterMiningIcon = loveframes.Create("imagebutton") | |
fasterMiningIcon:SetImage("GUI/fasterMiningTechicon.png") | |
fasterMiningIcon:SetParent(researchMenuFrame) | |
fasterMiningIcon:SetText("") | |
fasterMiningIcon:SetPos(startPositionX + 100, startPositionY) | |
fasterMiningIcon.OnClick = function(object) | |
if fasterMiningInst.researching < 1 and fasterMiningInst.researched < 1 and researchingTech == nil then | |
fasterMiningInst.researching = 1 | |
research(fasterMiningInst) | |
fasterMiningIcon:SetImage("GUI/researchicon.png") | |
end | |
end | |
fasterMiningTechLabel = loveframes.Create("text") | |
fasterMiningTechLabel:SetParent(researchMenuFrame) | |
fasterMiningTechLabel:SetPos(startPositionX + 95, startPositionY + 68) | |
fasterMiningTechLabel:SetFont(labelFont) | |
fasterMiningTechLabel:SetText("Faster Mining") | |
advancedFoodProductionIcon = loveframes.Create("imagebutton") | |
advancedFoodProductionIcon:SetImage("GUI/advancedFoodProductionTechIcon.png") | |
advancedFoodProductionIcon:SetParent(researchMenuFrame) | |
advancedFoodProductionIcon:SetText("") | |
advancedFoodProductionIcon:SetPos(startPositionX + 190, startPositionY) | |
advancedFoodProductionIcon.OnClick = function(object) | |
if advancedFoodProductionInst.researching < 1 and advancedFoodProductionInst.researched < 1 and researchingTech == nil then | |
advancedFoodProductionInst.researching = 1 | |
research(advancedFoodProductionInst) | |
advancedFoodProductionIcon:SetImage("GUI/researchicon.png") | |
end | |
end | |
advancedFoodProductionLabel = loveframes.Create("text") | |
advancedFoodProductionLabel:SetParent(researchMenuFrame) | |
advancedFoodProductionLabel:SetPos(startPositionX + 185, startPositionY + 68) | |
advancedFoodProductionLabel:SetFont(labelFont) | |
advancedFoodProductionLabel:SetText("Advanced Food \n Production") | |
enhancedResourceProcessingIcon = loveframes.Create("imagebutton") | |
enhancedResourceProcessingIcon:SetImage("GUI/enhancedResearchProcessingIcon.png") | |
enhancedResourceProcessingIcon:SetParent(researchMenuFrame) | |
enhancedResourceProcessingIcon:SetText("") | |
enhancedResourceProcessingIcon:SetPos(startPositionX + 280, startPositionY) | |
enhancedResourceProcessingIcon.OnClick = function(object) | |
if enhancedResourceProcessingInst.researching < 1 and enhancedResourceProcessingInst.researched < 1 and researchingTech == nil then | |
enhancedResourceProcessingInst.researching = 1 | |
research(enhancedResourceProcessingInst) | |
enhancedResourceProcessingIcon:SetImage("GUI/researchicon.png") | |
end | |
end | |
enhancedResourceProcessingLabel = loveframes.Create("text") | |
enhancedResourceProcessingLabel:SetParent(researchMenuFrame) | |
enhancedResourceProcessingLabel:SetPos(startPositionX + 275, startPositionY + 68) | |
enhancedResourceProcessingLabel:SetFont(labelFont) | |
enhancedResourceProcessingLabel:SetText(" Enhanced \n Resource Processing") | |
if rareEarthMiningInst.unlocked < 1 then | |
lockedDraw(startPositionX + 370, startPositionY, researchMenuFrame) | |
else | |
rareEarthMiningIcon = loveframes.Create("imagebutton") | |
rareEarthMiningIcon:SetImage("GUI/rareEarthMiningIcon.png") | |
rareEarthMiningIcon:SetParent(researchMenuFrame) | |
rareEarthMiningIcon:SetText("") | |
rareEarthMiningIcon:SetPos(startPositionX + 370, startPositionY) | |
rareEarthMiningIcon.OnClick = function(object) | |
if rareEarthMiningInst.rsearching < 1 and rareEarthMiningInst.researched < 1 and researchingTech == nil then | |
rareEarthMiningInst.rsearching = 1 | |
research(rareEarthMiningInst) | |
rareEarthMiningIcon:SetImage("GUI/researchicon.png") | |
end | |
end | |
rareEarthMiningLabel = loveframes.Create("text") | |
rareEarthMiningLabel:SetParent(researchMenuFrame) | |
rareEarthMiningLabel:SetPos(startPositionX + 370, startPositionY + 68) | |
rareEarthMiningLabel:SetFont(labelFont) | |
rareEarthMiningLabel:SetText("Rare Earth Mining") | |
end | |
researchMenuCreated = 1 | |
end | |
if manageMenu > 0 and manageMenuCreated < 1 then | |
manageMenuFrame = loveframes.Create("frame") | |
manageMenuFrame:SetSize(800,600) | |
manageMenuFrame:Center() | |
manageMenuFrame:SetName("Manage Colony") | |
manageMenuFrame:SetDraggable(true) | |
manageMenuFrame.OnClose = function(object) | |
manageMenu = 0 | |
manageMenuCreated = 0 | |
end | |
manageMenuCreated = 1 | |
end | |
if stats > 0 and statsMenuCreated < 1 then | |
statsMenuFrame = loveframes.Create("frame") | |
statsMenuFrame:SetSize(800,600) | |
statsMenuFrame:Center() | |
statsMenuFrame:SetName("Stats") | |
statsMenuFrame:SetDraggable(true) | |
statsMenuFrame.OnClose = function(object) | |
stats = 0 | |
statsMenuCreated = 0 | |
end | |
statsMenuCreated = 1 | |
end | |
font = love.graphics.newFont("big_noodle_titling.ttf", 25) | |
love.graphics.setFont(font) | |
love.graphics.print("$" .. printedMoney, 400, 0) | |
love.graphics.print("Resources: " .. printedResources, 500, 0) | |
love.graphics.print("Population: " .. population, 650, 0) | |
love.graphics.print("Size: " .. size, 800,0) | |
end | |
function love.mousereleased(x, y, button) | |
loveframes.mousereleased(x, y, button) | |
end | |
function love.keypressed(key, unicode) | |
loveframes.keypressed(key, unicode) | |
end | |
function love.keyreleased(key) | |
loveframes.keyreleased(key) | |
end | |
function love.focus(f) | |
end | |
function love.quit() | |
end | |
function lockedDraw(x, y, parent) | |
locked = loveframes.Create("image") | |
locked:SetParent(parent) | |
locked:SetImage("GUI/locked.png") | |
locked:SetPos(x, y) | |
lockedLabel = loveframes.Create("text") | |
lockedLabel:SetParent(parent) | |
lockedLabel:SetPos(x, y + 68) | |
lockedLabel:SetText(" ???") | |
end | |
function research(tech) | |
progressBar = loveframes.Create("progressbar") | |
tech.researched = 1 | |
if tech.researching > 0 then | |
progressBar:SetPos(0, 27) | |
progressBar:SetSize(80, 30) | |
progressBar:SetLerp(true) | |
progressBar:SetMinMax(0, tech.max) | |
progressBar:SetLerpRate(1) | |
researching = 1 | |
researchingTech = tech | |
end | |
end | |
function researchUp() | |
if researching > 0 then | |
if value == researchingTech.max then | |
researchingTech.researching = 0 | |
researching = 0 | |
newResearch = loveframes.Create("button") | |
newResearch:SetPos(0, 27) | |
newResearch:SetSize(80,30) | |
newResearch:SetText("Research New") | |
researchingTech = nil | |
end | |
value = progressBar:GetValue() | |
progressBar:SetValue(value + 1 ) | |
end | |
end | |
function mine() | |
resources = resources | |
end | |
cron.every(1, researchUp) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment