diff options
| author | Elizabeth Alexander Hunt <me@liz.coffee> | 2026-05-14 09:09:08 -0700 |
|---|---|---|
| committer | Elizabeth Alexander Hunt <me@liz.coffee> | 2026-05-14 09:09:08 -0700 |
| commit | 8cd9ec2e98d27b414bc7cff3a5a98b0aad9099ce (patch) | |
| tree | 07d56ae38d4131e571932322b3c5061d12bbd8d6 | |
| parent | e51b2ab9998588d2c4c842d861806c81011d751b (diff) | |
| download | dyl8-8cd9ec2e98d27b414bc7cff3a5a98b0aad9099ce.tar.gz dyl8-8cd9ec2e98d27b414bc7cff3a5a98b0aad9099ce.zip | |
Fixes crash on equip
| -rw-r--r-- | camera.lua | 7 | ||||
| -rw-r--r-- | dyl.lua | 20 | ||||
| -rw-r--r-- | dyl.p8 | 12 | ||||
| -rw-r--r-- | entity.lua | 3 | ||||
| -rw-r--r-- | math.lua | 4 | ||||
| -rw-r--r-- | util.lua | 10 |
6 files changed, 39 insertions, 17 deletions
@@ -3,7 +3,7 @@ SCREEN = vec2(128, 128) _chunk_size = vec2(100, 100) _chunk_size:apply(function (v) assert(v % 2 == 0) end) _padding = (SCREEN - _chunk_size) / 2 -_interpolate_step = 20 +_interpolate_step = 22 assert(_chunk_size.x < SCREEN.x and _chunk_size.y < SCREEN.y) Camera = {} @@ -39,8 +39,13 @@ function from_chunk(chunk) return chunk * _chunk_size end +_cull_factor = 1/4 function Camera:render(entity) screen_position = (entity.sprite_position or entity.position) - self.position + if not screen_position:in_bounds(SCREEN * -_cull_factor, SCREEN * (1 + _cull_factor)) then + return + end + entity:render(screen_position) end @@ -9,7 +9,7 @@ function slashing_particle(following) :b_sprite_position(vec2(following.sprite_position)) :b_line_of_sight(vec2(following.line_of_sight)) :b_add_state( - States.Active, { + States.Equipped, { animation = { pos_y = { sequence = { 115, 116, 117 }, dt = _slashing_timer_sec / 3, reflect = vec2(true, true) }, neg_y = { sequence = { 115, 116, 117 }, dt = _slashing_timer_sec / 3 }, @@ -18,7 +18,7 @@ function slashing_particle(following) } } ) - :b_state(States.Active) + :b_state(States.Equipped) function SlashingParticleBuilder:transition_state() end @@ -167,14 +167,11 @@ function sword() } ) :b_state(States.Equipped) - return SwordBuilder:build() + e = SwordBuilder:build() + assert(e.states[States.Equipped]) + return e end -_enemy = enemy() -_sword = sword() -_wife = wife() -_bow = bow() - function player() PlayerBuilder = EntityBuilder:new(World) function PlayerBuilder:transition_state() @@ -214,10 +211,15 @@ function player() :b_state(States.Idle) return PlayerBuilder:build() end + +_enemy = enemy() +_sword = sword() +_wife = wife() +_bow = bow() _player = player() _player:equip(_sword) -_walk_speed = 35 -- powerup increase? +_walk_speed = 40 -- powerup increase? function handle_input() dpos = vec2(0, 0) if btn(0) then dpos.x -= 1 end @@ -47,12 +47,12 @@ __gfx__ 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -00000000000000000000030005c00050000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -04444000000000000000300005cc0c50000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -0499400000000000000880000511c150000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -04444000000000000087880005111150000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -00440000000000000088880005111150000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -00000000000000000008800000555500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000990000000030005c00050000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +04444000009a79000000300005cc0c50000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +04994000009aa900000880000511c150000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +04444000009aa9000087880005111150000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +004400000097a9000088880005111150000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000990000008800000555500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00040000000400000000007004000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 @@ -151,6 +151,7 @@ _equipped_item_distance = 6 function Entity:equip(that, dist) dist = dist or _equipped_item_distance self.equipped[that.id] = { entity = that, distance = dist } + that:transition_to(States.Equipped) end function Entity:equipped_from(parent, dist) @@ -210,7 +211,7 @@ end function EntityBuilder:b_add_state(name, state) if self.states == nil then self.states = {} end self.states[name] = state - if self.state == nil then self.state = name end + if self.state == nil then self:b_state(name) end return self end function EntityBuilder:b_state(name) @@ -14,6 +14,10 @@ Vec2.__div = function(a, b) end Vec2.__tostring = function(a) return "(" .. fmt(a.x) .. "," .. fmt(a.y) .. ")" end +function Vec2:in_bounds(low, hi) + return self.x >= low.x and self.x <= hi.x and self.y >= low.y and self.y <= hi.y +end + function Vec2:magnitude() return sqrt(self.x * self.x + self.y * self.y) end @@ -57,6 +57,16 @@ function filter(a, pred) return filtered end +function keys(t) + ks = {} + i = 1 + for k, v in pairs(t) do + ks[i] = k + i += 1 + end + return ks +end + function fmt(x, depth) depth = depth or 1 if (depth > 4) then return "STACK_OVERFLOW" end |
