2021-10-22 16:23:05 +00:00
|
|
|
function LevelLoadTiles()
|
2022-02-17 22:39:31 +00:00
|
|
|
math.randomseed(3)
|
2022-02-12 09:35:45 +00:00
|
|
|
LevelData = dofile("data/levels/"..currLevel)
|
2022-01-29 07:49:45 +00:00
|
|
|
|
2021-10-16 23:06:11 +00:00
|
|
|
--[[
|
|
|
|
on level format:
|
|
|
|
|
|
|
|
id = tile identifier
|
|
|
|
depth = order in the render
|
|
|
|
force = rendering other tile instead of the one in this position
|
2022-01-29 07:49:45 +00:00
|
|
|
overlay = render another tile id or, if multiple tiles {id, id, id,}, choose at random
|
2021-10-16 23:06:11 +00:00
|
|
|
overlay_depth = foreground/background overlay depth
|
|
|
|
type = collision type
|
|
|
|
]]
|
2022-01-30 11:01:10 +00:00
|
|
|
LevelGetTileData()
|
2022-01-29 07:49:45 +00:00
|
|
|
LevelTiles = LevelData.tiles
|
|
|
|
LevelUpdateDimensions()
|
|
|
|
LevelIndexTiles()
|
|
|
|
TileCreateObjects()
|
|
|
|
end
|
2021-11-28 02:38:30 +00:00
|
|
|
|
2022-01-31 00:22:15 +00:00
|
|
|
|
|
|
|
function LevelExpandCanvas(horizontal,vertical)
|
2022-01-31 05:44:03 +00:00
|
|
|
local horizontal = horizontal or 0
|
|
|
|
local vertical = vertical or 0
|
2022-01-31 00:22:15 +00:00
|
|
|
local h = LevelGetTileWidth()
|
|
|
|
local v = LevelGetTileHeight()
|
|
|
|
|
|
|
|
-- get new canvas size
|
|
|
|
local newCanvasH = h + math.abs(horizontal)
|
|
|
|
local newCanvasV = v + math.abs(vertical)
|
|
|
|
|
|
|
|
-- lets make a new temporal canvas
|
|
|
|
local ExpandedLevel = {}
|
|
|
|
for i = 1, newCanvasV do
|
|
|
|
ExpandedLevel[i] = {}
|
|
|
|
for j = 1, newCanvasH do
|
|
|
|
ExpandedLevel[i][j] = InstanceTile(0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- lets guess how the new canvas and positions are offset
|
|
|
|
local expand_h = 0
|
|
|
|
if horizontal < 0 then
|
|
|
|
expand_h = -horizontal
|
|
|
|
end
|
|
|
|
|
|
|
|
local expand_v = 0
|
|
|
|
if vertical < 0 then
|
|
|
|
expand_v = -vertical
|
|
|
|
end
|
|
|
|
|
|
|
|
-- get data from old canvas to new canvas
|
|
|
|
for i = 1, #LevelTiles do
|
|
|
|
for j = 1, #LevelTiles[i] do
|
2022-01-31 05:44:03 +00:00
|
|
|
ExpandedLevel[i+expand_v][j+expand_h] = InstanceTile(LevelTiles[i][j].id)
|
2022-01-31 00:22:15 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- use new canvas
|
|
|
|
LevelTiles = ExpandedLevel
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function LevelReduceCanvas(horizontal,vertical)
|
2022-01-31 05:44:03 +00:00
|
|
|
local horizontal = horizontal or 0
|
|
|
|
local vertical = vertical or 0
|
2022-01-31 00:22:15 +00:00
|
|
|
local h = LevelGetTileWidth()
|
|
|
|
local v = LevelGetTileHeight()
|
|
|
|
|
|
|
|
-- get new canvas size
|
|
|
|
local newCanvasH = h - math.abs(horizontal)
|
|
|
|
local newCanvasV = v - math.abs(vertical)
|
|
|
|
|
|
|
|
-- lets make a new temporal canvas
|
|
|
|
local ExpandedLevel = {}
|
|
|
|
for i = 1, newCanvasV do
|
|
|
|
ExpandedLevel[i] = {}
|
|
|
|
for j = 1, newCanvasH do
|
|
|
|
ExpandedLevel[i][j] = InstanceTile(0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- lets guess how the new canvas and positions are offset
|
|
|
|
local expand_h = 0
|
|
|
|
if horizontal < 0 then
|
|
|
|
expand_h = -horizontal
|
|
|
|
end
|
|
|
|
|
|
|
|
local expand_v = 0
|
|
|
|
if vertical < 0 then
|
|
|
|
expand_v = -vertical
|
|
|
|
end
|
|
|
|
|
|
|
|
-- get data from old canvas to new canvas
|
|
|
|
for i = 1, #ExpandedLevel do
|
|
|
|
for j = 1, #ExpandedLevel[i] do
|
2022-01-31 05:44:03 +00:00
|
|
|
ExpandedLevel[i][j] = InstanceTile(LevelTiles[i+expand_v][j+expand_h].id)
|
2022-01-31 00:22:15 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- use new canvas
|
|
|
|
LevelTiles = ExpandedLevel
|
2022-01-31 05:44:03 +00:00
|
|
|
|
|
|
|
LevelExpandCanvas()
|
2022-01-31 00:22:15 +00:00
|
|
|
end
|
|
|
|
|
2022-01-30 11:01:10 +00:00
|
|
|
function LevelGetTileData()
|
|
|
|
for k, v in pairs(tileset) do
|
|
|
|
if v == LevelData.tileset then
|
2022-02-12 09:35:45 +00:00
|
|
|
TileData = dofile("data/tileset/"..k..".lua")
|
2022-01-30 11:01:10 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-01-29 07:49:45 +00:00
|
|
|
function LevelReloadTiles()
|
|
|
|
LevelUpdateDimensions()
|
|
|
|
end
|
2022-01-22 22:10:21 +00:00
|
|
|
|
2022-01-29 07:49:45 +00:00
|
|
|
function LevelUpdateDimensions()
|
2021-11-28 02:38:30 +00:00
|
|
|
LevelData.Width = LevelGetWidth()
|
|
|
|
LevelData.Height = LevelGetHeight()
|
2021-10-16 23:06:11 +00:00
|
|
|
end
|
|
|
|
|
2022-01-29 07:49:45 +00:00
|
|
|
function LevelGetTileHeight()
|
|
|
|
return #LevelTiles
|
2021-10-22 16:23:05 +00:00
|
|
|
end
|
|
|
|
|
2022-01-29 07:49:45 +00:00
|
|
|
function LevelGetTileWidth()
|
2021-10-16 23:06:11 +00:00
|
|
|
local width = 0
|
|
|
|
for i = 1, #LevelTiles do
|
|
|
|
if width < #LevelTiles[i] then width = #LevelTiles[i] end
|
|
|
|
end
|
2022-01-29 07:49:45 +00:00
|
|
|
return width
|
|
|
|
end
|
|
|
|
|
|
|
|
function LevelGetHeight()
|
|
|
|
return LevelGetTileHeight() * tileProperties.height
|
|
|
|
end
|
|
|
|
|
|
|
|
function LevelGetWidth()
|
|
|
|
return LevelGetTileWidth() * tileProperties.width
|
2021-10-16 23:06:11 +00:00
|
|
|
end
|
|
|
|
|
2021-10-22 16:23:05 +00:00
|
|
|
function LevelIndexTiles()
|
2021-10-16 23:06:11 +00:00
|
|
|
TileIndex = {}
|
|
|
|
|
2022-01-22 22:10:21 +00:00
|
|
|
-- index from tileset
|
2021-11-28 02:38:30 +00:00
|
|
|
local width = LevelData.tileset:getPixelWidth()/tileProperties.width
|
|
|
|
local height = LevelData.tileset:getPixelHeight()/tileProperties.height
|
2021-10-16 23:06:11 +00:00
|
|
|
for i = 0, height do
|
|
|
|
for j = 0, width do
|
|
|
|
TileIndex[i*width+j+1] = love.graphics.newQuad(
|
|
|
|
j*tileProperties.width,
|
|
|
|
i*tileProperties.height,
|
|
|
|
tileProperties.width,
|
|
|
|
tileProperties.height,
|
2021-11-28 02:38:30 +00:00
|
|
|
LevelData.tileset:getDimensions()
|
2021-10-16 23:06:11 +00:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
2022-01-29 07:49:45 +00:00
|
|
|
TileDataInitialize()
|
2021-10-16 23:06:11 +00:00
|
|
|
|
2022-01-29 07:49:45 +00:00
|
|
|
-- instance level tiles according to the Properties
|
|
|
|
for i = 1, #LevelTiles do
|
|
|
|
for j = 1, #LevelTiles[i] do
|
2022-01-31 00:22:15 +00:00
|
|
|
SetTile(i,j,LevelTiles[i][j])
|
2022-01-29 07:49:45 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function TileDataInitialize()
|
2022-01-22 22:10:21 +00:00
|
|
|
for _, Properties in pairs(TileData) do
|
|
|
|
if Properties.animation ~= nil then
|
|
|
|
Properties.tileset = love.graphics.newImage("assets/terrain/"..Properties.animation..".png")
|
|
|
|
Properties.imgs = {}
|
|
|
|
Properties.current_image = 1
|
|
|
|
Properties.current_subimage = 1
|
2021-10-16 23:06:11 +00:00
|
|
|
|
2022-01-22 22:10:21 +00:00
|
|
|
local tileset = Properties.tileset
|
2021-10-16 23:06:11 +00:00
|
|
|
local width = tileset:getPixelWidth()/tileProperties.width
|
|
|
|
local height = tileset:getPixelHeight()/tileProperties.height
|
|
|
|
local image_count = 0
|
|
|
|
|
|
|
|
for i = 0, height-1 do
|
|
|
|
for j = 0, width-1 do
|
|
|
|
local quad =
|
|
|
|
love.graphics.newQuad(
|
|
|
|
j*tileProperties.width,
|
|
|
|
i*tileProperties.height,
|
|
|
|
tileProperties.width,
|
|
|
|
tileProperties.height,
|
|
|
|
tileset:getDimensions()
|
|
|
|
)
|
|
|
|
image_count = image_count + 1
|
|
|
|
|
2022-01-22 22:10:21 +00:00
|
|
|
table.insert(Properties.imgs,quad)
|
2021-10-16 23:06:11 +00:00
|
|
|
end
|
|
|
|
end
|
2022-01-22 22:10:21 +00:00
|
|
|
Properties.image_count = image_count
|
2021-10-16 23:06:11 +00:00
|
|
|
end
|
|
|
|
end
|
2022-01-29 07:49:45 +00:00
|
|
|
end
|
2021-11-28 02:38:30 +00:00
|
|
|
|
2022-01-31 00:22:15 +00:00
|
|
|
function InstanceTile(id)
|
|
|
|
local tile = {}
|
2021-11-28 02:38:30 +00:00
|
|
|
|
2022-01-29 09:46:49 +00:00
|
|
|
tile.id = id
|
|
|
|
local Properties = TileData[tile.id]
|
|
|
|
|
|
|
|
if Properties ~= nil then
|
|
|
|
if type(Properties.overlay) == "table" then
|
|
|
|
tile.display_overlay = Properties.overlay[math.random(#Properties.overlay)]
|
|
|
|
else
|
|
|
|
tile.display_overlay = Properties.overlay
|
2021-11-28 02:38:30 +00:00
|
|
|
end
|
2022-01-29 09:46:49 +00:00
|
|
|
|
|
|
|
if type(Properties.force) == "table" then
|
|
|
|
tile.display = Properties.force[math.random(#Properties.force)]
|
|
|
|
else
|
|
|
|
tile.display = Properties.force
|
|
|
|
end
|
|
|
|
end
|
2022-01-31 00:22:15 +00:00
|
|
|
|
|
|
|
return tile
|
|
|
|
end
|
|
|
|
|
|
|
|
function SetTile(i,j,id)
|
|
|
|
LevelTiles[i][j] = InstanceTile(id)
|
2021-10-16 23:06:11 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function GridDisplay()
|
|
|
|
for i = 1, #LevelTiles do
|
|
|
|
for j = 1, #LevelTiles[i] do
|
|
|
|
love.graphics.rectangle(
|
|
|
|
"line",
|
2022-01-22 22:10:21 +00:00
|
|
|
tileProperties.scale * (j * tileProperties.width + (levelProperties.offset.x - tileProperties.width)) - Camera.pos.x,
|
|
|
|
tileProperties.scale * (i * tileProperties.height + (levelProperties.offset.y - tileProperties.height)) - Camera.pos.y,
|
2021-10-16 23:06:11 +00:00
|
|
|
tileProperties.scale * tileProperties.width,
|
|
|
|
tileProperties.scale * tileProperties.height
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-02-07 08:24:41 +00:00
|
|
|
function TileOptimizeObjects()
|
2022-02-07 11:07:57 +00:00
|
|
|
logPrint("Optimizing Objects...")
|
2022-02-07 08:24:41 +00:00
|
|
|
local unoptimized = 0
|
|
|
|
local isTileOptimized = {}
|
|
|
|
for i = 1, #LevelTiles do
|
|
|
|
isTileOptimized[i] = {}
|
|
|
|
for j= 1, #LevelTiles[i] do
|
|
|
|
isTileOptimized[i][j] = false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
for i = 1, #LevelTiles do
|
|
|
|
for j = 1, #LevelTiles[i] do
|
|
|
|
if LevelTiles[i][j].id ~= 0 then
|
|
|
|
local type = TileData[LevelTiles[i][j].id].type
|
|
|
|
if type == "whole" and not isTileOptimized[i][j] then
|
|
|
|
isTileOptimized[i][j] = true
|
|
|
|
local n = 1
|
|
|
|
local check = true
|
|
|
|
while check do
|
2022-02-07 11:07:57 +00:00
|
|
|
check = false
|
|
|
|
if LevelTiles[i][j+n] ~= nil
|
|
|
|
and TileData[LevelTiles[i][j+n].id] ~= nil
|
|
|
|
then
|
|
|
|
local type_check = TileData[LevelTiles[i][j+n].id].type
|
|
|
|
if type_check == "whole"
|
|
|
|
and not isTileOptimized[i][j+n]
|
|
|
|
then
|
|
|
|
check = true
|
|
|
|
isTileOptimized[i][j+n] = true
|
|
|
|
n = n + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local m = 1
|
|
|
|
local check = true
|
|
|
|
while check do
|
|
|
|
check = false
|
|
|
|
local checkline = true
|
2022-02-15 09:35:52 +00:00
|
|
|
-- for as long as line, check
|
2022-02-07 11:07:57 +00:00
|
|
|
for l = 0, n-1 do
|
|
|
|
checkline = false
|
|
|
|
if LevelTiles[i+m] ~= nil
|
|
|
|
and LevelTiles[i+m][j+l] ~= nil
|
|
|
|
and TileData[LevelTiles[i+m][j+l].id] ~= nil
|
|
|
|
then
|
|
|
|
local type_check = TileData[LevelTiles[i+m][j+l].id].type
|
|
|
|
if type_check == "whole"
|
2022-02-08 07:22:27 +00:00
|
|
|
and not isTileOptimized[i+m][j+l]
|
2022-02-07 11:07:57 +00:00
|
|
|
then
|
|
|
|
checkline = true
|
2022-02-07 11:16:58 +00:00
|
|
|
else
|
|
|
|
break
|
2022-02-07 08:24:41 +00:00
|
|
|
end
|
2022-02-15 09:35:52 +00:00
|
|
|
else
|
|
|
|
break
|
2022-02-07 08:24:41 +00:00
|
|
|
end
|
|
|
|
end
|
2022-02-07 11:07:57 +00:00
|
|
|
if checkline then
|
|
|
|
check = true
|
|
|
|
for l = 0, n-1 do
|
|
|
|
isTileOptimized[i+m][j+l] = true
|
|
|
|
end
|
|
|
|
m = m + 1
|
2022-02-07 11:16:58 +00:00
|
|
|
else
|
2022-02-15 09:35:52 +00:00
|
|
|
break
|
2022-02-07 11:07:57 +00:00
|
|
|
end
|
2022-02-07 08:24:41 +00:00
|
|
|
end
|
|
|
|
|
2022-02-08 07:22:27 +00:00
|
|
|
logPrint("- Group size: "..m.."x"..n)
|
2022-02-07 11:07:57 +00:00
|
|
|
unoptimized = unoptimized + m * n
|
2022-02-07 08:24:41 +00:00
|
|
|
local base_x = tileProperties.scale * j * tileProperties.width + tileProperties.scale * (levelProperties.offset.x - tileProperties.height)
|
|
|
|
local base_y = tileProperties.scale * i * tileProperties.height + tileProperties.scale * (levelProperties.offset.y - tileProperties.height)
|
|
|
|
|
|
|
|
local col = Collision:New(
|
|
|
|
base_x,
|
|
|
|
base_y,
|
|
|
|
base_x + tileProperties.width * tileProperties.scale * n,
|
2022-02-07 11:07:57 +00:00
|
|
|
base_y + tileProperties.height * tileProperties.scale * m
|
2022-02-07 08:24:41 +00:00
|
|
|
)
|
|
|
|
table.insert(LoadedObjects.Collisions,col)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-02-07 08:36:16 +00:00
|
|
|
logPrint("collisions optimized from " .. unoptimized .. " to " .. #LoadedObjects.Collisions)
|
2022-02-07 08:24:41 +00:00
|
|
|
end
|
|
|
|
|
2021-10-22 16:23:05 +00:00
|
|
|
function TileCreateObjects()
|
2022-01-22 22:10:21 +00:00
|
|
|
LoadedObjects.Collisions = {}
|
|
|
|
LoadedObjects.Platforms = {}
|
|
|
|
LoadedObjects.Ladders = {}
|
2022-02-10 14:53:50 +00:00
|
|
|
LoadedObjects.Hazards = {}
|
2021-10-16 23:06:11 +00:00
|
|
|
|
2022-02-07 08:24:41 +00:00
|
|
|
TileOptimizeObjects()
|
|
|
|
|
2021-10-16 23:06:11 +00:00
|
|
|
for i = 1, #LevelTiles do
|
|
|
|
for j = 1, #LevelTiles[i] do
|
2021-11-28 02:38:30 +00:00
|
|
|
if LevelTiles[i][j].id ~= 0 then
|
2021-10-16 23:06:11 +00:00
|
|
|
|
2022-02-07 08:24:41 +00:00
|
|
|
local type = TileData[LevelTiles[i][j].id].type
|
|
|
|
local light = TileData[LevelTiles[i][j].id].light
|
2021-10-16 23:06:11 +00:00
|
|
|
local base_x = tileProperties.scale * j * tileProperties.width + tileProperties.scale * (levelProperties.offset.x - tileProperties.height)
|
|
|
|
local base_y = tileProperties.scale * i * tileProperties.height + tileProperties.scale * (levelProperties.offset.y - tileProperties.height)
|
|
|
|
|
2021-10-27 09:06:08 +00:00
|
|
|
|
|
|
|
if light ~= 0 and light ~= nil then
|
|
|
|
CreateLight(
|
|
|
|
base_x + tileProperties.width/2 * tileProperties.scale,
|
|
|
|
base_y + tileProperties.height/2 * tileProperties.scale,
|
|
|
|
light
|
|
|
|
)
|
|
|
|
end
|
2021-11-28 02:38:30 +00:00
|
|
|
|
2022-02-07 08:24:41 +00:00
|
|
|
-- wholes are handled in optimization now
|
|
|
|
--[[if type == "whole" then
|
2021-10-22 16:23:05 +00:00
|
|
|
local col = Collision:New(
|
2021-10-16 23:06:11 +00:00
|
|
|
base_x,
|
|
|
|
base_y,
|
|
|
|
base_x + tileProperties.width * tileProperties.scale,
|
|
|
|
base_y + tileProperties.height * tileProperties.scale
|
|
|
|
)
|
2022-01-22 22:10:21 +00:00
|
|
|
table.insert(LoadedObjects.Collisions,col)
|
2022-02-07 08:24:41 +00:00
|
|
|
else]]if type == "half_bottom" then
|
2021-10-16 23:06:11 +00:00
|
|
|
|
2021-10-22 16:23:05 +00:00
|
|
|
local col = Collision:New(
|
2021-10-16 23:06:11 +00:00
|
|
|
base_x,
|
|
|
|
base_y + tileProperties.height/2 * tileProperties.scale,
|
|
|
|
base_x + tileProperties.width * tileProperties.scale,
|
|
|
|
base_y + tileProperties.height * tileProperties.scale
|
|
|
|
)
|
2022-01-22 22:10:21 +00:00
|
|
|
table.insert(LoadedObjects.Collisions,col)
|
2021-10-16 23:06:11 +00:00
|
|
|
|
2021-10-22 16:23:05 +00:00
|
|
|
elseif type == "half_top" then
|
|
|
|
|
|
|
|
local col = Collision:New(
|
|
|
|
base_x,
|
|
|
|
base_y ,
|
|
|
|
base_x + tileProperties.width * tileProperties.scale,
|
|
|
|
base_y + tileProperties.height/2 * tileProperties.scale
|
|
|
|
)
|
2022-01-22 22:10:21 +00:00
|
|
|
table.insert(LoadedObjects.Collisions,col)
|
2021-10-22 16:23:05 +00:00
|
|
|
|
|
|
|
elseif type == "half_right" then
|
|
|
|
|
|
|
|
local col = Collision:New(
|
|
|
|
base_x + tileProperties.height/2 * tileProperties.scale,
|
|
|
|
base_y,
|
|
|
|
base_x + tileProperties.width * tileProperties.scale,
|
|
|
|
base_y + tileProperties.height * tileProperties.scale
|
|
|
|
)
|
2022-01-22 22:10:21 +00:00
|
|
|
table.insert(LoadedObjects.Collisions,col)
|
2021-10-22 16:23:05 +00:00
|
|
|
|
|
|
|
elseif type == "half_left" then
|
|
|
|
|
|
|
|
local col = Collision:New(
|
|
|
|
base_x,
|
|
|
|
base_y,
|
|
|
|
base_x + tileProperties.height/2 * tileProperties.scale,
|
|
|
|
base_y + tileProperties.height * tileProperties.scale
|
|
|
|
)
|
2022-01-22 22:10:21 +00:00
|
|
|
table.insert(LoadedObjects.Collisions,col)
|
2021-10-22 16:23:05 +00:00
|
|
|
|
2021-10-16 23:06:11 +00:00
|
|
|
elseif type == "platform" then
|
2021-10-22 16:23:05 +00:00
|
|
|
local plat = Collision:New(
|
2021-10-16 23:06:11 +00:00
|
|
|
base_x,
|
|
|
|
base_y + tileProperties.scale * 2,
|
|
|
|
base_x + tileProperties.width * tileProperties.scale,
|
|
|
|
base_y + tileProperties.height/4 * tileProperties.scale + tileProperties.scale * 2
|
|
|
|
)
|
2022-01-22 22:10:21 +00:00
|
|
|
table.insert(LoadedObjects.Platforms,plat)
|
2021-10-16 23:06:11 +00:00
|
|
|
|
|
|
|
elseif type == "ramp2_bot_left_whole" then
|
|
|
|
for k = 1, 8 do
|
|
|
|
-- do ramp owo
|
2021-10-22 16:23:05 +00:00
|
|
|
local slope = Collision:New(
|
2021-10-16 23:06:11 +00:00
|
|
|
base_x,
|
|
|
|
base_y + k * tileProperties.scale - tileProperties.scale,
|
|
|
|
base_x + k * 2 * tileProperties.scale,
|
|
|
|
base_y + k * tileProperties.scale
|
|
|
|
)
|
2022-01-22 22:10:21 +00:00
|
|
|
table.insert(LoadedObjects.Collisions,slope)
|
2021-10-16 23:06:11 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
-- fill lower half
|
2021-10-22 16:23:05 +00:00
|
|
|
local col = Collision:New(
|
2021-10-16 23:06:11 +00:00
|
|
|
base_x,
|
|
|
|
base_y + tileProperties.height/2 * tileProperties.scale,
|
|
|
|
base_x + tileProperties.width * tileProperties.scale,
|
|
|
|
base_y + tileProperties.height * tileProperties.scale
|
|
|
|
)
|
2022-01-22 22:10:21 +00:00
|
|
|
table.insert(LoadedObjects.Collisions,col)
|
2021-10-16 23:06:11 +00:00
|
|
|
|
|
|
|
elseif type == "ramp2_bot_left_half" then
|
|
|
|
for k = 1, 8 do
|
|
|
|
-- do ramp owo
|
2021-10-22 16:23:05 +00:00
|
|
|
local slope = Collision:New(
|
2021-10-16 23:06:11 +00:00
|
|
|
base_x,
|
|
|
|
base_y + tileProperties.height/2 * tileProperties.scale + k * tileProperties.scale - tileProperties.scale,
|
|
|
|
base_x + k * 2 * tileProperties.scale,
|
|
|
|
base_y + tileProperties.height/2 * tileProperties.scale + k * tileProperties.scale
|
|
|
|
)
|
2022-01-22 22:10:21 +00:00
|
|
|
table.insert(LoadedObjects.Collisions,slope)
|
2021-10-16 23:06:11 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
elseif type == "ramp2_top_left_whole" then
|
|
|
|
for k = 1, 8 do
|
|
|
|
-- do ramp owo
|
2021-10-22 16:23:05 +00:00
|
|
|
local slope = Collision:New(
|
2021-10-16 23:06:11 +00:00
|
|
|
base_x,
|
|
|
|
base_y + tileProperties.height/2 * tileProperties.scale - tileProperties.scale + k * tileProperties.scale,
|
|
|
|
base_x + tileProperties.width * tileProperties.scale - (k-1) * 2 * tileProperties.scale,
|
|
|
|
base_y + tileProperties.height/2 * tileProperties.scale - tileProperties.scale + k * tileProperties.scale + tileProperties.scale
|
|
|
|
)
|
2022-01-22 22:10:21 +00:00
|
|
|
table.insert(LoadedObjects.Collisions,slope)
|
2021-10-16 23:06:11 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
-- fill higher half
|
2021-10-22 16:23:05 +00:00
|
|
|
local col = Collision:New(
|
2021-10-16 23:06:11 +00:00
|
|
|
base_x,
|
|
|
|
base_y,
|
|
|
|
base_x + tileProperties.width * tileProperties.scale,
|
|
|
|
base_y + tileProperties.height/2 * tileProperties.scale
|
|
|
|
)
|
2022-01-22 22:10:21 +00:00
|
|
|
table.insert(LoadedObjects.Collisions,col)
|
2021-10-16 23:06:11 +00:00
|
|
|
|
|
|
|
elseif type == "ramp2_top_left_half" then
|
|
|
|
for k = 1, 8 do
|
|
|
|
-- do ramp owo
|
2021-10-22 16:23:05 +00:00
|
|
|
local slope = Collision:New(
|
2021-10-16 23:06:11 +00:00
|
|
|
base_x,
|
|
|
|
base_y - tileProperties.scale + k * tileProperties.scale,
|
|
|
|
base_x + tileProperties.width * tileProperties.scale - (k-1) * 2 * tileProperties.scale,
|
|
|
|
base_y - tileProperties.scale + k * tileProperties.scale + tileProperties.scale
|
|
|
|
)
|
2022-01-22 22:10:21 +00:00
|
|
|
table.insert(LoadedObjects.Collisions,slope)
|
2021-10-16 23:06:11 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
elseif type == "ramp2_bot_right_whole" then
|
|
|
|
for k = 1, 8 do
|
|
|
|
-- do ramp owo
|
2021-10-22 16:23:05 +00:00
|
|
|
local slope = Collision:New(
|
2021-10-16 23:06:11 +00:00
|
|
|
base_x + (k-8) * -2 * tileProperties.scale,
|
|
|
|
base_y - tileProperties.scale + k * tileProperties.scale,
|
|
|
|
base_x + tileProperties.width * tileProperties.scale,
|
|
|
|
base_y - tileProperties.scale + k * tileProperties.scale + tileProperties.scale
|
|
|
|
)
|
2022-01-22 22:10:21 +00:00
|
|
|
table.insert(LoadedObjects.Collisions,slope)
|
2021-10-16 23:06:11 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
-- fill lower half
|
2021-10-22 16:23:05 +00:00
|
|
|
local col = Collision:New(
|
2021-10-16 23:06:11 +00:00
|
|
|
base_x,
|
|
|
|
base_y + tileProperties.height/2 * tileProperties.scale,
|
|
|
|
base_x + tileProperties.width * tileProperties.scale,
|
|
|
|
base_y + tileProperties.height * tileProperties.scale
|
|
|
|
)
|
2022-01-22 22:10:21 +00:00
|
|
|
table.insert(LoadedObjects.Collisions,col)
|
2021-10-16 23:06:11 +00:00
|
|
|
|
|
|
|
elseif type == "ramp2_bot_right_half" then
|
|
|
|
for k = 1, 8 do
|
|
|
|
-- do ramp owo
|
2021-10-22 16:23:05 +00:00
|
|
|
local slope = Collision:New(
|
2021-10-16 23:06:11 +00:00
|
|
|
base_x + (k-8) * -2 * tileProperties.scale,
|
|
|
|
base_y + tileProperties.height/2 * tileProperties.scale - tileProperties.scale + k * tileProperties.scale,
|
|
|
|
base_x + tileProperties.width * tileProperties.scale,
|
|
|
|
base_y + tileProperties.height/2 * tileProperties.scale - tileProperties.scale + k * tileProperties.scale + tileProperties.scale
|
|
|
|
)
|
2022-01-22 22:10:21 +00:00
|
|
|
table.insert(LoadedObjects.Collisions,slope)
|
2021-10-16 23:06:11 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
elseif type == "ramp2_top_right_half" then
|
|
|
|
for k = 1, 8 do
|
|
|
|
-- do ramp owo
|
2021-10-22 16:23:05 +00:00
|
|
|
local slope = Collision:New(
|
2021-10-16 23:06:11 +00:00
|
|
|
base_x + (k-8) * -2 * tileProperties.scale,
|
|
|
|
base_y + tileProperties.height/2 * tileProperties.scale - k * tileProperties.scale,
|
|
|
|
base_x + tileProperties.width * tileProperties.scale,
|
|
|
|
base_y + tileProperties.height/2 * tileProperties.scale - k * tileProperties.scale + tileProperties.scale
|
|
|
|
)
|
2022-01-22 22:10:21 +00:00
|
|
|
table.insert(LoadedObjects.Collisions,slope)
|
2021-10-16 23:06:11 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
elseif type == "ramp2_top_right_whole" then
|
|
|
|
for k = 1, 8 do
|
|
|
|
-- do ramp owo
|
2021-10-22 16:23:05 +00:00
|
|
|
local slope = Collision:New(
|
2021-10-16 23:06:11 +00:00
|
|
|
base_x + (k-8) * -2 * tileProperties.scale,
|
|
|
|
base_y + tileProperties.height/2 * tileProperties.scale + tileProperties.height/2 * tileProperties.scale - k * tileProperties.scale,
|
|
|
|
base_x + tileProperties.width * tileProperties.scale,
|
|
|
|
base_y + tileProperties.height/2 * tileProperties.scale + tileProperties.height/2 * tileProperties.scale - k * tileProperties.scale + tileProperties.scale
|
|
|
|
)
|
2022-01-22 22:10:21 +00:00
|
|
|
table.insert(LoadedObjects.Collisions,slope)
|
2021-10-16 23:06:11 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
-- fill higher half
|
2021-10-22 16:23:05 +00:00
|
|
|
local col = Collision:New(
|
2021-10-16 23:06:11 +00:00
|
|
|
base_x,
|
|
|
|
base_y,
|
|
|
|
base_x + tileProperties.width * tileProperties.scale,
|
|
|
|
base_y + tileProperties.height/2 * tileProperties.scale
|
|
|
|
)
|
2022-01-22 22:10:21 +00:00
|
|
|
table.insert(LoadedObjects.Collisions,col)
|
2021-10-16 23:06:11 +00:00
|
|
|
|
|
|
|
elseif type == "ramp1_bot_left" then
|
|
|
|
|
|
|
|
for k = 1, 16 do
|
|
|
|
-- do ramp owo
|
2021-10-22 16:23:05 +00:00
|
|
|
local slope = Collision:New(
|
2021-10-16 23:06:11 +00:00
|
|
|
base_x,
|
|
|
|
base_y + k * tileProperties.scale - tileProperties.scale,
|
|
|
|
base_x + k * tileProperties.scale,
|
|
|
|
base_y + k * tileProperties.scale
|
|
|
|
)
|
2022-01-22 22:10:21 +00:00
|
|
|
table.insert(LoadedObjects.Collisions,slope)
|
2021-10-16 23:06:11 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
elseif type == "ladder_right" then
|
|
|
|
|
2021-10-22 16:23:05 +00:00
|
|
|
local ladder = Collision:New(
|
2021-10-16 23:06:11 +00:00
|
|
|
base_x + (tileProperties.width-4)* tileProperties.scale,
|
|
|
|
base_y,
|
|
|
|
base_x + tileProperties.width * tileProperties.scale,
|
|
|
|
base_y + tileProperties.height * tileProperties.scale
|
|
|
|
)
|
2022-01-22 22:10:21 +00:00
|
|
|
table.insert(LoadedObjects.Ladders,ladder)
|
2021-10-16 23:06:11 +00:00
|
|
|
|
|
|
|
elseif type == "ladder_platform_right" then
|
|
|
|
|
2021-10-22 16:23:05 +00:00
|
|
|
local ladder = Collision:New(
|
2021-10-16 23:06:11 +00:00
|
|
|
base_x + (tileProperties.width-4)* tileProperties.scale,
|
|
|
|
base_y + tileProperties.scale * 2,
|
|
|
|
base_x + tileProperties.width * tileProperties.scale,
|
|
|
|
base_y + tileProperties.height * tileProperties.scale
|
|
|
|
)
|
2022-01-22 22:10:21 +00:00
|
|
|
table.insert(LoadedObjects.Ladders,ladder)
|
2021-10-16 23:06:11 +00:00
|
|
|
|
2021-10-22 16:23:05 +00:00
|
|
|
local plat = Collision:New(
|
2021-10-16 23:06:11 +00:00
|
|
|
base_x,
|
|
|
|
base_y + tileProperties.scale * 2,
|
|
|
|
base_x + tileProperties.width * tileProperties.scale,
|
|
|
|
base_y + tileProperties.height/4 * tileProperties.scale + tileProperties.scale * 2
|
|
|
|
)
|
2022-01-22 22:10:21 +00:00
|
|
|
table.insert(LoadedObjects.Platforms,plat)
|
2021-10-16 23:06:11 +00:00
|
|
|
|
|
|
|
elseif type == "ladder_left" then
|
|
|
|
|
|
|
|
|
2021-10-22 16:23:05 +00:00
|
|
|
local ladder = Collision:New(
|
2021-10-16 23:06:11 +00:00
|
|
|
base_x,
|
|
|
|
base_y,
|
|
|
|
base_x + tileProperties.scale * 4,
|
|
|
|
base_y + tileProperties.height * tileProperties.scale
|
|
|
|
)
|
2022-01-22 22:10:21 +00:00
|
|
|
table.insert(LoadedObjects.Ladders,ladder)
|
2021-10-16 23:06:11 +00:00
|
|
|
|
|
|
|
elseif type == "ladder_platform_left" then
|
|
|
|
|
|
|
|
|
2021-10-22 16:23:05 +00:00
|
|
|
local ladder = Collision:New(
|
2021-10-16 23:06:11 +00:00
|
|
|
base_x,
|
|
|
|
base_y + tileProperties.scale * 2,
|
|
|
|
base_x + tileProperties.scale * 4,
|
|
|
|
base_y + tileProperties.height * tileProperties.scale
|
|
|
|
)
|
2022-01-22 22:10:21 +00:00
|
|
|
table.insert(LoadedObjects.Ladders,ladder)
|
2021-10-16 23:06:11 +00:00
|
|
|
|
2021-10-22 16:23:05 +00:00
|
|
|
local plat = Collision:New(
|
2021-10-16 23:06:11 +00:00
|
|
|
base_x,
|
|
|
|
base_y + tileProperties.scale * 2,
|
|
|
|
base_x + tileProperties.width * tileProperties.scale,
|
|
|
|
base_y + tileProperties.height/4 * tileProperties.scale + tileProperties.scale * 2
|
|
|
|
)
|
2022-01-22 22:10:21 +00:00
|
|
|
table.insert(LoadedObjects.Platforms,plat)
|
2021-10-16 23:06:11 +00:00
|
|
|
|
2022-02-10 14:53:50 +00:00
|
|
|
elseif type == "bottom_hazard" then
|
|
|
|
|
|
|
|
|
|
|
|
local hazard = Collision:New(
|
|
|
|
base_x,
|
|
|
|
base_y + tileProperties.height * 12/16 * tileProperties.scale,
|
|
|
|
base_x + tileProperties.width * tileProperties.scale,
|
|
|
|
base_y + tileProperties.height * tileProperties.scale
|
|
|
|
)
|
|
|
|
table.insert(LoadedObjects.Hazards,hazard)
|
|
|
|
|
2021-10-16 23:06:11 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2022-02-17 23:03:32 +00:00
|
|
|
--CreateCollisionTable()
|
2021-10-16 23:06:11 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function AnimateTiles()
|
2022-01-22 22:10:21 +00:00
|
|
|
for _, Properties in pairs(TileData) do
|
2022-01-29 09:46:49 +00:00
|
|
|
if Properties ~= nil then
|
|
|
|
if Properties.animation ~= nil then
|
|
|
|
-- calculate subimage
|
|
|
|
Properties.current_subimage = Properties.current_subimage + current_dt
|
|
|
|
-- cycle image
|
|
|
|
if Properties.current_subimage >= Properties.delay then
|
|
|
|
Properties.current_subimage = Properties.current_subimage - Properties.delay
|
|
|
|
Properties.current_image = Properties.current_image + 1
|
|
|
|
end
|
2021-10-16 23:06:11 +00:00
|
|
|
|
2022-01-29 09:46:49 +00:00
|
|
|
if Properties.current_image > Properties.image_count then
|
|
|
|
Properties.current_image = Properties.current_image - Properties.image_count
|
|
|
|
end
|
2021-10-16 23:06:11 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-02-17 22:39:31 +00:00
|
|
|
function CreateCollisionTable()
|
|
|
|
-- init table
|
|
|
|
CollisionTable = {}
|
|
|
|
for j=0, 16*LevelGetTileHeight()-1 do
|
|
|
|
CollisionTable[j] = {}
|
|
|
|
for i=0, 16*LevelGetTileWidth()-1 do
|
|
|
|
CollisionTable[j][i] = false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
for _, collision in pairs(LoadedObjects.Collisions) do
|
|
|
|
for ci=0, math.floor(collision.width)-1 do
|
|
|
|
for cj=0, math.floor(collision.height)-1 do
|
|
|
|
print(ci..","..cj)
|
|
|
|
CollisionTable[collision.from.y+cj][collision.from.x+ci] = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function DrawColisionTable()
|
|
|
|
for j=1, #CollisionTable do
|
|
|
|
for i=1, #CollisionTable[j] do
|
|
|
|
if CollisionTable[j][i] then
|
|
|
|
love.graphics.setColor(0,1,0,1)
|
|
|
|
else
|
|
|
|
love.graphics.setColor(1,0,0,1)
|
|
|
|
end
|
|
|
|
love.graphics.points(i,j)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-11-28 02:38:30 +00:00
|
|
|
function DrawTile(tile,x,y,depth)
|
2022-01-29 09:46:49 +00:00
|
|
|
local Properties = TileData[tile.id]
|
2021-11-28 02:38:30 +00:00
|
|
|
|
2022-01-29 09:46:49 +00:00
|
|
|
if Properties ~= nil then
|
|
|
|
if Properties.animation ~= nil then
|
|
|
|
if Properties.imgs[Properties.current_image] ~= nil
|
|
|
|
and Properties.depth == depth
|
|
|
|
then love.graphics.draw(
|
|
|
|
Properties.tileset,
|
|
|
|
Properties.imgs[Properties.current_image],
|
|
|
|
x,
|
|
|
|
y,
|
|
|
|
0,
|
|
|
|
tileProperties.scale,
|
|
|
|
tileProperties.scale
|
|
|
|
)
|
|
|
|
end
|
|
|
|
elseif Properties.depth == depth then
|
|
|
|
if Properties.force ~= nil then
|
|
|
|
if Properties.force ~= 0 then
|
|
|
|
love.graphics.draw(
|
|
|
|
LevelData.tileset,
|
|
|
|
TileIndex[tile.display],
|
|
|
|
x,
|
|
|
|
y,
|
|
|
|
0,
|
|
|
|
tileProperties.scale,
|
|
|
|
tileProperties.scale
|
|
|
|
)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
love.graphics.draw(
|
|
|
|
LevelData.tileset,
|
|
|
|
TileIndex[tile.id],
|
2021-10-16 23:06:11 +00:00
|
|
|
x,
|
|
|
|
y,
|
|
|
|
0,
|
|
|
|
tileProperties.scale,
|
|
|
|
tileProperties.scale
|
2022-01-29 09:46:49 +00:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if Properties.overlay ~= nil then
|
|
|
|
if Properties.overlay_depth == depth or Properties.overlay_depth == nil and Properties.depth == depth then
|
|
|
|
if Properties.overlay_animated then
|
|
|
|
local overlay_properties = TileData[Properties.overlay]
|
2021-10-16 23:06:11 +00:00
|
|
|
love.graphics.draw(
|
2022-01-29 09:46:49 +00:00
|
|
|
overlay_properties.tileset,
|
|
|
|
overlay_properties.imgs[overlay_properties.current_image],
|
2021-10-16 23:06:11 +00:00
|
|
|
x,
|
|
|
|
y,
|
|
|
|
0,
|
|
|
|
tileProperties.scale,
|
|
|
|
tileProperties.scale
|
|
|
|
)
|
|
|
|
else
|
|
|
|
love.graphics.draw(
|
2021-11-28 02:38:30 +00:00
|
|
|
LevelData.tileset,
|
2022-01-29 09:46:49 +00:00
|
|
|
TileIndex[tile.display_overlay],
|
2021-10-16 23:06:11 +00:00
|
|
|
x,
|
|
|
|
y,
|
|
|
|
0,
|
|
|
|
tileProperties.scale,
|
|
|
|
tileProperties.scale
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2022-01-29 09:46:49 +00:00
|
|
|
--[[
|
|
|
|
love.graphics.setColor(0,0,1)
|
|
|
|
love.graphics.print(tostring(tile.display),x+16,y)
|
|
|
|
love.graphics.setColor(1,1,1)
|
|
|
|
]]
|
2021-10-16 23:06:11 +00:00
|
|
|
end
|
|
|
|
end
|