restructuring folders, planning on dev for games as standalone first and then porting them to the main thing

This commit is contained in:
2018-09-02 03:29:25 +02:00
parent d0fb98ad8c
commit 10be7e0363
6 changed files with 5 additions and 5 deletions

250
lib/minigames/snake.lua Normal file
View 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
View 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