From 3a3bea1ead407c5772160b4ab8ba3bcee5e7534f Mon Sep 17 00:00:00 2001 From: Hannah-Dagemark Date: Mon, 16 Oct 2023 08:44:17 +0200 Subject: [PATCH] World Gen #3, Inventory #2 -- Added item interaction -- Changed inventory management slightly -- Added slide-show system to world, world can now "move" to show more space. --- GFX/images/tree.png | Bin 0 -> 3918 bytes GFX/object_directory.lua | 3 + Maps/default.vsmf | 14 +++-- Maps/template.vsmf | 3 +- main.lua | 12 +++- scripts/inputs.lua | 13 +++- scripts/items.lua | 15 +++-- world.lua | 126 ++++++++++++++++++++++++++++++++++++--- 8 files changed, 164 insertions(+), 22 deletions(-) create mode 100644 GFX/images/tree.png create mode 100644 GFX/object_directory.lua diff --git a/GFX/images/tree.png b/GFX/images/tree.png new file mode 100644 index 0000000000000000000000000000000000000000..8fd65315db4a309e9218ae46b5e04b4a8a212f19 GIT binary patch literal 3918 zcmZWr2{=^k+dq>n#u8yHp(I&Hlq_SZD7 z#+Ieb$i9w|U1sn<{=V;h-|za)bzjf*Joo*(@B8<=&$-SyQC1d4JX~U2008iq7#rFE z00aTrCAND*)IxYGrouypfL?JpT}%7v#SN@Oc6J7*;QN$e!_`cm43!{{sBW z!|Mh7oeN^%`QqSl&jYT?`Qm$J_dL9wAXr>E?|+#%6I}nUxrgWXW!dv^-vT@oAu0tD z%CE$MosVD?)UJ{%E?2f&e-Cp24FPWi=-(5|?GAvp7X^iY+QB`zLfrt6Jb(bWT!BLo z++Y@%u8<`HMrBilK*C`3*mFTpl=M@6&2;$h3a>eA*g>NfB^h_ZE z(vSn*`;H|GviU&-{8>O~;4oE)c zk$A+TS}e)w0>JYQvH1bFwb|MHA=mZU*nI)bODtY8fMV4VeIr1vKr%=i*zW}J1LCwx zp}OF#bNy{BY=LbS)@=r4i>;eulU<1UhdqO3-#X)l5-VXtXp70lHgjWx(9P_=yDhZM z;l#edT!D6MGZH{ZFsa)oz^i`~W-Mxpt_FQhRT^){)t_-p8Ui#bl;FezC~1A!f~Bx0!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#g24MiMuf zzfGU{t=s#0wJXet@TfND;?UW|+TX;>%}9aNPaARibM{P15duY{aiY0YV%1*`)yNMR zpgwIW+v{Z6`*a*n9uMB3ufD6Ee^N&+tqS17dvygrd*#!5ZdES8u76X6QnG;g zVX!La%HLm}V^+@FI@B$kM5+=-%)UHDcUx2sdhhWI~t6jq$fL1rX=m2P0m{wmY#EZ@E?;9DL()J literal 0 HcmV?d00001 diff --git a/GFX/object_directory.lua b/GFX/object_directory.lua new file mode 100644 index 0000000..b95511d --- /dev/null +++ b/GFX/object_directory.lua @@ -0,0 +1,3 @@ +function loadObjects(objects) + tree = "images/tree.png" +end \ No newline at end of file diff --git a/Maps/default.vsmf b/Maps/default.vsmf index c56851b..d534061 100644 --- a/Maps/default.vsmf +++ b/Maps/default.vsmf @@ -1,6 +1,10 @@ -name=default -size=1920.1080 -id=001 +name;default +size;3 +currentSlide;1 +id;001 +toleft;blocked +toright;city statics=house1.100.1080.100,house2.500.1080.200 -interactables= -objects=bat.1000.1080.50,chair.300.1080.35,tree.1400.1080.100 \ No newline at end of file +items=bat.1000.1080.50,gun.500.1080.30,sword.2300.1080.45 +interactables=door.1700.1080.45,gate.2700.1080.80 +objects=chair.300.1080.35,tree.1400.1080.100,wall. \ No newline at end of file diff --git a/Maps/template.vsmf b/Maps/template.vsmf index e838604..3938a07 100644 --- a/Maps/template.vsmf +++ b/Maps/template.vsmf @@ -1,6 +1,7 @@ name=(name) -size=x.y +size=slidecount id=INT(XYZ) statics=static.x.y, interactables=interactable.x.y, +items=item.x.y, objects=object.x.y, \ No newline at end of file diff --git a/main.lua b/main.lua index 08bce41..01000b6 100644 --- a/main.lua +++ b/main.lua @@ -13,6 +13,7 @@ function love.load() window.x, window.y = love.window.getDesktopDimensions() math.randomseed(os.time()) Scene = "menu" + items_ini = require('scripts/items') inputs_ini = require('scripts/inputs') physics_ini = require('physics') menu_ini = require('menu') @@ -47,6 +48,7 @@ function love.update(dt) end keyboard_input_held(player, dt) gravity(player, dt) + World.mapMovement(player.x) mouvement(player, dt) for i = 1, #NPCs do gravity(NPCs[i], dt) @@ -98,6 +100,10 @@ function love.draw() end end 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 Y " .. player.physics.velocityY, 100, 350) love.graphics.print("Airtime " .. player.physics.airtime, 100, 400) @@ -193,11 +199,11 @@ end function inventory(mode, slot, item) if mode == "add" then - hotbar_cont[slot] = item + player.hotbar_cont[slot] = item elseif mode == "remove" then - hotbar_cont[slot] = nil + player.hotbar_cont[slot] = nil elseif mode == "move" then item = hotbar_cont[slot[1]] - hotbar_cont[slot[2]] = item + player.hotbar_cont[slot[2]] = item end end diff --git a/scripts/inputs.lua b/scripts/inputs.lua index c5c6e71..29661ad 100644 --- a/scripts/inputs.lua +++ b/scripts/inputs.lua @@ -40,7 +40,18 @@ function love.keypressed(key) 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.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 if key == keybinds.create then NPCs[#NPCs+1] = character.create({"attributes", "functions","bools","physics"}, false) diff --git a/scripts/items.lua b/scripts/items.lua index 3e4ffdf..150148b 100644 --- a/scripts/items.lua +++ b/scripts/items.lua @@ -1,8 +1,15 @@ -function item.create(type, commands) +itemgen = {} + +function itemgen.create(type, commands) local object = {} - for i = 1, #commands do - object[commands] - i = i + 1 + for i=1, #commands do + object[commands][i][1] = commands[i][2] end return object +end + +function itemgen.createFromWorld(id) + item = {} + item.name = World.map.items[id][1] + return item end \ No newline at end of file diff --git a/world.lua b/world.lua index ec13fef..3f8fc0f 100644 --- a/world.lua +++ b/world.lua @@ -1,8 +1,12 @@ World = { currentMap = nil, - generators = {} - map = {} + generators = {}, + map = { + x = 0, + isMoving = {false} + } } +checkSpace = {} function World.loadMap(name) local path = ("maps/"..tostring(name)..".vsmf") @@ -12,14 +16,15 @@ function World.loadMap(name) 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 - print ("Itterating character: " .. character) if hasPassedEqual == true then if character == "." then B = B + 1 @@ -39,14 +44,28 @@ function World.loadMap(name) 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 At: " .. character) + 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 for x=1, A do for y=1, B do @@ -64,25 +83,116 @@ function World.loadMap(name) end end end - if World.map.name[1] then + if World.map.name then print "Name Success" end - if World.map.size[1] then + if World.map.size then print "Map Success" end - if World.map.id[1] then + if World.map.id then print "ID Success" 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...") 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 \ No newline at end of file