VoidShot/world.lua
2024-04-27 14:07:17 +02:00

200 lines
No EOL
6.9 KiB
Lua

World = {
currentMap = nil,
generators = {},
map = {
x = 0,
isMoving = {false}
}
}
checkSpace = {}
function World.loadMap(name)
local path = ("maps/"..tostring(name)..".vsmf")
local line_num = 1
for line in love.filesystem.lines(path) do
line = tostring(line)
print ("Itterating line: " .. line)
local hasPassedSemicolon = false
local hasPassedEqual = false
local command = ""
local args = {}
local arg = ""
local B = 1
local A = 1
for character in string.gmatch(line, '.') do
if hasPassedEqual == true then
if character == "." then
B = B + 1
elseif character == "," then
A = A + 1
B = 1
else
if args[A] == nil then
args[A] = {}
args[A][B] = tostring(character)
print("Started arg. char. " .. args[A][B])
elseif args[A][B] == nil then
args[A][B] = tostring(character)
print("Started arg. char. " .. args[A][B] .. " (With whole pretext)")
else
args[A][B] = args[A][B] .. tostring(character)
print ("Argument " .. A .. ":" .. B .. " is now at: " .. args[A][B])
end
end
elseif hasPassedSemicolon == true then
if arg == nil then
arg = tostring(character)
else
arg = arg .. tostring(character)
print("Arg is now at " .. arg)
end
elseif character == "=" then
hasPassedEqual = true
print ("Passed Equal For: " .. command)
elseif character == ";" then
hasPassedSemicolon = true
print ("Passed Semicolon For: " .. command)
else
command = command .. character
print ("Command is now at: " .. command)
end
end
if arg ~= nil then
World.map[command] = arg
print("Wrote " .. arg .. " To " .. command)
end
if args[A] ~= nil then
if args[A][B] ~= nil then
for x=1, A do
for y=1, B do
print (command .. ": " .. args[x][y] .. "\n")
end
end
World.map[command] = {}
for x = 1, A do
World.map[command][x] = {}
print ("Wrote ".. command .. " at " .. x .. " successfully")
for y = 1, B do
World.map[command][x][y] = args[x][y]
print ("Added " .. args[x][y] .. " to " .. command .. " at " .. x .. ":".. y)
end
end
end
end
end
if World.map.name then
print "Name Success"
end
if World.map.size then
print "Map Success"
end
if World.map.id then
print "ID Success"
end
print("Map has loaded successfully! Loaded with parameters: " .. World.map.name .. ", " .. World.map.size .. ", " .. World.map.id)
print("Attempting hitbox generation...")
if World.map.objects then
World.generators.hitboxes("objects")
end
end
function World.drawMap()
love.graphics.push()
love.graphics.translate(World.map.x, 0)
object_load = require("GFX/object_directory")
if World.map.objects then
for i=1, #World.map.objects do
love.graphics.circle("line", World.map.objects[i][2], World.map.objects[i][3] - World.map.objects[i][4], World.map.objects[i][4])
end
end
if World.map.items then
for i=1, #World.map.items do
if World.map.items[i] then
love.graphics.rectangle("line", World.map.items[i][2], World.map.items[i][3] - World.map.items[i][4], World.map.items[i][4], World.map.items[i][4])
end
end
end
if World.map.interactables then
for i=1, #World.map.interactables do
love.graphics.rectangle("line", World.map.interactables[i][2], World.map.interactables[i][3] - World.map.interactables[i][4] * 2, World.map.interactables[i][4], World.map.interactables[i][4] * 2)
end
end
love.graphics.pop()
end
function World.generators.hitboxes(hitboxes)
World.map.hitboxes = World.map[hitboxes]
for i=1, #World.map[hitboxes] do
World.map.hitboxes = World.map[hitboxes][i]
print("Added " .. World.map[hitboxes][i][1] .. "'s Hitbox")
for x=1, #World.map[hitboxes][i] do
World.map.hitboxes = World.map[hitboxes][i][x]
end
end
end
function checkSpace.items(x,y)
for a=1, #World.map.items do
if tonumber(World.map.items[a][2]) > x-50 and tonumber(World.map.items[a][2]) < x+50 then
return a
end
end
return false
end
function checkSpace.interactables(x,y)
for a=1, #World.map.interactables do
if tonumber(World.map.interactables[a][2]) > x-50 and tonumber(World.map.interactables[a][3]) < x+50 then
return a
end
end
return false
end
function removeFromWorld(category, id)
World.map[category][id] = nil
end
function World.mapMovement(x)
if x < 320 and World.map.isMoving[1] == false then
if tonumber(World.map.currentSlide) > 1 then
World.map.isMoving = {true, "left", World.map.x + 1920 }
World.map.currentSlide = World.map.currentSlide - 1
else
print("Open the Global Map")
end
elseif x > 1600 and World.map.isMoving[1] == false then
if tonumber(World.map.currentSlide) < tonumber(World.map.size) then
World.map.isMoving = {true, "right", World.map.x - 1920 }
World.map.currentSlide = World.map.currentSlide + 1
else
print("Open the Global Map")
end
end
if World.map.isMoving[1] == true then
if World.map.isMoving[2] == "right" then
if World.map.x > World.map.isMoving[3] then
World.map.x = World.map.x - 50
player.x = player.x - 40
else
World.map.x = World.map.isMoving[3]
World.map.isMoving[2] = "nil"
print("World moved to the right")
end
elseif World.map.isMoving[2] == "left" then
if World.map.x < World.map.isMoving[3] then
World.map.x = World.map.x + 50
player.x = player.x + 40
else
World.map.x = World.map.isMoving[3]
World.map.isMoving[2] = "nil"
print("World moved to the left")
end
end
end
if x > 400 and x < 1500 and World.map.x == World.map.isMoving[3] then
World.map.isMoving[1] = false
end
end