halfway through bullet refactor
This commit is contained in:
parent
60b685d94b
commit
a4658e3ef4
113
vacuum_gambit.p8
113
vacuum_gambit.p8
@ -18,6 +18,11 @@ function csv(s)
|
|||||||
end
|
end
|
||||||
return ret
|
return ret
|
||||||
end
|
end
|
||||||
|
function const_fxn(x)
|
||||||
|
return function()
|
||||||
|
return x
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- generate standard "overlay"
|
-- generate standard "overlay"
|
||||||
-- constructor for type tt.
|
-- constructor for type tt.
|
||||||
@ -580,9 +585,15 @@ end
|
|||||||
-->8
|
-->8
|
||||||
-- bullet and gun behaviors
|
-- bullet and gun behaviors
|
||||||
|
|
||||||
bullet_base = {
|
function player_blt_cat()
|
||||||
enemyspd = 0.5
|
return pbullets
|
||||||
}
|
end
|
||||||
|
|
||||||
|
function enemy_blt_cat()
|
||||||
|
return ebullets
|
||||||
|
end
|
||||||
|
|
||||||
|
bullet_base = { }
|
||||||
mknew(bullet_base)
|
mknew(bullet_base)
|
||||||
|
|
||||||
gun_base = {
|
gun_base = {
|
||||||
@ -601,19 +612,11 @@ end
|
|||||||
|
|
||||||
function bullet_base:move()
|
function bullet_base:move()
|
||||||
self.x += self.dx
|
self.x += self.dx
|
||||||
if self.enemy then
|
|
||||||
self.y += self.dy
|
self.y += self.dy
|
||||||
if self.y > 128 then
|
if (self.y > 128) or (self.y < -8 * self.height) then
|
||||||
self:die()
|
self:die()
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
else
|
|
||||||
self.y -= self.dy
|
|
||||||
if self.y < -8*self.height then
|
|
||||||
self:die()
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -621,19 +624,20 @@ function bullet_base:draw()
|
|||||||
spr(self.sprite, self.x, self.y, self.width, self.height)
|
spr(self.sprite, self.x, self.y, self.width, self.height)
|
||||||
end
|
end
|
||||||
|
|
||||||
function bullet_base:spawn_at(x, y)
|
-- An `actually_shoot` factory
|
||||||
self.x = x - self.center_x_off
|
-- for trivial guns
|
||||||
if self.enemy then
|
function spawn_one(t)
|
||||||
self.dx *= self.enemyspd
|
return function(gun, x, y)
|
||||||
self.dy *= self.enemyspd
|
t.new{}:spawn_at(x, y)
|
||||||
self.y = y + self.top_y_off
|
|
||||||
ebullets:push_back(self)
|
|
||||||
else
|
|
||||||
self.y = y - (8 * self.height) + self.bottom_y_off
|
|
||||||
pbullets:push_back(self)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function bullet_base:spawn_at(x, y)
|
||||||
|
self.x = x - self.x_off
|
||||||
|
self.y = y - self.y_off
|
||||||
|
self.category():push_back(self)
|
||||||
|
end
|
||||||
|
|
||||||
function gun_base:shoot(x, y)
|
function gun_base:shoot(x, y)
|
||||||
if (lframe < self.shoot_ready) return false
|
if (lframe < self.shoot_ready) return false
|
||||||
if self.ammo then
|
if self.ammo then
|
||||||
@ -645,23 +649,12 @@ function gun_base:shoot(x, y)
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
function gun_base:actually_shoot(x, y)
|
|
||||||
local typ = self.t
|
|
||||||
local b = typ.new{
|
|
||||||
enemy = self.enemy,
|
|
||||||
sprite = self.enemy and typ.esprite or typ.psprite,
|
|
||||||
}
|
|
||||||
b:spawn_at(x, y)
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
-->8
|
-->8
|
||||||
-- bullets and guns
|
-- bullets and guns
|
||||||
|
|
||||||
zap = bullet_base.new{
|
zap_e = bullet_base.new{
|
||||||
--shape
|
--shape
|
||||||
psprite = 8, --index of player ammo sprite
|
sprite = 9, --index of enemy ammo sprite
|
||||||
esprite = 9, -- index of enemy ammo sprite
|
|
||||||
width = 1, --in 8x8 blocks
|
width = 1, --in 8x8 blocks
|
||||||
height = 1,
|
height = 1,
|
||||||
hurt = { -- hurtbox - where this ship can be hit
|
hurt = { -- hurtbox - where this ship can be hit
|
||||||
@ -670,33 +663,42 @@ zap = bullet_base.new{
|
|||||||
width = 2,
|
width = 2,
|
||||||
height = 8
|
height = 8
|
||||||
},
|
},
|
||||||
center_x_off = 1, -- how to position by ship
|
x_off = 1, -- how to position by ship
|
||||||
bottom_y_off = 0,
|
y_off = 0,
|
||||||
top_y_off = 0,
|
|
||||||
|
|
||||||
damage = 1,
|
damage = 1,
|
||||||
dx = 0, -- px/frame
|
dx = 0, -- px/frame
|
||||||
dy = 8,
|
dy = -4,
|
||||||
|
|
||||||
hitship = function(_, _)
|
hitship = const_fxn(true),
|
||||||
return true
|
|
||||||
end
|
category = enemy_blt_cat,
|
||||||
}
|
}
|
||||||
mknew(zap)
|
mknew(zap_e)
|
||||||
|
|
||||||
zap_gun = gun_base.new{
|
zap_p = zap_e.new{
|
||||||
enemy = false,
|
sprite = 8,
|
||||||
|
dy = 8,
|
||||||
|
category = player_blt_cat,
|
||||||
|
}
|
||||||
|
mknew(zap_p)
|
||||||
|
|
||||||
|
zap_gun_e = gun_base.new{
|
||||||
power = 20, -- power consumed per shot
|
power = 20, -- power consumed per shot
|
||||||
cooldown = 0x0.000a, -- frames between shots
|
cooldown = 0x0.000a, -- frames between shots
|
||||||
ammo = nil, -- unlimited ammo - main gun
|
ammo = nil, -- unlimited ammo - main gun
|
||||||
t = zap -- metatable of bullet to fire
|
actually_shoot = spawn_one(zap_e),
|
||||||
}
|
}
|
||||||
mknew(zap_gun)
|
mknew(zap_gun_e)
|
||||||
|
|
||||||
|
zap_gun_p = zap_gun_e.new{
|
||||||
|
actually_shoot = spawn_one(zap_p),
|
||||||
|
}
|
||||||
|
mknew(zap_gun_p)
|
||||||
|
|
||||||
blast = bullet_base.new{
|
blast = bullet_base.new{
|
||||||
--shape
|
--shape
|
||||||
psprite = 12, --index of player ammo sprite
|
sprite = 12, --index of player ammo sprite
|
||||||
esprite = 3, -- index of enemy ammo sprite
|
|
||||||
width = 1, --in 8x8 blocks
|
width = 1, --in 8x8 blocks
|
||||||
height = 1,
|
height = 1,
|
||||||
hurt = { -- hurtbox - where this ship can be hit
|
hurt = { -- hurtbox - where this ship can be hit
|
||||||
@ -705,9 +707,8 @@ blast = bullet_base.new{
|
|||||||
width = 6,
|
width = 6,
|
||||||
height = 6
|
height = 6
|
||||||
},
|
},
|
||||||
center_x_off = 4, -- how to position by ship
|
x_off = 4, -- how to position by ship
|
||||||
bottom_y_off = 0,
|
y_off = 0,
|
||||||
top_y_off = 0,
|
|
||||||
|
|
||||||
damage = 4,
|
damage = 4,
|
||||||
dx = 0, -- px/frame
|
dx = 0, -- px/frame
|
||||||
@ -736,18 +737,18 @@ blast = bullet_base.new{
|
|||||||
self.awaitcancel = false
|
self.awaitcancel = false
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
end
|
end,
|
||||||
|
category=player_blt_cat
|
||||||
}
|
}
|
||||||
mknew(blast)
|
mknew(blast)
|
||||||
|
|
||||||
blast_gun = gun_base.new{
|
blast_gun = gun_base.new{
|
||||||
icon = 13,
|
icon = 13,
|
||||||
enemy = false,
|
power = 0, -- only cost is ammo
|
||||||
power = 0, -- ammo, not power
|
|
||||||
cooldown = 0x0.0020, -- frames between shots
|
cooldown = 0x0.0020, -- frames between shots
|
||||||
ammo = 5,
|
ammo = 5,
|
||||||
maxammo = 5,
|
maxammo = 5,
|
||||||
t = blast -- type of bullet to fire
|
actually_shoot = spawn_one(blast),
|
||||||
}
|
}
|
||||||
mknew(blast_gun)
|
mknew(blast_gun)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user