What's happening is that the ent.hitbox variables don't exist for the first frame yet. Only when the update function is called, they're added in the ent table. To solve, just add them in the load function in char_cap.lua, sort of like so:
Code: Select all
function ent:load(x, y)
-- Character Settings
ent.name = "Captain Commando"
ent.health = 1000
ent.walkSpeed = 300
ent.jumpSpeed = -750 -- negative moves towards top of screen
ent.canJump = false
ent.inAir = true
ent.state = "idle" -- default state
ent.facing = -1
ent.xOffset = 0
ent.yOffset = -17 -- may be sloppy implementation for now...
ent.width = 128 -- base collision size
ent.height = 128 -- base collision size
ent.myColor = {0, 200, 50}
ent.alignX = 0
ent.alignY = 0
-------------- Add them here, for example:
ent.hitboxX = 1
ent.hitboxY = 1
ent.hitboxW = 1
ent.hitboxH = 1
ent.image = g.newImage('images/char/cap/cap.png')
local g128 = anim8.newGrid(128, 128, ent.image:getWidth(1280), ent.image:getHeight(832))
capIdle = anim8.newAnimation(g128(1, 1), 10) -- slot 1, from row 1
capWalkL = anim8.newAnimation(g128("1-10", 2), 0.08) -- slot 1-10, from row 2
capWalkR = anim8.newAnimation(g128("1-10", 2), 0.08) -- slot 1-10, from row 2
local g160 = anim8.newGrid(160, 128, ent.image:getWidth(1280), ent.image:getHeight(832))
capDash = anim8.newAnimation(g160("1-8", 3, "1-3", 4), 0.08) -- slot 1-10, from row 2
local g160x2 = anim8.newGrid(160, 160, ent.image:getWidth(1280), ent.image:getHeight(832), 0, 512)
capJump = anim8.newAnimation(g160x2("1-7", 1), 0.07, "pauseAtEnd")
capFall = anim8.newAnimation(g160x2("8-8", 1, "1-3", 2), 0.15, "pauseAtEnd")
ent.playerAnim = capFall
print("Captain Commando: Created")
end