diff options
| -rw-r--r-- | camera.lua | 6 | ||||
| -rw-r--r-- | collisions.lua | 9 | ||||
| -rw-r--r-- | dyl.lua | 107 | ||||
| -rw-r--r-- | dyl.p8 | 10 | ||||
| -rw-r--r-- | entity.lua | 12 | ||||
| -rw-r--r-- | map.lua | 24 |
6 files changed, 140 insertions, 28 deletions
@@ -42,11 +42,9 @@ 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 + if screen_position:in_bounds(SCREEN * -_cull_factor, SCREEN * (1 + _cull_factor)) then + entity:render(screen_position) end - - entity:render(screen_position) end function Camera:new(tracking) diff --git a/collisions.lua b/collisions.lua index 04575c4..f57554e 100644 --- a/collisions.lua +++ b/collisions.lua @@ -1,14 +1,17 @@ -sw, sh = 8, 8 function is_colliding(a, b) ax1, bx1 = a.position.x, b.position.x - ax2, bx2 = ax1 + sw, bx1 + sw + ax2, bx2 = ax1 + SPRITE_DIMS.x, bx1 + SPRITE_DIMS.y ay1, by1 = a.position.y, b.position.y - ay2, by2 = ay1 + sh, by1 + sh + ay2, by2 = ay1 + SPRITE_DIMS.y, by1 + SPRITE_DIMS.x return (ax1 < bx2 and ax2 > bx1 and ay1 < by2 and ay2 > by1) end function handle_collision(a, b) + if a.entity_type == Entities.Sword and b.entity_type == Entities.Player and b.equipped[a.id] == nil then + b:equip(a) + return + end if a.damage and b.health then if b:is_in_iframe() then return @@ -25,13 +25,40 @@ function slashing_particle(following) return SlashingParticleBuilder:build() end +function fire() + FireBuilder = EntityBuilder:new(World) + function FireBuilder:transition_state() + end + FireBuilder:b_type(Entities.Fire) + :b_position(vec2(50, 45)) + :b_sprite_position(vec2(50, 45)) + :b_line_of_sight(vec2(1, 0)) + :b_render_order(1) + :b_add_state( + States.Hot, { + animation = { + sequence = { 195, 196, 197, 198 }, dt = 0.20 + } + } + ) + :b_add_state( + States.Warm, { + animation = { + sequence = { 211, 212, 213, 214 }, dt = 0.20, + } + } + ) + :b_state(States.Hot) + return FireBuilder:build() +end + function enemy() EnemyBuilder = EntityBuilder:new(World) function EnemyBuilder:transition_state() end EnemyBuilder:b_type(Entities.Enemy) :b_health(10) - :b_position(vec2(30, 40)) + :b_position(vec2(30, -40)) :b_sprite_position(vec2(30, 40)) :b_line_of_sight(vec2(1, 0)) :b_render_order(1) @@ -68,8 +95,8 @@ function wife() :b_line_of_sight(vec2(1, 0)) :b_render_order(2) :b_collidable() - :b_position(vec2(50, 50)) - :b_sprite_position(vec2(30, 30)) + :b_position(vec2(42, 42)) + :b_sprite_position(vec2(42, 42)) :b_add_state( States.Idle, { animation = { @@ -107,8 +134,8 @@ function bow() :b_add_state( States.Drawn, { animation = { - pos_y = { sequence = { 81 }, dt = 1, reflect = vec2(false, true) }, - neg_y = { sequence = { 81 }, dt = 1 }, + pos_y = { sequence = { 97 }, dt = 1, reflect = vec2(false, true) }, + neg_y = { sequence = { 97 }, dt = 1 }, pos_x = { sequence = { 81 }, dt = 1 }, neg_x = { sequence = { 81 }, dt = 1, reflect = vec2(true, false) } } @@ -142,8 +169,7 @@ function sword() end SwordBuilder:b_type(Entities.Sword) :b_line_of_sight(vec2(1, 0)) - :b_position(vec2(0, 0)) - :b_sprite_position(vec2(0, 0)) + :b_position(vec2(-50, 20)) :b_render_order(0) :b_collidable() :b_add_state( @@ -166,10 +192,60 @@ function sword() } } ) - :b_state(States.Equipped) - e = SwordBuilder:build() - assert(e.states[States.Equipped]) - return e + :b_add_state( + States.Idle, { + animation = { + sequence = { 98 }, dt = 1 + } + } + ) + :b_state(States.Idle) + return SwordBuilder:build() +end + +function block(pos, sprite) + BlockBuilder = EntityBuilder:new(World) + function BlockBuilder:transition_state() + end + BlockBuilder + :b_type(Entities.Block) + -- :b_line_of_sight(vec2(1, 0)) + :b_render_order(2) + :b_collidable() + :b_position(vec2(pos)) + :b_add_state( + States.Idle, { + animation = { + sequence = { sprite }, dt = 1 + } + } + ) + :b_state(States.Idle) + return BlockBuilder:build() +end + +function door(pos) + return block(pos, 193) +end + +function building(pos) + b = { + { 0, 0, 2, 0 }, + { 1, 1, 1, 1 }, + { 1, 3, 1, 1 } + } + for y = 1,3 do + for x = 1,4 do + v = pos + (vec2(x - 1, y - 1) * SPRITE_DIMS) + if b[y][x] == 1 then + block(v, 192) + elseif b[y][x] == 2 then + block(v, 194) + elseif b[y][x] == 3 then + door(v) + end + end + end end function player() @@ -212,14 +288,17 @@ function player() return PlayerBuilder:build() end +building(vec2(10, -90)) + _enemy = enemy() _sword = sword() _wife = wife() -_bow = bow() +-- _bow = bow() +_fire = fire() _player = player() -_player:equip(_sword) +-- _player:equip(_sword) -_walk_speed = 40 -- powerup increase? +_walk_speed = 35 -- 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 -00000000000990000000030005c00050000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -04444000009a79000000300005cc0c50000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -04994000009aa900000880000511c150000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000030005c00050000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +04444000000990000000300005cc0c50000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +04994000009a7900000880000511c150000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 04444000009aa9000087880005111150000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -004400000097a9000088880005111150000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -00000000000990000008800000555500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00440000000990000088880005111150000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000008800000555500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00040000000400000000007004000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 @@ -4,8 +4,12 @@ Entities = { Enemy = 2, Bow = 3, Particle = 4, - Wife = 5 + Wife = 5, + Fire = 6, + Door = 7, + Block = 8 } + -- TODO: Why are these all in one object. We should have like "SpriteStates", "FireStates", etc. States = { Walk = "walk", Idle = "idle", @@ -13,9 +17,13 @@ States = { Equipped = "equipped", Slashing = "slashing", Drawing = "drawing", - Drawn = "drawn" + Drawn = "drawn", + Hot = "hot", + Warm = "warm" } +SPRITE_DIMS = vec2(8, 8) + Entity = {} Entity.__index = Entity @@ -0,0 +1,24 @@ +_t = { + H = { name = "home", color = 11 }, + C = { name = "current", color = 7, blink = true }, + K = { name = "visited", color = 6 }, + M = { name = "mystery", color = 2 }, + R = { name = "restock", color = 9 }, + E = { name = "empty", color = 0 } +} + +RealMap = { + { _t.E, _t.E, _t.E, _t.E, _t.E }, + { _t.E, _t.E, _t.E, _t.E, _t.E }, + { _t.R, _t.E, _t.H, _t.E, _t.E }, + { _t.E, _t.E, _t.E, _t.E, _t.E }, + { _t.E, _t.E, _t.E, _t.E, _t.E } +} + +DisplayMap = { + { _t.E, _t.E, _t.E, _t.E, _t.E }, + { _t.E, _t.E, _t.E, _t.E, _t.E }, + { _t.E, _t.E, _t.H, _t.E, _t.E }, + { _t.E, _t.E, _t.E, _t.E, _t.E }, + { _t.E, _t.E, _t.E, _t.E, _t.E } +}
\ No newline at end of file |
