character = { subclasses = { create = {} } } functiongenerator = {} check_space = {} function love.load() window = {} window.x, window.y = love.window.getDesktopDimensions() math.randomseed(os.time()) Scene = "menu" inputs_ini = require('scripts/inputs') physics_ini = require('physics') menu_ini = require('menu') npc_ini = require('scripts/NPC') menu.load() NPCs = {} ground = { x = 0, y = window.y, width = window.x, height = 1 } love.window.setMode(window.x, window.y) defaulkeybinds() player = character.create({"physics", "bools", "attributes", "functions"}) player.x = window.x/2-window.x/20 player.y = window.y/2-window.y/20 player.width = 20 player.height = 80 mouse = {} 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 keyboard_input_held(player, dt) gravity(player, dt) mouvement(player, dt) for i = 1, #NPCs do gravity(NPCs[i], dt) wander(NPCs[i], dt) mouvement(NPCs[i], dt) if NPCs[i].bools.isInteracting then sayHello(NPCs[i], dt) end end elseif Scene == "menu" then menu.update(dt) end 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.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) else love.graphics.rectangle("line", player.x-10, player.y-20, 20, 20) end 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() local helloText = love.graphics.newText(font, "Hello there") love.graphics.draw(helloText, NPCs[i].x, NPCs[i].y-10) end end elseif Scene == "menu" then menu.draw() 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 NPCs[i].bools.isInteracting = true end end end function defaulkeybinds() 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) local object = {} for i = 1, #chosenSubclasses do local current_subclass = chosenSubclasses[i] character.subclasses.create[current_subclass](object) end if isPlayerControlled == false then object.attributes.wanderpoint = math.random(0, window.x) object.bools.isInteracting = false object.attributes.time_spoken = 0 end return object end function character.subclasses.create.physics(object) object.physics = { velocityX = 0, velocityY = 0, airtime = 0, terminalVelocity = 53 } end function character.subclasses.create.bools(object) object.bools = { isAirborne = true, isWalking = false, isRunning = false, isFacingRight = true } end function character.subclasses.create.attributes(object) object.attributes = { maxRunningSpeed = 2 } end function character.subclasses.create.functions(object) object.functions = {} end