diff options
| author | Elizabeth Hunt <me@liz.coffee> | 2026-04-26 16:12:38 -0700 |
|---|---|---|
| committer | Elizabeth Hunt <me@liz.coffee> | 2026-04-26 16:12:38 -0700 |
| commit | c8444758afa213ed89c9cf6d4793bd7812b0b734 (patch) | |
| tree | 855876aa7fc99b5982c90a7295050a6dc3014b6c | |
| parent | a81b080cc830d3073fda40ec777ab24f72cacfb9 (diff) | |
| download | dyl8-c8444758afa213ed89c9cf6d4793bd7812b0b734.tar.gz dyl8-c8444758afa213ed89c9cf6d4793bd7812b0b734.zip | |
Checkpoint
| -rw-r--r-- | collisions.lua | 42 | ||||
| -rw-r--r-- | dyl.lua | 5 | ||||
| -rw-r--r-- | dyl.p8 | 22 | ||||
| -rw-r--r-- | entity.lua | 2 | ||||
| -rw-r--r-- | util.lua | 2 |
5 files changed, 37 insertions, 36 deletions
diff --git a/collisions.lua b/collisions.lua index feb138b..4b9c430 100644 --- a/collisions.lua +++ b/collisions.lua @@ -1,30 +1,30 @@ sw, sh = 8, 8 function is_colliding(a, b) - ax1, bx1 = a.position.x, b.position.x - ax2, bx2 = ax1 + sw, bx1 + sw - ay1, by1 = a.position.y, b.position.y - ay2, by2 = ay1 + sh, by1 + sh - return (ax1 < bx2 and ax2 > bx1 - and ay1 < by2 and ay2 > by1) + ax1, bx1 = a.position.x, b.position.x + ax2, bx2 = ax1 + sw, bx1 + sw + ay1, by1 = a.position.y, b.position.y + ay2, by2 = ay1 + sh, by1 + sh + return (ax1 < bx2 and ax2 > bx1 + and ay1 < by2 and ay2 > by1) end function handle_collision(a, b) --- if b.typ == types.enemy then --- --print(b.id,100,100) --- end + if b.entity_type == Entities.Enemy then + print(b.id, b.id * 10, b.id * 10) + end end function run_collisions() - collidable = filter(World, function (e) return e.collision end) - for _ai, a in ipairs(collidable) do - for _bi, b in ipairs(collidable) do - if a.id == b.id then - goto continue - end - if is_colliding(a, b) then - handle_collision(a, b) - end - ::continue:: + collidable = filter(_World, function(e) return e.collision end) + for _ai, a in pairs(collidable) do + for _bi, b in pairs(collidable) do + if a.id == b.id then + goto continue + end + if is_colliding(a, b) then + handle_collision(a, b) + end + ::continue:: + end end - end -end +end
\ No newline at end of file @@ -7,7 +7,7 @@ function spawn_slashing_particle(e) -- transitions slash_animation:equipped_from(e, _slash_animation_distance) end - return slash_animation:b_type(Entities.Enemy) + return slash_animation:b_type(Entities.Particle) :b_line_of_sight(e.line_of_sight) :b_position(vec2(e.position)) :b_sprite_position(vec2(position)) @@ -99,8 +99,9 @@ bow:b_type(Entities.Bow) :build() sword = entity() +_attack_burst_sec = 0.200 function sword:transition_state() - if button_just_pressed(5) and self.state == States.Equipped then + if button_just_pressed(5) and self.state == States.Equipped and self.state_stopwatch > _attack_burst_sec then self:transition_to(States.Slashing) spawn_slashing_particle(self) elseif self.state == States.Slashing and self.state_stopwatch > _slashing_timer_sec then @@ -54,12 +54,12 @@ __gfx__ 00000000000000000008800000555500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -00040000000400000000007000000070000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -00504000005040000000075000000750000008e00005500005090000000900000000000000000000000000000000000000000000000000000000000000000000 -0050900005777900000075000000750000008e000055560000555550055555600000000000000000000000000000000000000000000000000000000000000000 -005040000500400000975000009750000058e0000006550000550000005500000000000000000000000000000000000000000000000000000000000000000000 -00504000005040000049000000490000006500000055500000500000005000000000000000000000000000000000000000000000000000000000000000000000 -00040000000400000400000004000000060000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00040000000400000000007004000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00504000005040000000075000490000000008e00005500005090000000900000000000000000000000000000000000000000000000000000000000000000000 +0050900005777900000075000097000000008e000055560000555550055555600000000000000000000000000000000000000000000000000000000000000000 +005040000500400000975000000570000058e0000006550000550000005500000000000000000000000000000000000000000000000000000000000000000000 +00504000005040000049000000005700006500000055500000500000005000000000000000000000000000000000000000000000000000000000000000000000 +00040000000400000400000000000570060000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000070000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000070000000000000000000800000000000050000000600000000000000000000000000000000000000000000000000000000000000000000 @@ -70,13 +70,13 @@ __gfx__ 00000000000550000000000000090000060000000000000000500000000500000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -00056000000600000000000000000000006000000000050000000000000000000000000000000000000000000000000000000000000000000000000000000000 +000c6000000600000000000000000000006000000000050000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000005650600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -00000000000560000000000005600000005665000000066000000000000000000000000000000000000000000000000000000000000000000000000000000000 -00000000000060000000000050000000066506060000056000000000000000000000000000000000000000000000000000000000000000000000000000000000 -00000000000650000005605000000000005000000000005600000000000000000000000000000000000000000000000000000000000000000000000000000000 +000000000005c0000000000005c00000005c650000000c6000000000000000000000000000000000000000000000000000000000000000000000000000000000 +000000000000600000000000500000000c6506060000056000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000c50000005c05000000000005000000000005c00000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000056600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -00000000000600000060000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +000000000006000000c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 @@ -42,7 +42,7 @@ function Entity:b_sprite_position(vec) return self end function Entity:b_type(entity_type) - self.entity_type = type + self.entity_type = entity_type return self end function Entity:b_equipped(equipped) @@ -45,7 +45,7 @@ end function filter(a, pred) filtered = {} - for k, v in ipairs(a) do + for k, v in pairs(a) do if pred(v) then filtered[k] = v end |
