blades spawn and despawn

This commit is contained in:
PossiblyAxolotl 2022-04-23 23:03:32 -06:00
parent d166085035
commit 07b48b6e0d
7 changed files with 41 additions and 0 deletions

View file

@ -4,6 +4,7 @@ import "CoreLibs/ui"
import "Player"
import "Map"
import "Menu"
import "Saws"
mode = "menu"
map = "levels/level1.json"

View file

@ -17,6 +17,7 @@ function addMap(_file)
tilemap:setTileAtPosition(level.tiles[i].x,level.tiles[i].y,level.tiles[i].t)
end
if level.saws then loadBlades(level.saws) end
addPlayer(level.rocket.x,level.rocket.y, level.bigrocket.x, level.bigrocket.y)
gfx.sprite.addWallSprites(tilemap, {0,1})

View file

@ -25,6 +25,7 @@ function mainMenuCreation()
end
function createMenu(items)
killBlades()
killPlayer()
mode = "menu"
controlX = -80

37
Source/Saws.lua Normal file
View file

@ -0,0 +1,37 @@
local gfx <const> = playdate.graphics
local imgSaw = gfx.image.new("gfx/sawblade")
local imgTarget = gfx.image.new("gfx/target")
assert(imgSaw)
assert(imgTarget)
local blades = {}
function loadBlades(_blades)
for i = 1, #_blades,1 do
local b = _blades[i]
b.start = playdate.geometry.point.new(b.start.x,b.start.y)
b.ends = playdate.geometry.point.new(b.ends.x,b.ends.y)
b.saw = gfx.sprite.new(imgSaw)
b.saw:moveTo(b.start)
b.saw:setCollideRect(0,0,16,16)
b.saw:add()
b.t1 = gfx.sprite.new(imgTarget)
b.t1:moveTo(b.start)
b.t2 = gfx.sprite.new(imgTarget)
b.t2:moveTo(b.ends)
b.t1:add()
b.t2:add()
blades[i] = b
end
end
function killBlades()
for i = 1, #blades, 1 do
blades[i].t1:remove()
blades[i].t2:remove()
blades[i].saw:remove()
end
blades = {}
end

BIN
Source/gfx/sawblade.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 148 B

BIN
Source/gfx/target.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 115 B

1
Source/levels/saw.json Normal file
View file

@ -0,0 +1 @@
{"bigrocket":{"x":73.333333,"y":144.79638},"dimensions":{"x":22,"y":17},"rocket":{"x":276.27907,"y":144.651163},"saws":[{"ends":{"x":200.000014,"y":81.105913},"speed":1,"start":{"x":141.013825,"y":168.202765}},{"ends":{"x":313.824857,"y":185.714272},"speed":1,"start":{"x":235.023041,"y":184.331797}}],"tiles":[{"t":2,"x":2,"y":1},{"t":2,"x":14,"y":1},{"t":2,"x":14,"y":5},{"t":2,"x":22,"y":5},{"t":2,"x":8,"y":6},{"t":2,"x":2,"y":12},{"t":2,"x":8,"y":12},{"t":2,"x":11,"y":12},{"t":2,"x":14,"y":12},{"t":2,"x":8,"y":17},{"t":2,"x":22,"y":17},{"t":3,"x":3,"y":1},{"t":3,"x":4,"y":1},{"t":3,"x":5,"y":1},{"t":3,"x":6,"y":1},{"t":3,"x":7,"y":1},{"t":3,"x":8,"y":1},{"t":3,"x":9,"y":1},{"t":3,"x":10,"y":1},{"t":3,"x":11,"y":1},{"t":3,"x":12,"y":1},{"t":3,"x":13,"y":1},{"t":3,"x":15,"y":5},{"t":3,"x":16,"y":5},{"t":3,"x":17,"y":5},{"t":3,"x":18,"y":5},{"t":3,"x":19,"y":5},{"t":3,"x":20,"y":5},{"t":3,"x":21,"y":5},{"t":3,"x":3,"y":12},{"t":3,"x":4,"y":12},{"t":3,"x":5,"y":12},{"t":3,"x":6,"y":12},{"t":3,"x":7,"y":12},{"t":3,"x":9,"y":12},{"t":3,"x":10,"y":12},{"t":3,"x":9,"y":17},{"t":3,"x":10,"y":17},{"t":3,"x":11,"y":17},{"t":3,"x":12,"y":17},{"t":3,"x":13,"y":17},{"t":3,"x":14,"y":17},{"t":3,"x":15,"y":17},{"t":3,"x":16,"y":17},{"t":3,"x":17,"y":17},{"t":3,"x":18,"y":17},{"t":3,"x":19,"y":17},{"t":3,"x":20,"y":17},{"t":3,"x":21,"y":17},{"t":4,"x":2,"y":2},{"t":4,"x":14,"y":2},{"t":4,"x":2,"y":3},{"t":4,"x":14,"y":3},{"t":4,"x":2,"y":4},{"t":4,"x":14,"y":4},{"t":4,"x":2,"y":5},{"t":4,"x":2,"y":6},{"t":4,"x":14,"y":6},{"t":4,"x":22,"y":6},{"t":4,"x":2,"y":7},{"t":4,"x":8,"y":7},{"t":4,"x":14,"y":7},{"t":4,"x":22,"y":7},{"t":4,"x":2,"y":8},{"t":4,"x":8,"y":8},{"t":4,"x":14,"y":8},{"t":4,"x":22,"y":8},{"t":4,"x":2,"y":9},{"t":4,"x":8,"y":9},{"t":4,"x":14,"y":9},{"t":4,"x":22,"y":9},{"t":4,"x":2,"y":10},{"t":4,"x":8,"y":10},{"t":4,"x":14,"y":10},{"t":4,"x":22,"y":10},{"t":4,"x":2,"y":11},{"t":4,"x":8,"y":11},{"t":4,"x":14,"y":11},{"t":4,"x":22,"y":11},{"t":4,"x":22,"y":12},{"t":4,"x":8,"y":13},{"t":4,"x":22,"y":13},{"t":4,"x":8,"y":14},{"t":4,"x":22,"y":14},{"t":4,"x":8,"y":15},{"t":4,"x":22,"y":15},{"t":4,"x":8,"y":16},{"t":4,"x":22,"y":16}]}