Compare commits

..

No commits in common. "bad8452f3cc1ff994f92301bc2321b82d86919c8" and "e8ed97be9e512b24ca15c89cd72fd82a607f86d1" have entirely different histories.

View File

@ -153,7 +153,7 @@ function init_hpcols()
end
function wipe_level()
primary_ship = player.new()
primary_ship = new_p1()
init_hpcols()
pships = linked_list.new()
pships:push_back(primary_ship)
@ -440,150 +440,22 @@ function grab_p1_butts()
}
end
-->8
--ship behavior
scrollrate = 0.25 --in px/frame
ship_m = {
-- ships have no shield by default
shield = 0,
maxshield = 0,
shieldcost = 32767.9,
shieldcooldown = 180,
-- default generator behavior:
-- 10 seconds for a full charge
max_power = 600,
power = 600,
generator = 1, -- power gen per frame
invincible_until = -32768,
slip = true, -- most enemies slide
xmomentum = 0,
ymomentum = 0,
}
mknew(ship_m)
function ship_m:die()
self.dead = true
if (self.hp <= 0) boom(self.x+self.size*4, self.y+self.size*4,12*self.size, self.boss)
end
function ship_m:move()
self:refresh_shield()
self.power = min(self.max_power, self.power + self.generator)
butt = self:grab_butts()
if (butt[5] > 0) self:maybe_shoot(self.main_gun)
if (butt[4] > 0) self:maybe_shoot(self.special_gun)
if (butt[0]-butt[1] ~= 0 or butt[2]-butt[3] ~= 0) spark(self.sparks, self.x + 4*self.size, self.y + 4*self.size, butt, self.thrust, self.sparkodds)
self.xmomentum += (self.thrust * butt[1]) - (self.thrust * butt[0])
self.ymomentum += (self.thrust * butt[3]) - (self.thrust * butt[2])
self.xmomentum = mid(-self.maxspd, self.maxspd, self.xmomentum)
self.ymomentum = mid(-self.maxspd, self.maxspd, self.ymomentum)
self.x += self.xmomentum
self.y += self.ymomentum
if self == primary_self then
self.x = mid(0, 112 - 8 * self.size, self.x)
self.y = mid(0, 128 - 8 * self.size, self.y)
end
--friction
local d = self.drag
self.xmomentum -= mid(d, -d, self.xmomentum)
self.ymomentum -= mid(d, -d, self.ymomentum)
-- "scrolling" behavior
if self.slip then
self.y += scrollrate
if self.y >= 128 then
self:die()
return true
end
end
return false
end
function ship_m:draw()
if(self.fx_pal) pal(self.fx_pal)
spr(self.sprite, self.x, self.y, self.size, self.size)
pal()
end
function hurtbox(ship)
local h = ship.hurt
return {
x=ship.x + h.x_off,
y=ship.y + h.y_off,
width=h.width,
height=h.height
}
end
function ship_m:maybe_shoot(gun)
if (not gun) return
if (self.power < gun.power) return
if (not gun:shoot(self.x + self.fire_off_x, self.y + self.fire_off_y)) return
self.power -= gun.power
end
function ship_m:hitship(other)
return self:hitsomething(1)
end
function ship_m:hitbullet(b)
return self:hitsomething(b.damage)
end
function ship_m:hitsomething(dmg)
if (dmg <= 0) return false
if (lframe < self.invincible_until) return false
self.shield_refresh_ready = lframe + self.shieldcooldown
if self.shield >= dmg then
self.shield -= dmg
self:ow(true)
return false
end
dmg -= self.shield
self.shield = 0
self.hp -= dmg
if self.hp <= 0 then
self:die()
return true
end
self:ow(false)
return false
end
function ship_m:ow(shielded)
if (shielded) then
blip(self,12,3)
return
end
blip(self, 7, 3)
end
function ship_m:refresh_shield()
if (self.shield >= self.maxshield) return
if (lframe < self.shield_refresh_ready) return
if (self.power < self.shieldcost) return
self.shield += 1
self.power -= self.shieldcost
self.shield_refresh_ready = lframe + self.shieldcooldown
end
-->8
--ships, including player
-- XXX BOOKMARK XXX
function init_ship_mt()
setmetatable(player, ship_t)
setmetatable(frownie, ship_t)
setmetatable(blocky, frownie_t)
setmetatable(chasey, ship_t)
end
firespark = split"9, 8, 2, 5, 1"
smokespark = split"13, 13, 5, 5"
player = ship_m.new{
player = {
--shape
sprite = 1, --index of ship sprite
size = 1, --all ships are square; how many 8x8 sprites?
@ -632,13 +504,20 @@ player = ship_m.new{
return butts
end
}
mknew(player,
function(p)
p.main_gun = new_gun_of(zap_gun_t, false)
end
)
frownie = ship_m.new{
player_t = {
__index = player
}
function new_p1()
p = {
main_gun = new_gun_of(zap_gun_t, false)
}
setmetatable(p, player_t)
return p
end
frownie = {
--shape
sprite = 3, --index of ship sprite
size = 1, --all ships are square; how many 8x8 sprites?
@ -676,9 +555,11 @@ frownie = ship_m.new{
return butts
end, -- button fetch algorithm
}
mknew(frownie)
frownie_t = {
__index = frownie
}
blocky = frownie.new{
blocky = {
sprite = 10,
hp = 2,
hurt = {
@ -694,13 +575,16 @@ blocky = frownie.new{
else
self.sprite = 10
end
ship_m.ow(self)
ship_t.__index.ow(self)
end
}
mknew(blocky)
blocky_t = {
__index = blocky
}
function spawn_spewy_at(x, y)
local spewy = frownie.new{
local spewy = {
x = x,
y = y,
sprite = 26,
@ -724,11 +608,12 @@ function spawn_spewy_at(x, y)
return butts
end,
}
setmetatable(spewy, frownie_t)
eships:push_back(spewy)
return spewy
end
chasey = ship_m.new{
chasey = {
sprite = 5,
size = 1,
hurt = {
@ -761,20 +646,22 @@ chasey = ship_m.new{
return butts
end,
}
mknew(chasey)
chasey_t = {
__index = chasey
}
function spawn_chasey_at(x, y)
local c = chasey.new{
local c = {
x = x,
y = y,
main_gun = new_gun_of(zap_gun_t, true)
}
setmetatable(c, chasey_t)
eships:push_back(c)
return c
end
function spawn_xl_chasey_at(x, y)
local c = chasey.new{
local c = {
x = x,
y = y,
size = 2,
@ -801,10 +688,150 @@ function spawn_xl_chasey_at(x, y)
pal()
end,
}
setmetatable(c, chasey_t)
eships:push_back(c)
return c
end
-->8
--ship behavior
scrollrate = 0.25 --in px/frame
ship_m = {
-- ships have no shield by default
shield = 0,
maxshield = 0,
shieldcost = 32767.9,
shieldcooldown = 180,
-- default generator behavior:
-- 10 seconds for a full charge
max_power = 600,
power = 600,
generator = 1, -- power gen per frame
invincible_until = -32768,
slip = true, -- most enemies slide
xmomentum = 0,
ymomentum = 0,
}
ship_t = {
__index = ship_m,
}
function ship_m:die()
self.dead = true
if (self.hp <= 0) boom(self.x+self.size*4, self.y+self.size*4,12*self.size, self.boss)
end
function ship_m:move()
self:refresh_shield()
self.power = min(self.max_power, self.power + self.generator)
butt = self:grab_butts()
if (butt[5] > 0) self:maybe_shoot(self.main_gun)
if (butt[4] > 0) self:maybe_shoot(self.special_gun)
if (butt[0]-butt[1] ~= 0 or butt[2]-butt[3] ~= 0) spark(self.sparks, self.x + 4*self.size, self.y + 4*self.size, butt, self.thrust, self.sparkodds)
self.xmomentum += (self.thrust * butt[1]) - (self.thrust * butt[0])
self.ymomentum += (self.thrust * butt[3]) - (self.thrust * butt[2])
self.xmomentum = mid(-self.maxspd, self.maxspd, self.xmomentum)
self.ymomentum = mid(-self.maxspd, self.maxspd, self.ymomentum)
self.x += self.xmomentum
self.y += self.ymomentum
if self == primary_self then
self.x = mid(0, 112 - 8 * self.size, self.x)
self.y = mid(0, 128 - 8 * self.size, self.y)
end
--friction
local d = self.drag
self.xmomentum -= mid(d, -d, self.xmomentum)
self.ymomentum -= mid(d, -d, self.ymomentum)
-- "scrolling" behavior
if self.slip then
self.y += scrollrate
if self.y >= 128 then
self:die()
return true
end
end
return false
end
function ship_m:draw()
if(self.fx_pal) pal(self.fx_pal)
spr(self.sprite, self.x, self.y, self.size, self.size)
pal()
end
function hurtbox(ship)
local h = ship.hurt
return {
x=ship.x + h.x_off,
y=ship.y + h.y_off,
width=h.width,
height=h.height
}
end
function ship_m:maybe_shoot(gun)
if (not gun) return
if (self.power < gun.power) return
if (not gun:shoot(self.x + self.fire_off_x, self.y + self.fire_off_y)) return
self.power -= gun.power
end
function ship_m:hitship(other)
return self:hitsomething(1)
end
function ship_m:hitbullet(b)
return self:hitsomething(b.damage)
end
function ship_m:hitsomething(dmg)
if (dmg <= 0) return false
if (lframe < self.invincible_until) return false
self.shield_refresh_ready = lframe + self.shieldcooldown
if self.shield >= dmg then
self.shield -= dmg
self:ow(true)
return false
end
dmg -= self.shield
self.shield = 0
self.hp -= dmg
if self.hp <= 0 then
self:die()
return true
end
self:ow(false)
return false
end
function ship_m:ow(shielded)
if (shielded) then
blip(self,12,3)
return
end
blip(self, 7, 3)
end
function ship_m:refresh_shield()
if (self.shield >= self.maxshield) return
if (lframe < self.shield_refresh_ready) return
if (self.power < self.shieldcost) return
self.shield += 1
self.power -= self.shieldcost
self.shield_refresh_ready = lframe + self.shieldcooldown
end
-->8
-- collisions
-- box: x, y, width, height
@ -936,18 +963,19 @@ end
-->8
-- example level
function spawn_rnd_x(typ)
s = typ.new{
function spawn_rnd_x(mt)
s = {
x = rnd(104),
y = -(mt.__index.size * 8 - 1)
}
setmetatable(s, mt)
eships:push_back(s)
return s
end
function spawn_blocking_rnd_x(typ)
function spawn_blocking_rnd_x(mt)
freeze += 1
s = typ.new{
s = {
x = rnd(104),
y = -7,
ice = 1,
@ -957,24 +985,25 @@ function spawn_blocking_rnd_x(typ)
mt.__index.die(self)
end
}
setmetatable(s, mt)
eships:push_back(s)
return s
end
function spawn_frownie()
return spawn_rnd_x(frownie)
return spawn_rnd_x(frownie_t)
end
function spawn_blocking_frownie()
spawn_blocking_rnd_x(frownie)
spawn_blocking_rnd_x(frownie_t)
end
function spawn_blocky()
spawn_rnd_x(blocky)
spawn_rnd_x(blocky_t)
end
function spawn_blocking_blocky()
spawn_blocking_rnd_x(blocky)
spawn_blocking_rnd_x(blocky_t)
end
function spawn_spewy()
@ -992,7 +1021,7 @@ function spawn_blocking_spewy()
s.die = function(self)
freeze -= self.ice
self.ice = 0
frownie.die(self)
frownie_t.__index.die(self)
end
end
@ -1001,7 +1030,7 @@ function spawn_bonus_frownie()
f.sprite = 7
f.die = function(self)
spawn_repair_at(self.x+4, self.y+4)
frownie.die(self)
frownie_t.__index.die(self)
end
end
@ -1033,7 +1062,7 @@ function spawn_blocking_boss_chasey()
c.die = function(self)
freeze -= self.ice
self.ice = 0
chasey.die(self)
chasey_t.__index.die(self)
end
local nextspawn = lframe + 120