Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --# Main
- --The name of the project must match your Codea project name if dependencies are used.
- --Project: Space Jam
- --Version: Alpha 1.0
- --Comments: shuttle fighter with enemies using visible boundaries for detection
- function setup()
- displayMode(FULLSCREEN)
- scr = vec2(WIDTH/2,HEIGHT/2)
- local verts = {vec2(-22.5,-15),vec2(-22.5,15),vec2(22.5,15),vec2(22.5,-15)}
- ply = physics.body(POLYGON,unpack(verts))
- ply.type = DYNAMIC
- ply.interpolate = true
- ply.sleepingAllowed = false
- ply.gravityScale = 0
- ply.position = vec2(WIDTH/2,HEIGHT/2)
- plymesh = mesh()
- plymesh.texture = readImage("Documents:ply")
- plymesh:setColors(255,255,255,255)
- plyrect = plymesh:addRect(ply.x,ply.y,40,60)
- plymesh:setRectTex(plyrect,0,0,1,1)
- plyhp = 100
- Score = 0
- shop = 1
- menu = 0
- scroll = 0
- buy = 0
- equip1 = 0
- equip2 = 0
- shopbg = mesh()
- shopimg = image(215,567)
- shopscrl = mesh()
- bg = mesh()
- Shop:setup()
- bgr = bg:addRect(0,0,4000,4000)
- bg.texture = readImage("Documents:boundaries")
- bg:setRectTex(bgr,0,0,1,1)
- if readLocalData("score") then
- Score = readLocalData("score")
- else
- Score = 0
- end
- --[[saveLocalData("score",1000)
- saveLocalData("it2",nil)
- saveLocalData("it3",nil)
- saveLocalData("ow",nil)]]
- pos = vec2(WIDTH/2, HEIGHT/2)
- steer = vec2(0,0)
- speed = 400
- controller = VirtualStick {
- moved = function(v) steer = v end,
- released = function(v) steer = vec2(0,0) end
- }
- controller:activate()
- Etbl = {}
- bangle = {}
- for i=1,40 do
- local pos = vec2(math.random(-2000,2000),math.random(-2000,2000))
- Enemies(0)
- Etbl[i] = Enemies:create(pos.x,pos.y,math.random(1,2),100)
- if pos:dist(ply.position) < 300 then
- Etbl[i][3].position = Etbl[i][3].position + (Etbl[i][3].position-ply.position):normalize()*(300-Etbl[i][3].position:dist(ply.position))
- end
- bangle[i] = math.random(0,360)
- end
- local verts = {vec2(-2000,-2000),vec2(-2000,2000),vec2(2000,2000),vec2(2000,-2000),vec2(-2000,-2000)}
- walls = physics.body(CHAIN,false,unpack(verts))
- shooting = 0
- shootingdir = vec2(10,0)
- plyb = {}
- plyamnt = 0
- plybtime = 0
- bulletspeed = 5
- firerate = 5
- guntype = 1
- explosion = nil
- explosions = {}
- Inventory = {}
- Inventory[1] = 1
- if readLocalData("it2") ~= nil then
- Inventory[2] = readLocalData("it2")
- else
- Inventory[2] = nil
- end
- if readLocalData("it3") ~= nil then
- Inventory[3] = readLocalData("it3")
- else
- Inventory[3] = nil
- end
- touches = {}
- val = 50
- ast = {}
- for i = 1,val do
- local size = math.random(20,100)
- ast[i] = {}
- ast[i][1] = vec2(math.random(-2000,2000),math.random(-2000,2000))
- ast[i][2] = size
- ast[i][4] = mesh()
- local m = ast[i][4]
- local verts = {}
- local verts2 = {}
- local newverts = {}
- local height = math.random(-2000,2000)
- local width = math.random(-2000,2000)
- local p = {}
- local a = 9.5
- local size = math.random(5,15)/10
- for i = 1,60 do
- local rndm = math.random(65,100)
- local pos = vec2(math.sin(i/a-(90/57.3))*rndm*size+width,math.cos(i/a-(90/57.3))*rndm*size+height)
- if pos:dist(vec2(width,height)) > 90*size then
- table.insert(p,pos)
- end
- end
- table.insert(p,p[1])
- m:setColors(150,150,150,255)
- m.vertices = triangulate(p)
- m:setColors(150,150,150,255)
- end
- sbutton = mesh()
- srect = sbutton:addRect(150,125,200,150)
- sbutton.texture = readImage("Documents:fireb")
- sbutton:setColors(255,255,255,150)
- button = {}
- brect = {}
- button[1] = mesh()
- brect[1] = button[1]:addRect(125,300,150,100)
- button[1].texture = readImage("Documents:lasergun")
- button[1]:setColors(255,255,255,150)
- button[2] = mesh()
- brect[2] = button[2]:addRect(125,450,150,100)
- if Inventory[2] == nil then
- button[2].texture = readImage("Documents:noweapon")
- else
- button[2].texture = Equipped(Inventory[2])[1]
- end
- button[2]:setColors(255,255,255,150)
- button[3] = mesh()
- brect[3] = button[3]:addRect(125,600,150,100)
- if Inventory[3] == nil then
- button[3].texture = readImage("Documents:noweapon")
- else
- button[3].texture = Equipped(Inventory[3])[1]
- end
- button[3]:setColors(255,255,255,150)
- shopbuttontex = {readImage("Documents:plasmag"),readImage("Documents:Protongun"),
- readImage("Documents:photong"),readImage("Documents:iongun"),readImage("Documents:blitzer")}
- shopbutton = {}
- shoprect = {}
- for n = 2,6 do
- shopbutton[n] = mesh()
- shoprect[n] = shopbutton[n]:addRect(107.5,640-n*160,150,150)
- shopbutton[n].texture = shopbuttontex[n-1]
- shopbutton[n]:setColors(150,150,150,255)
- end
- m2 = mesh()
- mr2 = m2:addRect(1,1,1,1)
- m2:setColors(200,0,0,50)
- shopb = mesh()
- shopr = shopb:addRect(1,1,100,75)
- shopb.texture = readImage("Documents:shopb")
- shopb:setRectTex(shopr,0,0,1,1)
- shopb:setColors(255,255,255,255)
- end
- function angleOfPoint( pt )
- local x, y = pt.x, pt.y
- local radian = math.atan2(y,x)
- local angle = radian*180/math.pi
- if angle < 0 then angle = 360 + angle end
- return angle
- end
- function Equipped(x)
- if x == 1 then
- return {readImage("Documents:lasergun"),1,5,7}
- elseif x == 2 then
- return {readImage("Documents:plasmag"),2,7,5}
- elseif x == 3 then
- return {readImage("Documents:Protongun"),3,2,12}
- elseif x == 4 then
- return {readImage("Documents:photong"),4,4,12}
- elseif x == 5 then
- return {readImage("Documents:iongun"),5,5,9}
- elseif x == 6 then
- return {readImage("Documents:blitzer"),6,3,10}
- end
- end
- function changeGun(x)
- local gun = Equipped(x)
- if x == 1 then
- guntype = gun[2]
- firerate = gun[3]
- bulletspeed = gun[4]
- elseif gun then
- guntype = gun[2]
- firerate = gun[3]
- bulletspeed = gun[4]
- end
- end
- function Size(ent)
- if Etbl[ent] ~= nil then
- local type = Etbl[ent][5]
- if type == 1 then return 1
- elseif type == 2 then return 2
- end
- else
- return 0
- end
- end
- function moveScreen()
- scr.x = WIDTH/2 - ply.x
- scr.y = HEIGHT/2 - ply.y
- translate(scr.x,scr.y)
- end
- function applyAngle(ent,ang)
- if ang == nil then return end
- ent.angularVelocity = ang
- end
- -- This function gets called once every frame
- function draw()
- if shop == 0 then
- if menu == 0 then
- -- This sets a dark background color
- background(40, 40, 50)
- -- This sets the line thickness
- strokeWidth(5)
- ----
- ----
- pos = pos + steer*speed*DeltaTime
- ----
- moveScreen()
- for z = 1,val do
- ast[z][4]:draw()
- end
- bg:setRect(bgr,0,0,4000,4000)
- bg:draw()
- if steer ~= vec2() then
- angle = angleOfPoint(steer)
- while angle - ply.angle > 180 do
- angle = angle - 360
- end
- while angle - ply.angle < -180 do
- angle = angle + 360
- end
- ang = (angle-ply.angle)/10
- else
- ang = 0
- end
- --ply angle normalising
- while (ply.angle + ang) > 360 do
- ply.angle = ply.angle + ang - 360
- end
- while (ply.angle - ang) < 0 do
- ply.angle = ply.angle + ang + 360
- end
- --car angle force
- applyAngle(ply,((ply.angle+ang)-ply.angle)*100 - ply.angularVelocity/2)
- if steer:len() > 0.1 then
- ply:applyForce(steer*17.5)
- end
- ply.linearVelocity = ply.linearVelocity*0.965
- local angt = bangle[i]
- if body ~= nil then
- if body.position:dist(ply.position) > 150 then
- bangle[i] = math.random(-50,50)*7.5
- body.angularVelocity = bangle[i]
- body:applyForce(vec2(0,1000):rotate((body.angle-90)/57.3))
- end
- body.linearVelocity = body.linearVelocity * 0.97
- body.angularVelocity = body.angularVelocity * 0.9
- mb:setRect(mbr,body.x,body.y,400,400)
- mb:draw()
- m:setRect(r,body.x,body.y,40*Size(i),30*Size(i),(body.angle)/57.3)
- m:draw()
- end
- --end
- sbutton:setRect(srect,scr.x*-1+150,scr.y*-1+100,200,100)
- if shooting == 0 then
- sbutton:draw()
- end
- controller:draw()
- button[1]:setRect(brect[1],scr.x*-1+125,scr.y*-1+300,100,100)
- button[1]:draw()
- button[2]:setRect(brect[2],scr.x*-1+125,scr.y*-1+450,100,100)
- button[2]:draw()
- button[3]:setRect(brect[3],scr.x*-1+125,scr.y*-1+600,100,100)
- button[3]:draw()
- shopb:setRect(shopr,scr.x*-1+125,scr.y*-1+700,150,70)
- shopb:draw()
- plymesh:setRect(plyrect,ply.x,ply.y,50,35,ply.angle/57.3)
- plymesh:draw()
- for k,v in pairs(explosions) do
- if v:isDone() then
- table.remove(explosions,k)
- else
- v:draw()
- end
- end
- fontSize(15)
- stroke(150,150,150,200)
- fill(255,255)
- text("Health:",scr.x*-1+50,scr.y*-1+230)
- text("FPS: "..math.ceil(1/DeltaTime),scr.x*-1+54,scr.y*-1+200)
- text("Score: "..Score,scr.x*-1+55,scr.y*-1+170)
- fill(255-plyhp*2.55,plyhp*2.55,0,255)
- strokeWidth(4)
- rect(scr.x*-1+80,scr.y*-1+220,plyhp,20)
- elseif menu == 1 then
- background(40,255)
- strokeWidth(1)
- fill(75, 128, 86, 131)
- rect(0,0,WIDTH,HEIGHT)
- end
- elseif shop == 1 then
- background(0)
- Shop:draw()
- for i=1,#Etbl do
- if Etbl[i] ~= nil then
- local body = Etbl[i][3]
- if body.position:dist(ply.position) < 400 then
- body.linearVelocity = (body.position-ply.position):normalize()*100
- end
- end
- end
- end
- end
- --# Controller
- Controller = class()
- function Controller:activate()
- touched = function(t)
- self:touched(t)
- end
- end
- function Controller:draw()
- -- nothing
- end
- -- Utility functions
- function touchPos(t)
- return vec2(t.x, t.y)
- end
- function clamp(x, min, max)
- return math.max(min, math.min(max, x))
- end
- function clampAbs(x, maxAbs)
- return clamp(x, -maxAbs, maxAbs)
- end
- function clampLen(vec, maxLen)
- if vec == vec2(0,0) then
- return vec
- else
- return vec:normalize() * math.min(vec:len(), maxLen)
- end
- end
- -- projects v onto the direction represented by the given unit vector
- function project(v, unit)
- return v:dot(unit)
- end
- function sign(x)
- if x == 0 then
- return 0
- elseif x < 0 then
- return -1
- elseif x > 0 then
- return 1
- else
- return x -- x is NaN
- end
- end
- function doNothing()
- end
- --# VirtualStick
- VirtualStick = class(Controller)
- function VirtualStick:init(args)
- self.radius = args.radius or 100
- self.deadZoneRadius = args.deadZoneRadius or 25
- self.releasedCallback = args.released or doNothing
- self.steerCallback = args.moved or doNothing
- self.pressedCallback = args.pressed or doNothing
- touches = {}
- pos1 = vec2()
- pos2 = vec2()
- nt={}
- end
- function abs(v2)
- return math.abs(v2)
- end
- function VirtualStick:touched(t)
- if shop == 0 then
- if t.state == BEGAN and self.touchId == nil and touchPos(t).x > WIDTH/2 and touches[1] == nil then
- ended = 0
- touches[1] = t
- self.touchId = touches[1].id
- self.touchStart = vec2(WIDTH-150,150)
- self.stickOffset = vec2(0,0)
- self.pressedCallback()
- elseif touches[1] and t.id == touches[1].id then
- touches[1] = t
- local pos = touchPos(touches[1])
- if touches[1].state == MOVING then
- self.stickOffset = clampLen(pos - self.touchStart, self.radius)
- self.steerCallback(self:vector())
- elseif touches[1].state == ENDED or touches[1].state == CANCELLED then
- ended = 1
- self:reset()
- self.releasedCallback()
- touches[1] = nil
- end
- end
- if t.state == BEGAN and touchPos(t).x < WIDTH/2 and touches[2] == nil then
- if t.x > 50 and t.y > 50 and t.x < 250 and t.y < 150 then
- shooting = 1
- touches[2] = t
- sbutton:setColors(150,150,150,150)
- end
- elseif t.state == MOVING and touches[2] and t.id == touches[2].id then
- touches[2] = t
- if vec2(t.x,t.y):dist(vec2(150,100)) then
- shootingdir = (vec2(t.x,t.y)-vec2(150,100)):normalize()
- else
- shootingdir = vec2(0,10):rotate((ply.angle-90)/57.3):normalize()
- end
- elseif touches[2] and t.id == touches[2].id then
- if t.state == ENDED then
- shooting = 0
- sbutton:setColors(255,255,255,150)
- touches[2] = nil
- saveLocalData("score",Score)
- end
- end
- if t.state == BEGAN and touchPos(t).x < WIDTH/2 and touches[3] == nil then
- touches[3] = t
- if t.x > 50 and t.y > 250 and t.x < 200 and t.y < 350 then
- changeGun(Inventory[1])
- button[1]:setColors(150,150,154,150)
- end
- if t.x > 50 and t.y > 400 and t.x < 200 and t.y < 500 then
- changeGun(Inventory[2])
- button[2]:setColors(150,150,150,150)
- end
- if t.x > 50 and t.y > 550 and t.x < 200 and t.y < 650 then
- changeGun(Inventory[3])
- button[3]:setColors(150,150,150,150)
- end
- elseif touches[3] and t.id == touches[3].id then
- if t.state == ENDED then
- button[1]:setColors(255,255,255,150)
- button[2]:setColors(255,255,255,150)
- button[3]:setColors(255,255,255,150)
- touches[3] = nil
- if t.x > 50 and t.y > 665 and t.x < 200 and t.y < 735 then
- shop = 1
- end
- end
- end
- end
- if shop == 1 then
- Shop:touched(t)
- end
- end
- function VirtualStick:vector()
- local stickRange = self.radius - self.deadZoneRadius
- local stickAmount = math.max(self.stickOffset:len(), 0)
- local stickDirection = self.stickOffset:normalize()
- return stickDirection * (stickAmount/stickRange)
- end
- function VirtualStick:reset()
- self.touchId = nil
- self.touchStart = nil
- self.stickOffset = nil
- end
- function VirtualStick:draw()
- if self.touchId ~= nil then
- pushStyle()
- ellipseMode(RADIUS)
- strokeWidth(1)
- stroke(255, 255, 255, 255)
- noFill()
- pushMatrix()
- translate(scr.x*-1+self.touchStart.x,scr.y*-1+self.touchStart.y)
- fill(150,150,150,100)
- ellipse(0, 0, self.radius, self.radius)
- fill(164, 164, 164, 150)
- ellipse(0, 0, self.deadZoneRadius, self.deadZoneRadius)
- fill(150,150,150,100)
- translate(self.stickOffset.x, self.stickOffset.y)
- ellipse(0, 0, 25, 25)
- popMatrix()
- popStyle()
- else
- pushStyle()
- ellipseMode(RADIUS)
- strokeWidth(3)
- pushMatrix()
- translate(scr.x*-1+WIDTH-150,scr.y*-1+150)
- fill(150,150,150,100)
- ellipse(0,0,40)
- popMatrix()
- popStyle()
- end
- if touches[2] ~= nil then
- pushStyle()
- ellipseMode(RADIUS)
- strokeWidth(3)
- pushMatrix()
- translate(-scr.x,-scr.y)
- fill(150,150,150,200)
- ellipse(150,100,70)
- stroke(100,100,100,255)
- strokeWidth(10)
- local pos = vec2(150,100)+(vec2(touches[2].x,touches[2].y)-vec2(150,100)):normalize()*clamp(vec2(touches[2].x,touches[2].y):dist(vec2(150,100)),5,70)
- line(pos.x,pos.y,150,100)
- ellipse(pos.x,pos.y,25)
- popMatrix()
- popStyle()
- end
- end
- --# Enemies
- Enemies = class()
- function Enemies:init(deatht)
- self.dtime = deatht
- end
- function Enemies:create(x,y,type,health)
- -- you can accept and set parameters here
- local verts = {vec2(-20,-15)*type,vec2(-20,15)*type,vec2(20,15)*type,vec2(20,-15)*type}
- self.body = physics.body(POLYGON,unpack(verts))
- --self.body.type = DYNAMIC
- self.body.interpolate = false
- self.body.sleepingAllowed = false
- self.body.gravityScale = 0
- self.body.mass = 2
- self.body.position = vec2(x,y)
- self.body.angle = math.random(0,360)/57.3
- self.health = health*type^1.5
- self.time = math.random(0,99)
- self.bullets = {}
- self.bullettime = 0
- self.bulletamnt = 0
- self.type = type
- self.mesh = mesh()
- if type == 1 then
- self.mesh.texture = readImage("Documents:spaceship")
- elseif type == 2 then
- self.mesh.texture = readImage("Documents:big spaceship")
- end
- self.mesh:setColors(255,255,255,255)
- self.rect = self.mesh:addRect(self.body.x,self.body.y,20,30,self.body.angle)
- self.mesh:setRectTex(self.rect,0,0,1,1)
- self.bmesh = mesh()
- self.bmesh.texture = readImage("Documents:circle")
- self.brect = self.bmesh:addRect(self.body.x,self.body.y,400,400)
- self.bmesh:setColors(255,255,255,100)
- self.bmesh:setRectTex(self.brect,0,0,1,1)
- return {self.mesh,self.rect,self.body,self.health,self.type,self.time,self.bullets,self.bullettime,self.bulletamnt,self.bmesh,self.brect}
- end
- function Enemies:draw()
- -- Codea does not au
- end
- function Enemies:touched(touch)
- -- Codea does not automatically call this method
- end
- function Enemies:Die(x)
- local enemy = Etbl[x]
- local size = Size(x)
- Etbl[x][4] = 100*size^1.5
- Etbl[x][3].position = vec2(math.random(-1900,1900),math.random(-1900,1900))
- Score = Score + 25*size
- saveLocalData("score",Score)
- Etbl[x][1]:setColors(255,255,255,255)
- sound(SOUND_EXPLODE)
- end
- --# Shop
- Shop = class()
- function Shop:setup()
- -- you can accept and set parameters here
- self.m = mesh()
- self.r = self.m:addRect(WIDTH/2,HEIGHT/2,WIDTH,HEIGHT)
- self.m.texture = readImage("Documents:shop")
- self.m:setRectTex(self.r,0,0,1,1)
- shopbg = self.m
- self.m = mesh()
- self.m.texture = shopimg
- self.r = self.m:addRect(207.5,383.5,215,567)
- self.m:setRectTex(self.r,0,0,1,1)
- shopscrl = self.m
- dir = 0
- Selected = 0
- Cost = 0
- ydelta = 0
- if readLocalData("ow") ~= nil then
- ownedwep = readLocalData("ow")
- else
- ownedwep = ""
- end
- shopprices = {}
- shopprices[2] = 2000
- shopprices[3] = 3000
- shopprices[4] = 5000
- shopprices[5] = 12000
- shopprices[6] = 22000
- end
- function Shop:draw()
- -- Codea does not automatically call this method
- background(40,40,40,255)
- shopbg:draw()
- if buy > 0.1 then
- fill(150,150,150,150)
- buy = buy - 0.1
- end
- if buy <= 0.1 then
- buy = 0
- end
- if buy == 0 then
- fill(255, 255, 255, 0)
- end
- rect(350,430,165,75)
- if equip1 > 0.1 then
- fill(equip1*25.5,100)
- equip1 = equip1 - 0.1
- end
- if equip1 <= 0.1 then
- equip1 = 0
- end
- if equip1 == 0 then
- fill(255, 255, 255, 0)
- end
- rect(350,310,165,75)
- if equip2 > 0.1 then
- fill(equip2*25.5+50,100)
- equip2 = equip2 - 0.1
- end
- if equip2 <= 0.1 then
- equip2 = 0
- end
- if equip2 == 0 then
- fill(255, 255, 255, 0)
- end
- rect(350,210,165,80)
- fill()
- fill(190, 190, 190, 150)
- strokeWidth(10)
- stroke(0,50,255,150)
- rect(WIDTH-250,45,200,70)
- pushMatrix()
- resetMatrix()
- setContext(shopimg)
- background(155, 155, 155, 255)
- for i = 2,#shopbutton do
- shopbutton[i]:setRect(shoprect[i],107.5,800-i*160+scroll,150,150)
- shopbutton[i]:draw()
- fontSize(20)
- if string.find(ownedwep,i) then
- text("Owned",107.5,742-i*160+scroll)
- else
- text("$"..shopprices[i],107.5,742-i*160+scroll)
- end
- end
- setContext()
- popMatrix()
- shopscrl:draw()
- fill(46, 46, 46, 255)
- fontSize(50)
- text("Exit",WIDTH-150,80)
- fontSize(30)
- fill(255,200)
- text("Score: "..Score,WIDTH-200,HEIGHT-70)
- dir = dir + ydelta/20
- dir = dir *0.99
- scroll = scroll + dir
- if scroll < 0 then
- scroll = 0
- --dir = 0
- elseif scroll > 250 then
- scroll = 250
- --dir = 250
- end
- end
- function Shop:touched(t)
- if t.state == BEGAN and t.x > WIDTH-250 and t.x < WIDTH-50 and t.y > 45 and t.y < 115 then
- shop = 0
- end
- for i = 2,#shopbutton do
- if Selected < 1 and t.state == BEGAN and vec2(t.x,t.y):dist(vec2(215,895-i*160+scroll)) < 75 then
- if Score > shopprices[i] or string.find(ownedwep,i) ~= nil then
- shopbutton[i]:setColors(50,50,50,255)
- Selected = i
- Cost = shopprices[i]
- print(shopprices[i])
- else
- Selected = 0
- end
- elseif t.state == ENDED then
- if Selected == 0 then
- shopbutton[i]:setColors(150,150,150,255)
- end
- end
- if Selected > 0 and t.state == BEGAN and vec2(t.x,t.y):dist(vec2(215,895-i*160+scroll)) < 75 then
- if i ~= Selected and (Score > shopprices[i] or string.find(ownedwep,i) ~= nil) then
- shopbutton[Selected]:setColors(150,150,150,255)
- shopbutton[i]:setColors(50,50,50,255)
- Selected = i
- Cost = shopprices[i]
- print(shopprices[i])
- end
- end
- if t.state == MOVING and vec2(t.x,t.y):dist(vec2(215,895-i*160+scroll)) < 75 then
- if math.abs(t.deltaY) > 0.1 then
- ydelta = t.deltaY
- end
- end
- end
- if shopprices[Selected] and Score > shopprices[Selected] and Selected > 1 and t.state == BEGAN and t.x < 515 and t.x > 350 and t.y < 500 and t.y > 430 then
- if string.find(ownedwep,Selected) == nil then
- ownedwep = ownedwep..Selected..","
- saveLocalData("ow",ownedwep)
- Score = Score - shopprices[Selected]
- buy = 1
- saveLocalData("score",Score)
- end
- end
- if t.state == BEGAN and t.x < 510 and t.x > 350 and t.y < 385 and t.y > 310 and string.find(ownedwep,Selected) ~= nil and readLocalData("it3") ~= Selected then
- Inventory[2] = Selected
- button[2].texture = Equipped(Selected)[1]
- saveLocalData("it2",Selected)
- Selected = 0
- equip1 = 1
- end
- if t.state == BEGAN and t.x < 510 and t.x > 350 and t.y < 290 and t.y > 210 and string.find(ownedwep,Selected) ~= nil and readLocalData("it2") ~= Selected then
- Inventory[3] = Selected
- button[3].texture = Equipped(Selected)[1]
- saveLocalData("it3",Selected)
- Selected = 0
- equip2 = 1
- end
- end
- --# Explosion
- Explosion = class()
- function Explosion:init(pos,size)
- self.pos = pos+vec2(0,10):rotate(math.random(0,360)/57.3)
- self.time = 0
- self.size = size
- self.dir = {}
- self.rect = {}
- col = color(math.random(200,255),math.random(0,50),math.random(0,50))
- self.alpha = 255
- self.mesh = mesh()
- self.s = {}
- for i=1,10 do
- table.insert(self.dir,(vec2(0,1):rotate(math.rad(math.random(0,360))))*(math.random(2,5)/2)*self.size)
- self.mesh.texture = readImage("Tyrian Remastered:Explosion Huge")
- table.insert(self.rect,self.mesh:addRect(1,1,1,1))
- table.insert(self.s,math.random(10,40))
- end
- end
- function Explosion:draw()
- self.time = self.time + 0.5
- local p = self.pos
- self.mesh:setColors(255,255,255,self.alpha)
- for k,v in ipairs(self.dir) do
- kt = p + v*self.time
- --line(p.x,p.y,kt.x,kt.y)
- --ellipse(kt.x,kt.y,math.random(15,35))
- --local wh = self.s[k]
- local wh = self.s[k]+math.random(10,20)
- self.mesh:setRect(self.rect[k],kt.x,kt.y,wh,wh)
- self.mesh:draw()
- end
- end
- function Explosion:touched(touch)
- end
- function Explosion:isDone()
- if self.time >= 25.5 then
- return true
- else
- self.alpha = 255-(10*self.time)
- return false
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement