mirror of
https://github.com/bvanroll/3dsStuff.git
synced 2025-09-01 21:32:41 +00:00
i started creating the gamemanager idea and also the ui, started off with a basic main menu, options light up; added a debug mode which right now displays the name of the key you press, which would be handy for the 3ds
This commit is contained in:
107
gamemanager.lua
Normal file
107
gamemanager.lua
Normal file
@@ -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
|
||||||
|
|
41
main.lua
41
main.lua
@@ -1,10 +1,10 @@
|
|||||||
require "snake"
|
--[[require "snake"
|
||||||
require "swat"
|
require "swat"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function love.load()
|
function love.load()
|
||||||
--love.graphics.set3D(true)
|
|
||||||
snakeplayer:hardreset()
|
|
||||||
swat:load()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@@ -128,5 +128,36 @@ function love.mousepressed(a, b)
|
|||||||
local x, y = love.mouse.getPosition()
|
local x, y = love.mouse.getPosition()
|
||||||
fly:kill(x, y)
|
fly:kill(x, y)
|
||||||
end
|
end
|
||||||
|
]]
|
||||||
|
|
||||||
--require("potion-compat")
|
|
||||||
|
|
||||||
|
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")
|
88
snake.lua
88
snake.lua
@@ -63,6 +63,94 @@ function snakeplayer:hardreset()
|
|||||||
snake.score = 0
|
snake.score = 0
|
||||||
end
|
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)
|
function snakeplayer:move(xvel, yvel)
|
||||||
if self.xvel == -xvel and self.yvel == -yvel then
|
if self.xvel == -xvel and self.yvel == -yvel then
|
||||||
|
|
||||||
|
5
swat.lua
5
swat.lua
@@ -41,6 +41,11 @@ function swat:load()
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function swat:mousepressed(x, y)
|
||||||
|
fly:kill(x, y)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
function swat:update( dt)
|
function swat:update( dt)
|
||||||
if fly.timer then
|
if fly.timer then
|
||||||
fly.tl = fly.tl + dt
|
fly.tl = fly.tl + dt
|
||||||
|
97
ui.lua
Normal file
97
ui.lua
Normal file
@@ -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
|
Reference in New Issue
Block a user