Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
FwNew20150209
--# Background
Background = class()
function Background:init()
self.level = 0
self.sprite = readImage("Dropbox:FWBackground-Space-3")
self.sprite1 = readImage("Dropbox:FWBackground-Space-3")
self.sprite2 = readImage("Dropbox:FWBackground-Space-1")
self.sprite3 = readImage("Dropbox:FWBackground-Space-2")
self.bg = mesh()
self.bg.texture = "Dropbox:FWCloudsLayer-1"
self.elem = {}
self.frame = 0
self.width = 1500
self.sprite = self.sprite1
self.shaketimer = 0
self.scroll = HEIGHT-300
ws = 0
hs = 0
bgtint = 0
self.slowspawn = true
self.color = color(23, 25, 27, 255)
self:addpattern(HEIGHT,2)
self:addpattern(HEIGHT/2,8)
self:addpattern(HEIGHT+(HEIGHT/2),8)
self:addpattern(HEIGHT*2,2)
self:addpattern(HEIGHT*3,8)
self.color = color(31, 46, 65, 255)
self.sprite = self.sprite1
self.slowspawn = true
end
function Background:draw()
background(self.color)
self.frame = (self.frame+1)%600
self.scroll = self.scroll - 0.1
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
--text(table.maxn(self.elem),100,60)
self.width = self.width + 0.05
if bgtint < 255 and self.slowspawn == true then
bgtint = bgtint + 0.1
else
bgtint = 255
end
pushStyle()
tint(255,255,255,bgtint)
sprite(self.sprite,WIDTH/2+ws,self.scroll+hs,self.width)
popStyle()
for i,v in ipairs(self.elem) do
v.y = v.y - v.speed
self.bg:setRect(v.index,v.x+ws,v.y+hs,v.w,v.w)
if v.y <= -900 then
table.remove(self.elem,i)
self:addpattern(HEIGHT*2,v.speed)
end
if v.y == 1000 then
-- self:addpattern(HEIGHT*2,v.speed)
end
end
self.bg:draw()
end
function Background:Shake(i)
self.shaketimer = 20
end
function Background:addpattern(ypos,speed)
local x = math.random(WIDTH)
local bgindex = self.bg:addRect(x,ypos,1500,1500)
table.insert(self.elem,BackgroundElement(bgindex,x,ypos,speed))
end
BackgroundElement = class()
function BackgroundElement:init(ind,x,y,s,wi)
self.index = ind
self.x = x
self.y = y
self.speed = s
self.alpha = math.random(180,250)
self.w = wi or 1500
end
--# Background2
Background2 = class()
function Background2:init()
self.level = 0
self.sprite = readImage("Dropbox:FWStardust-1")
--self.sprite1 = readImage("Dropbox:FWTech-3")
--self.sprite2 = readImage("Dropbox:FWBackground-Space-1")
--self.sprite3 = readImage("Dropbox:FWBackground-Space-2")
self.bg = mesh()
self.bg.texture = "Dropbox:FWTech-3"
self.elem = {}
self.frame = 0
self.width = 1500
self.shaketimer = 0
self.scroll = HEIGHT-300
ws = 0
hs = 0
bgtint = 0
self.slowspawn = true
self.color = color(23, 25, 27, 255)
self:addpattern(HEIGHT/2,2)
self:addpattern(HEIGHT*2,2)
self.color = color(31, 46, 65, 255)
--self.sprite = self.sprite1
self.slowspawn = true
end
function Background2:draw()
background(self.color)
self.frame = (self.frame+1)%600
self.scroll = self.scroll - 0.1
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
--text(table.maxn(self.elem),100,60)
self.width = self.width + 0.05
if bgtint < 255 and self.slowspawn == true then
bgtint = bgtint + 0.1
else
bgtint = 255
end
pushStyle()
tint(255,255,255,bgtint)
sprite(self.sprite,WIDTH/2+ws,self.scroll+hs,self.width)
popStyle()
for i,v in ipairs(self.elem) do
v.y = v.y - (v.speed * 4)
self.bg:setRect(v.index,v.x+ws,v.y+hs,v.w,v.w,45)
if v.y <= -900 then
table.remove(self.elem,i)
self:addpattern(HEIGHT*2,v.speed)
end
if v.y == 1000 then
-- self:addpattern(HEIGHT*2,v.speed)
end
end
self.bg:draw()
end
function Background2:Shake(i)
self.shaketimer = 20
end
function Background2:addpattern(ypos,speed)
local x = WIDTH/2
local bgindex = self.bg:addRect(x,ypos,1500,1500)
self.bg:setRectColor(bgindex,math.random(255),math.random(255),math.random(255),255)
table.insert(self.elem,BackgroundElement(bgindex,x,ypos,speed))
end
--# Background3
Background3 = class()
function Background3:init()
self.level = 0
self.sprite = readImage("Dropbox:FWTech-4")
self.sprite1 = readImage("Dropbox:FWTech-3")
self.sprite2 = readImage("Dropbox:FWBackground-Space-1")
self.sprite3 = readImage("Dropbox:FWBackground-Space-2")
self.bg = mesh()
self.bg.texture = "Dropbox:FWShapes-1"
self.elem = {}
self.frame = 0
self.width = 500
self.sprite = self.sprite1
self.shaketimer = 0
self.scroll = HEIGHT-300
ws = 0
hs = 0
bgtint = 0
self.slowspawn = true
self.color = color(23, 25, 27, 255)
--[[
self:addpattern(HEIGHT,2)
self:addpattern(HEIGHT/2,8)
self:addpattern(HEIGHT+(HEIGHT/2),8)
self:addpattern(HEIGHT*2,2)
self:addpattern(HEIGHT*3,8)
--]]
self:addpattern(300,HEIGHT/2,2)
self:addpattern(500,HEIGHT*2,2)
self:addpattern(300,HEIGHT/2-300,2)
self:addpattern(500,HEIGHT*2-300,2)
self.color = color(31, 46, 65, 255)
self.sprite = self.sprite1
self.slowspawn = true
end
function Background3:draw()
background(self.color)
self.frame = (self.frame+1)%600
self.scroll = self.scroll - 0.1
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
text(table.maxn(self.elem),100,60)
self.width = self.width + 0.05
if bgtint < 255 and self.slowspawn == true then
bgtint = bgtint + 0.1
else
bgtint = 255
end
pushStyle()
tint(255,255,255,bgtint)
-- sprite(self.sprite,WIDTH/2+ws,self.scroll+hs,self.width)
popStyle()
for i,v in ipairs(self.elem) do
v.y = v.y - (v.speed * 4)
self.bg:setRect(v.index,v.x+ws,v.y+hs,v.w,v.w,0)
if v.y <= -900 then
table.remove(self.elem,i)
self:addpattern(HEIGHT*2,v.speed)
end
if v.y == 1000 then
-- self:addpattern(HEIGHT*2,v.speed)
end
end
self.bg:draw()
end
function Background3:Shake(i)
self.shaketimer = 20
end
function Background3:addpattern(x,ypos,speed)
local bgindex = self.bg:addRect(x,ypos,1500,1500)
self.bg:setRectTex(bgindex,0,0,0.31,0.9)
self.bg:setRectColor(bgindex,math.random(255),math.random(255),math.random(255),255)
table.insert(self.elem,BackgroundElement(bgindex,x,ypos,speed,250))
end
--# Bullets
--# 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
pos = vec2(0,0)
w = 40
h = 40
c = color(129, 255, 0, 255)
sc = 1 -- (math.sin(v+t*5)+1)/2*0.35 + 0.65
rotation = 0
end
function FoeMissilesm:spawnMissile(a,pos2,speed,btype)
local rot
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(142, 0, 197, 255)
end
if btype == 1 then
self.mesh:setRectTex(index,0.299,0,0.36,1)
c = color(0, 165, 255, 255)
end
if btype == 2 then
self.mesh:setRectTex(index,0.66,0,0.333,1)
c = color(255, 0, 241, 255)
speed = speed * 2
end
self.mesh:setRectColor(index, c)
rot = math.atan((pos2.x - Playerpos.x)/(Playerpos.y - pos2.y)) - 15
-- text("rot "..v.angle,250,100)
if pos2.y <= Playerpos.y then
rot = rot + 15.7
end
table.insert(self.missiles,FoeBolt(index,pos2.x,pos2.y,a,speed,btype,rot))
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,k)
---self.mesh:setRect(index,0, 0, 0, 0)
--table.remove(self.missiles,k)
end
function FoeMissilesm:draw(dt)
--text("shot : "..table.maxn(self.missiles),100,110)
w = 40
h = 40
self.mesh:draw()
c = color(129, 255, 0, 255)
sc = 1 -- (math.sin(v+t*5)+1)/2*0.35 + 0.65
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)
self.mesh:setRectColor(v.index,50,math.random(130,155),math.random(130,255),v.alpha)
if pos.x < -20 or pos.x > WIDTH + 20 then
--self:removeRect(v.index,k)
v.alpha = 0
table.remove(self.missiles,k)
end
if pos.y < -20 or pos.y > HEIGHT + 20 then
--self:removeRect(v.index,k)
v.alpha = 0
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 and v.alpha == 255 and PlayerHit == false then
v.alpha = 0
--self:removeRect(v.index,k)
--table.remove(self.missiles,k)
corona:sethit()
Utils:ShakeMedium()
Foe:addexplosion1(vec2(pos.x,pos.y))
PlayerDamage = PlayerDamage - 1--v.pow
PlayerHit = true
end
if PlayerHit == true then
PlayerHitTimer = PlayerHitTimer + 1
if PlayerHitTimer > 500 then
PlayerHit = false
PlayerHitTimer = 0
end
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 = speed or 0.25
self.btype = btype or 0
self.pos = vec2(self.x,self.y)
self.alpha = 255
end
--# Explosions
--# Explosions
Explosion = class()
function Explosion:init(pos)
self.pos = pos
self.width = math.random(150,190)
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, 48293, 0.5)
-- 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(90,180)
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.04+1.5)
self.ex[i].time = mr*0.05+7
self.ex[i].sets = mr*0.05+6
end
self.time = 2.5
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.5-self.time
pushStyle()
self.m:setColors(math.random(255),math.random(200),math.random(200),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
--# Foes
Foe = class()
local hitc = color(1, 1, 1, 255)
local nohitc = color(255, 255, 255, 255)
local ang
local playerangle
local rot
local sc
local pos
local c = color(129, 255, 0, 255)
local pos2 = vec2(math.random(WIDTH), HEIGHT + 15)
local index = 0
local turretindex = 0
local w,h = 0
local life = 5
local followrot = false
local decrease = 0
local shotcap = 0
local shadeindex = 0
local foetype = 0
local life = 5
function Foe:init()
self.explosions = {}
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.playerbullets = {}
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.m.shader = shader("Project:Ripple")
self.count = 0
self.shaketimer = 0
t = 0
self.color = color(10, 10, 10, 255)
bpos = vec2(0,0)
local w,h = spriteSize(self.m.texture)
dist = 0
culled = false
self.garbage = {}
self.forcepause = 0
end
function Foe:removeRect(ind,shadeindex,k)
-- self.m:setRect(ind,-1,-1, 0, 0)
table.remove(self.foes,k)
end
function Foe:Collision(sA, sB)
local widthA = sA.width/2
local heightA = sA.height/2
local widthB = sB.width/2
local heightB = sB.height/2
return sA.x+widthA > sB.x-widthB and sA.x-widthA < sB.x+widthB and sA.y+heightA > sB.y-heightB and sA.y-heightA < sB.y +heightB
end
function Foe:draw(dt)
self.frame = (self.frame+1)%450
self.shotintensity = (self.shotintensity+1)%60
-- text("playerbullets : "..table.maxn(self.playerbullets),100,80)
-- self.m.shader.time = ElapsedTime
-- self.m.shader.freq = 0.15
self.m:draw()
for i,v in ipairs(self.explosions) do
if v.finished == true then
table.remove(self.explosions,i)
end
v:draw()
end
for i,v in ipairs(self.garbage) do
self.m:setRectColor(v.x,0,0,0,0)
-- table.remove(self.foes,v.y)
table.remove(self.garbage,i)
--self.m:setRect(v.x, -1000, -1000,0, 0, 0)
end
for i,v in ipairs(self.foes) do
rot = 0
v.x = v.x + v.xa * v.speed
v.y = v.y - v.ya * v.speed
v.pos.x = v.x
v.pos.y = v.y
if v.followrotate == true then
-- rot = math.deg(math.atan((Playerpos.x - v.x)/(v.y - Playerpos.y)))
rot = math.atan((v.x - Playerpos.x)/(Playerpos.y - v.y))
-- text("rot "..v.angle,250,100)
if v.y <= Playerpos.y then
rot = rot + 15.7
end
end
self.m:setRect(v.shadeindex, v.x+ws+50, v.y+hs+50,v.width, v.height, rot)
self.m:setRect(v.index, v.x+ws, v.y+hs,v.width, v.height, rot)
if v.y > Playerpos.y and math.abs(v.x - Playerpos.x) < 100 and v.hittable == 1 then
for e,j in ipairs(self.playerbullets) do
--j.pos = vec2(j.x,j.y)
dist = j.pos:dist(v.pos)
if dist < 30 then
PlayerBullets:removeRect(j.index,e)
v.t = true
v.z = v.z - 5
if v.z <= 0 then
if v.foetype < 3 then
self:addexplosion2(v.pos)
else
self:addexplosion1(v.pos)
end
shp:showPop(""..v.scoreval,v.pos)
v.alpha = 0
v.hittable = 0
v.shotcap = 0
self.m:setRectColor(v.shadeindex,255,255,255,v.alpha)
self.m:setRectColor(v.index,0,0,0,v.alpha)
if v.foetype <= 3 then
Utils:ShakeMedium()
end
if v.foetype ~= 3 then
v.alpha = 0
v.shotcap = 0
self:RemoveTurret(v.id)
end
table.insert(self.garbage,vec2(v.index,i))
end
end
end
end
if v.foetype == 3 and v.shotcount <= v.shotcap then
if v.internaltimer > 0 then
if self.shotintensity%10 == 0 then
playerangle = math.deg(math.atan((Playerpos.x - v.x)/(v.y - Playerpos.y)))
playerangle = v.lastshotangle + 36
v.lastshotangle = playerangle
v.internaltimer = v.internaltimer - 1
if Playerpos.y > v.y then
playerangle = playerangle + 180
end
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)))
if Playerpos.y > v.y then
playerangle = playerangle + 180
end
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.y < -400 then
self:removeRect(v.index,0,i)
self:RemoveTurret(v.id)
end
if v.t == true then
v.u = v.u + 1
self.m:setRectColor(v.index,0,0,0,v.alpha)
if v.u >= 3 then
v.u = 0
v.t = false
end
else
self.m:setRectColor(v.index,255,255,255,v.alpha)
end
if v.stop == 1 and v.speed > 0 then
v.speed = v.speed - v.speeddecremental
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
if v.followrotate == true then
rot = math.atan((v.x - Playerpos.x)/(Playerpos.y - v.y))
if v.y <= Playerpos.y then
rot = rot + 15.7
end
end
end
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
--[[
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.foes) do
if v.foetype == 3 then
if v.internaltimer > 0 then
if self.shotintensity%30 == 0 then
playerangle = math.deg(math.atan((Playerpos.x - v.x)/(v.y - Playerpos.y)))
playerangle = v.lastshotangle + 36
v.lastshotangle = playerangle
v.internaltimer = v.internaltimer - 1
if Playerpos.y > v.y then
playerangle = playerangle + 180
end
--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)))
if Playerpos.y > v.y then
playerangle = playerangle + 180
end
-- 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 v.z <= 0 then
-- self.m:setRectTex(v.index,1,1,0,0)
-- table.remove(self.foes,k)
-- bu:addexplosion1(pos)
end
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 + 501 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)
self:removeRect(v.index,v.shadeindex,k)
end
if pos.y < Playerpos.y then
v.angle = v.angle + 150
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
p = Playerpos
if v.followrotate == true then
-- rot = math.deg(math.atan((Playerpos.x - v.x)/(v.y - Playerpos.y)))
rot = math.atan((v.x - Playerpos.x)/(Playerpos.y - v.y))
-- text("rot "..v.angle,250,100)
if v.y <= Playerpos.y then
rot = rot + 15.7
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
v.z = 0
v.alpha = 0
v.shotcap = 0
table.insert(self.garbage,vec2(v.index,i))
end
end
end
end
function Foe:AddFoes(_foetype,_foecount)
for i=1,_foecount or 1 do
if table.maxn(self.foes) < 30 and self.forcepause == 0 then
self.count = self.count + 1
pos2 = vec2(math.random(WIDTH), math.random(HEIGHT,HEIGHT+300))
local shadeindex = self.m:addRect(pos2.x+50,pos2.y+50, 70, 70)
index = self.m:addRect(pos2.x,pos2.y, 70, 70)
local shadecolor = color(0, 0, 0, 50)
self.m:setRectColor(shadeindex,shadecolor)
foetype = _foetype
w,h = 0
life = 5
followrot = false
decrease = 0
shotcap = 0
FoeID = FoeID + 1
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 = 280
h = 600
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)
scoreval = 15000
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 = 260
h = 550
followrot = false
decrease = 1
shotcap = 1000
scoreval = 10000
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 = 200
h = 500
followrot = false
decrease = 1
shotcap =100
scoreval = 5000
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 = 200
h = 600
followrot = false
decrease = 0
shotcap = 1000
scoreval = 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 = 100
h = 700
followrot = false
decrease = 0
shotcap = 1000
scoreval = 1500
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 = 150
h = 750
followrot = false
decrease = 0
shotcap = 1000
scoreval = 2000
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 = 150
h = 760
followrot = false
decrease = 0
shotcap = 1000
scoreval = 3000
self:AddTurret(FoeID,vec2(pos2.x,pos2.y),0,-20)
self:AddTurret(FoeID,vec2(pos2.x,pos2.y),-55,-20)
self:AddTurret(FoeID,vec2(pos2.x,pos2.y),0,30)
self:AddTurret(FoeID,vec2(pos2.x,pos2.y),-55,30)
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 = 90
followrot = false
decrease = 0
shotcap = 1
scoreval = 100
end
if foetype == 9 then
local c = color(67, 72, 72, 255)
self.m:setRectTex(index,0.865,0.455,0.06,0.11)
self.m:setRectTex(shadeindex,0.865,0.455,0.06,0.11)
self.m:setRectColor(index, c)
life = 40
w = 70
h = 70
followrot = true
decrease = 0
shotcap = 2
scoreval = 200
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.93,0.45,0.06,0.20)
self.m:setRectColor(index, c)
life = 40
w = 50
h = 70
followrot = false
decrease = 0
shotcap = 1
scoreval = 300
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(1,3),foetype,w,h,followrot,life,decrease,shotcap,scoreval))
end
end
end
function Foe:AddTurret(_parent,_pos,xdisplace,ydisplace)
local foetype = 3
if table.maxn(self.foes) < 200 and self.forcepause == 0 then
self.count = self.count + 1
local pos2 = _pos
local index = self.m:addRect(pos2.x,pos2.y, 55, 65)
shadecolor = color(0, 0, 0, 50)
local w,h = 0
local life = 5
local followrot = false
decrease = 0
shotcap = 0
shadeindex = 0
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 = 90
h = 60
followrot = true
decrease = 0
shotcap = 1000
scoreval = 750
ang = (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,scoreval))
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
function Foe:addexplosion1(pos)
table.insert(self.explosions,Explosun(pos))
end
function Foe:addexplosion2(pos)
for i=1,10 do
local newpos = vec2(pos.x+math.random(-100,100),pos.y+math.random(-200,200))
table.insert(self.explosions,Explosun(newpos,size))
end
end
Foe0 = class()
function Foe0:init(id,i,shadeindex,x,y,a,speed,ftype,w,h,followrotation,life,decrease,shotcap,scoreval)
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,2)
self.stop = decrease
if self.stop == 1 then
self.speeddecremental = 0.01
else
self.speeddecremental = 0.01
end
self.stoptimer = 100
self.internaltimer = 0
self.lastshotangle = 0
self.pos = vec2(self.x,self.y)
self.destroyed = false
self.alpha = 255
end
Turret = class()
function Turret:init(xdisplace,ydisplace,id,parent,i,shadeindex,x,y,a,speed,ftype,w,h,followrotation,life,decrease,shotcap,scoreval)
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,2)
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
self.lastshotangle = 0
self.alpha = 255
self.pos = vec2(self.x,self.y)
end
--# Hud
Hud = class()
function Hud:init()
self.beambar = hudbar
end
function Hud:draw()
-- sprite(self.beambar,50,120,60)
end
--# Main
displayMode(FULLSCREEN)
function setup()
font("HelveticaNeue-UltraLight")
fontSize(16)
sound(SOUND_EXPLODE, 48293, 0)
sound(SOUND_RANDOM, 46477, 0)
sound(SOUND_PICKUP, 16373, 0)
FoeClassA = readImage("Dropbox:Foe-Class-B")
Level = 0
Playerpos = vec2(0,0)
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")
-- bgColor = color(math.random(0,30), math.random(30,35), math.random(50,50))
bgColor = color(31, 45, 111, 255)
hudbar = readImage("Dropbox:FWTech-2")
hudtechsheet = readImage("Dropbox:FWTech-1")
--font("quantico-bold")
pl1 = Player1()
PlayerHit = false
PlayerHitTimer = 0
fps = FPS()
hb = HealthBar(60,60,600,20,Player_Energy)
--PlayerScore = PlayerScore(vec2(100,120))
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 = Background()
PlayerBullets = PlayerBullets()
Foe = Foe()
FoeMissilesm = FoeMissilesm()
-- PlayerBullets.foes = Foe.foes
Foe.playerbullets = PlayerBullets.missiles
shp = ScoreHitPop()
biz = Biz()
corona = PlayerCorona()
--hb = HealthBar(60,60,600,20,Player_Energy)
hud = Hud()
--Utils = Utils()
--mdm = MissionDescMessage()
FoeID = 0
--music("Game Music One:Pulsar",true)
--music.volume = 0.5
Level = 2
-- bg:setup(Level)
end
function draw()
background(41, 103, 75, 255)
biz:draw()
fps:draw()
hud:draw()
hb:draw(PlayerDamage)
--shp:draw()
end
function touched(t)
pl1:touched(t)
end
Biz = class()
function Biz:init()
self.gametimer = 0
end
function Biz:draw()
bg:draw()
Foe:draw()
PlayerBullets:draw()
FoeMissilesm:draw()
pl1:draw()
self.gametimer = (self.gametimer + 1)%320
if self.gametimer%40 == 0 then
Foe:AddFoes(math.random(8,10),10)
-- Foe:AddFoes(math.random(4,7),1)
-- Foe:AddFoes(math.random(0,2),1)
end
end
--# Players
--# 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
corona:draw()
if self.frame%6 == 0 then
ang = math.deg(math.atan((Playerpos.x - Playerpos.x)/(HEIGHT + 100 - Playerpos.y)))
ang = ang + 180
PlayerBullets:spawnMissile(ang,self.pos,40)
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,70)
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,70)
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
self.coronas = {}
self.corona = mesh()
self.sprite = hudtechsheet
self.corona.texture = self.sprite
self.hid = false
self.hitcounter = 255
coronaindex = 0
coronaindex = self.corona:addRect(Playerpos.x,Playerpos.y,200,200)
self.corona:setRectTex(coronaindex,0.5,0,0.5,0.5)
self.corona:setRectColor(coronaindex, 0,200,200,100)
table.insert(self.coronas,CoronaItem1(coronaindex,0.1))
coronaindex = self.corona:addRect(Playerpos.x,Playerpos.y,200,200)
self.corona:setRectTex(coronaindex,0,0,0.5,0.5)
self.corona:setRectColor(coronaindex, 250,250,250,150)
table.insert(self.coronas,CoronaItem2(coronaindex,-0.1))
end
function PlayerCorona:draw()
self.timer = (self.timer+5)%320
self.radius = self.radius + 5
self.alpha = self.alpha - 5
self.corona:draw()
pushStyle()
fontSize(26)
fill(0, 0, 0, 255)
text((PlayerDamage/20*100).."%",Playerpos.x+83,Playerpos.y-3)
fill(60, 255, 0, 255)
text((PlayerDamage/20*100).."%",Playerpos.x+80,Playerpos.y)
popStyle()
for i,v in ipairs(self.coronas) do
v.rotation = v.rotation + v.rotationincremental
if self.hit == true then
self.hitcounter = self.hitcounter -1
v.color.g = v.color.g - 5
v.color.b = v.color.b - 5
if self.hitcounter <= 0 then
--v.color.g = 0
--v.color.r = 212 - v.color.g
end
if self.hitcounter == 0 then
self.hit = false
end
else
if v.color.g < (PlayerDamage / (20/255) ) then
v.color.g = v.color.g + 5
end
if v.color.b < v.originalcolor.b then
v.color.b = v.color.b + 5
end
--v.color.g = PlayerDamage / (20/255)
--v.color.r = 212 - v.color.g
if self.hitcounter <= 255 then
self.hitcounter = self.hitcounter + 1
end
end
self.corona:setRectColor(v.index, v.color.r,v.color.g,v.color.b,150)
self.corona:setRect(v.index,Playerpos.x,Playerpos.y,v.w,v.h,v.rotation)
end
end
function PlayerCorona:setpos(pos)
self.pos = pos
end
function PlayerCorona:sethit()
self.hit = true
self.hitcounter = 300
end
CoronaItem1 = class()
function CoronaItem1:init(index,inc)
self.index = index
self.rotation = 0
self.rotationincremental = inc or 0.1
self.alpha = 120
self.color = color(48, 144, 189, 255)
self.originalcolor = self.color
self.w = 200
self.h = 200
end
CoronaItem2 = class()
function CoronaItem2:init(index,inc)
self.index = index
self.rotation = 0
self.rotationincremental = inc or 0.1
self.alpha = 120
self.color = color(206, 212, 215, 255)
self.originalcolor = self.color
self.w = 200
self.h = 200
end
--# Utilities
--# Utilities
Arc = class()
local delta = math.pi / 36
-- If the Arc is closed, radius will be drawn
function Arc:init(startAngle, endAngle, radius, closed)
self.startAngle = startAngle
self.endAngle = endAngle
self.radius = radius
if closed ~= nil then
self.closed = closed
else
self.closed = false
end
self.points = {vec2(0, 0)}
for angle = startAngle, endAngle, delta do
local b = math.cos(angle) * radius
local h = math.sin(angle) * radius
table.insert(self.points, vec2(b, h))
end
end
function Arc:draw()
local n = #self.points
local startPoint = 1
local endPoint = n-2
if self.closed then
startPoint = 0
endPoint = n-1
end
for i = startPoint, endPoint do
local p1 = self.points[i%n + 1]
local p2 = self.points[(i+1)%n + 1]
line(p1.x, p1.y, p2.x, p2.y)
end
end
--# 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()
-- PlayerScore: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
PlayerScore = class()
vPlayerScore = 0
vPlayerShot = 0
vPlayerPowerup = 0
function PlayerScore:init(pos)
self.pos = pos
self.playerscore = 0
self.playershot = 0
self.playerpowerup = 0
self.shaketimer = 0
local ws,hs = 0
end
function PlayerScore:draw()
if self.playerscore < vPlayerScore then
self.playerscore = self.playerscore+50
end
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
pushStyle()
textMode(CORNER)
fontSize(34)
fill(255,255,255)
text("P1 : "..self.playerscore,self.pos.x+ws,self.pos.y+hs)
popStyle()
end
function PlayerScore:UpdateScore(addedVal)
vPlayerScore = vPlayerScore + addedVal
end
function PlayerScore:Shake()
self.shaketimer = 20
end
--# Weapons
--# 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
tindex = 0
index = 0
c = color(17, 197, 0, 255)
pos = vec2(0,0)
w,h = spriteSize(self.mesh.texture)
c = color(129, 255, 0, 255)
tremble = 0
foepos = vec2(0,2)
sc = 0
v = 0
end
function PlayerBullets:spawnMissile(a,pos2,speed)
tindex = tindex + 1
if table.maxn(self.missiles) < 100 and self.forcepause == 0 then
self.count = self.count + 1
index = self.mesh:addRect(pos2.x+20, pos2.y+45, 12, 125)
-- self.missiles[tindex] = FoeBolt(index,pos2.x+10,pos2.y+25,a,speed)
table.insert(self.missiles,FoeBolt(index,pos2.x+20,pos2.y+45,a,speed))
self.mesh:setRectTex(index,0,0,0.19,1)
index = self.mesh:addRect(pos2.x-20, pos2.y+45, 12, 125)
tindex = tindex + 1
table.insert(self.missiles,FoeBolt(index,pos2.x-20,pos2.y+45,a,speed))
self.mesh:setRectTex(index,0,0,0.19,1)
index = self.mesh:addRect(pos2.x, pos2.y+65, 12, 125)
tindex = tindex + 1
table.insert(self.missiles,FoeBolt(index,pos2.x,pos2.y+65,a,speed))
self.mesh:setRectTex(index,0,0,0.19,1)
if self.count == 100 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,k)
--self.mesh:setRectTex(index,1, 1, 1, 1)
--self.mesh.vertices = {0,0,0}
table.remove(self.missiles,k)
self.mesh:setRect(index,0, 0, 0, 0)
end
function PlayerBullets:draw(dt)
-- text("p1 shots : "..table.maxn(self.missiles),100,130)
self.mesh:draw()
if self.count >= 200 then
self.count = 0
self.forcepause = 1
end
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, 12, 125, 0)
if pos.x < -20 or pos.x > WIDTH + 20 then
self:removeRect(v.index,k)
---table.remove(self.missiles,k)
end
if pos.y < -120 or pos.y > HEIGHT + 120 then
self:removeRect(v.index,k)
--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
v.pos.x = v.x
v.pos.y = v.y
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.