naming convention for most stuff but not all

This commit is contained in:
lustlion
2022-03-04 23:28:30 +01:00
parent c978855711
commit cef2096577
29 changed files with 354 additions and 436 deletions

View File

@@ -1,7 +1,7 @@
Player = Entity:New()
Player = Entity:new()
function Player:New(x,y)
local o = Entity:New(x,y)
function Player:new(x,y)
local o = Entity:new(x,y)
o.type = "player"
-- physics
@@ -43,7 +43,7 @@ function Player:New(x,y)
o.walljumpFriction = 0.3 -- gameworld pixels
-- light values
o.lightRange = 40 -- screen pixels
o.light_radius = 40 -- screen pixels
-- status
o.canJump = true
@@ -69,13 +69,13 @@ function Player:New(x,y)
-- sprite
o.target_offset = {x = 0, y = 0}
o.body = Animation:New(animation.nancy.idle)
o.mask = Animation:New(animation.moth_mask.idle)
o.body = Animation:new(animation.nancy.idle)
o.mask = Animation:new(animation.moth_mask.idle)
o:centerOffset(o.body)
o:getBoundingBox(o.body,0,3,-1,-3)
o:createBox(o.body,0,3,-1,-3)
-- lights
o.light = Light:New(o.pos.x,o.pos.y,o.lightRange)
o.light = Light:new(o.pos.x,o.pos.y,o.light_radius)
table.insert(LoadedObjects.Entities,o)
o.id = #LoadedObjects.Entities
@@ -85,8 +85,8 @@ function Player:New(x,y)
return o
end
function Player:Smart()
self:LightAdjust(self.target_offset.x,self.target_offset.y)
function Player:doLogic()
self:adjustLight(self.target_offset.x,self.target_offset.y)
-- reset coyoteValue
if self.isOnGround then
@@ -134,7 +134,7 @@ function Player:Smart()
if self.dashCooldownTimer == 0
and not self.isDashing
and self.dashCount > 0 then
self:Unhook()
self:unhook()
-- state player
self.isDashing = true
@@ -164,9 +164,9 @@ function Player:Smart()
if self.canHook and Keybind:CheckPressed(Keybind.move.hook) then
if self.isHooked then
self:Unhook()
self:unhook()
else
local anchor = self:CheckNearest("hook_anchor",self.hookDistance)
local anchor = self:checkNearest("hook_anchor",self.hookDistance)
if anchor then
self.isHooked = true
self.hookDistance = anchor.hookDistance
@@ -179,7 +179,7 @@ function Player:Smart()
end
end
function Player:DoPhysics()
function Player:doPhysics()
if self.dashTimer <= 0 then
if self.isOnGround then
self.vel.x = self.vel.x * (1-self.groundFriction)
@@ -219,7 +219,7 @@ function Player:DoPhysics()
y = self.sprite_flip.y
}
}
Particle:New(self.pos.x,self.pos.y,particle_data)
Particle:new(self.pos.x,self.pos.y,particle_data)
self.dashCooldownTimer = self.dashCooldownTime
-- dash movement
self.vel.x = self.dashSpeed * math.cos(self.dashDirection)
@@ -252,7 +252,7 @@ function Player:DoPhysics()
y = self.sprite_flip.y
}
}
Particle:New(self.pos.x,self.pos.y,particle_data)
Particle:new(self.pos.x,self.pos.y,particle_data)
local pos_x = self.hookAnchor.x + dist * math.cos(hook_angle)
local pos_y = self.hookAnchor.y + dist * math.sin(hook_angle)
@@ -291,16 +291,16 @@ function Player:DoPhysics()
-- if u collision w hazard, respawn
if self:isCollidingAt(self.pos.x, self.pos.y, LoadedObjects.Hazards) then
self:Respawn()
self:respawn()
end
end
function Player:Respawn()
function Player:respawn()
self.pos.x = self.anchorRespawn.x
self.pos.y = self.anchorRespawn.y
end
function Player:HandleAnimation()
function Player:handleAnimation()
-- flip sprite to look in the direction is moving
if self.isHooked then
if self.vel.x ~= 0 then
@@ -312,17 +312,17 @@ function Player:HandleAnimation()
-- animation priority
if self.vel.y > 1.25 or self.isSliding then
self.body = self.body:ChangeTo(animation.nancy.fall)
self.mask = self.mask:ChangeTo(self.maskType.fall)
self.body = self.body:change(animation.nancy.fall)
self.mask = self.mask:change(self.maskType.fall)
elseif self.vel.y < 0 then
self.body = self.body:ChangeTo(animation.nancy.jump)
self.mask = self.mask:ChangeTo(self.maskType.jump)
self.body = self.body:change(animation.nancy.jump)
self.mask = self.mask:change(self.maskType.jump)
elseif self.vel.x + self.move_x ~= 0 then
self.body = self.body:ChangeTo(animation.nancy.run)
self.mask = self.mask:ChangeTo(self.maskType.run)
self.body = self.body:change(animation.nancy.run)
self.mask = self.mask:change(self.maskType.run)
else
self.body = self.body:ChangeTo(animation.nancy.idle)
self.mask = self.mask:ChangeTo(self.maskType.idle)
self.body = self.body:change(animation.nancy.idle)
self.mask = self.mask:change(self.maskType.idle)
end
-- special case: idle animation gets slower by time
@@ -341,21 +341,21 @@ function Player:HandleAnimation()
)
end
self.body:Animate()
self:Draw(self.body)
self.body:animate()
self:draw(self.body)
if self.dashCount > 0 then
self:Draw(self.mask)
self:draw(self.mask)
end
self.move_x = 0
end
function Player:Unhook()
function Player:unhook()
self.isHooked = false
self.hookAnchor = nil
end
function Player:Debug()
Entity.Debug(self)
function Player:debug()
Entity.debug(self)
love.graphics.print("wallHit: "..self.wallHit)
end