Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Frontwave
--# Main
-- FrontWaveV4
displayMode(FULLSCREEN)
function setup()
sound(SOUND_EXPLODE, 48329, 0)
sound(SOUND_RANDOM, 46477, 0)
FoeClassA = readImage("Dropbox:Foe-Class-B")
sprite0 = readImage("Dropbox:mfree_fly_1")
size0 = spriteSize(sprite0)
sprite1 = readImage("Dropbox:m45_right_2")
size1 = spriteSize(sprite1)
sprite2 = readImage("Dropbox:m45_left_2")
size2 = spriteSize(sprite2)
sprite3 = readImage("Dropbox:m45_right_3")
size3 = spriteSize(sprite3)
sprite4 = readImage("Dropbox:m45_left_3")
size4 = spriteSize(sprite4)
sprite5 = readImage("Dropbox:m45_right_4")
size5 = spriteSize(sprite5)
sprite6 = readImage("Dropbox:m45_left_4")
-- 818
-- 370
-- bgColor = color(math.random(0,30), math.random(30,35), math.random(50,50))
bgColor = color(84, 76, 76, 255)
font("bitdust two")
pl1 = Player1()
fps = FPS()
Playerpos = vec2(0,0)
PlayerDamage = 20
BgExagonSprite = readImage("Dropbox:exagon")
FoeSprite0 = readImage("Dropbox:Bomber2")
FoeSprite1 = readImage("Dropbox:Battleship")
BulletSprite = readImage("Dropbox:expl_t1")
ExplosionTile = readImage("Dropbox:expl_t1")
SmokeSprite = readImage("Dropbox:expl2")
FoeMissileSprite = readImage("Dropbox:FoeBullets-1")
Explosionsprite = readImage("Dropbox:expl3")
PlayerBulletSprite0 = readImage("Dropbox:Player-Bullets")
bg = Backgrounds()
PlayerBullets = PlayerBullets()
Foe = Foe()
FoeMissilesm = FoeMissilesm()
PlayerBullets.foes = Foe.foes
shp = ScoreHitPop()
bu = Business()
hb = HealthBar(60,60,600,20,Player_Energy)
Bomber2 = readImage("Dropbox:Bomber2")
Bomber2C = readImage("Dropbox:Bomber2C")
Bomber2B = readImage("Dropbox:Bomber2B")
AssaultBoat = readImage("Dropbox:Assaultboat")
AssaultBoatC = readImage("Dropbox:AssaultboatC")
BomberB = readImage("Dropbox:BomberB")
BomberC = readImage("Dropbox:BomberC")
Utils = Utils()
mdm = MissionDescMessage()
FoeID = 0
end
function draw()
background(bgColor)
fdb = FoeDamageBar()
bg:draw()
Foe:draw()
PlayerBullets:draw()
bu:draw()
shp:draw()
mdm:draw()
end
function touched(t)
pl1:touched(t)
end
--# Backgrounds
Backgrounds = class()
function Backgrounds:init()
self.missiles = {}
self.texture = BgExagonSprite
self.spriteSize = vec2(9, 9)
self.mesh = mesh()
self.mesh.texture = BgExagonSprite
self.foes = {}
self.index = 0
self.count = 0
self.forcepause = 0
self.shaketimer = 0
t = 0
local move
end
function Backgrounds:spawnTexture(pos2,target,speed)
if table.maxn(self.missiles) < 200 and self.forcepause == 0 and table.maxn(self.missiles) <= 5 then
self.count = self.count + 1
local index = self.mesh:addRect(pos2.x, pos2.y+15, 519, 713)
table.insert(self.missiles,BgExagon(index,pos2,target,speed))
local c = color(17, math.random(255), math.random(255), 255)
self.mesh:setRectColor(index, c)
if self.count == 5 then
self.forcepause = 1
end
end
if table.maxn(self.missiles) == 0 then
self.forcepause = 0
self.count = 0
self.mesh:clear()
end
end
function Backgrounds:removeRect(index)
self.mesh:setRectColor(index,0,0,0,0)
end
function Backgrounds:draw(dt)
text("bgs ptrns : "..table.maxn(self.missiles),100,210)
local pos
local w,h = spriteSize(self.mesh.texture)
self.mesh:draw()
for k,v in ipairs(self.missiles) do
if v.pos.y < 0 then
self:removeRect(v.index)
table.remove(self.missiles,k)
local xpos = math.random(1,WIDTH)
bg:spawnTexture(vec2(xpos, HEIGHT+500),vec2(xpos,-500), 3)
end
if v.pos.y == -600 then
end
move = v.target - v.pos
if move:len() > v.speed then
move = move / move:len() * v.speed
end
v.pos = v.pos + move
if self.shaketimer >= 0 then
self.shaketimer = self.shaketimer - 0.5
ws = math.random(self.shaketimer*(-1),self.shaketimer)
hs = math.random(self.shaketimer*(-1),self.shaketimer)
else
ws = 0
hs = 0
end
local sc = 1 -- (math.sin(v+t*5)+1)/2*0.35 + 0.65
self.mesh:setRect(v.index, v.pos.x+ws, v.pos.y+hs,519, 713, 0)
end
t = t + DeltaTime * 0.1
end
function Backgrounds:Shake()
self.shaketimer = 30
end
BgExagon = class()
function BgExagon:init(index,pos,target, speed)
self.index = index
self.speed = speed
self.pos = pos
self.target = target
end
--# Bullets
FoeMissilesm = class()
FoeMissiles = 0
function FoeMissilesm:init()
self.missiles = {}
self.texture = FoeMissileSprite
self.spriteSize = vec2(9, 9)
self.mesh = mesh()
self.mesh.texture = self.texture
self.index = 0
self.count = 0
self.forcepause = 0
self.shaketimer = 0
t = 0
end
function FoeMissilesm:spawnMissile(a,pos2,speed,btype)
if table.maxn(self.missiles) < 250 and self.forcepause == 0 then
self.count = self.count + 1
local index = self.mesh:addRect(pos2.x, pos2.y, 12, 12)
local c = color(197, 0, 197, 255)
if btype == 0 then
self.mesh:setRectTex(index,0,0,0.30,1)
c = color(197, 0, 197, 255)
end
if btype == 1 then
self.mesh:setRectTex(index,0.30,0,0.36,1)
c = color(0, 165, 255, 255)
end
if btype == 2 then
-- self.mesh:setRectTex(index,0.6,0,0.283,1)
end
self.mesh:setRectColor(index, c)
local rotation = math.atan((Playerpos.x - a)/(a - Playerpos.y))
table.insert(self.missiles,FoeBolt(index,pos2.x,pos2.y,a,speed,btype,rotation+50))
if self.count == 200 then
self.forcepause = 1
end
end
if table.maxn(self.missiles) == 0 then
self.forcepause = 0
self.count = 0
self.mesh:clear()
self.missiles = {}
end
end
function FoeMissilesm:removeRect(index)
self.mesh:setRectTex(index,1, 1, 0, 0)
end
function FoeMissilesm:draw(dt)
text("shot : "..table.maxn(self.missiles),100,110)
local pos
local w = 40
local h = 40
self.mesh:draw()
local c = color(129, 255, 0, 255)
local sc = 1 -- (math.sin(v+t*5)+1)/2*0.35 + 0.65
local rotation = 0
if self.shaketimer >= 0 then
self.shaketimer = self.shaketimer - 0.5
ws = math.random(self.shaketimer*(-1),self.shaketimer)
hs = math.random(self.shaketimer*(-1),self.shaketimer)
else
ws = 0
hs = 0
end
for k,v in ipairs(self.missiles) do
pos = vec2(v.x,v.y)
if v.btype == 0 then
rotation = t*50
v.speed = v.speed + 0.05
end
if v.btype == 1 then
rotation = v.rotation
v.speed = v.speed + 0.02
end
if v.btype == 2 then
v.speed = v.speed + 0.02
end
self.mesh:setRect(v.index, pos.x+ws, pos.y+hs,w/2 * sc, h/2 * sc, rotation)
if pos.x < -20 or pos.x > WIDTH + 20 then
self:removeRect(v.index)
table.remove(self.missiles,k)
end
if pos.y < -20 or pos.y > HEIGHT + 20 then
self:removeRect(v.index)
table.remove(self.missiles,k)
end
v.x = v.x + v.xa * v.speed
v.y = v.y - v.ya * v.speed
if pos:dist(Playerpos) < 30 then
self:removeRect(v.index)
table.remove(self.missiles,k)
Utils:ShakeMedium()
bu:addexplosion1(vec2(pos.x,pos.y))
PlayerDamage = PlayerDamage - v.pow
end
end
FoeMissilesCount = self.count
t = t + DeltaTime * 0.1
end
function FoeMissilesm:Shake()
self.shaketimer = 20
end
FoeBolt = class()
function FoeBolt:init(i,x,y,a,speed,btype,rotation)
self.index = i
self.x = x
self.y = y
self.angle = a
self.rotation = rotation
self.xa = math.sin(math.rad(self.angle))
self.ya = math.cos(math.rad(self.angle))
self.timer = 0
self.pow = 3
self.width = width or 9
self.speed = 0.25
self.btype = btype or 0
end
--# Business
Business = class()
function Business:init()
self.playerbullets = {}
self.coronas = {}
self.foes = {}
self.explosions = {}
self.gametimer = 0
self.bullet = mesh()
self.bullet.texture = FoeMissileSprite
self.index = self.bullet:addRect(0, 0, 3,3)
self.bulletcount = 0
self.forcepause = 0
local xpos = 0
local ypos = 0
for i=1,5 do
xpos = math.random(50,WIDTH-50)
ypos = math.random(-500,HEIGHT+500)
bg:spawnTexture(vec2(xpos, ypos),vec2(xpos,-500), 3)
end
end
function Business:draw()
self.gametimer = (self.gametimer + 1)%320
if self.gametimer%100 == 0 then
Foe:AddFoes(math.random(9,9),30)
Foe:AddFoes(math.random(0,2),1)
--Foe:AddFoes(math.random(4,7),1)
end
fps:draw()
pl1:draw()
FoeMissilesm:draw(DeltaTime)
for i,v in ipairs(self.explosions) do
if v.finished == true then
table.remove(self.explosions,i)
end
v:draw()
end
end
function Business:addbulletgroup(pos, target, speed)
if self.forcepause == 0 then
self.bulletcount = self.bulletcount + 2
table.insert(self.playerbullets,BulletBase(self.index,vec2(pos.x+5,pos.y), vec2(pos.x-15,target.y), speed ))
table.insert(self.playerbullets,BulletBase(self.index,vec2(pos.x-5,pos.y), vec2(pos.x+15,target.y), speed ))
end
if table.maxn(self.playerbullets) == 0 then
self.forcepause = 0
end
if self.bulletcount >= 100 then
self.bulletcount = 0
end
end
function Business:addcorona(pos)
table.insert(self.coronas,PlayerCorona(pos))
end
function Business:addexplosion1(pos)
table.insert(self.explosions,Explosun(pos))
end
function Business:addexplosion2(pos)
for i=1,10 do
local newpos = vec2(pos.x+math.random(-100,100),pos.y+math.random(-100,100))
table.insert(self.explosions,Explosun(newpos,size))
end
end
function Business:addsmoke1(pos)
table.insert(self.explosions,Explosmoke(pos))
end
function Business:AddFoes()
for i=1,30 do
local ang = math.deg(math.atan((Playerpos.x - posx)/(posy - Playerpos.y)))
table.insert(self.foes,Foe0(vec2(math.random(50,WIDTH),HEIGHT+30),vec2(math.random(50,WIDTH),-30),math.random(2,5),0))
end
end
--# Explosions
Explosion = class()
function Explosion:init(pos)
self.pos = pos
self.width = math.random(100,150)
self.index = 0
self.m = mesh()
self.m.texture = Explosionsprite
self.index = self.m:addRect(self.pos.x, self.pos.y, self.width, self.width)
self.alpha = 500
end
function Explosion:draw()
pushStyle()
blendMode(SRC_COLOR,ONE,ONE_MINUS_SRC_ALPHA,ONE)
self.width = self.width - 5
self.alpha = self.alpha - 15
self.m:setColors(math.max(55-self.alpha*40,40),math.max(self.alpha*20,30),self.alpha*5,math.max(self.alpha*50,0))
self.m:setRect(self.index,self.pos.x,self.pos.y,self.width,self.width)
self.m:draw()
popStyle()
end
Explosun = class()
function Explosun:init(pos,...)
-- sound(SOUND_EXPLODE, 48329)
--sound(SOUND_EXPLODE, 29156)
self.pos = pos
self.m = mesh()
self.m.texture = ExplosionTile
self.ex = {}
self.finished = false
if ... then self.size = ... else self.size = 5 end
for i=1,self.size do
self.ex[i] = {}
local mr = math.random(40,80)
self.ex[i].r = self.m:addRect(pos.x,pos.y,mr,mr)
self.ex[i].pos = pos
local bias = vec2(math.random(-50,50),math.random(-50,50))*0.1
self.ex[i].vel = (vec2(math.sin(((math.pi*2)/self.size)*i),math.cos(((math.pi*2)/self.size)*i))*math.random(10,100))/250
self.ex[i].vel = self.ex[i].vel*self.size*1.5
self.ex[i].size = vec2(mr,mr)*(self.size*0.03+1.5)
self.ex[i].time = mr*0.05+7
self.ex[i].sets = mr*0.05+6
end
self.time = 2
end
function Explosun:draw()
local alpha = math.max(self.time*10,10)
for k,v in pairs(self.ex) do
self.ex[k].pos = v.pos + v.vel
self.ex[k].vel = self.ex[k].vel*(0.93-(v.pos:dist(self.pos)/900))
local size = v.size-(1-self.time)*v.size*2
size.x = math.max(size.x,0)
size.y = math.max(size.y,0)
size = v.size*((v.sets)-self.time)/v.sets
if self.time>1 then
else
alpha = self.time*70
end
self.m:setRect(v.r,v.pos.x,v.pos.y,size.x,size.y)
end
self.time = self.time-0.04*(DeltaTime*60)
if self.time<0 then self.finished = true end
local time = 2-self.time
pushStyle()
self.m:setColors(0,10,50,alpha)
blendMode(SRC_COLOR,ONE_MINUS_SRC_COLOR,ZERO,ONE)
self.m:draw()
if self.time>1.2 then
self.m:setColors(math.max(255-time*40,40),math.max(150-time*20,30),time*5,math.max(self.time*50+50,0))
blendMode(SRC_COLOR,ONE,ONE_MINUS_SRC_ALPHA,ONE)
self.m:draw()
end
popStyle()
end
--# Foes
Foe = class()
local hitc = color(1, 1, 1, 255)
local nohitc = color(255, 255, 255, 255)
function Foe:init()
self.groupid = groupid
self.foes = {}
self.pos = pos
self.layout = layout or 0
self.foetype = 1
self.pow = pow or 2
self.width = size or 30
self.hittable = hittable or 1
self.speed = speed or 1
self.inc = 0
self.z = life or 30
self.initialZ = self.z
self.t = false
self.scoreval = scoreval or 100
self.w = math.random(300)
self.u = 0
self.target = target
self.frame = 0
self.shotintensity = 0
self.sprite = FoeClassA
self.m = mesh()
self.m.texture = self.sprite
-- self.index = self.m:addRect(0, 0, 40,40)
self.count = 0
self.shaketimer = 0
t = 0
self.color = color(10, 10, 10, 255)
end
function Foe:removeRect(index,shadeindex)
self.m:setRectColor(index,0,0,0,0)
self.m:setRectColor(shadeindex,0,0,0,0)
end
function Foe:draw(dt)
self.frame = (self.frame+1)%450
self.shotintensity = (self.shotintensity+1)%60
text("foes : "..table.maxn(self.foes),100,80)
local pos
local w,h = spriteSize(self.m.texture)
self.m:draw()
local c = color(129, 255, 0, 255)
if self.shaketimer >= 0 then
self.shaketimer = self.shaketimer - 0.5
ws = math.random(self.shaketimer*(-1),self.shaketimer)
hs = math.random(self.shaketimer*(-1),self.shaketimer)
else
ws = 0
hs = 0
end
local ang
local playerangle
local rot
local sc
for k,v in ipairs(self.foes) do
if v.foetype == 3 then
if v.internaltimer > 0 then
if self.shotintensity%20 == 0 then
playerangle = math.deg(math.atan((Playerpos.x - v.x)/(v.y - Playerpos.y)))
v.internaltimer = v.internaltimer - 1
FoeMissilesm:spawnMissile(playerangle,vec2(v.x,v.y),0,v.shottype)
v.shotcount = v.shotcount + 1
end
end
end
if v.w == self.frame or v.w == self.frame - 10 or v.w == self.frame - 20 then
v.shotcount = v.shotcount + 1
if v.foetype == 0 then
for i=1,10 do
if v.shotcount < v.shotcap then
FoeMissilesm:spawnMissile(i*36,vec2(v.x,v.y),0,v.shottype)
v.shotcount = v.shotcount + 1
end
end
end
if v.foetype == 1 or v.foetype > 3 then
if v.shotcount < v.shotcap then
for i=1,5 do
playerangle = math.deg(math.atan((Playerpos.x - v.x)/(v.y - Playerpos.y)))
FoeMissilesm:spawnMissile(playerangle,vec2(v.x,v.y),0,v.shottype,playerangle)
v.shotcount = v.shotcount + 1
end
end
end
if v.foetype == 3 then
if v.shotcount < v.shotcap then
v.internaltimer = 200
end
end
end
if v.stop == 1 and v.speed > 0 then
v.speed = v.speed - v.speeddecremental
end
if v.stop == 0 then
--v.speed = v.speed + v.speeddecremental
end
if v.speed == 0 then
v.stoptimer = v.stoptimer - 1
if v.stoptimer == 0 then
--v.stop = 0
--v.speed = 0
end
end
if v.foetype ~= 3 then
v.x = v.x + v.xa * v.speed
v.y = v.y - v.ya * v.speed
if v.foetype <= 2 or v.foetype > 3 then
self:SetTurretPos(v.id,vec2(v.x,v.y))
end
else
end
v.inc = v.inc + 0.01
pos = vec2(v.x,v.y)
if pos.x < -20 or pos.x > WIDTH + 20 then
self.m:setRectTex(v.index,1,1,0,0)
self.m:setRectTex(v.shadeindex,1,1,0,0)
self:RemoveTurret(v.id)
table.remove(self.foes,k)
end
if pos.y < -200 or pos.y > HEIGHT + 300 then
self.m:setRectTex(v.index,1,1,0,0)
self.m:setRectTex(v.shadeindex,1,1,0,0)
self:RemoveTurret(v.id)
table.remove(self.foes,k)
end
if v.t == true then
v.u = v.u + 1
self.m:setRectColor(v.index,hitc)
if v.u >= 3 then
v.u = 0
v.t = false
end
else
self.m:setRectColor(v.index,nohitc)
end
sc = 0.40 -- (math.sin(v+t*5)+1)/2*0.35 + 0.65
rot = 0
if v.followrotate == true then
rot = (math.atan(( pos.x-Playerpos.x)/( Playerpos.y-pos.y)))
if v.y < Playerpos.y then
rot = rot - 180
end
end
self.m:setRect(v.index, pos.x+ws, pos.y+hs,v.width, v.height, rot)
self.m:setRect(v.shadeindex, pos.x+ws+50, pos.y+hs+50,v.width, v.height, rot)
if pos:dist(Playerpos) < 30 then
Utils:ShakeMedium()
bu:addexplosion1(vec2(pos.x,pos.y))
self.m:setRectTex(v.shadeindex,1,1,0,0)
self.m:setRectTex(v.index,1,1,0,0)
table.remove(self.foes,k)
PlayerDamage = PlayerDamage - v.pow
-- sound(SOUND_RANDOM, 46477)
end
end
FoeMissilesCount = self.count
t = t + DeltaTime * 0.1
end
function Foe:SetTurretPos(_id,_pos)
for i,v in ipairs(self.foes) do
if v.foetype == 3 then
--print(_id.." "..v.parent.."("..v.id.." "..v.foetype..")")
if _id == v.parent then
v.x = _pos.x + v.xdisplace
v.y = _pos.y + v.ydisplace
end
end
end
end
function Foe:RemoveTurret(_id)
for i,v in ipairs(self.foes) do
if v.foetype == 3 then
if _id == v.parent then
table.remove(self.foes,i)
self.m:setRectTex(v.index,1,1,0,0)
end
end
end
end
function Foe:AddFoes(_foetype,_foecount)
--458
--296
for i=1,_foecount or 1 do
if table.maxn(self.foes) < 10 and self.forcepause == 0 then
self.count = self.count + 1
local pos2 = vec2(math.random(WIDTH), HEIGHT + 15)
local index = self.m:addRect(pos2.x,pos2.y, 55, 65)
local shadeindex = self.m:addRect(pos2.x+50,pos2.y+50, 55, 65)
local shadecolor = color(0, 0, 0, 50)
self.m:setRectColor(shadeindex,shadecolor)
local foetype = _foetype
local w,h = 0
local life = 5
local followrot = false
local decrease = 0
local shotcap = 0
FoeID = FoeID + 1
--battleship
if foetype == 0 then
local c = color(67, 72, 72, 255)
self.m:setRectTex(index,0,0,0.19,1)
self.m:setRectTex(shadeindex,0,0,0.19,1)
self.m:setRectColor(index, c)
life = 400
w = 180
h = 500
followrot = false
decrease = 1
shotcap = 1000
self:AddTurret(FoeID,vec2(pos2.x,pos2.y),50,-165)
self:AddTurret(FoeID,vec2(pos2.x,pos2.y),-50,-165)
self:AddTurret(FoeID,vec2(pos2.x,pos2.y),50,-45)
self:AddTurret(FoeID,vec2(pos2.x,pos2.y),-50,-45)
self:AddTurret(FoeID,vec2(pos2.x,pos2.y),0,120)
end
if foetype == 1 then
local c = color(67, 72, 72, 255)
self.m:setRectTex(index,0.205,0,0.16,1)
self.m:setRectTex(shadeindex,0.20,0,0.16,1)
self.m:setRectColor(index, c)
life = 350
w = 160
h = 450
followrot = false
decrease = 1
shotcap = 1000
self:AddTurret(FoeID,vec2(pos2.x,pos2.y),50,45)
self:AddTurret(FoeID,vec2(pos2.x,pos2.y),-50,45)
self:AddTurret(FoeID,vec2(pos2.x,pos2.y),0,120)
self:AddTurret(FoeID,vec2(pos2.x,pos2.y),0,-120)
end
if foetype == 2 then
local c = color(67, 72, 72, 255)
self.m:setRectTex(index,0.38,0.2,0.14,1)
self.m:setRectTex(shadeindex,0.38,0.2,0.14,1)
self.m:setRectColor(index, c)
life = 300
w = 140
h = 400
followrot = false
decrease = 1
shotcap = 100
self:AddTurret(FoeID,vec2(pos2.x,pos2.y),0,-80)
self:AddTurret(FoeID,vec2(pos2.x,pos2.y),0,-170)
end
if foetype == 4 then
local c = color(67, 72, 72, 255)
self.m:setRectTex(index,0.53,0,0.10,1)
self.m:setRectTex(shadeindex,0.53,0,0.10,1)
self.m:setRectColor(index, c)
life = 250
w = 150
h = 550
followrot = false
decrease = 1
shotcap = 1000
self:AddTurret(FoeID,vec2(pos2.x,pos2.y),0,60)
self:AddTurret(FoeID,vec2(pos2.x,pos2.y),0,-70)
end
if foetype == 5 then
local c = color(67, 72, 72, 255)
self.m:setRectTex(index,0.633,0,0.06,1)
self.m:setRectTex(shadeindex,0.633,0,0.06,1)
self.m:setRectColor(index, c)
life = 200
w = 80
h = 550
followrot = false
decrease = 1
shotcap = 1000
self:AddTurret(FoeID,vec2(pos2.x,pos2.y),0,-40)
end
if foetype == 6 then
local c = color(67, 72, 72, 255)
self.m:setRectTex(index,0.64,0,0.08,1)
self.m:setRectTex(shadeindex,0.64,0,0.08,1)
self.m:setRectColor(index, c)
life = 120
w = 180
h = 550
followrot = false
decrease = 1
shotcap = 1000
end
if foetype == 7 then
local c = color(67, 72, 72, 255)
self.m:setRectTex(index,0.72,0,0.08,1)
self.m:setRectTex(shadeindex,0.72,0,0.08,1)
self.m:setRectColor(index, c)
life = 150
w = 110
h = 460
followrot = false
decrease = 1
shotcap = 1000
end
if foetype == 8 then
local c = color(67, 72, 72, 255)
self.m:setRectTex(index,0.78,0.45,0.06,0.20)
self.m:setRectTex(shadeindex,0.78,0.45,0.06,0.20)
self.m:setRectColor(index, c)
life = 40
w = 60
h = 70
followrot = true
decrease = 0
shotcap = 1000
end
if foetype == 9 then
local c = color(67, 72, 72, 255)
self.m:setRectTex(index,0.85,0.45,0.06,0.20)
self.m:setRectTex(shadeindex,0.85,0.45,0.06,0.20)
self.m:setRectColor(index, c)
life = 40
w = 60
h = 80
followrot = true
decrease = 0
shotcap = 1000
end
if foetype == 10 then
local c = color(67, 72, 72, 255)
self.m:setRectTex(index,0.93,0.45,0.06,0.20)
self.m:setRectTex(shadeindex,0.85,0.45,0.06,0.20)
self.m:setRectColor(index, c)
life = 40
w = 40
h = 60
followrot = true
decrease = 0
shotcap = 1000
end
local ang = 0
ang = math.deg(math.atan((Playerpos.x - pos2.x)/(pos2.y - Playerpos.y))) table.insert(self.foes,Foe0(FoeID,index,shadeindex,pos2.x,pos2.y,ang,math.random(2,3),foetype,w,h,followrot,life,decrease,shotcap))
if self.count == 50 then
self.forcepause = 1
end
end
end
if table.maxn(self.foes) == 0 then
self.forcepause = 0
self.count = 0
self.m:clear()
end
if table.maxn(self.foes) == 0 then
self.m:clear()
self.forcepause = 0
end
end
function Foe:AddTurret(_parent,_pos,xdisplace,ydisplace)
--458
--296
local foetype = 3
if table.maxn(self.foes) < 20 and self.forcepause == 0 then
self.count = self.count + 1
local pos2 = _pos
local index = self.m:addRect(pos2.x,pos2.y, 55, 65)
-- local shadeindex = self.m:addRect(pos2.x,pos2.y, 55, 65)
local shadecolor = color(0, 0, 0, 50)
-- self.m:setRectColor(shadeindex,shadecolor)
local w,h = 0
local life = 5
local followrot = false
local decrease = 0
local shotcap = 0
local shadeindex = 0
local c = color(67, 72, 72, 255)
self.m:setRectTex(index,0.38,0,0.14,0.18)
self.m:setRectColor(index, c)
life = 120
w = 70
h = 80
followrot = true
decrease = 0
shotcap = 1000
-- FoeID = FoeID + 1
local ang = 0
ang = math.deg(math.atan((Playerpos.x - pos2.x)/(pos2.y - Playerpos.y))) table.insert(self.foes,Turret(xdisplace,ydisplace,FoeID,_parent,index,shadeindex,pos2.x,pos2.y,ang,math.random(2,3),foetype,w,h,followrot,life,decrease,shotcap))
if self.count == 50 then
self.forcepause = 1
end
end
if table.maxn(self.foes) == 0 then
self.forcepause = 0
self.count = 0
self.m:clear()
end
if table.maxn(self.foes) == 0 then
self.m:clear()
self.forcepause = 0
end
return index
end
function Foe:Shake(i)
self.shaketimer = 20
end
Foe0 = class()
function Foe0:init(id,i,shadeindex,x,y,a,speed,ftype,w,h,followrotation,life,decrease,shotcap)
self.id = id
self.parent = 0
self.inc = 0
self.index = i
self.shadeindex = shadeindex
self.groupid = groupid or 0
self.angle = a
self.x = x
self.y = y
self.layout = layout or 0
self.foetype = ftype or 0
self.pow = pow or 2
self.width = w
self.height = h
self.hittable = hittable or 1
self.speed = speed or 1
self.foebullets = {}
self.protect = protect or false
self.fatal = fatal or false
self.followrotate = followrotation or false
self.rotation = 270
self.targetangle = 0
self.inc = 0
self.z = life or 5
self.type = ftype or 0
self.initialZ = self.z
self.t = false
self.scoreval = scoreval or 100
self.w = math.random(450)
self.u = 0
self.xa = math.sin(math.rad(self.angle))
self.ya = math.cos(math.rad(self.angle))
self.shotcount = 0
--self.shotcap = math.random(1,260)
self.shotcap = shotcap or 20
self.shottype = math.random(0,1)
self.stop = decrease
if self.stop == 1 then
self.speeddecremental = 0.01
else
self.speeddecremental = 0.01
end
self.stoptimer = 100
self.internaltimer = 0
end
Turret = class()
function Turret:init(xdisplace,ydisplace,id,parent,i,shadeindex,x,y,a,speed,ftype,w,h,followrotation,life,decrease,shotcap)
self.xdisplace = xdisplace
self.ydisplace = ydisplace
self.id = id
self.parent = parent
self.inc = 0
self.index = i
self.shadeindex = shadeindex
self.groupid = groupid or 0
self.angle = a
self.x = x
self.y = y
self.layout = layout or 0
self.foetype = ftype or 0
self.pow = pow or 2
self.width = w
self.height = h
self.hittable = hittable or 1
self.speed = speed or 1
self.foebullets = {}
self.protect = protect or false
self.fatal = fatal or false
self.followrotate = followrotation or false
self.rotation = 270
self.targetangle = 0
self.inc = 0
self.z = life or 5
self.type = ftype or 0
self.initialZ = self.z
self.t = false
self.scoreval = scoreval or 100
self.w = math.random(450)
self.u = 0
self.xa = math.sin(math.rad(self.angle))
self.ya = math.cos(math.rad(self.angle))
self.shotcount = 0
--self.shotcap = math.random(1,260)
self.shotcap = shotcap or 20
self.shottype = math.random(0,1)
self.stop = decrease or 0
if self.stop == 1 then
self.speeddecremental = 0.01
else
self.speeddecremental = 0.01
end
self.stoptimer = 10000
self.internaltimer = 0
end
--# Players
Player1 = class()
function Player1:init(pos, damage, shield, weapon, powerup, size)
self.pos = pos or vec2(WIDTH/2,100)
self.oldpos = self.pos
self.damage = damage or 14
self.shield = shield or 0
self.weapon = weapon or 0
self.powerup = powerup or 0
self.sprite0 = sprite0
self.size0 = size0
self.sprite1 = sprite1
self.size1 = size1
self.sprite2 = sprite2
self.size2 = size2
self.sprite3 = sprite3
self.size3 = size3
self.sprite4 = sprite4
self.size4 = size4
self.sprite5 = sprite5
self.size5 = size5
self.sprite6 = sprite6
self.size6 = size6
self.sprite = self.sprite0
self.target= self.pos
self.speed = 3
self.speedinc = 0
self.xaxis = 0
self.tempxaxis = 0
self.returnmaneuver = false
self.moving = false
self.frame = 0
self.coronatimer = 0
self.shadetimer = 0
self.shaketimer = 0
end
function Player1:draw()
self.frame = (self.frame+1)%20
self.shadetimer = (self.shadetimer+1)%6
self.coronatimer = (self.coronatimer+1)%120
if self.frame%8 == 0 then
ang = math.deg(math.atan((Playerpos.x - Playerpos.x)/(HEIGHT + 100 - Playerpos.y)))
ang = ang + 180
PlayerBullets:spawnMissile(ang,self.pos,10)
end
hb:draw(PlayerDamage)
if self.xaxis < self.tempxaxis then
self.xaxis = self.xaxis + 0.25
end
if self.xaxis > self.tempxaxis then
self.xaxis = self.xaxis - 0.25
end
if self.xaxis > 0 and self.xaxis <= 1 then
self.sprite = self.sprite1
end
if self.xaxis > 1 and self.xaxis <= 2 then
self.sprite = self.sprite3
end
if self.xaxis > 3 and self.xaxis <= 4 then
self.sprite = self.sprite5
end
if self.xaxis < 0 and self.xaxis >= -1 then
self.sprite = self.sprite2
end
if self.xaxis < -1 and self.xaxis >= -2 then
self.sprite = self.sprite4
end
if self.xaxis < -3 and self.xaxis >= -4 then
self.sprite = self.sprite6
end
if self.xaxis == 0 then
self.sprite = self.sprite0
end
--self.sprite = self.sprite0
if self.pos == self.target and self.moving == true then
self.returnmaneuver = true
end
if self.returnmaneuver == true then
self.tempxaxis = 0
if self.xaxis == 0 then
self.returnmaneuver = false
self.moving = false
end
end
Playerpos = self.pos
if self.shadetimer%3 == 0 then
pushStyle()
pushMatrix()
translate(self.pos.x+65,self.pos.y+65)
-- rotate(90)
tint(0,60)
sprite(self.sprite,0,0,40)
popStyle()
popMatrix()
end
pushStyle()
pushMatrix()
if self.shaketimer >= 0 then
self.shaketimer = self.shaketimer - 0.5
ws = math.random(self.shaketimer*(-1),self.shaketimer)
hs = math.random(self.shaketimer*(-1),self.shaketimer)
else
ws = 0
hs = 0
end
translate(self.pos.x+ws,self.pos.y+hs)
--rotate(90)
sprite(self.sprite,0,0,50)
popStyle()
popMatrix()
end
function Player1:Shake()
self.shaketimer = 20
end
function Player1:touched(t)
if t.state == ENDED then
bu:addcorona(t)
end
self.target = vec2(t.x,t.y)
self.oldpos = self.pos
if t.x > self.pos.x then
self.tempxaxis = 4.5
end
if t.x < self.pos.x then
self.tempxaxis = -4.5
end
tween.stopAll()
tween.delay = 0
tween(4,self.pos,{t.x,t.y},{easing = tween.easing.quadOut, loop = tween.loop.once})
self.moving = true
end
PlayerCorona = class()
function PlayerCorona:init(pos)
self.pos = pos
self.radius = 200
self.timer = 0
self.alpha = 255
end
function PlayerCorona:draw()
self.timer = (self.timer+5)%320
self.radius = self.radius + 5
self.alpha = self.alpha - 5
popStyle()
noFill()
stroke(255,255,255,self.alpha)
strokeWidth(3)
ellipse(self.pos.x,self.pos.y,self.radius)
pushStyle()
end
function PlayerCorona:setpos(pos)
self.pos = pos
end
--# Utilities
--# FPS
FPS = class()
function FPS:init(frac)
self.val = 60
self.frac = frac or 0.01
-- self.t0 = os.clock()
self.t0 = ElapsedTime
end
function FPS:draw()
pushStyle()
local vShift = 0
-- if jobs:active() then vShift = 30 end
-- if jobs.active then vShift = 30 end
-- update FPS value with some smoothing
local old = self.val
local frac = self.frac
-- local t1 = os.clock()
local t1 = ElapsedTime
local delta = t1 - self.t0
self.t0 = t1
local new = 1/delta or old
if new>65 then new=65 end
local ratio = new/old
if 0.5<ratio and ratio<2 then new = old*(1-frac)+ new*frac end
self.val = new
-- write the FPS on the screen
if math.floor(new) >= 60 then
fill(48, 255, 0, 255)
else
fill(255, 0, 0, 255)
end
-- fontSize(25)
--font("BITDUST TWO")
rectMode(CENTER)
text(math.floor(new).." FPS",WIDTH/2,20-vShift)
popStyle()
end
ScoreHitPop = class()
function ScoreHitPop:init()
self.pops = {}
self.pops2 = {}
self.frame = 0
end
function ScoreHitPop:showPop(value,pos)
table.insert(self.pops, ScoreHitPopProperties(value, vec2(pos.x,pos.y+100)))
end
function ScoreHitPop:showPop2(value,pos)
table.insert(self.pops, ScoreHitPopProperties(value, vec2(pos.x,pos.y+100),1))
end
function ScoreHitPop:showPop3(value,pos)
table.insert(self.pops, ScoreHitPopProperties(value, vec2(pos.x,pos.y+100),2,500))
end
function ScoreHitPop:showPop4(value,pos)
table.insert(self.pops, ScoreHitPopProperties(value, vec2(pos.x,pos.y+100),3,500))
end
function ScoreHitPop:reset()
self.pops = {}
self.pops2 = {}
self.frame = 0
end
function ScoreHitPop:draw()
fontSize(16)
self.frame = (self.frame+1)%15
for i,v in ipairs(self.pops) do
if v.poptype == 0 then
if v.timer > -1 then
v.timer = v.timer - 1.5
end
if v.timer <= 0 then
table.remove(self.pops,i)
end
if v.timer > 200 then
v.pos.y = v.pos.y + 0.2
end
if v.timer > 150 and v.timer < 200 then
v.pos.y = v.pos.y + 0.4
end
if v.timer > 100 and v.timer < 150 then
v.pos.y = v.pos.y + 0.8
end
if v.timer > 50 and v.timer < 100 then
v.pos.y = v.pos.y + 1.6
end
if v.timer < 50 then
v.pos.y = v.pos.y + 3.2
end
pushStyle()
fill(0,0,0,v.timer)
text(v.value,v.pos.x+3,v.pos.y-3)
popStyle()
pushStyle()
if v.timer < 150 then
if self.frame%10 == 0 or self.frame%11 == 0 or self.frame%12 == 0 or self.frame%13 == 0 or self.frame%14 == 0 or self.frame%15 == 0 then
fill(255,255,255,1)
else
fill(255,255,255,255)
end
else
fill(255,255,255,255)
end
if v.timer < 50 then
fill(255,255,255,v.timer)
end
text(v.value,v.pos.x,v.pos.y)
popStyle()
end
if v.poptype == 1 then
pushStyle()
--textMode(CORNER)
textAlign(CENTER)
fill(v.timer,v.timer,255,v.timer)
if v.fontsize < 30 then
v.fontsize = v.fontsize + 1
end
v.pos.y = v.pos.y + 0.5
v.pos.x = v.pos.x + 0.5
v.timer = v.timer - 10
if v.timer <= 0 then
table.remove(self.pops,i)
end
--text(v.value,v.pos.x,v.pos.y)
popStyle()
end
if v.poptype == 2 then
pushStyle()
--textMode(CORNER)
-- textAlign(CENTER)
v.timer = v.timer - 2
fill(v.timer,v.timer,v.timer,v.timer)
--text(v.value,v.pos.x,v.pos.y)
if v.timer <= 0 then
table.remove(self.pops,i)
end
popStyle()
end
if v.poptype == 3 then
pushStyle()
--textMode(CORNER)
-- textAlign(CENTER)
--v.y = v.y + 0.1
v.timer = v.timer - 2
fill(255,v.timer,v.timer,v.timer)
--text(v.value,v.pos.x,v.pos.y)
if v.timer <= 0 then
table.remove(self.pops,i)
end
popStyle()
end
end
end
function ScoreHitPop:touched(touch)
end
ScoreHitPopProperties = class()
function ScoreHitPopProperties:init(value, pos,poptype,timer)
self.pos = pos
self.value = value
self.timer = timer or 255
self.poptype = poptype or 0
self.fontsize = 15
end
HealthBar = class()
local oldValue = 1
local dec = 0
local perc
local dir = 0
local showToPlayerpos = 0
local showTimer = 0
local hidesecondBar = 0
function HealthBar:init(x,y,w,v,s,n)
self.x = x
self.y = y
self.width = w
self.health = v
self.max = 20
self.green = self.health / (self.max/255)
self.red = 255- self.health / (self.max/255)
self.strokewidth = s or 20
self.varname = n -- a string containing the name of the variable this watches(optional)
self.shaketimer = 0
--hmd = HeatMessage(self.x+(self.width/self.max*self.health)+30,self.y,"DANGER",15)
end
function HealthBar:Shake()
self.shaketimer = 20
end
function HealthBar:reset()
self.health = Player_Energy
end
function HealthBar:draw(v)
if v >= 0 then
if self.health >= 0 then
perc = math.floor(self.health * 100 / self.max)
if v < self.health then
self.health = self.health - 0.1
end
if v > self.health then
self.health = self.health + 0.1
end
if self.health > self.max then
self.health = self.max
end
self.green = self.health / (self.max/255)
self.red = 255- self.green
pushStyle()
lineCapMode(SQUARE)
stroke(self.red,self.green,self.green)
strokeWidth(self.strokewidth)
if self.shaketimer >= 0 then
self.shaketimer = self.shaketimer - 0.5
ws = math.random(self.shaketimer*(-1),self.shaketimer)
hs = math.random(self.shaketimer*(-1),self.shaketimer)
else
ws = 0
hs = 0
end
line(self.x+ws,self.y-10+hs,self.x+(self.width/self.max*self.health)+ws,self.y-10+hs)
popStyle()
if showTimer <= 255 and showToPlayerpos == 1 then
showTimer = showTimer + 5
end
if showTimer >= 0 and showToPlayerpos == 0 then
showTimer = showTimer - 5
end
if showTimer == 0 then
hidesecondBar = 0
end
if hidesecondBar == 1 then
pushStyle()
stroke(self.red,self.green,0,showTimer)
strokeWidth(2)
tint(255,255,255,showTimer)
popStyle()
pushStyle()
pushStyle()
fill(255,255,255,showTimer)
text(perc.."%",Playerpos.x+25+(100/self.max*self.health)+22+ws,Playerpos.y+25+2-2+hs)
popStyle()
end
end
popStyle()
pushStyle()
fill(255,255,255,255)
fontSize(26)
text(perc.."%",self.x+(self.width/self.max*self.health)+50+ws,self.y-10+hs)
popStyle()
if self.health <= 5 then
--hmd:setPosition(self.x+(self.width/self.max*self.health)+60,self.y)
--hmd:draw()
end
end
end
Utils = class()
function Utils:init()
end
function Utils:ShakeMedium()
Foe:Shake(2)
hb:Shake()
FoeMissilesm:Shake()
pl1:Shake()
bg:Shake()
end
FoeDamageBar = class()
local perc = 100
local oldval = 0
local oldperc = 100
local displayval = 0
function FoeDamageBar:init()
self.max = 100
self.blockcounter = 1
end
function FoeDamageBar:draw(maxval,val,pos)
perc = math.floor(val * 100 / maxval)
pushStyle()
--fontSize(12)
-- font("Futura-CondensedMedium")
--fill(0,0,0,255)
--text(perc.."%",pos.x,pos.y)
if perc >= 0 and perc <= 10 then
fill(255, 0, 0, 255)
end
if perc > 10 and perc <= 20 then
fill(255, 148, 0, 255)
end
if perc > 20 and perc <= 30 then
fill(230, 142, 10, 255)
end
if perc > 30 and perc <= 40 then
fill(255, 226, 0, 255)
end
if perc > 40 and perc <= 50 then
fill(206, 251, 1, 255)
end
if perc > 50 and perc <= 60 then
fill(175, 250, 0, 255)
end
if perc > 60 and perc <= 70 then
fill(171, 250, 0, 255)
end
if perc > 70 and perc <= 80 then
fill(164, 250, 0, 255)
end
if perc > 80 and perc <= 90 then
fill(124, 250, 0, 255)
end
if perc > 90 then
fill(131, 250, 0, 255)
end
text(perc.." % ",pos.x,pos.y)
popStyle()
end
MissionDescMessage = class()
function MissionDescMessage:init()
self.pops = {}
end
function MissionDescMessage:reset()
self.pops = {}
end
function MissionDescMessage:showPop(value,pos)
local maxn = table.maxn(self.pops)
if maxn > 0 then
local prevpos = vec2(self.pops[maxn].pos.x,self.pops[maxn].pos.y )
table.insert(self.pops, MissionDescMessageProperties(value, vec2(pos.x,prevpos.y-50)))
else
table.insert(self.pops, MissionDescMessageProperties(value, vec2(pos.x,pos.y+100)))
end
end
function MissionDescMessage:draw()
for i,v in ipairs(self.pops) do
pushStyle()
if v.timer > -1 then
if v.timer < 255 then
v.timer = v.timer - 15
else
v.timer = v.timer - 1
end
end
if v.timer <= 0 then
table.remove(self.pops,i)
end
--v.pos.y = v.pos.y + 0.2
fill(0,0,0,v.timer)
text(v.value,v.pos.x+3,v.pos.y-3)
fill(255,255,255,v.timer)
text(v.value,v.pos.x,v.pos.y)
popStyle()
end
end
function MissionDescMessage:touched(touch)
end
MissionDescMessageProperties = class()
function MissionDescMessageProperties:init(value, pos)
self.pos = pos
self.value = value
self.timer = 500
end
--# Weapons
PlayerBullets = class()
function PlayerBullets:init()
self.missiles = {}
self.texture = PlayerBulletSprite0
self.spriteSize = vec2(9, 9)
self.mesh = mesh()
self.mesh.texture = PlayerBulletSprite0
self.foes = {}
self.index = 0
self.count = 0
self.forcepause = 0
self.shaketimer = 0
t = 0
end
function PlayerBullets:spawnMissile(a,pos2,speed)
if table.maxn(self.missiles) < 200 and self.forcepause == 0 then
self.count = self.count + 1
local c = color(17, 197, 0, 255)
local index = self.mesh:addRect(pos2.x+10, pos2.y+25, 6, 65)
table.insert(self.missiles,FoeBolt(index,pos2.x+10,pos2.y+25,a,speed))
self.mesh:setRectTex(index,0,0,0.19,1)
index = self.mesh:addRect(pos2.x-10, pos2.y+25, 6, 65)
table.insert(self.missiles,FoeBolt(index,pos2.x-10,pos2.y+25,a,speed))
self.mesh:setRectTex(index,0,0,0.19,1)
index = self.mesh:addRect(pos2.x, pos2.y+25, 6, 65)
table.insert(self.missiles,FoeBolt(index,pos2.x,pos2.y+25,a,speed))
self.mesh:setRectTex(index,0,0,0.19,1)
if self.count == 200 then
self.forcepause = 1
end
end
if table.maxn(self.missiles) == 0 then
self.forcepause = 0
self.count = 0
self.mesh:clear()
self.missiles = {}
end
end
function PlayerBullets:removeRect(index)
self.mesh:setRectTex(index,1, 1, 0, 0)
end
function PlayerBullets:draw(dt)
text("p1 shots : "..table.maxn(self.missiles),100,130)
local pos
local w,h = spriteSize(self.mesh.texture)
self.mesh:draw()
local c = color(129, 255, 0, 255)
local tremble
local foepos
local sc
for k,v in ipairs(self.missiles) do
pos = vec2(v.x,v.y)
self.mesh:setRect(v.index, pos.x+ws, pos.y+hs, 6, 65, 0)
for e,j in ipairs(self.foes) do
foepos = vec2(j.x,j.y)
if foepos:dist(pos) < 30 then
self:removeRect(v.index)
j.t = true
j.z = j.z - 2.5
if j.z <= 0 then
tremble = math.random(1,10)
if j.foetype < 8 then
bu:addexplosion2(foepos)
Utils:ShakeMedium()
else
bu:addexplosion1(foepos)
end
shp:showPop(j.scoreval,foepos)
Foe:removeRect(j.index,j.shadeindex)
table.remove(self.foes,e)
end
end
end
if pos.x < -20 or pos.x > WIDTH + 20 then
self:removeRect(v.index)
table.remove(self.missiles,k)
end
if pos.y < -120 or pos.y > HEIGHT + 120 then
self:removeRect(v.index)
table.remove(self.missiles,k)
end
v.speed = 30
v.x = v.x + v.xa * v.speed
v.y = v.y - v.ya * v.speed
if self.shaketimer >= 0 then
self.shaketimer = self.shaketimer - 0.5
ws = math.random(self.shaketimer*(-1),self.shaketimer)
hs = math.random(self.shaketimer*(-1),self.shaketimer)
else
ws = 0
hs = 0
end
sc = 1
end
t = t + DeltaTime * 0.1
end
function PlayerBullets:Shake()
self.shaketimer = 20
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.