declare bullet_base before bullets

This commit is contained in:
Kistaro Windrider 2023-09-30 15:02:34 -07:00
parent 6f9517cee1
commit fb95085bd9
Signed by: kistaro
SSH Key Fingerprint: SHA256:TBE2ynfmJqsAf0CP6gsflA0q5X5wD5fVKWPsZ7eVUg8

View File

@ -1087,6 +1087,85 @@ example_level = {
[700]=spawn_blocking_boss_chasey, [700]=spawn_blocking_boss_chasey,
[701]=eol [701]=eol
} }
-->8
-- bullet and gun behaviors
bullet_base = {
enemyspd = 0.5
}
mknew(bullet_base)
gun_base = {
shoot_ready = -32768,
icon = 20
}
mknew(gun_base)
function bullet_base:hitship(_)
self:die()
return true
end
function bullet_base:die()
end
function bullet_base:move()
self.x += self.dx
if self.enemy then
self.y += self.dy
if self.y > 128 then
self:die()
return true
end
else
self.y -= self.dy
if self.y < -8*self.height then
self:die()
return true
end
end
return false
end
function bullet_base:draw()
spr(self.sprite, self.x, self.y, self.width, self.height)
end
function bullet_base:spawn_at(x, y)
self.x = x - self.center_x_off
if self.enemy then
self.dx *= self.enemyspd
self.dy *= self.enemyspd
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
function gun_base:shoot(x, y)
if (lframe < self.shoot_ready) return false
if self.ammo then
if (self.ammo <= 0) return false
self.ammo -= 1
end
self.shoot_ready = lframe + self.cooldown
self:actually_shoot(x, y)
return true
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
@ -1287,83 +1366,6 @@ vulcan_gun = gun_base.new{
} }
mknew(vulcan_gun) mknew(vulcan_gun)
-->8
-- bullet and gun behaviors
bullet_base = {
enemyspd = 0.5
}
mknew(bullet_base)
gun_base = {
shoot_ready = -32768,
icon = 20
}
mknew(gun_base)
function bullet_base:hitship(_)
self:die()
return true
end
function bullet_base:die()
end
function bullet_base:move()
self.x += self.dx
if self.enemy then
self.y += self.dy
if self.y > 128 then
self:die()
return true
end
else
self.y -= self.dy
if self.y < -8*self.height then
self:die()
return true
end
end
return false
end
function bullet_base:draw()
spr(self.sprite, self.x, self.y, self.width, self.height)
end
function bullet_base:spawn_at(x, y)
self.x = x - self.center_x_off
if self.enemy then
self.dx *= self.enemyspd
self.dy *= self.enemyspd
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
function gun_base:shoot(x, y)
if (lframe < self.shoot_ready) return false
if self.ammo then
if (self.ammo <= 0) return false
self.ammo -= 1
end
self.shoot_ready = lframe + self.cooldown
self:actually_shoot(x, y)
return true
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
-- readme.md -- readme.md