diff --git a/gamemanager.lua b/gamemanager.lua new file mode 100644 index 0000000..d13e7d6 --- /dev/null +++ b/gamemanager.lua @@ -0,0 +1,107 @@ +require "ui" + + + +require "snake" +require "swat" + + +--[[ + this library is the library that is combining the minigames into one usable thing, + it will also house the ui elements and general game management (duh). + +]] + + +man = { + paused = true, + debug = true, + tgame = "snake", --game thats happening on top screen + bgame = "swat", --game thats happening on bottom screen + lastkey = "" +} + + + +function man:load() + --love.graphics.set3D(true) + if not man.debug then + snakeplayer:hardreset() + swat:load() + ui:load() + end +end + +function man:update(dt) + if not man.debug then + if not man.paused then + if man.tgame == "snake" then + snakeplayer:update(dt) + end + if man.bgame == "swat" then + swat:update(dt) + end + else + ui:update(dt) + end + end +end + +function man:draw() + if not man.debug then + if not man.paused then + if man.tgame == "snake" then + snakeplayer:draw() + end + if man.bgame == "swat" then + fly:draw() + end + else + ui:draw() + end + else + love.graphics.print("the last button pressed was: "..man.lastkey) + end +end + +function man:keypressed(key) + if not man.debug then + if key == "start" then + man.paused = not man.paused + return + end + if not man.paused then + if man.tgame == "snake" then + snakeplayer:keypressed(key) + end + else + ui:keypressed(key) + end + else + man.lastkey = key + end +end + +function man:keyreleased(key) + if not man.debug then + if not man.paused then + + else + ui:keyreleased(key) + end + end +end + +function man:mousepressed(sx, sy) + local x, y = love.mouse.getPosition() + if not man.debug then + if not man.paused then + if man.bgame == "swat" then + swat:mousepressed(x, y) + end + else + ui:mousepressed(x, y) + end + end +end + diff --git a/main.lua b/main.lua index a98d723..d94221f 100644 --- a/main.lua +++ b/main.lua @@ -1,10 +1,10 @@ -require "snake" +--[[require "snake" require "swat" + + function love.load() - --love.graphics.set3D(true) - snakeplayer:hardreset() - swat:load() + end @@ -128,5 +128,36 @@ function love.mousepressed(a, b) local x, y = love.mouse.getPosition() fly:kill(x, y) end +]] ---require("potion-compat") \ No newline at end of file + + +require "gamemanager" + + +function love.load() + man:load() +end + +function love.update(dt) + man:update(dt) +end + +function love.draw() + man:draw() +end + +function love.keypressed(key) + man:keypressed(key) +end + +function love.keyreleased(key) + man:keyreleased(key) +end + +function love.mousepressed(x, y) + man:mousepressed(x, y) +end + +--this is for debugging on pc +require("potion-compat") \ No newline at end of file diff --git a/snake.lua b/snake.lua index afe7fd8..4a39466 100644 --- a/snake.lua +++ b/snake.lua @@ -63,6 +63,94 @@ function snakeplayer:hardreset() snake.score = 0 end +function snakeplayer:keypressed(key) + if (key == "start") then + --gamemanager:quit() + gamemanager:pause() + end + if (key == "up") then + snakeplayer:move(0, -1) + end + if (key == "down") then + snakeplayer:move(0, 1) + + end + if (key == "left") then + snakeplayer:move(-1, 0) + + end + if (key == "right") then + snakeplayer:move(1, 0) + + end + if (key == "cstickup") then + snakeplayer:move(0, -1) + end + if (key == "cstickdown") then + snakeplayer:move(0, 1) + + end + if (key == "cstickleft") then + snakeplayer:move(-1, 0) + + end + if (key == "cstickright") then + snakeplayer:move(1, 0) + + end + if (key == "cpadup") then + snakeplayer:move(0, -1) + end + if (key == "cpaddown") then + snakeplayer:move(0, 1) + + end + if (key == "cpadleft") then + snakeplayer:move(-1, 0) + + end + if (key == "cpadright") then + snakeplayer:move(1, 0) + + end + if (key == "x") then + snakeplayer:move(0, -1) + end + if (key == "b") then + snakeplayer:move(0, 1) + + end + if (key == "y") then + snakeplayer:move(-1, 0) + + end + if (key == "a") then + snakeplayer:move(1, 0) + end + + if (key == "select") then + --snakeplayer:hardreset() + end + if (key == "lbutton") then + + end + if (key == "rbutton") then + + end + if (key == "l") then + + end + if (key == "r") then + + end + if (key == "lzbutton") then + + end + if (key == "rzbutton") then + + end +end + function snakeplayer:move(xvel, yvel) if self.xvel == -xvel and self.yvel == -yvel then diff --git a/swat.lua b/swat.lua index 19694f9..20d3cda 100644 --- a/swat.lua +++ b/swat.lua @@ -41,6 +41,11 @@ function swat:load() end +function swat:mousepressed(x, y) + fly:kill(x, y) +end + + function swat:update( dt) if fly.timer then fly.tl = fly.tl + dt diff --git a/ui.lua b/ui.lua new file mode 100644 index 0000000..2fdf083 --- /dev/null +++ b/ui.lua @@ -0,0 +1,97 @@ + +ui = { + twidth = 0, + theight = 0, + bwidth = 0, + bheight = 0 +} + +menu = { + main = { + items = { + "select games", + "settings", + "about", + "exit" + } + }, + prop = { + x = 100, + x2 = 200, + bars = 50, + offset = 20, + xoff = 5, + cursel = 1, + curitems = 0 + } +} + +function ui:load() + love.graphics.setScreen("top") + ui.twidth = love.graphics.getWidth() + ui.theight = love.graphics.getHeight() + love.graphics.setScreen("bottom") + ui.bwidth = love.graphics.getWidth() + ui.bheight = love.graphics.getHeight() +end + + +function ui:draw() + menu.prop.curitems = table.getn(menu.main.items) + --sqr = + for i in ipairs(menu.main.items) do + temp = ((ui.theight - menu.prop.bars)/(menu.prop.curitems)) * i + --love.graphics.rectangle("fill", menu.prop.xoff, menu.prop.bars , ui.twidth, menu.prop.bars) + local x, y = love.mouse.getPosition() + if i == menu.prop.cursel then + love.graphics.setColor(255, 0, 0) + end + love.graphics.printf(menu.main.items[i], menu.prop.x, temp , menu.prop.x2, "center") + love.graphics.setColor(255,255,255) + end +end + +function ui:update(dt) + if menu.prop.cursel < 1 then + menu.prop.cursel = menu.prop.curitems + elseif menu.prop.cursel > menu.prop.curitems then + menu.prop.cursel = 1 + end +end + +function ui:keypressed(key) + if key == "up" then + menu.prop.cursel = menu.prop.cursel - 1 + end + if key == "down" then + menu.prop.cursel = menu.prop.cursel + 1 + + end + if key == "left" then + + end + if key == "right" then + + end + if key == "cpadup" then + menu.prop.cursel = menu.prop.cursel - 1 + end + if key == "cpaddown" then + menu.prop.cursel = menu.prop.cursel + 1 + + end + if key == "cpadleft" then + + end + if key == "cpadright" then + + end +end + +function ui:keyreleased(key) + +end + +function ui:mousepressed(x, y) + +end \ No newline at end of file