VoidShot/main.lua
Hannah-Dagemark 3a3bea1ead 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.
2023-10-16 08:44:17 +02:00

209 lines
6.4 KiB
Lua

character = {
subclasses = {
create = {}
}
}
functiongenerator = {}
check_space = {}
function love.load()
globalMode = "devMode"
window = {}
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')
npc_ini = require('scripts/NPC')
map_ini = require('world')
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 = {}
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)
World.mapMovement(player.x)
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
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)
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
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("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)
---
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
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"
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)
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
else
character.subclasses.create.inventory(object)
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,
inventoryOpen = false
}
end
function character.subclasses.create.attributes(object)
object.attributes = {
maxRunningSpeed = 2
}
end
function character.subclasses.create.functions(object)
object.functions = {}
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
player.hotbar_cont[slot] = item
elseif mode == "remove" then
player.hotbar_cont[slot] = nil
elseif mode == "move" then
item = hotbar_cont[slot[1]]
player.hotbar_cont[slot[2]] = item
end
end