From c9a1ef3d82b479aff52689e20aad75f5714c1e79 Mon Sep 17 00:00:00 2001 From: Hannah-Dagemark Date: Fri, 15 Sep 2023 20:52:30 +0200 Subject: [PATCH] World Gen #1, Inventory #1 -- Added loading of .vsmf map files -- Updated some variable names -- Added developer information to the top left of the screen -- Added a trial inventory --- Maps/default.vsmf | 6 ++++ Maps/template.vsmf | 6 ++++ SaveGames/Template.txt | 13 ++++++++ main.lua | 70 ++++++++++++++++++++++++++++++++++++++++-- menu.lua | 1 + scripts/inputs.lua | 21 ++++++++----- world.lua | 57 ++++++++++++++++++++++++++++++++++ 7 files changed, 164 insertions(+), 10 deletions(-) create mode 100644 Maps/default.vsmf create mode 100644 Maps/template.vsmf create mode 100644 world.lua diff --git a/Maps/default.vsmf b/Maps/default.vsmf new file mode 100644 index 0000000..c879d2a --- /dev/null +++ b/Maps/default.vsmf @@ -0,0 +1,6 @@ +name=default +size=1920.1080 +id=001 +statics=house1.100.1080,house2.500.1080 +interactables= +objects=bat.1000.1080.50 \ No newline at end of file diff --git a/Maps/template.vsmf b/Maps/template.vsmf new file mode 100644 index 0000000..e838604 --- /dev/null +++ b/Maps/template.vsmf @@ -0,0 +1,6 @@ +name=(name) +size=x.y +id=INT(XYZ) +statics=static.x.y, +interactables=interactable.x.y, +objects=object.x.y, \ No newline at end of file diff --git a/SaveGames/Template.txt b/SaveGames/Template.txt index e69de29..7d2b5a0 100644 --- a/SaveGames/Template.txt +++ b/SaveGames/Template.txt @@ -0,0 +1,13 @@ +-- Info about the savegame +savegame = {} +savegame.createDate = "" +savegame.loadDate = "" +savegame.name = "" +savegame.characterName = "" +savegame.playTime = 0 + +-- These events will run upon initialization + +character = {} + +NPCs = {} \ No newline at end of file diff --git a/main.lua b/main.lua index f63bb79..08bce41 100644 --- a/main.lua +++ b/main.lua @@ -8,6 +8,7 @@ functiongenerator = {} check_space = {} function love.load() + globalMode = "devMode" window = {} window.x, window.y = love.window.getDesktopDimensions() math.randomseed(os.time()) @@ -16,6 +17,7 @@ function love.load() physics_ini = require('physics') menu_ini = require('menu') npc_ini = require('scripts/NPC') + map_ini = require('world') menu.load() NPCs = {} ground = { @@ -32,11 +34,17 @@ function love.load() player.width = 20 player.height = 80 mouse = {} + currentMap = "none" function player.functions.getRunningSpeed(runningStatus) if runningStatus then return player.attributes.maxRunningSpeed*2 else return player.attributes.maxRunningSpeed end end end function love.update(dt) if Scene == "gameTest" then + if currentMap ~= "default" then + print ("loading map...") + World.loadMap("default") + currentMap = "default" + end keyboard_input_held(player, dt) gravity(player, dt) mouvement(player, dt) @@ -56,7 +64,10 @@ end function love.draw() love.graphics.print(Scene, 100, 100) if Scene == "gameTest" then - if love.graphics.getColor() ~= 1, 1, 1 then love.graphics.setColor(1, 1, 1) end + love.graphics.setColor(1, 1, 1) + + World.drawMap() + love.graphics.rectangle("line", player.x, player.y, player.width, player.height) if player.bools.isFacingRight then love.graphics.rectangle("line", player.x+10, player.y-20, 20, 20) @@ -66,6 +77,7 @@ function love.draw() for i = 1, #NPCs do love.graphics.rectangle("fill", NPCs[i].x, NPCs[i].y, NPCs[i].width, NPCs[i].height) end + for i = 1, #NPCs do if NPCs[i].bools.isInteracting then local font = love.graphics.getFont() @@ -73,6 +85,30 @@ function love.draw() love.graphics.draw(helloText, NPCs[i].x, NPCs[i].y-10) end end + if player.bools.inventoryOpen then + -- Draw Inventory + else + for i = 1, player.hotbar_len do + if player.current_equip == i then + love.graphics.setColor(0, 1, 0.2) + else + love.graphics.setColor(1, 1, 1) + end + love.graphics.rectangle("line", window.x - ((player.hotbar_len + 1) * 100) + (i * 100), 0, 100, 100) + end + end + if globalMode == "devMode" then + love.graphics.print("Velocity X " .. player.physics.velocityX, 100, 300) + love.graphics.print("Velocity Y " .. player.physics.velocityY, 100, 350) + love.graphics.print("Airtime " .. player.physics.airtime, 100, 400) + --- + love.graphics.print("Is Airborne " .. tostring(player.bools.isAirbornes), 100, 450) + love.graphics.print("Is Walking " .. tostring(player.bools.isWalking), 100, 500) + love.graphics.print("Is Running " .. tostring(player.bools.isRunning), 100, 550) + love.graphics.print("Is Facing Right " .. tostring(player.bools.isFacingRight), 100, 600) + love.graphics.print("Inventory Open " .. tostring(player.bools.inventoryOpen), 100, 650) + end + elseif Scene == "menu" then menu.draw() end @@ -94,6 +130,13 @@ function defaulkeybinds() keybinds.interact = "e" keybinds.run = "lshift" keybinds.create = "f" + keybinds.primary = "1" + keybinds.secondary = "2" + keybinds.functionality = "t" + keybinds.minor = "g" + keybinds.additional1 = "3" + keybinds.additional2 = "4" + keybinds.additional3 = "5" end function character.create(chosenSubclasses, isPlayerControlled) @@ -108,6 +151,8 @@ function character.create(chosenSubclasses, isPlayerControlled) object.attributes.wanderpoint = math.random(0, window.x) object.bools.isInteracting = false object.attributes.time_spoken = 0 + else + character.subclasses.create.inventory(object) end return object @@ -126,7 +171,8 @@ function character.subclasses.create.bools(object) isAirborne = true, isWalking = false, isRunning = false, - isFacingRight = true + isFacingRight = true, + inventoryOpen = false } end function character.subclasses.create.attributes(object) @@ -136,4 +182,22 @@ function character.subclasses.create.attributes(object) end function character.subclasses.create.functions(object) object.functions = {} -end \ No newline at end of file +end +function character.subclasses.create.inventory(object) + object.hotbar_cont = {} + object.inventory_cont = {} + object.hotbar_len = 2 + object.inventory_len = 0 + object.current_equip = 1 +end + +function inventory(mode, slot, item) + if mode == "add" then + hotbar_cont[slot] = item + elseif mode == "remove" then + hotbar_cont[slot] = nil + elseif mode == "move" then + item = hotbar_cont[slot[1]] + hotbar_cont[slot[2]] = item + end +end diff --git a/menu.lua b/menu.lua index 56461bf..1df6303 100644 --- a/menu.lua +++ b/menu.lua @@ -7,6 +7,7 @@ menuButtons = { Quit = {} } font_ini = require('scripts/fonts') +world_ini = require('world') function menu.load() RGB = 1 RGB_hover = 0.5 diff --git a/scripts/inputs.lua b/scripts/inputs.lua index e5c6a61..c5c6e71 100644 --- a/scripts/inputs.lua +++ b/scripts/inputs.lua @@ -16,12 +16,12 @@ function keyboard_input_held(object, dt) if love.keyboard.isDown("lshift") then object.bools.isRunning = true end - if love.keyboard.isDown(keybind.left) and love.keyboard.isDown(keybind.right) then + if love.keyboard.isDown(keybinds.left) and love.keyboard.isDown(keybinds.right) then -- you're stopped now :3c - elseif love.keyboard.isDown(keybind.left) then + elseif love.keyboard.isDown(keybinds.left) then object.bools.isWalking = true if math.abs(object.physics.velocityX) + 0.1 < object.functions.getRunningSpeed(object.bools.isRunning) then object.physics.velocityX = object.physics.velocityX - 0.1 else object.physics.velocityX = object.functions.getRunningSpeed(object.bools.isRunning)* -1 end - elseif love.keyboard.isDown(keybind.right) then + elseif love.keyboard.isDown(keybinds.right) then object.bools.isWalking = true if math.abs(object.physics.velocityX) < object.functions.getRunningSpeed(object.bools.isRunning) then object.physics.velocityX = object.physics.velocityX + 0.1 else object.physics.velocityX = object.functions.getRunningSpeed(object.bools.isRunning) end end @@ -38,19 +38,26 @@ end function love.keypressed(key) if Scene == "gameTest" then - if key == keybind.jump then player.physics.velocityY = player.physics.velocityY - 3 end - if key == keybind.interact then + if key == keybinds.jump and player.bools.isAirborne == false then player.physics.velocityY = player.physics.velocityY - 5 end + if key == keybinds.interact then check_space.interactables(player.x, player.y) end - if key == keybind.create then + if key == keybinds.create then NPCs[#NPCs+1] = character.create({"attributes", "functions","bools","physics"}, false) NPCs[#NPCs].x = math.random(0, window.x-20) NPCs[#NPCs].y = window.y/2-window.y/20 NPCs[#NPCs].width = 20 NPCs[#NPCs].height = 80 end + if key == keybinds.primary then + player.current_equip = 1 + end + if key == keybinds.secondary then + player.current_equip = 2 + end + else - if key == keybind.jump then + if key == keybinds.jump then titleCard.duration = true end end diff --git a/world.lua b/world.lua new file mode 100644 index 0000000..42f023f --- /dev/null +++ b/world.lua @@ -0,0 +1,57 @@ +World = { + currentMap = nil, + map = {} +} + +function World.loadMap(name) + local path = ("maps/"..tostring(name)..".vsmf") + --path = ("world.txt") + for line in love.filesystem.lines(path) do + line = tostring(line) + print ("Itterating line: " .. line) + + local hasPassedEqual = false + local command = "" + local args = {""} + local i = 1 + + for character in string.gmatch(line, '.') do + print ("Itterating character: " .. character) + if hasPassedEqual == true then + if character == "." then + i = i + 1 + else + if args [i] == nil then + args[i] = character + else + args[i] = args[i] .. character + end + end + elseif character == "=" then + hasPassedEqual = true + else + command = command .. character + end + end + print (command .. " " .. args[1] .. "\n") + for x = 1, #args do + if x == 1 then + World.map[command] = {} + World.map[command][args[1]] = {} + World.map[command].catalogue = {} + table.insert(World.map[command].catalogue, args[1]) + print ("Put " .. args[1] .. " in " .. command) + else + World.map[command][args[1]][x - 1] = args[x] + print ("Added " .. args[x] .. " to " .. args[1] .. " at " .. x-1) + end + end + end +end +function World.drawMap() + if World.map.objects then + for i = 1, #World.map.objects.catalogue do + love.graphics.circle("line", World.map.objects[World.map.objects.catalogue[i]][1], World.map.objects[World.map.objects.catalogue[i]][2] - World.map.objects[World.map.objects.catalogue[i]][3], World.map.objects[World.map.objects.catalogue[i]][3]) + end + end +end \ No newline at end of file