naming conventions act 2: the end

This commit is contained in:
lustlion
2022-03-06 09:35:45 +01:00
parent edd064c2fd
commit 05bf757ea5
29 changed files with 509 additions and 536 deletions

View File

@@ -24,8 +24,7 @@ function Arrow:new(x,y,rotation,speed)
to = {x = 0.5, y = 0.5} -- gameworld pixels
}
table.insert(LoadedObjects.Entities,o)
o.id = #LoadedObjects.Entities
o:id()
setmetatable(o, self)
self.__index = self

View File

@@ -29,8 +29,7 @@ function CursedBook:new(x,y)
o.light_range = 500
o.light = Light:new(o.pos.x,o.pos.y,o.light_range,2,HEX2RGB("#fe00d1"))
table.insert(LoadedObjects.Entities,o)
o.id = #LoadedObjects.Entities
o:id()
setmetatable(o, self)
self.__index = self
@@ -38,8 +37,8 @@ function CursedBook:new(x,y)
end
function CursedBook:doLogic()
self.target.x = main_Player.pos.x - main_Player.target_offset.x
self.target.y = main_Player.pos.y - main_Player.target_offset.y
self.target.x = main_player.pos.x - main_player.target_offset.x
self.target.y = main_player.pos.y - main_player.target_offset.y
local distance_x = self.target.x - self.pos.x
local distance_y = self.target.y - self.pos.y
local angle = GetAngleFromVector(distance_x,distance_y)

View File

@@ -17,8 +17,7 @@ function Decoration:new(x,y,animation,light_radius)
o.light = Light:new(o.pos.x,o.pos.y,o.light_radius)
end
table.insert(LoadedObjects.Entities,o)
o.id = #LoadedObjects.Entities
o:id()
setmetatable(o, self)
self.__index = self

View File

@@ -20,14 +20,13 @@ function Fairy:new(x,y)
-- light
o.light_radius = 80
o.light = Light:new(o.pos.x,o.pos.y,o.light_radius,nil,HEX2RGB("#fed100"))
o.light = Light:new(o.pos.x,o.pos.y,o.light_radius,nil,hex2rgb("#fed100"))
-- timer
o.particle_timer = 0
o.particle_time = 5
table.insert(LoadedObjects.Entities,o)
o.id = #LoadedObjects.Entities
o:id()
setmetatable(o, self)
self.__index = self
@@ -36,10 +35,10 @@ end
function Fairy:doLogic()
if self:checkVisionLine(main_Player,self.vision_range) then
if self:checkVisionLine(main_player,self.vision_range) then
self.target.x = main_Player.pos.x + main_Player.target_offset.x
self.target.y = main_Player.pos.y + main_Player.target_offset.y
self.target.x = main_player.pos.x + main_player.target_offset.x
self.target.y = main_player.pos.y + main_player.target_offset.y
local below = 1
while not isThereObjectAt(
@@ -64,7 +63,7 @@ function Fairy:doLogic()
local distance_x = self.target.x - self.pos.x
local distance_y = self.target.y - self.pos.y
local angle = GetAngleFromVector(distance_x,distance_y)
local angle = getAngleFromVector(distance_x,distance_y)
local distance = math.sqrt(distance_x ^ 2 + distance_y ^ 2)
if distance < self.range then
@@ -80,7 +79,7 @@ function Fairy:doLogic()
local particle_data = {
animation = animation.particle.simple,
sprite_tint = HEX2RGB("#fed100"),
sprite_tint = hex2rgb("#fed100"),
direction = angle-math.rad(180+math.random(60)-30),
speed = 0.8*(distance/50),
speed_increase = -0.01,
@@ -91,7 +90,7 @@ end
function Fairy:handleAnimation()
self.body:animate()
--if self:isCollidingWith(main_Player) then self.sprite_tint = {1,0,0} else self.sprite_tint = {1,1,1} end
--if self:isCollidingWith(main_player) then self.sprite_tint = {1,0,0} else self.sprite_tint = {1,1,1} end
self:draw(self.body)
end
@@ -111,5 +110,5 @@ end
function Fairy:debug()
Entity.debug(self)
self:checkVisionLineDebug(main_Player,self.vision_range)
self:checkVisionLineDebug(main_player,self.vision_range)
end

View File

@@ -1,20 +1,18 @@
HookAnchor = Entity:new()
function HookAnchor:new(x,y,hookDistance)
function HookAnchor:new(x,y,hook_distance)
local o = Entity:new(x,y)
o.type = "hook_anchor"
o.pos = {x = x, y = y}
o.hookDistance = hookDistance or 100
o.hook_distance = hook_distance or 100
-- animations
o.body = Animation:new(animation.fairy.flying)
o:centerOffset(o.body)
o:createBox(o.body)
table.insert(LoadedObjects.Entities,o)
o.id = #LoadedObjects.Entities
o:id()
setmetatable(o, self)
self.__index = self
@@ -33,7 +31,7 @@ function HookAnchor:drawBackground()
"fill",
-Camera.pos.x + self.pos.x,
-Camera.pos.y + self.pos.y,
self.hookDistance
self.hook_distance
)
end

View File

@@ -30,8 +30,7 @@ function Kupo:new(x,y)
o.light_radius = o.range/2
o.light = Light:new(o.pos.x,o.pos.y,o.light_radius)
table.insert(LoadedObjects.Entities,o)
o.id = #LoadedObjects.Entities
o:id()
setmetatable(o, self)
self.__index = self
@@ -41,12 +40,12 @@ end
function Kupo:doLogic()
self:adjustLight(self.target_offset.x,self.target_offset.y)
self.target.x = main_Player.pos.x - main_Player.target_offset.x
self.target.y = main_Player.pos.y - main_Player.target_offset.y
self.target.x = main_player.pos.x - main_player.target_offset.x
self.target.y = main_player.pos.y - main_player.target_offset.y
local distance_x = self.target.x - self.pos.x
local distance_y = self.target.y - self.pos.y
local distance = math.sqrt(distance_x ^ 2 + distance_y ^ 2)
local angle = GetAngleFromVector(distance_x,distance_y)
local angle = getAngleFromVector(distance_x,distance_y)
self.draw_bow = false
if distance <= self.range then
if self.hostile == true then

View File

@@ -5,64 +5,65 @@ function Player:new(x,y)
o.type = "player"
-- physics
o.moveSpeed = 1.3 -- gameworld pixels
o.zeroSpeed = 0.01 -- gameworld pixels
o.zero_speed = 0.01 -- gameworld pixels
o.move_x = 0 -- gameworld pixels
o.noDriftFrames = 0 -- frames
o.move_speed = 1.3 -- gameworld pixels
o.airFriction = 0.01 -- gameworld pixels
o.groundFriction = 0.3 -- gameworld pixels
o.nodrift_frames = 0 -- frames
o.jumpImpulse = 3.5 -- gameworld pixels
o.air_friction = 0.01 -- gameworld pixels
o.ground_friction = 0.3 -- gameworld pixels
o.wall_friction = 0.3 -- gameworld pixels
o.coyoteValue = 5 -- frames
o.coyoteAmount = 5 -- int
o.jump_impulse = 3.5 -- gameworld pixels
o.coyote_value = 5 -- frames
o.coyote_amount = 5 -- int
o.dashCooldownTime = 0.1 -- seconds
o.dashCooldownTimer = 0 -- seconds
-- dash values
o.dashTimer = 0 -- seconds
o.dashTime = 0.15 -- seconds
o.dashDistance = 40 -- gameworld pixels
o.dashSpeed = o.dashDistance / (o.dashTime*60) -- pixels
o.dashCount = 1 -- int
o.dashAmount = 10 -- int
o.dash_timer = 0 -- seconds
o.dash_time = 0.15 -- seconds
o.dash_distance = 40 -- gameworld pixels
o.dash_speed = o.dash_distance / (o.dash_time*60) -- pixels
o.dash_count = 1 -- int
o.dash_amount = 10 -- int
o.dash_cooldown_time = 0.1 -- seconds
o.dash_cooldown_timer = 0 -- seconds
-- hook values
o.hookSwingSpeed = math.rad(0.05)
o.hookAnchor = {
o.hook_swing_speed = math.rad(0.05)
o.hook_anchor = {
x = nil,
y = nil
}
-- walljump values
o.walljumpNoDriftAmount = 12
o.walljumpImpulse = { x = 2.5, y = 3.5 }
o.walljumpFriction = 0.3 -- gameworld pixels
o.walljump_nodrift_amount = 12
o.walljump_impulse = { x = 2.5, y = 3.5 }
-- light values
o.light_radius = 40 -- screen pixels
-- status
o.canJump = true
o.canFall = true
o.canFriction = true
o.canHook = true
o.canWalljump = true
o.can_jump = true
o.can_fall = true
o.can_friction = true
o.can_hook = true
o.can_walljump = true
o.isDashing = false
o.isHooked = false
o.isSliding = false
o.isJumping = false
o.isOnGround = false
o.isOnLadder = false
o.is_dashing = false
o.is_hooked = false
o.is_sliding = false
o.is_jumping = false
o.is_on_ground = false
o.is_on_ladder = false
o.maskType = animation.moth_mask
o.wallHit = 0
o.mask_type = animation.moth_mask
o.wall_hit = 0
o.anchorRespawn = {
o.respawn_anchor = {
x = o.pos.x,
y = o.pos.y
}
@@ -71,14 +72,14 @@ function Player:new(x,y)
o.target_offset = {x = 0, y = 0}
o.body = Animation:new(animation.nancy.idle)
o.mask = Animation:new(animation.moth_mask.idle)
o:centerOffset(o.body)
o:createBox(o.body,0,3,-1,-3)
-- lights
o.light = Light:new(o.pos.x,o.pos.y,o.light_radius)
table.insert(LoadedObjects.Entities,o)
o.id = #LoadedObjects.Entities
o:id()
setmetatable(o, self)
self.__index = self
@@ -86,67 +87,66 @@ function Player:new(x,y)
end
function Player:doLogic()
self:adjustLight(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
-- reset coyote_value
if self.is_on_ground then
self.coyote_value = self.coyote_amount
elseif self.coyote_value > 0 then
self.coyote_value = self.coyote_value - 1
end
-- not dashing, normal movment
if self.dashTimer <= 0 then
if self.dash_timer <= 0 then
-- horizontal movement
if not self.isHooked then
if self.noDriftFrames > 0 then
if not self.is_hooked then
if self.nodrift_frames > 0 then
self.move_x = 0
elseif Keybind:CheckDown(Keybind.move.left) then
elseif Keybind:checkDown(Keybind.move.left) then
self.move_x = -1
self.vel.x = math.min(self.vel.x, -self.moveSpeed)
elseif Keybind:CheckDown(Keybind.move.right) then
self.vel.x = math.min(self.vel.x, -self.move_speed)
elseif Keybind:checkDown(Keybind.move.right) then
self.move_x = 1
self.vel.x = math.max(self.vel.x, self.moveSpeed)
self.vel.x = math.max(self.vel.x, self.move_speed)
end
end
-- jump if on ground (coyotevalue) or if 0
if self.canJump and Keybind:CheckPressed(Keybind.move.jump) then
if self.canWalljump and self.wallHit ~= 0 then
self.isSliding = false
self.vel.y = -self.walljumpImpulse.y
self.vel.x = -self.walljumpImpulse.x * self.wallHit
if self.can_jump and Keybind:checkPressed(Keybind.move.jump) then
if self.can_walljump and self.wall_hit ~= 0 then
self.is_sliding = false
self.vel.y = -self.walljump_impulse.y
self.vel.x = -self.walljump_impulse.x * self.wall_hit
self.move_x = 0
self.sprite_flip.x = -self.sprite_flip.x
self.noDriftFrames = self.walljumpNoDriftAmount
elseif self.coyoteValue > 0 then
self.vel.y = -self.jumpImpulse
self.coyoteValue = 0
self.nodrift_frames = self.walljump_nodrift_amount
elseif self.coyote_value > 0 then
self.vel.y = -self.jump_impulse
self.coyote_value = 0
end
end
end
-- dash timer
self.dashCooldownTimer = math.max(0,self.dashCooldownTimer - current_dt)
self.dash_cooldown_timer = math.max(0,self.dash_cooldown_timer - current_dt)
-- try to dash
if Keybind:CheckDown(Keybind.move.dash) then
if self.dashCooldownTimer == 0
and not self.isDashing
and self.dashCount > 0 then
if Keybind:checkDown(Keybind.move.dash) then
if self.dash_cooldown_timer == 0
and not self.is_dashing
and self.dash_count > 0 then
self:unhook()
-- state player
self.isDashing = true
self.dashCount = self.dashCount - 1
self.is_dashing = true
self.dash_count = self.dash_count - 1
-- get dash direction
local vertical = 0
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.down) then vertical = vertical + 1 end
if Keybind:checkDown(Keybind.move.up) then vertical = vertical - 1 end
local horizontal = 0
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.right) 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
@@ -154,23 +154,23 @@ function Player:doLogic()
end
-- set dash values
self.dashDirection = GetAngleFromVector(horizontal, vertical)
self.dashTimer = math.floor(self.dashTime * game.framerate)
self.dashDirection = getAngleFromVector(horizontal, vertical)
self.dash_timer = math.floor(self.dash_time * game.framerate)
end
else
-- not dashing!
self.isDashing = false
self.is_dashing = false
end
if self.canHook and Keybind:CheckPressed(Keybind.move.hook) then
if self.isHooked then
if self.can_hook and Keybind:checkPressed(Keybind.move.hook) then
if self.is_hooked then
self:unhook()
else
local anchor = self:checkNearest("hook_anchor",self.hookDistance)
local anchor = self:checkNearest("hook_anchor",self.hook_distance)
if anchor then
self.isHooked = true
self.hookDistance = anchor.hookDistance
self.hookAnchor = {
self.is_hooked = true
self.hook_distance = anchor.hook_distance
self.hook_anchor = {
x = anchor.pos.x,
y = anchor.pos.y
}
@@ -180,39 +180,39 @@ function Player:doLogic()
end
function Player:doPhysics()
if self.dashTimer <= 0 then
if self.isOnGround then
self.vel.x = self.vel.x * (1-self.groundFriction)
if self.dash_timer <= 0 then
if self.is_on_ground then
self.vel.x = self.vel.x * (1-self.ground_friction)
else
self.vel.x = self.vel.x * (1-self.airFriction)
self.vel.x = self.vel.x * (1-self.air_friction)
end
self.isSliding = false
if self.wallHit == 0 then
self.vel.y = self.vel.y * (1-self.airFriction)
elseif self.noDriftFrames ~= self.walljumpNoDriftAmount then
self.isSliding = true
self.vel.y = self.vel.y * (1-self.walljumpFriction)
self.is_sliding = false
if self.wall_hit == 0 then
self.vel.y = self.vel.y * (1-self.air_friction)
elseif self.nodrift_frames ~= self.walljump_nodrift_amount then
self.is_sliding = true
self.vel.y = self.vel.y * (1-self.wall_friction)
end
if math.abs(self.vel.x) < self.zeroSpeed then self.vel.x = 0 end
if math.abs(self.vel.x) < self.zero_speed then self.vel.x = 0 end
end
-- reset state
self.canFall = true
self.isOnGround = false
self.can_fall = true
self.is_on_ground = false
-- adjust timers
self.dashTimer = self.dashTimer - 1
self.noDriftFrames = self.noDriftFrames - 1
self.dash_timer = self.dash_timer - 1
self.nodrift_frames = self.nodrift_frames - 1
-- DASH STATE
if self.dashTimer > 0 then
self.canFall = false
if self.dash_timer > 0 then
self.can_fall = false
-- dash particle
local particle_data = {
animation = self.body,
sprite_tint = HEX2RGB("#fed100"),
sprite_tint = hex2rgb("#fed100"),
sprite_alpha = 0.5,
sprite_flip = {
x = self.sprite_flip.x,
@@ -220,32 +220,32 @@ function Player:doPhysics()
}
}
Particle:new(self.pos.x,self.pos.y,particle_data)
self.dashCooldownTimer = self.dashCooldownTime
self.dash_cooldown_timer = self.dash_cooldown_time
-- dash movement
self.vel.x = self.dashSpeed * math.cos(self.dashDirection)
self.vel.y = self.dashSpeed * math.sin(self.dashDirection)
self.vel.x = self.dash_speed * math.cos(self.dashDirection)
self.vel.y = self.dash_speed * math.sin(self.dashDirection)
end
-- hook state
if self.isHooked then
if self.is_hooked then
self.move_x = 0
local hook = Vector(self.pos.x, self.pos.y, self.hookAnchor.x, self.hookAnchor.y)
local dist = math.min(GetVectorValue(hook), self.hookDistance)
local hook = vector(self.pos.x, self.pos.y, self.hook_anchor.x, self.hook_anchor.y)
local dist = math.min(getVectorValue(hook), self.hook_distance)
local hook_angle = GetAngleFromVector(hook[1],hook[2])-math.rad(180)
local hook_angle = getAngleFromVector(hook[1],hook[2])-math.rad(180)
if Keybind:CheckDown(Keybind.move.right) then
hook_angle = hook_angle - self.hookSwingSpeed
if Keybind:checkDown(Keybind.move.right) then
hook_angle = hook_angle - self.hook_swing_speed
end
if Keybind:CheckDown(Keybind.move.left) then
hook_angle = hook_angle + self.hookSwingSpeed
if Keybind:checkDown(Keybind.move.left) then
hook_angle = hook_angle + self.hook_swing_speed
end
local particle_data = {
animation = self.body,
sprite_tint = HEX2RGB("#fed100"),
sprite_tint = hex2rgb("#fed100"),
sprite_alpha = 0.5,
sprite_flip = {
x = self.sprite_flip.x,
@@ -254,8 +254,8 @@ function Player:doPhysics()
}
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)
local pos_x = self.hook_anchor.x + dist * math.cos(hook_angle)
local pos_y = self.hook_anchor.y + dist * math.sin(hook_angle)
self.vel.x = self.vel.x + pos_x - self.pos.x
self.vel.y = self.vel.y + pos_y - self.pos.y
self.pos.x = pos_x
@@ -263,18 +263,18 @@ function Player:doPhysics()
end
if self.canFall then
if self.can_fall then
-- not in dash
self.dashTimer = 0
self.dash_timer = 0
self.vel.y = self.vel.y + gravity
end
-- horizontal collision
if not self:isCollidingAt(self.pos.x + self.vel.x, self.pos.y, LoadedObjects.Collisions) then
self.pos.x = self.pos.x + self.vel.x
self.wallHit = 0
self.wall_hit = 0
else
self.wallHit = math.sign(self.vel.x)
self.wall_hit = math.sign(self.vel.x)
self.vel.x = 0
end
@@ -283,8 +283,8 @@ function Player:doPhysics()
self.pos.y = self.pos.y + self.vel.y
else
if self.vel.y > 0 then
self.isOnGround = true
self.dashCount = self.dashAmount
self.is_on_ground = true
self.dash_count = self.dash_amount
end
self.vel.y = 0
end
@@ -293,16 +293,18 @@ function Player:doPhysics()
if self:isCollidingAt(self.pos.x, self.pos.y, LoadedObjects.Hazards) then
self:respawn()
end
self:adjustLight(self.target_offset.x,self.target_offset.y)
end
function Player:respawn()
self.pos.x = self.anchorRespawn.x
self.pos.y = self.anchorRespawn.y
self.pos.x = self.respawn_anchor.x
self.pos.y = self.respawn_anchor.y
end
function Player:handleAnimation()
-- flip sprite to look in the direction is moving
if self.isHooked then
if self.is_hooked then
if self.vel.x ~= 0 then
self.sprite_flip.x = math.sign(self.vel.x)
end
@@ -311,18 +313,18 @@ function Player:handleAnimation()
end
-- animation priority
if self.vel.y > 1.25 or self.isSliding then
if self.vel.y > 1.25 or self.is_sliding then
self.body = self.body:change(animation.nancy.fall)
self.mask = self.mask:change(self.maskType.fall)
self.mask = self.mask:change(self.mask_type.fall)
elseif self.vel.y < 0 then
self.body = self.body:change(animation.nancy.jump)
self.mask = self.mask:change(self.maskType.jump)
self.mask = self.mask:change(self.mask_type.jump)
elseif self.vel.x + self.move_x ~= 0 then
self.body = self.body:change(animation.nancy.run)
self.mask = self.mask:change(self.maskType.run)
self.mask = self.mask:change(self.mask_type.run)
else
self.body = self.body:change(animation.nancy.idle)
self.mask = self.mask:change(self.maskType.idle)
self.mask = self.mask:change(self.mask_type.idle)
end
-- special case: idle animation gets slower by time
@@ -332,30 +334,30 @@ function Player:handleAnimation()
end
end
if self.isHooked then
if self.is_hooked 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
-Camera.pos.x + self.hook_anchor.x,
-Camera.pos.y + self.hook_anchor.y
)
end
self.body:animate()
self:draw(self.body)
if self.dashCount > 0 then
if self.dash_count > 0 then
self:draw(self.mask)
end
self.move_x = 0
end
function Player:unhook()
self.isHooked = false
self.hookAnchor = nil
self.is_hooked = false
self.hook_anchor = nil
end
function Player:debug()
Entity.debug(self)
love.graphics.print("wallHit: "..self.wallHit)
love.graphics.print("wall_hit: "..self.wall_hit)
end