mirror of
https://github.com/bvanroll/3dsStuff.git
synced 2025-09-02 13:52:40 +00:00
restructuring folders, planning on dev for games as standalone first and then porting them to the main thing
This commit is contained in:
107
lib/helpers/gamemanager.lua
Normal file
107
lib/helpers/gamemanager.lua
Normal file
@@ -0,0 +1,107 @@
|
||||
require "lib.tools.ui"
|
||||
|
||||
|
||||
|
||||
require "lib.minigames.snake"
|
||||
require "lib.minigames.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
|
||||
|
348
lib/helpers/potion-compat.lua
Normal file
348
lib/helpers/potion-compat.lua
Normal file
@@ -0,0 +1,348 @@
|
||||
--[[
|
||||
FOR NINTENDO 3DS ONLY
|
||||
|
||||
You may use this for -Love Potion- only!
|
||||
This is to allow filesystem calls to be made
|
||||
without the need to understand io operation.
|
||||
|
||||
Only works for Love Potion 1.0.8
|
||||
|
||||
If you want to use view this in 3DSXL mode:
|
||||
Use love.graphics.scale(scale, scale) before drawing in love.draw!
|
||||
|
||||
require this at the **END** of your main.lua file
|
||||
|
||||
TurtleP
|
||||
--]]
|
||||
|
||||
if not love.filesystem then
|
||||
love.filesystem = {}
|
||||
|
||||
function love.filesystem.isFile(path)
|
||||
return io.open(path)
|
||||
end
|
||||
|
||||
function love.filesystem.isDirectory(path)
|
||||
return love.filesystem.isFile(path):read(1) == 21
|
||||
end
|
||||
|
||||
function love.filesystem.write(path, data)
|
||||
if path and data then
|
||||
local file = io.open(path, "w")
|
||||
|
||||
if file then
|
||||
file:write(data)
|
||||
|
||||
file:flush()
|
||||
|
||||
file:close()
|
||||
else
|
||||
error("Could not create file!")
|
||||
end
|
||||
else
|
||||
error("Could not write file: " .. path .. "!")
|
||||
end
|
||||
end
|
||||
|
||||
function love.filesystem.read(path)
|
||||
if path then
|
||||
local file = io.open(path, "r")
|
||||
|
||||
if file then
|
||||
return file:read()
|
||||
else
|
||||
error("Could not read file, does not exist!")
|
||||
end
|
||||
else
|
||||
assert(type(path) == "string", "String expected, got " .. type(path))
|
||||
end
|
||||
end
|
||||
|
||||
function love.filesystem.remove(path)
|
||||
if path then
|
||||
os.remove(path)
|
||||
end
|
||||
end
|
||||
|
||||
local function fsize(file)
|
||||
local startf = file:seek("start")
|
||||
|
||||
local sizeof = file:seek("end")
|
||||
|
||||
file:seek("set", startf)
|
||||
|
||||
return sizeof
|
||||
end
|
||||
|
||||
function love.filesystem.getDirectoryItems(path)
|
||||
if type(path) ~= "string" then
|
||||
error("String expected, got " .. type(path))
|
||||
else
|
||||
if love.filesystem.isDirectory(path) then
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if not love.graphics.scale then
|
||||
function love.graphics.scale(scalarX, scalarY)
|
||||
--do nothing
|
||||
end
|
||||
end
|
||||
|
||||
if not love.graphics.setDefaultFilter then
|
||||
function love.graphics.setDefaultFilter(min, max)
|
||||
--do nothing
|
||||
end
|
||||
end
|
||||
|
||||
if not love.audio.setVolume then
|
||||
function love.audio.setVolume(volume)
|
||||
--do nothing
|
||||
end
|
||||
end
|
||||
|
||||
if not love.math then
|
||||
love.math = {}
|
||||
|
||||
function love.math.random(min, max)
|
||||
return math.random(min, max)
|
||||
end
|
||||
end
|
||||
|
||||
local oldSetColor = love.graphics.setColor
|
||||
function love.graphics.setColor(r, g, b, a)
|
||||
if type(r) == "table" then
|
||||
oldSetColor(unpack(r))
|
||||
else
|
||||
oldSetColor(r, g, b, a)
|
||||
end
|
||||
end
|
||||
|
||||
--Because tables
|
||||
local oldSetColor = love.graphics.setColor
|
||||
function love.graphics.setColor(r, g, b, a)
|
||||
if type(r) == "table" then
|
||||
oldSetColor(unpack(r))
|
||||
else
|
||||
oldSetColor(r, g, b, a)
|
||||
end
|
||||
end
|
||||
|
||||
if love.system.getOS() == "3ds" then
|
||||
return
|
||||
end
|
||||
|
||||
local _KEYNAMES =
|
||||
{
|
||||
"a", "b", "select", "start",
|
||||
"dright", "dleft", "dup", "ddown",
|
||||
"rbutton", "lbutton", "x", "y",
|
||||
"lzbutton", "rzbutton", "cstickright",
|
||||
"cstickleft", "cstickup", "cstickdown",
|
||||
"cpadright", "cpadleft", "cpadup", "cpaddown"
|
||||
}
|
||||
|
||||
BUTTONCONFIG =
|
||||
{
|
||||
["a"] = "z",
|
||||
["b"] = "x",
|
||||
["y"] = "c",
|
||||
["x"] = "v",
|
||||
["start"] = "return",
|
||||
["select"] = "rshift",
|
||||
["dup"] = "w",
|
||||
["dleft"] = "a",
|
||||
["dright"] = "d",
|
||||
["ddown"] = "s",
|
||||
["rbutton"] = "kp0",
|
||||
["lbutton"] = "rctrl",
|
||||
["cpadright"] = "right",
|
||||
["cpadleft"] = "left",
|
||||
["cpadup"] = "up",
|
||||
["cpaddown"] = "down",
|
||||
["cstickleft"] = "",
|
||||
["cstickright"] ="",
|
||||
["cstickup"] = "",
|
||||
["cstickdown"] = ""
|
||||
}
|
||||
|
||||
function love.graphics.setDepth(depthValue)
|
||||
assert(depthValue and type(depthValue) == "number", "Number expected: got " .. type(depthValue))
|
||||
end
|
||||
|
||||
function love.graphics.set3D(enable3D)
|
||||
assert(enable3D and type(enable3D) == "boolean", "Boolean expected: got " .. type(depthValue))
|
||||
end
|
||||
|
||||
local olddraw = love.graphics.draw
|
||||
function love.graphics.draw(...)
|
||||
local args = {...}
|
||||
|
||||
local image = args[1]
|
||||
local quad
|
||||
local x, y, r = 0, 0, 0
|
||||
local scalex, scaley
|
||||
|
||||
if type(args[2]) == "userdata" then
|
||||
quad = args[2]
|
||||
x = args[3] or 0
|
||||
y = args[4] or 0
|
||||
scalex, scaley = args[5], args[6]
|
||||
else
|
||||
x, y = args[2] or 0, args[3] or 0
|
||||
r = args[4] or 0
|
||||
end
|
||||
|
||||
if love.graphics.getScreen() == "bottom" then
|
||||
x = x + 40
|
||||
y = y + 240
|
||||
end
|
||||
|
||||
if not quad then
|
||||
if r then
|
||||
olddraw(image, x + image:getWidth() / 2, y + image:getHeight() / 2, r, 1, 1, image:getWidth() / 2, image:getHeight() / 2)
|
||||
else
|
||||
olddraw(image, x, y)
|
||||
end
|
||||
else
|
||||
olddraw(image, quad, x, y, 0, 1, 1)
|
||||
end
|
||||
end
|
||||
|
||||
local oldRectangle = love.graphics.rectangle
|
||||
function love.graphics.rectangle(mode, x, y, width, height)
|
||||
local x = x or 0
|
||||
local y = y or 0
|
||||
if love.graphics.getScreen() == "bottom" then
|
||||
x = x + 40
|
||||
y = y + 240
|
||||
end
|
||||
oldRectangle(mode, x, y, width, height)
|
||||
end
|
||||
|
||||
local oldCircle = love.graphics.circle
|
||||
function love.graphics.circle(mode, x, y, r, segments)
|
||||
local x = x or 0
|
||||
local y = y or 0
|
||||
if love.graphics.getScreen() == "bottom" then
|
||||
x = x + 40
|
||||
y = y + 240
|
||||
end
|
||||
oldCircle(mode, x, y, r, segments)
|
||||
end
|
||||
|
||||
local oldPrint = love.graphics.print
|
||||
function love.graphics.print(text, x, y, r, scalex, scaley, sx, sy)
|
||||
local x = x or 0
|
||||
local y = y or 0
|
||||
if love.graphics.getScreen() == "bottom" then
|
||||
x = x + 40
|
||||
y = y + 240
|
||||
end
|
||||
oldPrint(text, x, y, r, scalex, scaley, sx, sy)
|
||||
end
|
||||
|
||||
local oldKey = love.keypressed
|
||||
function love.keypressed(key)
|
||||
for k, v in pairs(BUTTONCONFIG) do
|
||||
if key == v then
|
||||
oldKey(k)
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local oldKey = love.keyreleased
|
||||
function love.keyreleased(key)
|
||||
for k, v in pairs(BUTTONCONFIG) do
|
||||
if key == v then
|
||||
oldKey(k)
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if key == "1" or key == "2" then
|
||||
love.system.setModel(tonumber(key))
|
||||
end
|
||||
end
|
||||
|
||||
function math.clamp(low, n, high)
|
||||
return math.min(math.max(low, n), high)
|
||||
end
|
||||
|
||||
local oldMousePressed = love.mousepressed
|
||||
function love.mousepressed(x, y, button)
|
||||
x, y = math.clamp(0, x - 40, 320), math.clamp(0, y - 240, 240)
|
||||
|
||||
if oldMousePressed then
|
||||
oldMousePressed(x, y, 1)
|
||||
end
|
||||
end
|
||||
|
||||
local oldMouseReleased = love.mousereleased
|
||||
function love.mousereleased(x, y, button)
|
||||
x, y = math.clamp(0, x - 40, 320), math.clamp(0, y - 240, 240)
|
||||
|
||||
if oldMouseReleased then
|
||||
oldMouseReleased(x, y, 1)
|
||||
end
|
||||
end
|
||||
|
||||
_SCREEN = "top"
|
||||
|
||||
models = {"3DS", "3DSXL"}
|
||||
function love.system.getModel()
|
||||
return models[scale]
|
||||
end
|
||||
|
||||
function love.system.setModel(s)
|
||||
scale = s
|
||||
|
||||
love.window.setMode(400 * scale, 240 * scale, {vsync = true})
|
||||
|
||||
love.window.setTitle(love.filesystem.getIdentity() .. " :: " .. love.system.getModel())
|
||||
end
|
||||
|
||||
love.system.setModel(1)
|
||||
|
||||
function love.graphics.setScreen(screen)
|
||||
assert(type(screen) == "string", "String expected, got " .. type(screen))
|
||||
_SCREEN = screen
|
||||
|
||||
love.graphics.setColor(32, 32, 32)
|
||||
|
||||
love.graphics.rectangle("fill", 0, 240, 40, 240)
|
||||
love.graphics.rectangle("fill", 360, 240, 40, 240)
|
||||
|
||||
love.graphics.setColor(255, 255, 255)
|
||||
|
||||
if screen == "top" then
|
||||
love.graphics.setScissor(0, 0, 400 * scale, 240 * scale)
|
||||
elseif screen == "bottom" then
|
||||
love.graphics.setScissor(40 * scale, 240 * scale, 320 * scale, 240 * scale)
|
||||
end
|
||||
end
|
||||
|
||||
function love.graphics.getWidth()
|
||||
if love.graphics.getScreen() == "bottom" then
|
||||
return 320
|
||||
end
|
||||
return 400
|
||||
end
|
||||
|
||||
function love.graphics.getHeight()
|
||||
return 240
|
||||
end
|
||||
|
||||
function love.graphics.getScreen()
|
||||
return _SCREEN
|
||||
end
|
||||
|
||||
local oldclear = love.graphics.clear
|
||||
function love.graphics.clear(r, g, b, a)
|
||||
love.graphics.setScissor()
|
||||
|
||||
oldclear(r, g, b, a)
|
||||
end
|
250
lib/minigames/snake.lua
Normal file
250
lib/minigames/snake.lua
Normal file
@@ -0,0 +1,250 @@
|
||||
|
||||
--[[
|
||||
|
||||
so 3ds uses 2 screens, what if i wanted to make this game cover 2 screens, or even what if i wanted to play 2 games on 2 screens
|
||||
actually loving that second idea. gonna try to make it
|
||||
|
||||
|
||||
|
||||
]]
|
||||
|
||||
|
||||
snake = {
|
||||
beep = love.audio.newSource("data/beep.wav", "static"),
|
||||
death = love.audio.newSource("data/death.wav", "static"),
|
||||
fps = 10,
|
||||
frames = 0,
|
||||
hgrid = 20,
|
||||
vgrid = 11,
|
||||
screen = "top",
|
||||
score = 0,
|
||||
bgCol = {
|
||||
r = 0,
|
||||
g = 0,
|
||||
b = 0
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
snakeplayer = {
|
||||
x = 1,
|
||||
y = 1,
|
||||
w = 1,
|
||||
xvel = 0,
|
||||
yvel = 0,
|
||||
mode = "fill",
|
||||
col = {
|
||||
r = 1,
|
||||
g = 1,
|
||||
b = 1
|
||||
},
|
||||
blocks = {
|
||||
|
||||
},
|
||||
tar = {
|
||||
x = 8,
|
||||
y = 3,
|
||||
}
|
||||
}
|
||||
|
||||
function snakeplayer:reset()
|
||||
self.xvel = 0
|
||||
self.yvel = 0
|
||||
end
|
||||
|
||||
function snakeplayer:hardreset()
|
||||
self.xvel = 0
|
||||
self.yvel = 0
|
||||
self.x = 10
|
||||
self.y = 10
|
||||
self.blocks = {}
|
||||
love.graphics.setScreen(snake.screen)
|
||||
self.w = love.graphics.getWidth()/snake.hgrid
|
||||
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
|
||||
|
||||
else
|
||||
self.xvel = xvel
|
||||
self.yvel = yvel
|
||||
end
|
||||
end
|
||||
|
||||
function snakeplayer:update(dt)
|
||||
if snake.frames >= 1/snake.fps then
|
||||
if self.x > snake.hgrid then
|
||||
self.x = 0
|
||||
end
|
||||
if self.x < 0 then
|
||||
self.x = snake.hgrid
|
||||
end
|
||||
if self.y > snake.vgrid then
|
||||
self.y = 0
|
||||
end
|
||||
if self.y < 0 then
|
||||
self.y = snake.vgrid
|
||||
end
|
||||
if self.tar.x == self.x and self.tar.y == self.y then
|
||||
table.insert(self.blocks, {x = self.x, y = self.y})
|
||||
self.tar.x = math.floor(math.random() * snake.hgrid)
|
||||
self.tar.y = math.floor(math.random() * snake.vgrid)
|
||||
snake.beep:play()
|
||||
snake.score= snake.score + 1
|
||||
end
|
||||
for i = table.getn(self.blocks), 1, -1 do
|
||||
if i == 1 then
|
||||
self.blocks[i].x = self.x
|
||||
self.blocks[i].y = self.y
|
||||
else
|
||||
self.blocks[i].x = self.blocks[i-1].x
|
||||
self.blocks[i].y = self.blocks[i-1].y
|
||||
end
|
||||
end
|
||||
self.x = self.x+self.xvel
|
||||
self.y = self.y+self.yvel
|
||||
for i in ipairs(self.blocks) do
|
||||
if self.x == self.blocks[i].x and self.y == self.blocks[i].y then
|
||||
snake.death:play()
|
||||
snakeplayer:hardreset()
|
||||
return
|
||||
--love.event.quit()
|
||||
end
|
||||
end
|
||||
snake.frames = 0
|
||||
end
|
||||
snake.frames = snake.frames+dt
|
||||
end
|
||||
|
||||
function snakeplayer:draw()
|
||||
love.graphics.setScreen(snake.screen)
|
||||
love.graphics.setColor(snake.bgCol.r, snake.bgCol.g, snake.bgCol.b)
|
||||
love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), love.graphics.getHeight())
|
||||
love.graphics.setColor(0,255,0)
|
||||
for i in ipairs(self.blocks) do
|
||||
love.graphics.rectangle(self.mode, self.blocks[i].x*self.w, self.blocks[i].y*self.w, self.w, self.w)
|
||||
end
|
||||
love.graphics.setColor(self.col.r*255, 0, 0)
|
||||
love.graphics.rectangle(self.mode, self.tar.x * self.w, self.tar.y * self.w, self.w, self.w)
|
||||
love.graphics.setColor(self.col.r*255, self.col.g*255, self.col.b*255)
|
||||
love.graphics.rectangle(self.mode, self.x*self.w, self.y*self.w, self.w, self.w)
|
||||
end
|
||||
|
||||
|
||||
|
||||
--[[
|
||||
buttons for 3ds:
|
||||
a
|
||||
b
|
||||
x
|
||||
y
|
||||
up
|
||||
down
|
||||
left
|
||||
right
|
||||
cpadup
|
||||
cpaddown
|
||||
cpadleft
|
||||
cpadright
|
||||
cstickup
|
||||
cstickdown
|
||||
cstickleft
|
||||
cstickright
|
||||
lbutton
|
||||
rbutton
|
||||
lzbutton
|
||||
rzbutton
|
||||
start
|
||||
select
|
||||
|
||||
|
||||
]]
|
162
lib/minigames/swat.lua
Normal file
162
lib/minigames/swat.lua
Normal file
@@ -0,0 +1,162 @@
|
||||
fly = {
|
||||
sx = 0, --startx or current x
|
||||
sy = 0, --starty or current y
|
||||
x = 50, --destination x
|
||||
y = 50, --destination -y
|
||||
width = 75,
|
||||
height = 66,
|
||||
sprite = love.graphics.newImage("data/fly.png"), --image
|
||||
quad = love.graphics.newQuad(87, 40, 75, 66, 368, 195), --162 106
|
||||
rot = 0, --rotation
|
||||
scl = 20, --scale
|
||||
alive = false, --is the fly alive
|
||||
ttl = 4, --time to live before the fly dies
|
||||
tl = 0, --time lived
|
||||
timer = false --flies only start living when they stop moving, this is to keep tracking that
|
||||
}
|
||||
|
||||
swat = {
|
||||
beep = love.audio.newSource("data/beep.wav", "static"),
|
||||
death = love.audio.newSource("data/death.wav", "static"),
|
||||
screen = "bottom",
|
||||
score = 0,
|
||||
diff = .1, --difficulty
|
||||
frames = 0,
|
||||
width = 1,--set later width of screen
|
||||
height = 1,--set later height of screen
|
||||
bgCol = { --background colors of screen
|
||||
r = 255,
|
||||
g = 255,
|
||||
b = 255
|
||||
}
|
||||
}
|
||||
|
||||
function swat:load()
|
||||
love.graphics.setScreen(swat.screen)
|
||||
swat.width = love.graphics.getWidth()
|
||||
swat.height = love.graphics.getHeight()
|
||||
swat.score = 0
|
||||
swat.frames = 0
|
||||
fly:newFly()
|
||||
end
|
||||
|
||||
|
||||
function swat:mousepressed(x, y)
|
||||
fly:kill(x, y)
|
||||
end
|
||||
|
||||
|
||||
function swat:update( dt)
|
||||
if fly.timer then
|
||||
fly.tl = fly.tl + dt
|
||||
end
|
||||
if fly.tl >= (fly.ttl - (swat.score * swat.diff)) then
|
||||
swat.score = swat.score -1
|
||||
fly:newFly()
|
||||
end
|
||||
if fly.alive then
|
||||
--draw the existing fly if he's not on path, move him on his path.
|
||||
if fly.sx ~= fly.x or fly.sy ~= fly.y then
|
||||
if fly.sx < fly.x then
|
||||
fly.sx = fly.sx +1
|
||||
end
|
||||
if fly.sx > fly.x then
|
||||
fly.sx = fly.sx - 1
|
||||
end
|
||||
if fly.sy > fly.y then
|
||||
fly.sy = fly.sy -1
|
||||
end
|
||||
if fly.sy < fly.y then
|
||||
fly.sy = fly.sy +1
|
||||
end
|
||||
else
|
||||
--reached position, enable timer
|
||||
fly.timer = true
|
||||
|
||||
end
|
||||
else
|
||||
--make a new fly
|
||||
swat.beep:play()
|
||||
fly:newFly()
|
||||
end
|
||||
end
|
||||
|
||||
function fly:draw()
|
||||
love.graphics.setScreen(swat.screen)
|
||||
love.graphics.setColor(swat.bgCol.r, swat.bgCol.g, swat.bgCol.b)
|
||||
--love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), love.graphics.getHeight())
|
||||
if fly.alive then
|
||||
love.graphics.draw(fly.sprite, fly.quad, fly.sx, fly.sy, 0, 0, 0,0,0)
|
||||
end
|
||||
|
||||
love.graphics.setColor(0,255,0)
|
||||
--love.graphics.print("score: ".. swat.score)
|
||||
end
|
||||
|
||||
function fly:newFly()
|
||||
fly.x = math.floor(math.random() * swat.width - fly.width)
|
||||
fly.y = math.floor(math.random() * swat.height - fly.height)
|
||||
temp = math.floor(math.random() * 4) + 1
|
||||
if temp <= 1 then
|
||||
fly.sx = math.floor(math.random() * swat.width)
|
||||
fly.sy = 0
|
||||
elseif temp <= 2 then
|
||||
fly.sy = math.floor(math.random() * swat.height)
|
||||
fly.sx = 0
|
||||
elseif temp <= 3 then
|
||||
fly.sx = math.floor(math.random() * swat.width)
|
||||
fly.sy = swat.height
|
||||
else
|
||||
fly.sy = math.floor(math.random() * swat.height)
|
||||
fly.sx = swat.width
|
||||
end
|
||||
fly.alive = true
|
||||
fly.ttl = 4
|
||||
fly.tl = 0
|
||||
fly.timer = false
|
||||
fly.anf = 0
|
||||
end
|
||||
|
||||
--[[
|
||||
|
||||
fly = {
|
||||
sx = 0, --startx or current x
|
||||
sy = 0, --starty or current y
|
||||
x = 50, --destination x
|
||||
y = 50, --destination -y
|
||||
width = 75,
|
||||
height = 66,
|
||||
sprite = love.graphics.newImage("data/fly.png"), --image
|
||||
quad = love.graphics.newQuad(87, 40, 75, 66, 368, 195), --162 106
|
||||
rot = 0, --rotation
|
||||
scl = 20, --scale
|
||||
alive = true, --is the fly alive
|
||||
ttl = 4, --time to live before the fly dies
|
||||
tl = 0, --time lived
|
||||
timer = false --flies only start living when they stop moving, this is to keep tracking that
|
||||
}
|
||||
|
||||
|
||||
]]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function fly:kill(x, y)
|
||||
if x > fly.sx and x < fly.sx+fly.width and y > fly.sy and y < fly.sy+fly.height then
|
||||
|
||||
fly:newFly()
|
||||
swat.score = swat.score+1
|
||||
return
|
||||
end
|
||||
end
|
97
lib/tools/ui.lua
Normal file
97
lib/tools/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