-- Added item interaction -- Changed inventory management slightly -- Added slide-show system to world, world can now "move" to show more space.
This commit is contained in:
parent
360d26a036
commit
3a3bea1ead
8 changed files with 164 additions and 22 deletions
BIN
GFX/images/tree.png
Normal file
BIN
GFX/images/tree.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.8 KiB |
3
GFX/object_directory.lua
Normal file
3
GFX/object_directory.lua
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
function loadObjects(objects)
|
||||||
|
tree = "images/tree.png"
|
||||||
|
end
|
||||||
|
|
@ -1,6 +1,10 @@
|
||||||
name=default
|
name;default
|
||||||
size=1920.1080
|
size;3
|
||||||
id=001
|
currentSlide;1
|
||||||
|
id;001
|
||||||
|
toleft;blocked
|
||||||
|
toright;city
|
||||||
statics=house1.100.1080.100,house2.500.1080.200
|
statics=house1.100.1080.100,house2.500.1080.200
|
||||||
interactables=
|
items=bat.1000.1080.50,gun.500.1080.30,sword.2300.1080.45
|
||||||
objects=bat.1000.1080.50,chair.300.1080.35,tree.1400.1080.100
|
interactables=door.1700.1080.45,gate.2700.1080.80
|
||||||
|
objects=chair.300.1080.35,tree.1400.1080.100,wall.
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
name=(name)
|
name=(name)
|
||||||
size=x.y
|
size=slidecount
|
||||||
id=INT(XYZ)
|
id=INT(XYZ)
|
||||||
statics=static.x.y,
|
statics=static.x.y,
|
||||||
interactables=interactable.x.y,
|
interactables=interactable.x.y,
|
||||||
|
items=item.x.y,
|
||||||
objects=object.x.y,
|
objects=object.x.y,
|
||||||
12
main.lua
12
main.lua
|
|
@ -13,6 +13,7 @@ function love.load()
|
||||||
window.x, window.y = love.window.getDesktopDimensions()
|
window.x, window.y = love.window.getDesktopDimensions()
|
||||||
math.randomseed(os.time())
|
math.randomseed(os.time())
|
||||||
Scene = "menu"
|
Scene = "menu"
|
||||||
|
items_ini = require('scripts/items')
|
||||||
inputs_ini = require('scripts/inputs')
|
inputs_ini = require('scripts/inputs')
|
||||||
physics_ini = require('physics')
|
physics_ini = require('physics')
|
||||||
menu_ini = require('menu')
|
menu_ini = require('menu')
|
||||||
|
|
@ -47,6 +48,7 @@ function love.update(dt)
|
||||||
end
|
end
|
||||||
keyboard_input_held(player, dt)
|
keyboard_input_held(player, dt)
|
||||||
gravity(player, dt)
|
gravity(player, dt)
|
||||||
|
World.mapMovement(player.x)
|
||||||
mouvement(player, dt)
|
mouvement(player, dt)
|
||||||
for i = 1, #NPCs do
|
for i = 1, #NPCs do
|
||||||
gravity(NPCs[i], dt)
|
gravity(NPCs[i], dt)
|
||||||
|
|
@ -98,6 +100,10 @@ function love.draw()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if globalMode == "devMode" then
|
if globalMode == "devMode" then
|
||||||
|
|
||||||
|
love.graphics.print("World X " .. World.map.x, 100, 150)
|
||||||
|
love.graphics.print("X " .. player.x, 100, 200)
|
||||||
|
love.graphics.print("Y " .. player.y, 100, 250)
|
||||||
love.graphics.print("Velocity X " .. player.physics.velocityX, 100, 300)
|
love.graphics.print("Velocity X " .. player.physics.velocityX, 100, 300)
|
||||||
love.graphics.print("Velocity Y " .. player.physics.velocityY, 100, 350)
|
love.graphics.print("Velocity Y " .. player.physics.velocityY, 100, 350)
|
||||||
love.graphics.print("Airtime " .. player.physics.airtime, 100, 400)
|
love.graphics.print("Airtime " .. player.physics.airtime, 100, 400)
|
||||||
|
|
@ -193,11 +199,11 @@ end
|
||||||
|
|
||||||
function inventory(mode, slot, item)
|
function inventory(mode, slot, item)
|
||||||
if mode == "add" then
|
if mode == "add" then
|
||||||
hotbar_cont[slot] = item
|
player.hotbar_cont[slot] = item
|
||||||
elseif mode == "remove" then
|
elseif mode == "remove" then
|
||||||
hotbar_cont[slot] = nil
|
player.hotbar_cont[slot] = nil
|
||||||
elseif mode == "move" then
|
elseif mode == "move" then
|
||||||
item = hotbar_cont[slot[1]]
|
item = hotbar_cont[slot[1]]
|
||||||
hotbar_cont[slot[2]] = item
|
player.hotbar_cont[slot[2]] = item
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,18 @@ function love.keypressed(key)
|
||||||
if Scene == "gameTest" then
|
if Scene == "gameTest" then
|
||||||
if key == keybinds.jump and player.bools.isAirborne == false then player.physics.velocityY = player.physics.velocityY - 5 end
|
if key == keybinds.jump and player.bools.isAirborne == false then player.physics.velocityY = player.physics.velocityY - 5 end
|
||||||
if key == keybinds.interact then
|
if key == keybinds.interact then
|
||||||
check_space.interactables(player.x, player.y)
|
if checkSpace.items(player.x, player.y) then
|
||||||
|
local id = checkSpace.items(player.x, player.y)
|
||||||
|
print("Found Item near player")
|
||||||
|
local newItem = itemgen.createFromWorld(id)
|
||||||
|
inventory("add", player.current_equip, newItem)
|
||||||
|
print("Added item " .. World.map.items[id][1])
|
||||||
|
removeFromWorld("items", id)
|
||||||
|
elseif checkSpace.interactables(player.x, player.y) then
|
||||||
|
print("Interacted with smthn")
|
||||||
|
else
|
||||||
|
print("Attempted to interact, found nothing")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
if key == keybinds.create then
|
if key == keybinds.create then
|
||||||
NPCs[#NPCs+1] = character.create({"attributes", "functions","bools","physics"}, false)
|
NPCs[#NPCs+1] = character.create({"attributes", "functions","bools","physics"}, false)
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,15 @@
|
||||||
function item.create(type, commands)
|
itemgen = {}
|
||||||
|
|
||||||
|
function itemgen.create(type, commands)
|
||||||
local object = {}
|
local object = {}
|
||||||
for i = 1, #commands do
|
for i=1, #commands do
|
||||||
object[commands]
|
object[commands][i][1] = commands[i][2]
|
||||||
i = i + 1
|
|
||||||
end
|
end
|
||||||
return object
|
return object
|
||||||
|
end
|
||||||
|
|
||||||
|
function itemgen.createFromWorld(id)
|
||||||
|
item = {}
|
||||||
|
item.name = World.map.items[id][1]
|
||||||
|
return item
|
||||||
end
|
end
|
||||||
126
world.lua
126
world.lua
|
|
@ -1,8 +1,12 @@
|
||||||
World = {
|
World = {
|
||||||
currentMap = nil,
|
currentMap = nil,
|
||||||
generators = {}
|
generators = {},
|
||||||
map = {}
|
map = {
|
||||||
|
x = 0,
|
||||||
|
isMoving = {false}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
checkSpace = {}
|
||||||
|
|
||||||
function World.loadMap(name)
|
function World.loadMap(name)
|
||||||
local path = ("maps/"..tostring(name)..".vsmf")
|
local path = ("maps/"..tostring(name)..".vsmf")
|
||||||
|
|
@ -12,14 +16,15 @@ function World.loadMap(name)
|
||||||
line = tostring(line)
|
line = tostring(line)
|
||||||
print ("Itterating line: " .. line)
|
print ("Itterating line: " .. line)
|
||||||
|
|
||||||
|
local hasPassedSemicolon = false
|
||||||
local hasPassedEqual = false
|
local hasPassedEqual = false
|
||||||
local command = ""
|
local command = ""
|
||||||
local args = {}
|
local args = {}
|
||||||
|
local arg = ""
|
||||||
local B = 1
|
local B = 1
|
||||||
local A = 1
|
local A = 1
|
||||||
|
|
||||||
for character in string.gmatch(line, '.') do
|
for character in string.gmatch(line, '.') do
|
||||||
print ("Itterating character: " .. character)
|
|
||||||
if hasPassedEqual == true then
|
if hasPassedEqual == true then
|
||||||
if character == "." then
|
if character == "." then
|
||||||
B = B + 1
|
B = B + 1
|
||||||
|
|
@ -39,14 +44,28 @@ function World.loadMap(name)
|
||||||
print ("Argument " .. A .. ":" .. B .. " is now at: " .. args[A][B])
|
print ("Argument " .. A .. ":" .. B .. " is now at: " .. args[A][B])
|
||||||
end
|
end
|
||||||
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
|
elseif character == "=" then
|
||||||
hasPassedEqual = true
|
hasPassedEqual = true
|
||||||
print ("Passed Equal At: " .. character)
|
print ("Passed Equal For: " .. command)
|
||||||
|
elseif character == ";" then
|
||||||
|
hasPassedSemicolon = true
|
||||||
|
print ("Passed Semicolon For: " .. command)
|
||||||
else
|
else
|
||||||
command = command .. character
|
command = command .. character
|
||||||
print ("Command is now at: " .. command)
|
print ("Command is now at: " .. command)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if arg ~= nil then
|
||||||
|
World.map[command] = arg
|
||||||
|
print("Wrote " .. arg .. " To " .. command)
|
||||||
|
end
|
||||||
if args[A] ~= nil then
|
if args[A] ~= nil then
|
||||||
for x=1, A do
|
for x=1, A do
|
||||||
for y=1, B do
|
for y=1, B do
|
||||||
|
|
@ -64,25 +83,116 @@ function World.loadMap(name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if World.map.name[1] then
|
if World.map.name then
|
||||||
print "Name Success"
|
print "Name Success"
|
||||||
end
|
end
|
||||||
if World.map.size[1] then
|
if World.map.size then
|
||||||
print "Map Success"
|
print "Map Success"
|
||||||
end
|
end
|
||||||
if World.map.id[1] then
|
if World.map.id then
|
||||||
print "ID Success"
|
print "ID Success"
|
||||||
end
|
end
|
||||||
print("Map has loaded successfully! Loaded with parameters: " .. World.map.name[1][1] .. ", " .. World.map.size[1][1] .. " " .. World.map.size[1][2] .. ", " .. World.map.id[1][1])
|
print("Map has loaded successfully! Loaded with parameters: " .. World.map.name .. ", " .. World.map.size .. ", " .. World.map.id)
|
||||||
print("Attempting hitbox generation...")
|
print("Attempting hitbox generation...")
|
||||||
if World.map.objects then
|
if World.map.objects then
|
||||||
World.generators.hitboxes("objects")
|
World.generators.hitboxes("objects")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function World.drawMap()
|
function World.drawMap()
|
||||||
|
love.graphics.push()
|
||||||
|
love.graphics.translate(World.map.x, 0)
|
||||||
|
object_load = require("GFX/object_directory")
|
||||||
if World.map.objects then
|
if World.map.objects then
|
||||||
for i=1, #World.map.objects do
|
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])
|
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
|
||||||
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
|
end
|
||||||
Loading…
Add table
Add a link
Reference in a new issue