Compare commits
4 Commits
0c3a36f1fd
...
level_pars
Author | SHA1 | Date | |
---|---|---|---|
b91ebeb775
|
|||
ab687f8f6d
|
|||
bef95df6a1
|
|||
24435a3c15
|
585
updatedshmup.p8
585
updatedshmup.p8
@ -548,6 +548,284 @@ function ship_m:refresh_shield()
|
||||
self.shield_refresh_ready = lframe + self.shieldcooldown
|
||||
end
|
||||
|
||||
-->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
|
||||
-- bullets and guns
|
||||
|
||||
zap = bullet_base.new{
|
||||
--shape
|
||||
psprite = 8, --index of player ammo sprite
|
||||
esprite = 9, -- index of enemy ammo sprite
|
||||
width = 1, --in 8x8 blocks
|
||||
height = 1,
|
||||
hurt = { -- hurtbox - where this ship can be hit
|
||||
x_off = 0, -- upper left corner
|
||||
y_off = 0, -- relative to sprite
|
||||
width = 2,
|
||||
height = 8
|
||||
},
|
||||
center_x_off = 1, -- how to position by ship
|
||||
bottom_y_off = 0,
|
||||
top_y_off = 0,
|
||||
|
||||
damage = 1,
|
||||
dx = 0, -- px/frame
|
||||
dy = 8,
|
||||
|
||||
hitship = function(_, _)
|
||||
return true
|
||||
end
|
||||
}
|
||||
mknew(zap)
|
||||
|
||||
zap_gun = gun_base.new{
|
||||
enemy = false,
|
||||
power = 20, -- power consumed per shot
|
||||
cooldown = 0x0.000a, -- frames between shots
|
||||
ammo = nil, -- unlimited ammo - main gun
|
||||
t = zap -- metatable of bullet to fire
|
||||
}
|
||||
mknew(zap_gun)
|
||||
|
||||
blast = bullet_base.new{
|
||||
--shape
|
||||
psprite = 12, --index of player ammo sprite
|
||||
esprite = 3, -- index of enemy ammo sprite
|
||||
width = 1, --in 8x8 blocks
|
||||
height = 1,
|
||||
hurt = { -- hurtbox - where this ship can be hit
|
||||
x_off = 1, -- upper left corner
|
||||
y_off = 1, -- relative to sprite
|
||||
width = 6,
|
||||
height = 6
|
||||
},
|
||||
center_x_off = 4, -- how to position by ship
|
||||
bottom_y_off = 0,
|
||||
top_y_off = 0,
|
||||
|
||||
damage = 4,
|
||||
dx = 0, -- px/frame
|
||||
dy = 2,
|
||||
awaitcancel = false,
|
||||
|
||||
-- disable damage for 2 frames
|
||||
-- when hitting something
|
||||
hitship = function(self, _)
|
||||
if self.damage > 0 and not self.awaitcancel then
|
||||
self.awaitcancel = true
|
||||
once_next_frame(function()
|
||||
new_events:push_back{
|
||||
wait = 2,
|
||||
obj = self,
|
||||
saved_dmg = self.damage,
|
||||
move = function(self)
|
||||
self.wait -= 1
|
||||
if self.wait <= 0 then
|
||||
self.obj.damage = self.saved_dmg
|
||||
return true
|
||||
end
|
||||
end,
|
||||
}
|
||||
self.damage = 0
|
||||
self.awaitcancel = false
|
||||
end)
|
||||
end
|
||||
end
|
||||
}
|
||||
mknew(blast)
|
||||
|
||||
blast_gun = gun_base.new{
|
||||
icon = 13,
|
||||
enemy = false,
|
||||
power = 0, -- ammo, not power
|
||||
cooldown = 0x0.0020, -- frames between shots
|
||||
ammo = 5,
|
||||
maxammo = 5,
|
||||
t = blast -- type of bullet to fire
|
||||
}
|
||||
mknew(blast_gun)
|
||||
|
||||
protron = bullet_base.new{
|
||||
--shape
|
||||
psprite = 23, --index of player ammo sprite
|
||||
esprite = 24, -- index of enemy ammo sprite
|
||||
width = 1, --in 8x8 blocks
|
||||
height = 1,
|
||||
hurt = { -- hurtbox - where this ship can be hit
|
||||
x_off = 1, -- upper left corner
|
||||
y_off = 1, -- relative to sprite
|
||||
width = 2,
|
||||
height = 2
|
||||
},
|
||||
center_x_off = 1, -- how to position by ship
|
||||
bottom_y_off = 4,
|
||||
top_y_off = 0,
|
||||
|
||||
damage = 1,
|
||||
dx = 0, -- px/frame
|
||||
dy = 3,
|
||||
}
|
||||
mknew(protron)
|
||||
|
||||
protron_gun = gun_base.new{
|
||||
icon = 25,
|
||||
enemy = false,
|
||||
power = 35,
|
||||
cooldown = 0x0.000f, -- frames between shots
|
||||
ammo = nil,
|
||||
maxammo = nil,
|
||||
actually_shoot = function(self, x, y)
|
||||
local sprite = protron.psprite
|
||||
if (self.enemy) sprite=protron.esprite
|
||||
for i=1,3 do
|
||||
local b = protron.new{
|
||||
enemy=self.enemy,
|
||||
sprite=sprite,
|
||||
dx = i,
|
||||
dy = 4-i
|
||||
}
|
||||
b:spawn_at(x,y)
|
||||
local b2 = protron.new{
|
||||
enemy=self.enemy,
|
||||
sprite=sprite,
|
||||
dx = -i,
|
||||
dy = 4-i
|
||||
}
|
||||
b2:spawn_at(x,y)
|
||||
end
|
||||
local bup = protron.new{
|
||||
enemy=self.enemy,
|
||||
sprite=sprite,
|
||||
dy=4
|
||||
}
|
||||
bup:spawn_at(x,y)
|
||||
end
|
||||
}
|
||||
mknew(protron_gun)
|
||||
|
||||
vulcan = bullet_base.new{
|
||||
--shape
|
||||
psprite = 22, --index of player ammo sprite
|
||||
esprite = 21, -- index of enemy ammo sprite
|
||||
width = 1, --in 8x8 blocks
|
||||
height = 1,
|
||||
hurt = { -- hurtbox - where this ship can be hit
|
||||
x_off = 0, -- upper left corner
|
||||
y_off = 0, -- relative to sprite
|
||||
width = 1,
|
||||
height = 4
|
||||
},
|
||||
center_x_off = 0.5, -- how to position by ship
|
||||
bottom_y_off = 4,
|
||||
top_y_off = 0,
|
||||
|
||||
damage = 0.5,
|
||||
dx = 0, -- px/frame
|
||||
dy = 4,
|
||||
}
|
||||
mknew(vulcan)
|
||||
|
||||
vulcan_gun = gun_base.new{
|
||||
icon = 37,
|
||||
enemy = false,
|
||||
power = 8,
|
||||
cooldown = 0x0.0002, -- frames between shots
|
||||
ammo = nil,
|
||||
maxammo = nil,
|
||||
dxs = {0.35, -0.35, -0.7, 0.7, 0.35, -0.35},
|
||||
xoffs = {1, 0, -1, 1, 0, -1},
|
||||
dxidx = 1,
|
||||
actually_shoot = function(self, x, y)
|
||||
local sprite = self.enemy and vulcan.esprite or vulcan.psprite
|
||||
local b = vulcan.new{
|
||||
enemy=self.enemy,
|
||||
sprite=sprite,
|
||||
dx = self.dxs[self.dxidx],
|
||||
}
|
||||
b:spawn_at(self.xoffs[self.dxidx]+x,y)
|
||||
self.dxidx += 1
|
||||
if (self.dxidx > #self.dxs) self.dxidx = 1
|
||||
end
|
||||
}
|
||||
mknew(vulcan_gun)
|
||||
|
||||
-->8
|
||||
--ships, including player
|
||||
|
||||
@ -869,7 +1147,7 @@ function load_level(levelfile)
|
||||
current_level[row[1]] = eol
|
||||
else
|
||||
row.next = x
|
||||
currentlevel[row[1]]=row
|
||||
current_level[row[1]]=row
|
||||
end
|
||||
end
|
||||
assert(found_eol)
|
||||
@ -901,8 +1179,6 @@ end
|
||||
-->8
|
||||
-- example level
|
||||
|
||||
|
||||
|
||||
function spawn_blocking_rnd_x(typ)
|
||||
freeze += 1
|
||||
s = typ.new{
|
||||
@ -921,7 +1197,7 @@ function spawn_blocking_rnd_x(typ)
|
||||
end
|
||||
|
||||
function spawn_frownie()
|
||||
return spawn_rnd_x(frownie)
|
||||
return spawn_rnd(frownie)
|
||||
end
|
||||
|
||||
function spawn_blocking_frownie()
|
||||
@ -929,19 +1205,19 @@ function spawn_blocking_frownie()
|
||||
end
|
||||
|
||||
function spawn_blocky()
|
||||
spawn_rnd_x(blocky)
|
||||
spawn_rnd(blocky)
|
||||
end
|
||||
|
||||
function spawn_blocking_blocky()
|
||||
spawn_blocking_rnd_x(blocky)
|
||||
spawn_rnd(blocky, 1)
|
||||
end
|
||||
|
||||
function spawn_spewy()
|
||||
return spawn_spewy_at(rnd(104), -7)
|
||||
return spawn_rnd(spewy)
|
||||
end
|
||||
|
||||
function spawn_chasey()
|
||||
return spawn_chasey_at(rnd(104), -7)
|
||||
return spawn_rnd(chasey)
|
||||
end
|
||||
|
||||
function spawn_blocking_spewy()
|
||||
@ -986,15 +1262,7 @@ helpers = {
|
||||
}
|
||||
|
||||
function spawn_blocking_boss_chasey()
|
||||
freeze += 1
|
||||
local c = spawn_xl_chasey_at(44, -15)
|
||||
c.ice = 1
|
||||
c.die = function(self)
|
||||
freeze -= self.ice
|
||||
self.ice = 0
|
||||
chasey.die(self)
|
||||
end
|
||||
|
||||
local c = spawn_rnd(xl_chasey, 1)
|
||||
local nextspawn = lframe + 0x0.0080
|
||||
events:push_back{move=function()
|
||||
if lframe >= nextspawn then
|
||||
@ -1017,6 +1285,7 @@ end
|
||||
|
||||
-- blocking: 1 or 0
|
||||
function spawn_rnd(typ, blocking, goodie,altspr)
|
||||
blocking = blocking or 0
|
||||
freeze += blocking
|
||||
s = typ.new{
|
||||
x = rnd(104),
|
||||
@ -1045,13 +1314,13 @@ end
|
||||
function multi(times, interval, fnm, ...)
|
||||
local f,irm,vargs = _ENV[fnm],interval,pack(...)
|
||||
assert(type(f) == "function", fnm.." not a function")
|
||||
fnm(...)
|
||||
f(...)
|
||||
events:push_back{move=function()
|
||||
irm-=1
|
||||
if irm <= 0 then
|
||||
irm=interval
|
||||
times-=1
|
||||
fnm(unpack(vargs))
|
||||
f(unpack(vargs))
|
||||
return times <= 1
|
||||
end
|
||||
end}
|
||||
@ -1091,284 +1360,6 @@ example_level_csv=[[1,spawn_frownie
|
||||
700,spawn_blocking_boss_chasey
|
||||
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
|
||||
-- bullets and guns
|
||||
|
||||
zap = bullet_base.new{
|
||||
--shape
|
||||
psprite = 8, --index of player ammo sprite
|
||||
esprite = 9, -- index of enemy ammo sprite
|
||||
width = 1, --in 8x8 blocks
|
||||
height = 1,
|
||||
hurt = { -- hurtbox - where this ship can be hit
|
||||
x_off = 0, -- upper left corner
|
||||
y_off = 0, -- relative to sprite
|
||||
width = 2,
|
||||
height = 8
|
||||
},
|
||||
center_x_off = 1, -- how to position by ship
|
||||
bottom_y_off = 0,
|
||||
top_y_off = 0,
|
||||
|
||||
damage = 1,
|
||||
dx = 0, -- px/frame
|
||||
dy = 8,
|
||||
|
||||
hitship = function(_, _)
|
||||
return true
|
||||
end
|
||||
}
|
||||
mknew(zap)
|
||||
|
||||
zap_gun = gun_base.new{
|
||||
enemy = false,
|
||||
power = 20, -- power consumed per shot
|
||||
cooldown = 0x0.000a, -- frames between shots
|
||||
ammo = nil, -- unlimited ammo - main gun
|
||||
t = zap -- metatable of bullet to fire
|
||||
}
|
||||
mknew(zap_gun)
|
||||
|
||||
blast = bullet_base.new{
|
||||
--shape
|
||||
psprite = 12, --index of player ammo sprite
|
||||
esprite = 3, -- index of enemy ammo sprite
|
||||
width = 1, --in 8x8 blocks
|
||||
height = 1,
|
||||
hurt = { -- hurtbox - where this ship can be hit
|
||||
x_off = 1, -- upper left corner
|
||||
y_off = 1, -- relative to sprite
|
||||
width = 6,
|
||||
height = 6
|
||||
},
|
||||
center_x_off = 4, -- how to position by ship
|
||||
bottom_y_off = 0,
|
||||
top_y_off = 0,
|
||||
|
||||
damage = 4,
|
||||
dx = 0, -- px/frame
|
||||
dy = 2,
|
||||
awaitcancel = false,
|
||||
|
||||
-- disable damage for 2 frames
|
||||
-- when hitting something
|
||||
hitship = function(self, _)
|
||||
if self.damage > 0 and not self.awaitcancel then
|
||||
self.awaitcancel = true
|
||||
once_next_frame(function()
|
||||
new_events:push_back{
|
||||
wait = 2,
|
||||
obj = self,
|
||||
saved_dmg = self.damage,
|
||||
move = function(self)
|
||||
self.wait -= 1
|
||||
if self.wait <= 0 then
|
||||
self.obj.damage = self.saved_dmg
|
||||
return true
|
||||
end
|
||||
end,
|
||||
}
|
||||
self.damage = 0
|
||||
self.awaitcancel = false
|
||||
end)
|
||||
end
|
||||
end
|
||||
}
|
||||
mknew(blast)
|
||||
|
||||
blast_gun = gun_base.new{
|
||||
icon = 13,
|
||||
enemy = false,
|
||||
power = 0, -- ammo, not power
|
||||
cooldown = 0x0.0020, -- frames between shots
|
||||
ammo = 5,
|
||||
maxammo = 5,
|
||||
t = blast -- type of bullet to fire
|
||||
}
|
||||
mknew(blast_gun)
|
||||
|
||||
protron = bullet_base.new{
|
||||
--shape
|
||||
psprite = 23, --index of player ammo sprite
|
||||
esprite = 24, -- index of enemy ammo sprite
|
||||
width = 1, --in 8x8 blocks
|
||||
height = 1,
|
||||
hurt = { -- hurtbox - where this ship can be hit
|
||||
x_off = 1, -- upper left corner
|
||||
y_off = 1, -- relative to sprite
|
||||
width = 2,
|
||||
height = 2
|
||||
},
|
||||
center_x_off = 1, -- how to position by ship
|
||||
bottom_y_off = 4,
|
||||
top_y_off = 0,
|
||||
|
||||
damage = 1,
|
||||
dx = 0, -- px/frame
|
||||
dy = 3,
|
||||
}
|
||||
mknew(protron)
|
||||
|
||||
protron_gun = gun_base.new{
|
||||
icon = 25,
|
||||
enemy = false,
|
||||
power = 35,
|
||||
cooldown = 0x0.000f, -- frames between shots
|
||||
ammo = nil,
|
||||
maxammo = nil,
|
||||
actually_shoot = function(self, x, y)
|
||||
local sprite = protron.psprite
|
||||
if (self.enemy) sprite=protron.esprite
|
||||
for i=1,3 do
|
||||
local b = protron.new{
|
||||
enemy=self.enemy,
|
||||
sprite=sprite,
|
||||
dx = i,
|
||||
dy = 4-i
|
||||
}
|
||||
b:spawn_at(x,y)
|
||||
local b2 = protron.new{
|
||||
enemy=self.enemy,
|
||||
sprite=sprite,
|
||||
dx = -i,
|
||||
dy = 4-i
|
||||
}
|
||||
b2:spawn_at(x,y)
|
||||
end
|
||||
local bup = protron.new{
|
||||
enemy=self.enemy,
|
||||
sprite=sprite,
|
||||
dy=4
|
||||
}
|
||||
bup:spawn_at(x,y)
|
||||
end
|
||||
}
|
||||
mknew(protron_gun)
|
||||
|
||||
vulcan = bullet_base.new{
|
||||
--shape
|
||||
psprite = 22, --index of player ammo sprite
|
||||
esprite = 21, -- index of enemy ammo sprite
|
||||
width = 1, --in 8x8 blocks
|
||||
height = 1,
|
||||
hurt = { -- hurtbox - where this ship can be hit
|
||||
x_off = 0, -- upper left corner
|
||||
y_off = 0, -- relative to sprite
|
||||
width = 1,
|
||||
height = 4
|
||||
},
|
||||
center_x_off = 0.5, -- how to position by ship
|
||||
bottom_y_off = 4,
|
||||
top_y_off = 0,
|
||||
|
||||
damage = 0.5,
|
||||
dx = 0, -- px/frame
|
||||
dy = 4,
|
||||
}
|
||||
mknew(vulcan)
|
||||
|
||||
vulcan_gun = gun_base.new{
|
||||
icon = 37,
|
||||
enemy = false,
|
||||
power = 8,
|
||||
cooldown = 0x0.0002, -- frames between shots
|
||||
ammo = nil,
|
||||
maxammo = nil,
|
||||
dxs = {0.35, -0.35, -0.7, 0.7, 0.35, -0.35},
|
||||
xoffs = {1, 0, -1, 1, 0, -1},
|
||||
dxidx = 1,
|
||||
actually_shoot = function(self, x, y)
|
||||
local sprite = self.enemy and vulcan.esprite or vulcan.psprite
|
||||
local b = vulcan.new{
|
||||
enemy=self.enemy,
|
||||
sprite=sprite,
|
||||
dx = self.dxs[self.dxidx],
|
||||
}
|
||||
b:spawn_at(self.xoffs[self.dxidx]+x,y)
|
||||
self.dxidx += 1
|
||||
if (self.dxidx > #self.dxs) self.dxidx = 1
|
||||
end
|
||||
}
|
||||
mknew(vulcan_gun)
|
||||
|
||||
-->8
|
||||
-- readme.md
|
||||
|
||||
|
Reference in New Issue
Block a user