mirror of
https://github.com/bvanroll/3dsStuff.git
synced 2025-08-28 11:22:40 +00:00
forgot to commit some stuff yesterday, hope the changelog is still in there, but i added a compatibility file someone made to make stuff easyer to emulate on pc
This commit is contained in:
3
main.lua
3
main.lua
@@ -16,9 +16,7 @@ end
|
||||
|
||||
|
||||
function love.draw()
|
||||
love.graphics.setScreen('top')
|
||||
snakeplayer:draw()
|
||||
love.graphics.setScreen('bottom')
|
||||
fly:draw()
|
||||
end
|
||||
|
||||
@@ -127,3 +125,4 @@ end
|
||||
|
||||
|
||||
|
||||
--require("potion-compat")
|
348
potion-compat.lua
Normal file
348
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
|
@@ -16,6 +16,7 @@ snake = {
|
||||
frames = 0,
|
||||
hgrid = 20,
|
||||
vgrid = 11,
|
||||
screen = "top",
|
||||
bgCol = {
|
||||
r = 0,
|
||||
g = 0,
|
||||
@@ -56,7 +57,7 @@ function snakeplayer:hardreset()
|
||||
self.x = 10
|
||||
self.y = 10
|
||||
self.blocks = {}
|
||||
love.graphics.setScreen("top")
|
||||
love.graphics.setScreen(snake.screen)
|
||||
self.w = love.graphics.getWidth()/snake.hgrid
|
||||
end
|
||||
|
||||
@@ -114,11 +115,10 @@ function snakeplayer:update(dt)
|
||||
end
|
||||
|
||||
function snakeplayer:draw()
|
||||
love.graphics.setScreen('top')
|
||||
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)
|
||||
temp = 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
|
||||
|
54
swat.lua
54
swat.lua
@@ -1,29 +1,30 @@
|
||||
fly = {
|
||||
sx = 0,
|
||||
sy = 0,
|
||||
x = 50,
|
||||
y = 50,
|
||||
sprite = love.graphics.newImage("data/fly.png"),
|
||||
af = love.graphics.newQuad(0, 0, 512, 512, 1024, 512),
|
||||
bf = love.graphics.newQuad(512, 0, 512, 512, 1024, 512),
|
||||
rot = 0,
|
||||
scl = 20,
|
||||
anf = 0,
|
||||
anc = false,
|
||||
ans = 10,
|
||||
alive = true,
|
||||
ttl = 4,
|
||||
tl = 0,
|
||||
timer = false
|
||||
sx = 0, --startx or current x
|
||||
sy = 0, --starty or current y
|
||||
x = 50, --destination x
|
||||
y = 50, --destination -y
|
||||
sprite = love.graphics.newImage("data/fly.png"), --image
|
||||
af = love.graphics.newQuad(0, 0, 512, 512, 1024, 512), --a frame
|
||||
bf = love.graphics.newQuad(512, 0, 512, 512, 1024, 512), --b frame
|
||||
rot = 0, --rotation
|
||||
scl = 20, --scale
|
||||
anf = 0, --animation frames
|
||||
anc = false, --animation counter (false is af true is bf or some shit)
|
||||
ans = 1, --animation speed (if animation frames is equal to this the anim changes)
|
||||
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
|
||||
}
|
||||
|
||||
swat = {
|
||||
screen = "bottom",
|
||||
score = 0,
|
||||
diff = 1,
|
||||
diff = 1, --difficulty
|
||||
frames = 0,
|
||||
width = 1,
|
||||
height = 1,
|
||||
bgCol = {
|
||||
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
|
||||
@@ -31,7 +32,7 @@ swat = {
|
||||
}
|
||||
|
||||
function swat:load()
|
||||
love.graphics.setScreen("bottom")
|
||||
love.graphics.setScreen(swat.screen)
|
||||
swat.width = love.graphics.getWidth()
|
||||
swat.height = love.graphics.getHeight()
|
||||
swat.score = 0
|
||||
@@ -50,6 +51,10 @@ function swat:update( dt)
|
||||
if fly.timer then
|
||||
fly.tl = fly.tl + dt
|
||||
end
|
||||
if fly.tl >= fly.ttl 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
|
||||
@@ -77,7 +82,7 @@ function swat:update( dt)
|
||||
end
|
||||
|
||||
function fly:draw()
|
||||
love.graphics.setScreen("bottom")
|
||||
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.anf > fly.ans then
|
||||
@@ -89,10 +94,9 @@ function fly:draw()
|
||||
end
|
||||
end
|
||||
if fly.anc then
|
||||
love.graphics.draw(fly.sprite, fly.af, fly.sx, fly.sy, fly.rot, 0.2, 0.2)
|
||||
love.graphics.draw(fly.sprite, fly.af, 1, 1, 0, 0, 0,0,0)
|
||||
else
|
||||
love.graphics.draw(fly.sprite, fly.bf, fly.sx, fly.sy, fly.rot, 1, 1)
|
||||
|
||||
love.graphics.draw(fly.sprite, fly.bf, 1, 1, 0, 0, 0,0,0)
|
||||
end
|
||||
|
||||
end
|
||||
|
Reference in New Issue
Block a user