rope, moved entities from LoadedEntities to LoadedObjects.Entities
This commit is contained in:
parent
7f42dea6fa
commit
ff99b79563
|
@ -40,7 +40,7 @@ function DebugEntities()
|
||||||
for _, particle in pairs(LoadedParticles) do
|
for _, particle in pairs(LoadedParticles) do
|
||||||
particle:Debug()
|
particle:Debug()
|
||||||
end
|
end
|
||||||
for _, enty in pairs(LoadedEntities) do
|
for _, enty in pairs(LoadedObjects.Entities) do
|
||||||
enty:Debug()
|
enty:Debug()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -108,7 +108,7 @@ function EditorDoEdit()
|
||||||
elseif vertical < 0 then
|
elseif vertical < 0 then
|
||||||
expand_v = vertical
|
expand_v = vertical
|
||||||
end
|
end
|
||||||
love.graphics.print("> " .. horizontal .. ", " .. vertical)
|
love.graphics.print("> " .. horizontal .. ", " .. vertical .. "; " .. math.floor(mouse_x / game.scale + Camera.pos.x) .. ", " .. math.floor(mouse_y / game.scale + Camera.pos.y))
|
||||||
love.graphics.print("> " .. LevelWidth .. "(" .. expand_h .. "), " .. LevelHeight .. "(".. expand_v .. ")", 0, 10)
|
love.graphics.print("> " .. LevelWidth .. "(" .. expand_h .. "), " .. LevelHeight .. "(".. expand_v .. ")", 0, 10)
|
||||||
|
|
||||||
if not palette then
|
if not palette then
|
||||||
|
|
|
@ -2,7 +2,9 @@ Arrow = Entity:New(x,y)
|
||||||
|
|
||||||
function Arrow:New(x,y,rotation,speed)
|
function Arrow:New(x,y,rotation,speed)
|
||||||
local o = Entity:New(x,y)
|
local o = Entity:New(x,y)
|
||||||
arrow = arrow + 1
|
|
||||||
|
o.type = "arrow"
|
||||||
|
|
||||||
o.pos = {x = x, y = y}
|
o.pos = {x = x, y = y}
|
||||||
o.speed = speed or 0
|
o.speed = speed or 0
|
||||||
o.sprite_rotation = rotation or 0
|
o.sprite_rotation = rotation or 0
|
||||||
|
@ -17,8 +19,8 @@ Arrow = Entity:New(x,y)
|
||||||
-- animations
|
-- animations
|
||||||
o.body = Animation:New(animation.kupo.arrow)
|
o.body = Animation:New(animation.kupo.arrow)
|
||||||
|
|
||||||
table.insert(LoadedEntities,o)
|
table.insert(LoadedObjects.Entities,o)
|
||||||
o.id = #LoadedEntities
|
o.id = #LoadedObjects.Entities
|
||||||
|
|
||||||
setmetatable(o, self)
|
setmetatable(o, self)
|
||||||
self.__index = self
|
self.__index = self
|
||||||
|
|
|
@ -3,6 +3,7 @@ CursedBook = Entity:New(x,y)
|
||||||
function CursedBook:New(x,y)
|
function CursedBook:New(x,y)
|
||||||
local o = Entity:New(x,y)
|
local o = Entity:New(x,y)
|
||||||
|
|
||||||
|
o.type = "cursed_book"
|
||||||
-- behaviour
|
-- behaviour
|
||||||
o.pos = {x = x, y = y}
|
o.pos = {x = x, y = y}
|
||||||
o.speed = 0.01
|
o.speed = 0.01
|
||||||
|
@ -28,8 +29,8 @@ CursedBook = Entity:New(x,y)
|
||||||
o.light_range = 500
|
o.light_range = 500
|
||||||
o.light = CreateLight(o.pos.x,o.pos.y,o.light_range,2,HEX2RGB("#fe00d1"))
|
o.light = CreateLight(o.pos.x,o.pos.y,o.light_range,2,HEX2RGB("#fe00d1"))
|
||||||
|
|
||||||
table.insert(LoadedEntities,o)
|
table.insert(LoadedObjects.Entities,o)
|
||||||
o.id = #LoadedEntities
|
o.id = #LoadedObjects.Entities
|
||||||
|
|
||||||
setmetatable(o, self)
|
setmetatable(o, self)
|
||||||
self.__index = self
|
self.__index = self
|
||||||
|
|
|
@ -3,6 +3,8 @@ Decoration = Entity:New(x,y)
|
||||||
function Decoration:New(x,y,animation,lightRange)
|
function Decoration:New(x,y,animation,lightRange)
|
||||||
local o = Entity:New(x,y)
|
local o = Entity:New(x,y)
|
||||||
|
|
||||||
|
o.type = "decoration"
|
||||||
|
|
||||||
o.pos = {x = x, y = y}
|
o.pos = {x = x, y = y}
|
||||||
|
|
||||||
-- animations
|
-- animations
|
||||||
|
@ -15,8 +17,8 @@ function Decoration:New(x,y,animation,lightRange)
|
||||||
o.light = CreateLight(o.pos.x,o.pos.y,o.lightRange)
|
o.light = CreateLight(o.pos.x,o.pos.y,o.lightRange)
|
||||||
end
|
end
|
||||||
|
|
||||||
table.insert(LoadedEntities,o)
|
table.insert(LoadedObjects.Entities,o)
|
||||||
o.id = #LoadedEntities
|
o.id = #LoadedObjects.Entities
|
||||||
|
|
||||||
setmetatable(o, self)
|
setmetatable(o, self)
|
||||||
self.__index = self
|
self.__index = self
|
||||||
|
|
|
@ -3,6 +3,8 @@ Fairy = Entity:New(x,y)
|
||||||
function Fairy:New(x,y)
|
function Fairy:New(x,y)
|
||||||
local o = Entity:New(x,y)
|
local o = Entity:New(x,y)
|
||||||
|
|
||||||
|
o.type = "fairy"
|
||||||
|
|
||||||
-- behaviour
|
-- behaviour
|
||||||
o.pos = {x = x, y = y}
|
o.pos = {x = x, y = y}
|
||||||
o.speed = 1.4
|
o.speed = 1.4
|
||||||
|
@ -24,8 +26,8 @@ Fairy = Entity:New(x,y)
|
||||||
o.particle_timer = 0
|
o.particle_timer = 0
|
||||||
o.particle_time = 5
|
o.particle_time = 5
|
||||||
|
|
||||||
table.insert(LoadedEntities,o)
|
table.insert(LoadedObjects.Entities,o)
|
||||||
o.id = #LoadedEntities
|
o.id = #LoadedObjects.Entities
|
||||||
|
|
||||||
setmetatable(o, self)
|
setmetatable(o, self)
|
||||||
self.__index = self
|
self.__index = self
|
||||||
|
|
|
@ -3,6 +3,8 @@ Kupo = Entity:New(x,y)
|
||||||
function Kupo:New(x,y)
|
function Kupo:New(x,y)
|
||||||
local o = Entity:New(x,y)
|
local o = Entity:New(x,y)
|
||||||
|
|
||||||
|
o.type = "kupo"
|
||||||
|
|
||||||
o.pos = {x = x, y = y}
|
o.pos = {x = x, y = y}
|
||||||
o.speed = 20
|
o.speed = 20
|
||||||
o.range = 200
|
o.range = 200
|
||||||
|
@ -28,8 +30,8 @@ Kupo = Entity:New(x,y)
|
||||||
o.lightRange = o.range/2
|
o.lightRange = o.range/2
|
||||||
o.light = CreateLight(o.pos.x,o.pos.y,o.lightRange)
|
o.light = CreateLight(o.pos.x,o.pos.y,o.lightRange)
|
||||||
|
|
||||||
table.insert(LoadedEntities,o)
|
table.insert(LoadedObjects.Entities,o)
|
||||||
o.id = #LoadedEntities
|
o.id = #LoadedObjects.Entities
|
||||||
|
|
||||||
setmetatable(o, self)
|
setmetatable(o, self)
|
||||||
self.__index = self
|
self.__index = self
|
||||||
|
|
|
@ -5,7 +5,6 @@ Particle = Entity:New(x,y)
|
||||||
|
|
||||||
o.pos = {x = x, y = y}
|
o.pos = {x = x, y = y}
|
||||||
|
|
||||||
|
|
||||||
o.speed = particle_data.speed or 0
|
o.speed = particle_data.speed or 0
|
||||||
o.direction = particle_data.direction or o.direction
|
o.direction = particle_data.direction or o.direction
|
||||||
o.sprite_rotation = particle_data.sprite_rotation or o.sprite_rotation
|
o.sprite_rotation = particle_data.sprite_rotation or o.sprite_rotation
|
||||||
|
|
|
@ -3,9 +3,8 @@
|
||||||
|
|
||||||
function Player:New(x,y)
|
function Player:New(x,y)
|
||||||
local o = Entity:New(x,y)
|
local o = Entity:New(x,y)
|
||||||
Player.health = 3
|
|
||||||
Player.coins = 0
|
|
||||||
|
|
||||||
|
o.type = "player"
|
||||||
-- physics
|
-- physics
|
||||||
o.moveSpeed = 1.3 -- gameworld pixels
|
o.moveSpeed = 1.3 -- gameworld pixels
|
||||||
o.zeroSpeed = 0.01 -- gameworld pixels
|
o.zeroSpeed = 0.01 -- gameworld pixels
|
||||||
|
@ -22,6 +21,7 @@
|
||||||
o.dashCooldownTime = 0.1 -- seconds
|
o.dashCooldownTime = 0.1 -- seconds
|
||||||
o.dashCooldownTimer = 0 -- seconds
|
o.dashCooldownTimer = 0 -- seconds
|
||||||
|
|
||||||
|
-- dash values
|
||||||
o.dashTimer = 0 -- seconds
|
o.dashTimer = 0 -- seconds
|
||||||
o.dashTime = 0.15 -- seconds
|
o.dashTime = 0.15 -- seconds
|
||||||
o.dashDistance = 40 -- gameworld pixels
|
o.dashDistance = 40 -- gameworld pixels
|
||||||
|
@ -29,30 +29,36 @@
|
||||||
o.dashCount = 1 -- int
|
o.dashCount = 1 -- int
|
||||||
o.dashAmount = 10 -- int
|
o.dashAmount = 10 -- int
|
||||||
|
|
||||||
|
-- hook values
|
||||||
|
o.hookDistance = 100
|
||||||
|
o.hookedDistance = 80
|
||||||
|
o.hookAnchor = {
|
||||||
|
x = nil,
|
||||||
|
y = nil
|
||||||
|
}
|
||||||
|
|
||||||
o.boxCollision = {
|
o.boxCollision = {
|
||||||
from = {x = -8, y = -16}, --gameworld pixels
|
from = {x = -8, y = -16}, --gameworld pixels
|
||||||
to = {x = 8, y = 0} -- gameworld pixels
|
to = {x = 8, y = 0} -- gameworld pixels
|
||||||
}
|
}
|
||||||
|
|
||||||
o.lightRange = 0 -- screen pixels
|
o.lightRange = 10 -- screen pixels
|
||||||
|
|
||||||
-- status
|
-- status
|
||||||
o.isDashing = false
|
o.isDashing = false
|
||||||
o.isJumping = false
|
o.isJumping = false
|
||||||
|
o.isHooked = false
|
||||||
o.isOnGround = true
|
o.isOnGround = true
|
||||||
o.isOnLadder = false
|
o.isOnLadder = false
|
||||||
o.canJump = true
|
o.canJump = true
|
||||||
o.canFall = true
|
o.canFall = true
|
||||||
o.canFriction = true
|
o.canFriction = true
|
||||||
o.maskType = animation.moth_mask
|
o.maskType = animation.moth_mask
|
||||||
|
|
||||||
o.anchorRespawn = {
|
o.anchorRespawn = {
|
||||||
x = o.pos.x,
|
x = o.pos.x,
|
||||||
y = o.pos.y
|
y = o.pos.y
|
||||||
}
|
}
|
||||||
o.anchorRope = {
|
|
||||||
x = nil,
|
|
||||||
y = nil
|
|
||||||
}
|
|
||||||
|
|
||||||
-- sprite
|
-- sprite
|
||||||
o.target_offset = {x = 0, y = 0}
|
o.target_offset = {x = 0, y = 0}
|
||||||
|
@ -64,8 +70,8 @@
|
||||||
-- lights
|
-- lights
|
||||||
o.light = CreateLight(o.pos.x,o.pos.y,o.lightRange)
|
o.light = CreateLight(o.pos.x,o.pos.y,o.lightRange)
|
||||||
|
|
||||||
table.insert(LoadedEntities,o)
|
table.insert(LoadedObjects.Entities,o)
|
||||||
o.id = #LoadedEntities
|
o.id = #LoadedObjects.Entities
|
||||||
|
|
||||||
setmetatable(o, self)
|
setmetatable(o, self)
|
||||||
self.__index = self
|
self.__index = self
|
||||||
|
@ -73,15 +79,24 @@
|
||||||
end
|
end
|
||||||
|
|
||||||
function Player:Smart()
|
function Player:Smart()
|
||||||
self:LightAdjust(-self.target_offset.x,-self.target_offset.y)
|
self:LightAdjust(self.target_offset.x,self.target_offset.y)
|
||||||
|
|
||||||
|
-- reset coyoteValue
|
||||||
|
if self.isOnGround then
|
||||||
|
self.coyoteValue = self.coyoteAmount
|
||||||
|
elseif self.coyoteValue > 0 then
|
||||||
|
self.coyoteValue = self.coyoteValue - 1
|
||||||
|
end
|
||||||
|
|
||||||
if self.dashTimer <= 0 then
|
if self.dashTimer <= 0 then
|
||||||
|
-- horizontal movement
|
||||||
if Keybind:CheckDown(Keybind.move.left) then
|
if Keybind:CheckDown(Keybind.move.left) then
|
||||||
self.move_x = -self.moveSpeed
|
self.move_x = -self.moveSpeed
|
||||||
elseif Keybind:CheckDown(Keybind.move.right) then
|
elseif Keybind:CheckDown(Keybind.move.right) then
|
||||||
self.move_x = self.moveSpeed
|
self.move_x = self.moveSpeed
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- jump if on ground (coyotevalue)
|
||||||
if Keybind:CheckDown(Keybind.move.jump) then
|
if Keybind:CheckDown(Keybind.move.jump) then
|
||||||
if self.coyoteValue > 0 then
|
if self.coyoteValue > 0 then
|
||||||
self.vel.y = -self.jumpImpulse
|
self.vel.y = -self.jumpImpulse
|
||||||
|
@ -90,19 +105,20 @@ function Player:Smart()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.isOnGround then
|
-- dash timer
|
||||||
self.coyoteValue = self.coyoteAmount
|
|
||||||
elseif self.coyoteValue > 0 then
|
|
||||||
self.coyoteValue = self.coyoteValue - 1
|
|
||||||
end
|
|
||||||
|
|
||||||
self.dashCooldownTimer = math.max(0,self.dashCooldownTimer - current_dt)
|
self.dashCooldownTimer = math.max(0,self.dashCooldownTimer - current_dt)
|
||||||
|
|
||||||
|
-- try to dash
|
||||||
if Keybind:CheckDown(Keybind.move.dash) then
|
if Keybind:CheckDown(Keybind.move.dash) then
|
||||||
if self.dashCooldownTimer == 0
|
if self.dashCooldownTimer == 0
|
||||||
and not self.isDashing
|
and not self.isDashing
|
||||||
and self.dashCount > 0 then
|
and self.dashCount > 0 then
|
||||||
|
|
||||||
|
-- state player
|
||||||
self.dashCount = self.dashCount - 1
|
self.dashCount = self.dashCount - 1
|
||||||
self.isDashing = true
|
self.isDashing = true
|
||||||
|
|
||||||
|
-- get dash direction
|
||||||
local vertical = 0
|
local vertical = 0
|
||||||
if Keybind:CheckDown(Keybind.move.down) then vertical = vertical + 1 end
|
if Keybind:CheckDown(Keybind.move.down) then vertical = vertical + 1 end
|
||||||
if Keybind:CheckDown(Keybind.move.up) then vertical = vertical - 1 end
|
if Keybind:CheckDown(Keybind.move.up) then vertical = vertical - 1 end
|
||||||
|
@ -110,16 +126,32 @@ function Player:Smart()
|
||||||
if Keybind:CheckDown(Keybind.move.right) then horizontal = horizontal + 1 end
|
if Keybind:CheckDown(Keybind.move.right) then horizontal = horizontal + 1 end
|
||||||
if Keybind:CheckDown(Keybind.move.left) then horizontal = horizontal - 1 end
|
if Keybind:CheckDown(Keybind.move.left) then horizontal = horizontal - 1 end
|
||||||
|
|
||||||
|
-- if no direction, then dash forward
|
||||||
if horizontal == 0 and vertical == 0 then
|
if horizontal == 0 and vertical == 0 then
|
||||||
horizontal = self.sprite_flip.x
|
horizontal = self.sprite_flip.x
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- set dash values
|
||||||
self.dashDirection = GetAngleFromVector(horizontal, vertical)
|
self.dashDirection = GetAngleFromVector(horizontal, vertical)
|
||||||
self.dashTimer = self.dashTime
|
self.dashTimer = self.dashTime
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
-- not dashing!
|
||||||
self.isDashing = false
|
self.isDashing = false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if Keybind:CheckDown(Keybind.move.hook) then
|
||||||
|
local anchor = self:CheckNearest("decoration",self.hookDistance)
|
||||||
|
if anchor then
|
||||||
|
self.isHooked = true
|
||||||
|
self.hookAnchor = {
|
||||||
|
x = anchor.pos.x,
|
||||||
|
y = anchor.pos.y
|
||||||
|
}
|
||||||
|
end
|
||||||
|
else
|
||||||
|
self.isHooked = false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Player:DoPhysics()
|
function Player:DoPhysics()
|
||||||
|
@ -131,13 +163,16 @@ function Player:DoPhysics()
|
||||||
end
|
end
|
||||||
if math.abs(self.vel.x) < self.zeroSpeed then self.vel.x = 0 end
|
if math.abs(self.vel.x) < self.zeroSpeed then self.vel.x = 0 end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- reset state
|
-- reset state
|
||||||
|
self.canFall = true
|
||||||
self.isOnGround = false
|
self.isOnGround = false
|
||||||
-- adjust timers
|
-- adjust timers
|
||||||
self.dashTimer = self.dashTimer - current_dt
|
self.dashTimer = self.dashTimer - current_dt
|
||||||
|
|
||||||
-- DASH STATE
|
-- DASH STATE
|
||||||
if self.dashTimer > 0 then
|
if self.dashTimer > 0 then
|
||||||
|
self.canFall = false
|
||||||
-- dash particle
|
-- dash particle
|
||||||
local particle_data = {
|
local particle_data = {
|
||||||
animation = self.body,
|
animation = self.body,
|
||||||
|
@ -153,28 +188,44 @@ function Player:DoPhysics()
|
||||||
-- dash movement
|
-- dash movement
|
||||||
self.vel.x = self.dashSpeed * math.cos(self.dashDirection)
|
self.vel.x = self.dashSpeed * math.cos(self.dashDirection)
|
||||||
self.vel.y = self.dashSpeed * math.sin(self.dashDirection)
|
self.vel.y = self.dashSpeed * math.sin(self.dashDirection)
|
||||||
else
|
end
|
||||||
-- not in dash; fall normally
|
|
||||||
|
-- hook state
|
||||||
|
if self.isHooked then
|
||||||
|
local hook = Vector(self.pos.x, self.pos.y, self.hookAnchor.x, self.hookAnchor.y)
|
||||||
|
if GetVectorValue(hook) > self.hookedDistance then
|
||||||
|
local hook_angle = GetAngleFromVector(hook[1],hook[2])
|
||||||
|
self.pos.x = self.hookAnchor.x + self.hookedDistance * math.cos(-math.rad(180)+hook_angle)
|
||||||
|
self.pos.y = self.hookAnchor.y + self.hookedDistance * math.sin(-math.rad(180)+hook_angle)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
if self.canFall then
|
||||||
|
-- not in dash or hook; fall normally
|
||||||
self.dashTimer = 0
|
self.dashTimer = 0
|
||||||
self.vel.y = self.vel.y + gravity
|
self.vel.y = self.vel.y + gravity
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- horizontal collision
|
||||||
if not self:isCollidingAt(self.pos.x + self.vel.x + self.move_x, self.pos.y, LoadedObjects.Collisions) then
|
if not self:isCollidingAt(self.pos.x + self.vel.x + self.move_x, self.pos.y, LoadedObjects.Collisions) then
|
||||||
self.pos.x = self.pos.x + self.vel.x + self.move_x
|
self.pos.x = self.pos.x + self.vel.x + self.move_x
|
||||||
else
|
else
|
||||||
self.vel.x = 0
|
self.vel.x = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- vertical collision
|
||||||
if not self:isCollidingAt(self.pos.x, self.pos.y + self.vel.y, LoadedObjects.Collisions) then
|
if not self:isCollidingAt(self.pos.x, self.pos.y + self.vel.y, LoadedObjects.Collisions) then
|
||||||
self.pos.y = self.pos.y + self.vel.y
|
self.pos.y = self.pos.y + self.vel.y
|
||||||
else
|
else
|
||||||
if self.vel.y > 0 then
|
if self.vel.y > 0 then
|
||||||
self.isOnGround = true
|
self.isOnGround = true
|
||||||
self.dashCount = self.dashAmount
|
self.dashCount = self.dashAmount
|
||||||
|
end
|
||||||
self.vel.y = 0
|
self.vel.y = 0
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
|
-- if u collision w hazard, respawn
|
||||||
if self:isCollidingAt(self.pos.x, self.pos.y, LoadedObjects.Hazards) then
|
if self:isCollidingAt(self.pos.x, self.pos.y, LoadedObjects.Hazards) then
|
||||||
self:Respawn()
|
self:Respawn()
|
||||||
end
|
end
|
||||||
|
@ -190,8 +241,8 @@ function Player:HandleAnimation()
|
||||||
if self.move_x ~= 0 then self.sprite_flip.x = math.sign(self.move_x) end
|
if self.move_x ~= 0 then self.sprite_flip.x = math.sign(self.move_x) end
|
||||||
|
|
||||||
-- animation priority
|
-- animation priority
|
||||||
if self.vel.y > 1.25 then
|
|
||||||
self.body = self.body:ChangeTo(animation.nancy.fall)
|
self.body = self.body:ChangeTo(animation.nancy.fall)
|
||||||
|
if self.vel.y > 1.25 then
|
||||||
self.mask = self.mask:ChangeTo(self.maskType.fall)
|
self.mask = self.mask:ChangeTo(self.maskType.fall)
|
||||||
elseif self.vel.y < 0 then
|
elseif self.vel.y < 0 then
|
||||||
self.body = self.body:ChangeTo(animation.nancy.jump)
|
self.body = self.body:ChangeTo(animation.nancy.jump)
|
||||||
|
@ -209,6 +260,15 @@ function Player:HandleAnimation()
|
||||||
if self.body.anim_speed < 0.5 then self.body.anim_speed = self.body.anim_speed + 0.001 end
|
if self.body.anim_speed < 0.5 then self.body.anim_speed = self.body.anim_speed + 0.001 end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if self.isHooked then
|
||||||
|
love.graphics.line(
|
||||||
|
-Camera.pos.x + self.pos.x,
|
||||||
|
-Camera.pos.y + self.pos.y,
|
||||||
|
-Camera.pos.x + self.hookAnchor.x,
|
||||||
|
-Camera.pos.y + self.hookAnchor.y
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
self.body:Animate()
|
self.body:Animate()
|
||||||
self:Draw(self.body)
|
self:Draw(self.body)
|
||||||
if self.dashCount > 0 then
|
if self.dashCount > 0 then
|
||||||
|
|
|
@ -28,6 +28,27 @@ function Entity:New(x,y)
|
||||||
return o
|
return o
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Entity:CheckNearest(type,maxdistance)
|
||||||
|
local return_entity = nil
|
||||||
|
local shortest = -1
|
||||||
|
for _, entity in pairs(LoadedObjects.Entities) do
|
||||||
|
if not type or entity.type == type then
|
||||||
|
local distance_x = entity.pos.x - self.pos.x
|
||||||
|
local distance_y = entity.pos.y - self.pos.y
|
||||||
|
local distance = math.sqrt(distance_x ^ 2 + distance_y ^ 2)
|
||||||
|
|
||||||
|
if not maxdistance or distance < maxdistance then
|
||||||
|
if shortest == -1 or distance < shortest then
|
||||||
|
shortest = distance
|
||||||
|
return_entity = entity
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return return_entity
|
||||||
|
end
|
||||||
|
|
||||||
function Entity:Smart()
|
function Entity:Smart()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -63,12 +84,12 @@ function Entity:Kill()
|
||||||
KillLight(self.light)
|
KillLight(self.light)
|
||||||
end
|
end
|
||||||
if self.id ~= nil then
|
if self.id ~= nil then
|
||||||
for _, e in pairs(LoadedEntities) do
|
for _, e in pairs(LoadedObjects.Entities) do
|
||||||
if e.id > self.id then
|
if e.id > self.id then
|
||||||
e.id = e.id - 1
|
e.id = e.id - 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
table.remove(LoadedEntities,self.id)
|
table.remove(LoadedObjects.Entities,self.id)
|
||||||
end
|
end
|
||||||
self = nil
|
self = nil
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,7 +4,7 @@ function GameStep()
|
||||||
for _, particle in pairs(LoadedParticles) do
|
for _, particle in pairs(LoadedParticles) do
|
||||||
particle:Smart()
|
particle:Smart()
|
||||||
end
|
end
|
||||||
for _, enty in pairs(LoadedEntities) do
|
for _, enty in pairs(LoadedObjects.Entities) do
|
||||||
enty:Smart()
|
enty:Smart()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -12,7 +12,7 @@ function GameStep()
|
||||||
for _, particle in pairs(LoadedParticles) do
|
for _, particle in pairs(LoadedParticles) do
|
||||||
particle:DoPhysics()
|
particle:DoPhysics()
|
||||||
end
|
end
|
||||||
for _, enty in pairs(LoadedEntities) do
|
for _, enty in pairs(LoadedObjects.Entities) do
|
||||||
enty:DoPhysics()
|
enty:DoPhysics()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ end
|
||||||
|
|
||||||
function GameworldDrawEntities()
|
function GameworldDrawEntities()
|
||||||
love.graphics.setColor(1,1,1)
|
love.graphics.setColor(1,1,1)
|
||||||
for _, enty in pairs(LoadedEntities) do
|
for _, enty in pairs(LoadedObjects.Entities) do
|
||||||
enty:HandleAnimation()
|
enty:HandleAnimation()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -53,19 +53,22 @@ function Keybind:Default()
|
||||||
--Menu
|
--Menu
|
||||||
Keybind.menu.pause= { keys = {"escape"}}
|
Keybind.menu.pause= { keys = {"escape"}}
|
||||||
Keybind.menu.confirm= { keys = {"z", "space", 1}}
|
Keybind.menu.confirm= { keys = {"z", "space", 1}}
|
||||||
|
|
||||||
--Move
|
--Move
|
||||||
Keybind.move.left = { keys = {"left", "a"}}
|
Keybind.move.left = { keys = {"left", "a"}}
|
||||||
Keybind.move.right = { keys = {"right", "d"}}
|
Keybind.move.right = { keys = {"right", "d"}}
|
||||||
Keybind.move.up = { keys = {"up", "w"}}
|
Keybind.move.up = { keys = {"up", "w"}}
|
||||||
Keybind.move.down = { keys = {"down", "s"}}
|
Keybind.move.down = { keys = {"down", "s"}}
|
||||||
Keybind.move.jump = { keys = {"z", "space"}}
|
Keybind.move.jump = { keys = {"z", "space"}}
|
||||||
Keybind.move.attack = { keys = {"x", 1}}
|
Keybind.move.hook = { keys = {"x", 1}}
|
||||||
Keybind.move.dash = { keys = {"c", 2}}
|
Keybind.move.dash = { keys = {"c", 2}}
|
||||||
|
|
||||||
--Debug
|
--Debug
|
||||||
Keybind.debug.debug = { keys = {"f1"}}
|
Keybind.debug.debug = { keys = {"f1"}}
|
||||||
Keybind.debug.reposition = { keys = {"f2"}}
|
Keybind.debug.reposition = { keys = {"f2"}}
|
||||||
Keybind.debug.reload = { keys = {"f3"}}
|
Keybind.debug.reload = { keys = {"f3"}}
|
||||||
Keybind.debug.editor = { keys = {"f4"}}
|
Keybind.debug.editor = { keys = {"f4"}}
|
||||||
|
|
||||||
-- Editor
|
-- Editor
|
||||||
Keybind.editor.palette = { keys = {"tab"}}
|
Keybind.editor.palette = { keys = {"tab"}}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,16 @@ function math.sign(x)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Vector(init_x, init_y, final_x, final_y)
|
||||||
|
local distance_x = final_x - init_x
|
||||||
|
local distance_y = final_y - init_y
|
||||||
|
return {distance_x, distance_y}
|
||||||
|
end
|
||||||
|
|
||||||
|
function GetVectorValue(vector)
|
||||||
|
return math.sqrt(vector[1] ^ 2 + vector[2] ^ 2)
|
||||||
|
end
|
||||||
|
|
||||||
function GetAngleFromVector(x,y)
|
function GetAngleFromVector(x,y)
|
||||||
local reduce = 0
|
local reduce = 0
|
||||||
if x < 0 then
|
if x < 0 then
|
||||||
|
|
1
main.lua
1
main.lua
|
@ -43,7 +43,6 @@ function love.load()
|
||||||
levelNum = 1
|
levelNum = 1
|
||||||
currLevel = levelList[levelNum]
|
currLevel = levelList[levelNum]
|
||||||
logPrint("currLevel: "..currLevel)
|
logPrint("currLevel: "..currLevel)
|
||||||
LoadedEntities = {}
|
|
||||||
LoadedParticles = {}
|
LoadedParticles = {}
|
||||||
LevelLoadTiles()
|
LevelLoadTiles()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue