From 520dddedf6bc792b9458eafe29b62f3e372ea520 Mon Sep 17 00:00:00 2001 From: Hannah-Dagemark Date: Tue, 5 Sep 2023 15:15:24 +0200 Subject: [PATCH] Changed locations, added Localization folder Nothing except Title. Minor push, no update. --- scripts/temp.c => Localization/Temp.txt | 0 SaveGames/Template.txt | 0 Scripts/NPC.lua | 20 ++++++ main.lua | 87 +++---------------------- scripts/inputs.lua | 47 +++++++++++++ 5 files changed, 77 insertions(+), 77 deletions(-) rename scripts/temp.c => Localization/Temp.txt (100%) create mode 100644 SaveGames/Template.txt create mode 100644 Scripts/NPC.lua diff --git a/scripts/temp.c b/Localization/Temp.txt similarity index 100% rename from scripts/temp.c rename to Localization/Temp.txt diff --git a/SaveGames/Template.txt b/SaveGames/Template.txt new file mode 100644 index 0000000..e69de29 diff --git a/Scripts/NPC.lua b/Scripts/NPC.lua new file mode 100644 index 0000000..9364298 --- /dev/null +++ b/Scripts/NPC.lua @@ -0,0 +1,20 @@ +function wander(object, dt) + if object.x > object.attributes.wanderpoint + 2 or object.x < object.attributes.wanderpoint - 2 then + object.bools.isWalking = true + if object.x < object.attributes.wanderpoint then + object.physics.velocityX = 1 + else + object.physics.velocityX = -1 + end + else + object.attributes.wanderpoint = math.random(0, window.x) + end +end + +function sayHello(object, dt) + object.attributes.time_spoken = object.attributes.time_spoken + dt + if object.attributes.time_spoken > 2 then + object.bools.isInteracting = false + object.attributes.time_spoken = 0 + end +end \ No newline at end of file diff --git a/main.lua b/main.lua index ae51e00..f63bb79 100644 --- a/main.lua +++ b/main.lua @@ -15,6 +15,7 @@ function love.load() inputs_ini = require('scripts/inputs') physics_ini = require('physics') menu_ini = require('menu') + npc_ini = require('scripts/NPC') menu.load() NPCs = {} ground = { @@ -36,7 +37,7 @@ end function love.update(dt) if Scene == "gameTest" then - input(player, dt) + keyboard_input_held(player, dt) gravity(player, dt) mouvement(player, dt) for i = 1, #NPCs do @@ -55,7 +56,7 @@ end function love.draw() love.graphics.print(Scene, 100, 100) if Scene == "gameTest" then - if love.graphics.getColor() ~= 1 then love.graphics.setColor(1, 1, 1) end + if love.graphics.getColor() ~= 1, 1, 1 then love.graphics.setColor(1, 1, 1) end 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) @@ -77,74 +78,6 @@ function love.draw() end end - -function input(object, dt) - object.bools.isWalking = false - object.bools.isRunning = false - mouse.x, mouse.y = love.mouse.getPosition - if love.keyboard.isDown("lshift") then - object.bools.isRunning = true - end - if love.keyboard.isDown(keybind.left) and love.keyboard.isDown(keybind.right) then - -- you're stopped now :3c - elseif love.keyboard.isDown(keybind.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 - 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 -end - -function wander(object, dt) - if object.x > object.attributes.wanderpoint + 2 or object.x < object.attributes.wanderpoint - 2 then - object.bools.isWalking = true - if object.x < object.attributes.wanderpoint then - object.physics.velocityX = 1 - else - object.physics.velocityX = -1 - end - else - object.attributes.wanderpoint = math.random(0, window.x) - end -end - -function love.mousemoved(x, y) - if x > player.x then - player.bools.isFacingRight = true - else - player.bools.isFacingRight = false - end -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 - check_space.interactables(player.x, player.y) - end - if key == keybind.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 - else - if key == keybind.jump then - titleCard.duration = true - end - end -end - -function sayHello(object, dt) - object.attributes.time_spoken = object.attributes.time_spoken + dt - if object.attributes.time_spoken > 2 then - object.bools.isInteracting = false - object.attributes.time_spoken = 0 - end -end - function check_space.interactables(x, y) for i = 1, #NPCs do if x > NPCs[i].x -50 and x < NPCs[i].x +50 then @@ -154,13 +87,13 @@ function check_space.interactables(x, y) end function defaulkeybinds() - keybind = {} - keybind.left = "a" - keybind.right = "d" - keybind.jump = "space" - keybind.interact = "e" - keybind.run = "lshift" - keybind.create = "f" + keybinds = {} + keybinds.left = "a" + keybinds.right = "d" + keybinds.jump = "space" + keybinds.interact = "e" + keybinds.run = "lshift" + keybinds.create = "f" end function character.create(chosenSubclasses, isPlayerControlled) diff --git a/scripts/inputs.lua b/scripts/inputs.lua index 7719145..e5c6a61 100644 --- a/scripts/inputs.lua +++ b/scripts/inputs.lua @@ -7,4 +7,51 @@ function mouseOver(object) end end return false +end + +function keyboard_input_held(object, dt) + object.bools.isWalking = false + object.bools.isRunning = false + mouse.x, mouse.y = love.mouse.getPosition + if love.keyboard.isDown("lshift") then + object.bools.isRunning = true + end + if love.keyboard.isDown(keybind.left) and love.keyboard.isDown(keybind.right) then + -- you're stopped now :3c + elseif love.keyboard.isDown(keybind.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 + 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 +end + + +function love.mousemoved(x, y) + if x > player.x then + player.bools.isFacingRight = true + else + player.bools.isFacingRight = false + end +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 + check_space.interactables(player.x, player.y) + end + if key == keybind.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 + else + if key == keybind.jump then + titleCard.duration = true + end + end end \ No newline at end of file