Removed initial player creation, replaced with a function that creates a character. Added ability to generate NPCs by pressing [Interact Key] Added key binds Added NPC wandering and ability to say hello upon interaction
44 lines
No EOL
1.6 KiB
Lua
44 lines
No EOL
1.6 KiB
Lua
main = require('main')
|
|
function gravity(object, dt)
|
|
if object.bools.isAirborne == true then
|
|
object.physics.airtime = object.physics.airtime + dt
|
|
end
|
|
if clearanceCheck(object, dt) == "ground" then
|
|
object.y = ground.y - (object.height + 1)
|
|
object.physics.velocityY = 0
|
|
object.physics.airtime = 0
|
|
object.bools.isAirborne = false
|
|
elseif object.y ~= ground.y - (object.height + 1) then
|
|
object.bools.isAirborne = true
|
|
end
|
|
object.physics.gravity = 4.91*object.physics.airtime
|
|
if object.physics.velocityY + object.physics.gravity > object.physics.terminalVelocity then
|
|
object.physics.velocityY = object.physics.terminalVelocity
|
|
else
|
|
object.physics.velocityY = object.physics.velocityY + object.physics.gravity
|
|
end
|
|
|
|
end
|
|
|
|
function mouvement(object, dt)
|
|
object.y = object.y + object.physics.velocityY
|
|
object.x = object.x + object.physics.velocityX
|
|
if object.bools.isWalking == false and object.physics.velocityX ~=0 then
|
|
object.physics.velocityX = 0
|
|
end
|
|
if not object.bools.isRunning and math.abs(object.physics.velocityX) > object.attributes.maxRunningSpeed + 0.1 then
|
|
if object.physics.velocityX > 0 then
|
|
object.physics.velocityX = object.attributes.maxRunningSpeed
|
|
else
|
|
object.physics.velocityX = object.attributes.maxRunningSpeed * -1
|
|
end
|
|
end
|
|
end
|
|
|
|
function clearanceCheck(object, dt)
|
|
if ground.y <= object.y + object.height + object.physics.velocityY + 1 then
|
|
return "ground"
|
|
else
|
|
return "GTG"
|
|
end
|
|
end |