summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--camera.lua7
-rw-r--r--dyl.lua20
-rw-r--r--dyl.p812
-rw-r--r--entity.lua3
-rw-r--r--math.lua4
-rw-r--r--util.lua10
6 files changed, 39 insertions, 17 deletions
diff --git a/camera.lua b/camera.lua
index 22be0fc..b2dcf4c 100644
--- a/camera.lua
+++ b/camera.lua
@@ -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
diff --git a/dyl.lua b/dyl.lua
index a1174a9..e0914bd 100644
--- a/dyl.lua
+++ b/dyl.lua
@@ -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
diff --git a/dyl.p8 b/dyl.p8
index abc8922..2cfd619 100644
--- a/dyl.p8
+++ b/dyl.p8
@@ -47,12 +47,12 @@ __gfx__
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
-00000000000000000000030005c00050000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
-04444000000000000000300005cc0c50000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
-0499400000000000000880000511c150000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
-04444000000000000087880005111150000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
-00440000000000000088880005111150000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
-00000000000000000008800000555500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000990000000030005c00050000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+04444000009a79000000300005cc0c50000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+04994000009aa900000880000511c150000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+04444000009aa9000087880005111150000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+004400000097a9000088880005111150000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000990000008800000555500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00040000000400000000007004000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
diff --git a/entity.lua b/entity.lua
index 2758071..e383b4f 100644
--- a/entity.lua
+++ b/entity.lua
@@ -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)
diff --git a/math.lua b/math.lua
index dc5ba64..429e1ab 100644
--- a/math.lua
+++ b/math.lua
@@ -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
diff --git a/util.lua b/util.lua
index 5fd41d3..8f1de2a 100644
--- a/util.lua
+++ b/util.lua
@@ -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