mirror of
https://github.com/bvanroll/3dsStuff.git
synced 2025-08-28 19:32:41 +00:00
everything i originally planned on works now, this is officially 1.0, gonna merge it with main and the next plan is to create a lives system instead of a score system
This commit is contained in:
8
main.lua
8
main.lua
@@ -4,6 +4,7 @@ require "swat"
|
|||||||
function love.load()
|
function love.load()
|
||||||
--love.graphics.set3D(true)
|
--love.graphics.set3D(true)
|
||||||
snakeplayer:hardreset()
|
snakeplayer:hardreset()
|
||||||
|
swat:load()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@@ -123,6 +124,9 @@ function love.keyreleased(key)
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function love.mousepressed(a, b)
|
||||||
|
local x, y = love.mouse.getPosition()
|
||||||
|
fly:kill(x, y)
|
||||||
|
end
|
||||||
|
|
||||||
|
--require("potion-compat")
|
||||||
require("potion-compat")
|
|
@@ -16,7 +16,8 @@ snake = {
|
|||||||
frames = 0,
|
frames = 0,
|
||||||
hgrid = 20,
|
hgrid = 20,
|
||||||
vgrid = 11,
|
vgrid = 11,
|
||||||
screen = "bottom",
|
screen = "top",
|
||||||
|
score = 0,
|
||||||
bgCol = {
|
bgCol = {
|
||||||
r = 0,
|
r = 0,
|
||||||
g = 0,
|
g = 0,
|
||||||
@@ -59,6 +60,7 @@ function snakeplayer:hardreset()
|
|||||||
self.blocks = {}
|
self.blocks = {}
|
||||||
love.graphics.setScreen(snake.screen)
|
love.graphics.setScreen(snake.screen)
|
||||||
self.w = love.graphics.getWidth()/snake.hgrid
|
self.w = love.graphics.getWidth()/snake.hgrid
|
||||||
|
snake.score = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
function snakeplayer:move(xvel, yvel)
|
function snakeplayer:move(xvel, yvel)
|
||||||
@@ -89,6 +91,7 @@ function snakeplayer:update(dt)
|
|||||||
self.tar.x = math.floor(math.random() * snake.hgrid)
|
self.tar.x = math.floor(math.random() * snake.hgrid)
|
||||||
self.tar.y = math.floor(math.random() * snake.vgrid)
|
self.tar.y = math.floor(math.random() * snake.vgrid)
|
||||||
snake.beep:play()
|
snake.beep:play()
|
||||||
|
snake.score= snake.score + 1
|
||||||
end
|
end
|
||||||
for i = table.getn(self.blocks), 1, -1 do
|
for i = table.getn(self.blocks), 1, -1 do
|
||||||
if i == 1 then
|
if i == 1 then
|
||||||
|
69
swat.lua
69
swat.lua
@@ -3,20 +3,24 @@ fly = {
|
|||||||
sy = 0, --starty or current y
|
sy = 0, --starty or current y
|
||||||
x = 50, --destination x
|
x = 50, --destination x
|
||||||
y = 50, --destination -y
|
y = 50, --destination -y
|
||||||
|
width = 75,
|
||||||
|
height = 66,
|
||||||
sprite = love.graphics.newImage("data/fly.png"), --image
|
sprite = love.graphics.newImage("data/fly.png"), --image
|
||||||
quad = love.graphics.newQuad(87, 40, 75, 66, 368, 195), --162 106
|
quad = love.graphics.newQuad(87, 40, 75, 66, 368, 195), --162 106
|
||||||
rot = 0, --rotation
|
rot = 0, --rotation
|
||||||
scl = 20, --scale
|
scl = 20, --scale
|
||||||
alive = true, --is the fly alive
|
alive = false, --is the fly alive
|
||||||
ttl = 4, --time to live before the fly dies
|
ttl = 4, --time to live before the fly dies
|
||||||
tl = 0, --time lived
|
tl = 0, --time lived
|
||||||
timer = false --flies only start living when they stop moving, this is to keep tracking that
|
timer = false --flies only start living when they stop moving, this is to keep tracking that
|
||||||
}
|
}
|
||||||
|
|
||||||
swat = {
|
swat = {
|
||||||
screen = "top",
|
beep = love.audio.newSource("data/beep.wav", "static"),
|
||||||
|
death = love.audio.newSource("data/death.wav", "static"),
|
||||||
|
screen = "bottom",
|
||||||
score = 0,
|
score = 0,
|
||||||
diff = 1, --difficulty
|
diff = .1, --difficulty
|
||||||
frames = 0,
|
frames = 0,
|
||||||
width = 1,--set later width of screen
|
width = 1,--set later width of screen
|
||||||
height = 1,--set later height of screen
|
height = 1,--set later height of screen
|
||||||
@@ -38,15 +42,10 @@ end
|
|||||||
|
|
||||||
|
|
||||||
function swat:update( dt)
|
function swat:update( dt)
|
||||||
if swat.frames == swat.diff then
|
|
||||||
|
|
||||||
swat.frames = 0
|
|
||||||
end
|
|
||||||
swat.frames = swat.frames+dt
|
|
||||||
if fly.timer then
|
if fly.timer then
|
||||||
fly.tl = fly.tl + dt
|
fly.tl = fly.tl + dt
|
||||||
end
|
end
|
||||||
if fly.tl >= fly.ttl then
|
if fly.tl >= (fly.ttl - (swat.score * swat.diff)) then
|
||||||
swat.score = swat.score -1
|
swat.score = swat.score -1
|
||||||
fly:newFly()
|
fly:newFly()
|
||||||
end
|
end
|
||||||
@@ -72,6 +71,7 @@ function swat:update( dt)
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
--make a new fly
|
--make a new fly
|
||||||
|
swat.beep:play()
|
||||||
fly:newFly()
|
fly:newFly()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -79,16 +79,18 @@ end
|
|||||||
function fly:draw()
|
function fly:draw()
|
||||||
love.graphics.setScreen(swat.screen)
|
love.graphics.setScreen(swat.screen)
|
||||||
love.graphics.setColor(swat.bgCol.r, swat.bgCol.g, swat.bgCol.b)
|
love.graphics.setColor(swat.bgCol.r, swat.bgCol.g, swat.bgCol.b)
|
||||||
love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), love.graphics.getHeight())
|
--love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), love.graphics.getHeight())
|
||||||
if fly.alive then
|
if fly.alive then
|
||||||
love.graphics.draw(fly.sprite, fly.quad, fly.sx, fly.sy, 0, 0, 0,0,0)
|
love.graphics.draw(fly.sprite, fly.quad, fly.sx, fly.sy, 0, 0, 0,0,0)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
love.graphics.setColor(0,255,0)
|
||||||
|
--love.graphics.print("score: ".. swat.score)
|
||||||
end
|
end
|
||||||
|
|
||||||
function fly:newFly()
|
function fly:newFly()
|
||||||
fly.x = math.floor(math.random() * swat.width)
|
fly.x = math.floor(math.random() * swat.width - fly.width)
|
||||||
fly.y = math.floor(math.random() * swat.height)
|
fly.y = math.floor(math.random() * swat.height - fly.height)
|
||||||
temp = math.floor(math.random() * 4) + 1
|
temp = math.floor(math.random() * 4) + 1
|
||||||
if temp <= 1 then
|
if temp <= 1 then
|
||||||
fly.sx = math.floor(math.random() * swat.width)
|
fly.sx = math.floor(math.random() * swat.width)
|
||||||
@@ -110,3 +112,46 @@ function fly:newFly()
|
|||||||
fly.anf = 0
|
fly.anf = 0
|
||||||
end
|
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
|
Reference in New Issue
Block a user