Created
June 19, 2013 18:40
-
-
Save briarfox/5816766 to your computer and use it in GitHub Desktop.
Particular Particles Release v2.1.9 -Particle Effects Editor.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Particular Particles Tab Order Version: 2.1.9 | |
------------------------------ | |
This file should not be included in the Codea project. | |
#Main | |
#Particular | |
#SavedOutput | |
#ChangeLog |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[[ | |
VERSION 2.1.9 | |
-Added an update notification | |
-Added ChangeLog | |
--]] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Copyright 2012 Javier Moral | |
-- | |
-- Licensed under the Apache License, Version 2.0 (the "License"); | |
-- you may not use this file except in compliance with the License. | |
-- You may obtain a copy of the License at | |
-- | |
-- http://www.apache.org/licenses/LICENSE-2.0 | |
-- | |
-- Unless required by applicable law or agreed to in writing, software | |
-- distributed under the License is distributed on an "AS IS" BASIS, | |
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
-- See the License for the specific language governing permissions and | |
-- limitations under the License. | |
--Updated and maintained by Briarfox | |
VERSION = "2.1.9" --Do not Edit This | |
PROJECTNAME = "Particular Particles" --Please set this to whatever you named your project | |
LoadParticleTab = true | |
t = 0.0 | |
lastGen = 0.0 | |
fps = 0 | |
frameCount = 0 | |
smokeButtonPos = vec2(60,30) | |
flameButtonPos = vec2(170,30) | |
dustButtonPos = vec2(60,90) | |
trailButtonPos = vec2(170,90) | |
customButtonPos = vec2(280,30) | |
anim = false | |
animAngle = 0 | |
drawDir = false | |
imageGrid = nil | |
PARTICLES = 1 | |
DRAWPACK = 2 | |
APPSTATE = PARTICLES | |
-- Use this function to perform your initial setup | |
function setup() | |
VersionUpdateChecker.check() | |
math.randomseed(os.time()) | |
backingMode(RETAINED) | |
loadPartParam() | |
emitter = Particular(WIDTH/2,HEIGHT/2,output) | |
emitter.particularMesh.texture = "Cargo Bot:Star" | |
presetDefault() | |
prevTouch = 0 | |
newTouch = 0 | |
end | |
-- This function gets called once every frame | |
function draw() | |
if APPSTATE == DRAWPACK then drawPack() end | |
if coLoad then | |
ok,grid = coroutine.resume(coLoad) | |
if type(grid)=="table" then imageGrid = grid end | |
end | |
if APPSTATE == PARTICLES then | |
loadParameters() | |
noSmooth() | |
fill(0, 0, 0, 255) | |
rect(0,0,WIDTH,HEIGHT) | |
if anim == true then | |
animateEmitter() | |
end | |
emitter:draw() | |
if (Draw_Emitters == 1) then | |
fill(0, 230, 255, 255) | |
strokeWidth(3) | |
stroke(255, 255, 255, 255) | |
ellipse(emitter.x,emitter.y,20) | |
noStroke() | |
end | |
if frameCount == 31 then | |
frameCount = 0 | |
else | |
frameCount = frameCount + 1 | |
end | |
t = t + DeltaTime | |
if frameCount == 30 then | |
fps = 1.0/DeltaTime | |
end | |
fontSize(15) | |
font("ArialMT") | |
fill(255) | |
text(string.format("Fps: %2.2f",fps),WIDTH - 60, 30) | |
text(string.format("Time: %2.2f",t), WIDTH - 60, 50) | |
drawButtons() | |
end | |
end | |
function drawButtons() | |
fill(94, 0, 255, 81) | |
rect(5,5,220,130) | |
fill(255) | |
text("Presets:",40,125) | |
font("Baskerville-Bold") | |
fill(242, 41, 41, 255) | |
fontSize(30) | |
drawButton(smokeButtonPos.x, | |
smokeButtonPos.y, | |
"Smoke") | |
drawButton(flameButtonPos.x, | |
flameButtonPos.y, | |
"Flame") | |
drawButton(dustButtonPos.x, | |
dustButtonPos.y, | |
"Dust") | |
drawButton(trailButtonPos.x, | |
trailButtonPos.y, | |
"Trail") | |
drawButton(customButtonPos.x, | |
customButtonPos.y, | |
"Custom") | |
end | |
function animateEmitter() | |
emitter.x = WIDTH/2 + math.cos(animAngle) * 150 | |
emitter.y = HEIGHT/2 + math.sin(animAngle) * 100 | |
animAngle = animAngle + 0.05 | |
end | |
function loadParameters() | |
emitter.partPerSec = Particles_Sec | |
emitter.sizeX = Emitter_SizeX | |
emitter.sizeY = Emitter_SizeY | |
emitter.life = Life | |
emitter.lifeVariation = Life_Variation | |
emitter.initPartSize = PartSize | |
emitter.partSizeVariation = PartSize_Variation | |
emitter.finalPartSize = Part_End_Life_Size | |
emitter.velocity = Velocity | |
emitter.velocityVariation = Velocity_Variation | |
emitter.rotSpd = Rotation_Speed | |
emitter.rotSpdVariation = Rotation_Speed_Variation | |
emitter.initOpacity = Opacity | |
emitter.opacityVariation = Opacity_Variation | |
emitter.finalOpacity = Opacity_End | |
emitter.windX = WindX | |
emitter.airResistance = Air_Resistance | |
emitter.gravity = Gravity_Val | |
emitter.useGravityVector = Use_Gravity_Vector | |
emitter.sizeWiggle = Size_Wiggle | |
emitter.turbulencePosAffect = Turbulence_Pos_Affect | |
end | |
function drawButton(x,y,caption) | |
font("ArialRoundedMTBold") | |
sprite("Cargo Bot:Dialogue Button",x,y) | |
fill(84, 84, 84, 255) | |
fontSize(26) | |
text(caption,x+1,y+1) | |
fill(255) | |
fontSize(26) | |
text(caption,x,y) | |
end | |
function touched(touch) | |
if(touch.state == ENDED) then | |
if isTouched(touch.x, | |
touch.y, | |
smokeButtonPos.x - 20, | |
smokeButtonPos.y - 20, | |
smokeButtonPos.x + 20, | |
smokeButtonPos.y + 20) then | |
presetSmoke() | |
--sound(SOUND_HIT,1) | |
return | |
end | |
if isTouched(touch.x, | |
touch.y, | |
flameButtonPos.x - 20, | |
flameButtonPos.y - 20, | |
flameButtonPos.x + 20, | |
flameButtonPos.y + 20) then | |
presetFlame() | |
--sound(SOUND_HIT,1) | |
return | |
end | |
if isTouched(touch.x, | |
touch.y, | |
dustButtonPos.x - 20, | |
dustButtonPos.y - 20, | |
dustButtonPos.x + 20, | |
dustButtonPos.y + 20) then | |
presetDust() | |
--sound(SOUND_HIT,1) | |
return | |
end | |
if isTouched(touch.x, | |
touch.y, | |
trailButtonPos.x - 20, | |
trailButtonPos.y - 20, | |
trailButtonPos.x + 20, | |
trailButtonPos.y + 20) then | |
presetTrail() | |
--sound(SOUND_HIT,1) | |
return | |
end | |
if isTouched(touch.x, | |
touch.y, | |
customButtonPos.x - 20, | |
customButtonPos.y - 20, | |
customButtonPos.x + 20, | |
customButtonPos.y + 20) then | |
local f=function() APPSTATE = DRAWPACK imageGrid = loadMenu() end | |
f() | |
--sound(SOUND_HIT,1) | |
return | |
end | |
end | |
if anim == false and isTouched(touch.x, | |
touch.y, | |
emitter.x - 40, | |
emitter.y - 40, | |
emitter.x + 40, | |
emitter.y + 40) then | |
emitter.x = touch.x | |
emitter.y = touch.y | |
if emitter.y < 150 then | |
emitter.y = 150 | |
end | |
return | |
end | |
if APPSTATE == DRAWPACK then | |
if imageGrid then | |
if touch.state == BEGAN then prevTouch = touch.y end | |
if touch.state == ENDED then newTouch = touch.y end | |
if newTouch >= prevTouch-10 and newTouch <= prevTouch +10 then | |
for i,j in pairs(imageGrid) do | |
for k,l in pairs(j) do | |
imageGrid[i][k]:isTouched(touch) | |
end | |
end | |
else | |
for i,j in pairs(imageGrid) do | |
for k,l in pairs(j) do | |
imageGrid[i][k].y = imageGrid[i][k].y + (touch.deltaY*2) | |
end | |
end | |
end | |
end | |
end | |
end | |
function isTouched(tx,ty,x1,y1,x2,y2) | |
if tx >= x1 and tx <= x2 then | |
if ty >= y1 and ty <= y2 then | |
return true | |
end | |
end | |
return false | |
end | |
function presetDefault() | |
anim = false | |
emitter.particularMesh.texture = "Cargo Bot:Star" | |
Particles_Sec = 100 | |
Life = 30 | |
Life_Variation = 0 | |
PartSize = 35 | |
PartSize_Variation = 0 | |
Part_End_Life_Size = -1 | |
Velocity = 10 | |
Velocity_Variation = 0 | |
Rotation_Speed = 0 | |
Rotation_Speed_Variation = 0 | |
Opacity = 255 | |
Opacity_Variation = 0 | |
Opacity_End = -1 | |
Air_Resistance = 0.1 | |
Gravity_Val = 0 | |
Use_Gravity_Vector = 0 | |
Size_Wiggle = 0 | |
Turbulence_Pos_Affect = 0 | |
end | |
function presetSmoke() | |
anim = false | |
emitter.particularMesh.texture = "Cargo Bot:Smoke Particle" | |
Emitter_SizeX = 0 | |
Emitter_SizeY = 0 | |
Particles_Sec = 10 | |
Life = 60 | |
Life_Variation = 20 | |
PartSize = 10 | |
PartSize_Variation = 100 | |
Part_End_Life_Size = 155 | |
Velocity = 5.7 | |
Velocity_Variation = 100 | |
Rotation_Speed = 0.08 | |
Rotation_Speed_Variation = 45 | |
Opacity = 125 | |
Opacity_Variation = 100 | |
Opacity_End = 20 | |
WindX = 0 | |
Air_Resistance = 0.2 | |
Gravity_Val = -1.15 | |
Use_Gravity_Vector = 0 | |
Size_Wiggle = 0 | |
Turbulence_Pos_Affect = 0 | |
end | |
function presetFlame() | |
anim = false | |
emitter.particularMesh.texture = | |
"Tyrian Remastered:Explosion Huge" | |
Emitter_SizeX = 0 | |
Emitter_SizeY = 0 | |
Particles_Sec = 100 | |
Life = 30 | |
Life_Variation = 50 | |
PartSize = 55 | |
PartSize_Variation = 100 | |
Part_End_Life_Size = 0 | |
Velocity = 2 | |
Velocity_Variation = 100 | |
Rotation_Speed = 0.2 | |
Rotation_Speed_Variation = 0 | |
Opacity = 100 | |
Opacity_Variation = 100 | |
Opacity_End = 255 | |
WindX = 0 | |
Air_Resistance = 0.1 | |
Gravity_Val = -1 | |
Use_Gravity_Vector = 0 | |
Size_Wiggle = 0 | |
Turbulence_Pos_Affect = 5 | |
end | |
function presetDust() | |
anim = false | |
emitter.particularMesh.texture = | |
"Tyrian Remastered:Energy Orb 1" | |
Emitter_SizeX = WIDTH - 100 | |
Emitter_SizeY = HEIGHT - 100 | |
Particles_Sec = 100 | |
Life = 150 | |
Life_Variation = 50 | |
PartSize = 5 | |
PartSize_Variation = 95 | |
Part_End_Life_Size = 0 | |
Velocity = 0 | |
Velocity_Variation = 0 | |
Rotation_Speed = 0.2 | |
Rotation_Speed_Variation = 50 | |
Opacity = 70 | |
Opacity_Variation = 80 | |
Opacity_End = 0 | |
WindX = -10 | |
Air_Resistance = 0.1 | |
Gravity_Val = 0.3 | |
Use_Gravity_Vector = 0 | |
Size_Wiggle = 0 | |
Turbulence_Pos_Affect = 5 | |
end | |
function presetTrail() | |
anim = true | |
emitter.particularMesh.texture = | |
"Cargo Bot:Star Filled" | |
Emitter_SizeX = 5 | |
Emitter_SizeY = 5 | |
Particles_Sec = 100 | |
Life = 150 | |
Life_Variation = 50 | |
PartSize = 15 | |
PartSize_Variation = 90 | |
Part_End_Life_Size = 5 | |
Velocity = 1.9 | |
Velocity_Variation = 90 | |
Rotation_Speed = 0.2 | |
Rotation_Speed_Variation = 50 | |
Opacity = 180 | |
Opacity_Variation = 80 | |
Opacity_End = 5 | |
WindX = -5 | |
Air_Resistance = 0.1 | |
Gravity_Val = -0.05 | |
Use_Gravity_Vector = 0 | |
Size_Wiggle = 1 | |
Turbulence_Pos_Affect = 5 | |
end | |
function saveCB() | |
if Particle_Name ~= "" then | |
Particle_Name = string.gsub(Particle_Name, "%s+", "") | |
local str = readProjectTab("SavedOutput") | |
if _G[Particle_Name] then | |
str = removeParticle(str,Particle_Name) | |
end | |
str = string.gsub(str,"end %-%-%#","") | |
str = str.."--"..Particle_Name.." Saved Particle" | |
str = str.."\n"..Particle_Name.." = class(Particular)" | |
str = str.."\n\t"..Particle_Name..".settings = {}" | |
--str = str.."\n"..Particle_Name..".particularMesh.texture = 'YOURIMAGES:image'".. | |
-- "--Uncomment and Replace with your image" | |
str = str.."\n\t\t"..Particle_Name..".settings.img = \"" | |
..emitter.particularMesh.texture.."\" --Set Texture Here" | |
str = str.."\n\t\t"..Particle_Name..".settings.partPerSec = "..Particles_Sec | |
str = str.."\n\t\t"..Particle_Name..".settings.sizeX = "..Emitter_SizeX | |
str = str.."\n\t\t"..Particle_Name..".settings.sizeY = "..Emitter_SizeY | |
str = str.."\n\t\t"..Particle_Name..".settings.life = "..Life | |
str = str.."\n\t\t"..Particle_Name..".settings.lifeVariation = "..Life_Variation | |
str = str.."\n\t\t"..Particle_Name..".settings.initPartSize = "..PartSize | |
str = str.."\n\t\t"..Particle_Name..".settings.partSizeVariation = "..PartSize_Variation | |
str = str.."\n\t\t"..Particle_Name..".settings.finalPartSize = "..Part_End_Life_Size | |
str = str.."\n\t\t"..Particle_Name..".settings.velocity = "..Velocity | |
str = str.."\n\t\t"..Particle_Name..".settings.velocityVariation = "..Velocity_Variation | |
str = str.."\n\t\t"..Particle_Name..".settings.rotSpd = "..Rotation_Speed | |
str = str.."\n\t\t"..Particle_Name..".settings.rotSpdVariation = "..Rotation_Speed_Variation | |
str = str.."\n\t\t"..Particle_Name..".settings.initOpacity = "..Opacity | |
str = str.."\n\t\t"..Particle_Name..".settings.opacityVariation = "..Opacity_Variation | |
str = str.."\n\t\t"..Particle_Name..".settings.finalOpacity = "..Opacity_End | |
str = str.."\n\t\t"..Particle_Name..".settings.windX = "..WindX | |
str = str.."\n\t\t"..Particle_Name..".settings.airResistance = "..Air_Resistance | |
str = str.."\n\t\t"..Particle_Name..".settings.gravity = "..Gravity_Val | |
str = str.."\n\t\t"..Particle_Name..".settings.useGravityVector = "..Use_Gravity_Vector | |
str = str.."\n\t\t"..Particle_Name..".settings.sizeWiggle = "..Size_Wiggle | |
str = str.."\n\t\t"..Particle_Name..".settings.turbulencePosAffect = "..Turbulence_Pos_Affect | |
str = str.."\nfunction "..Particle_Name..":init(x,y)" | |
str = str.."\n\tParticular.init(self,x,y,"..Particle_Name..".settings)".."\nend" | |
str = str.."\n--"..Particle_Name.."\n\n" | |
str = str.."end --#\n" | |
saveProjectTab("SavedOutput",str) | |
output.clear() | |
print("Particle Saved...") | |
else | |
output.clear() | |
print("Please Specify a name to save as...") | |
end | |
end | |
function loadCB() | |
local f = loadstring(readProjectTab("SavedOutput")) | |
f() | |
if _G[Particle_Name] then | |
if _G[Particle_Name] then | |
emitter.particularMesh.texture = _G[Particle_Name].settings.img | |
end | |
Particles_Sec = _G[Particle_Name].settings.partPerSec | |
Emitter_SizeX = _G[Particle_Name].settings.sizeX | |
Emitter_SizeY = _G[Particle_Name].settings.sizeY | |
Life = _G[Particle_Name].settings.life | |
Life_Variation = _G[Particle_Name].settings.lifeVariation | |
PartSize = _G[Particle_Name].settings.initPartSize | |
PartSize_Variation = _G[Particle_Name].settings.partSizeVariation | |
Part_End_Life_Size = _G[Particle_Name].settings.finalPartSize | |
Velocity = _G[Particle_Name].settings.velocity | |
Velocity_Variation = _G[Particle_Name].settings.velocityVariation | |
Rotation_Speed = _G[Particle_Name].settings.rotSpd | |
Rotation_Speed_Variation = _G[Particle_Name].settings.rotSpdVariation | |
Opacity = _G[Particle_Name].settings.initOpacity | |
Opacity_Variation = _G[Particle_Name].settings.opacityVariation | |
Opacity_End = _G[Particle_Name].settings.finalOpacity | |
WindX = _G[Particle_Name].settings.windX | |
Air_Resistance = _G[Particle_Name].settings.airResistance | |
Gravity_Val = _G[Particle_Name].settings.gravity | |
Use_Gravity_Vector = _G[Particle_Name].settings.useGravityVector | |
Size_Wiggle = _G[Particle_Name].settings.sizeWiggle | |
Turbulence_Pos_Affect = _G[Particle_Name].settings.turbulencePosAffect | |
output.clear() | |
print("Particle Loaded...") | |
else | |
output.clear() | |
print("Please specify a valid saved particle!") | |
end | |
end | |
function randomCB() | |
Particles_Sec = math.random(0,200) | |
Emitter_SizeX = math.random(0,500) | |
Emitter_SizeY = math.random(0,500) | |
Life = math.random(0,100) | |
Life_Variation = math.random(0,100) | |
PartSize = math.random(0,100) | |
PartSize_Variation = math.random(0,100) | |
Part_End_Life_Size = math.random(-1,100) | |
Velocity = math.random()+math.random(0,50) | |
Velocity_Variation = math.random(0,100) | |
local rot = math.random(0,1) | |
local tmp = math.random() | |
if rot == 0 then | |
while tmp>.20 do | |
tmp = math.random() | |
end | |
Rotation_Speed = tmp | |
else | |
while tmp>.20 do | |
tmp = math.random() | |
end | |
Rotation_Speed = -tmp | |
end | |
Rotation_Speed_Variation = math.random(0,100) | |
Opacity = math.random(0,255) | |
Opacity_Variation = math.random(0,100) | |
Opacity_End = math.random(-1,255) | |
WindX = math.random(-50,50) | |
Air_Resistance = math.random() | |
Gravity_Val = math.random() + math.random(-5,5) | |
Use_Gravity_Vector = math.random(0,1) | |
Size_Wiggle = math.random(0,1) | |
Turbulence_Pos_Affect = math.random(0,20) | |
end | |
function removeParticle(s,name) | |
local str = string.gsub(s, "--"..Particle_Name..".--"..Particle_Name," ") | |
str = string.gsub(str,"\n\n\n\n","") | |
return str | |
end | |
function drawPack() | |
background(0, 0, 0, 255) | |
if imageGrid then | |
for i,j in pairs(imageGrid) do | |
for k,l in pairs(j) do | |
imageGrid[i][k]:draw() | |
end | |
end | |
end | |
--readImage("Platformer Art:Coin") | |
end | |
function loadPartParam() | |
parameter.text("Particle_Name") | |
parameter.action("Save_Settings",saveCB) | |
parameter.action("Load_Settings",loadCB) | |
parameter.action("Randomize",randomCB) | |
parameter.integer("Draw_Emitters",0,1,0) | |
parameter.integer("Particles_Sec",0,200,100) | |
parameter.integer("Emitter_SizeX",0,500,0) | |
parameter.integer("Emitter_SizeY",0,500,0) | |
parameter.integer("Life",0,100,30) | |
parameter.integer("Life_Variation",0,100,0) | |
parameter.integer("PartSize",0,100,35) | |
parameter.integer("PartSize_Variation",0,100,0) | |
parameter.integer("Part_End_Life_Size",-1,500,-1) | |
parameter.number("Velocity",0,50,10) | |
parameter.integer("Velocity_Variation",0,100,0) | |
parameter.number("Rotation_Speed",-0.2,0.2,0) | |
parameter.integer("Rotation_Speed_Variation",0,100,0) | |
parameter.integer("Opacity",0,255,255) | |
parameter.integer("Opacity_Variation",0,100,0) | |
parameter.integer("Opacity_End",-1,255,-1) | |
parameter.integer("WindX",-50,50,0) | |
parameter.number("Air_Resistance",0,1,0.1) | |
parameter.number("Gravity_Val",-5,5,0) | |
parameter.integer("Use_Gravity_Vector",0,1,0) | |
parameter.integer("Size_Wiggle",0,1,0) | |
parameter.integer("Turbulence_Pos_Affect",0,20,0) | |
end | |
ImageFrame = class() | |
function ImageFrame:init(x,y,imgstr) | |
self.x = x | |
self.y = y | |
self.t = nil | |
self.imgstr = imgstr | |
self.callback = nil | |
self.img = readImage(imgstr) | |
--print(self.img) | |
local tmp = math.max(self.img.width,self.img.height) | |
self.w = math.min(100,tmp) | |
end | |
function ImageFrame:draw() | |
sprite(self.img,self.x+50,self.y+50,self.w,self.w) | |
end | |
function ImageFrame:isTouched(touch) | |
if imageGrid then | |
if touch.state == ENDED then | |
if touch.x >= self.x and touch.x <= self.x + 100 then | |
if touch.y >= self.y and touch.y <= self.y + 100 then | |
if self.callback then | |
self.callback() | |
else | |
emitter.particularMesh.texture = self.imgstr | |
APPSTATE = PARTICLES | |
end | |
end | |
end | |
end | |
end | |
end | |
function setImages(spritepack) | |
local grid = {} | |
local list = spriteList(spritepack) | |
local columns = math.floor(WIDTH/110) | |
local rows = math.ceil(#list/columns) | |
local ctr = 1 | |
local x,y = 10,HEIGHT-110 | |
for k=1,rows,1 do | |
grid[k]={} | |
for l=1,columns,1 do | |
if ctr<=#list then | |
local str = spritepack..":"..list[ctr] | |
ctr = ctr+1 | |
local i = ImageFrame(x,y,str) | |
grid[k][l]=i | |
x = x+110 | |
end | |
end | |
y=y-110 | |
x = 10 | |
end | |
return grid | |
end | |
function loadMenu() | |
print("Loading Menu Please Wait") | |
print("Double Tap to select.") | |
local grid = {} | |
local list = {"Cargo Bot","Planet Cute","Platformer Art","Small World","SpaceCute", | |
"Space Art","Tyrian Remastered","Documents"} | |
local icons = {"Cargo Bot:Icon","Planet Cute:Icon","Platformer Art:Icon","Small World:Icon", | |
"SpaceCute:Icon","Space Art:Icon","Tyrian Remastered:Icon", | |
"Cargo Bot:Condition Yellow"} | |
local columns = math.floor(WIDTH/110) | |
local rows = math.ceil(#list/columns) | |
local ctr = 1 | |
local x,y = 10,HEIGHT-110 | |
for k=1,rows,1 do | |
grid[k]={} | |
for l=1,columns,1 do | |
if ctr<=#list then | |
local str = icons[ctr] | |
local i = ImageFrame(x,y,str) | |
local sPack = list[ctr] | |
i.callback = function() print("Loading Sprites, please wait.") imageGrid = setImages(sPack) end | |
grid[k][l]=i | |
x = x+110 | |
ctr = ctr+1 | |
end | |
end | |
y=y-110 | |
x = 10 | |
end | |
return grid | |
end | |
ImageFrame = class() | |
function ImageFrame:init(x,y,imgstr) | |
self.x = x | |
self.y = y | |
self.t = nil | |
self.imgstr = imgstr | |
self.callback = nil | |
self.img = readImage(imgstr) | |
--print(self.img) | |
local tmp = math.max(self.img.width,self.img.height) | |
self.w = math.min(100,tmp) | |
end | |
function ImageFrame:draw() | |
sprite(self.img,self.x+50,self.y+50,self.w,self.w) | |
end | |
function ImageFrame:isTouched(touch) | |
if imageGrid then | |
if touch.state == ENDED then | |
if touch.x >= self.x and touch.x <= self.x + 100 then | |
if touch.y >= self.y and touch.y <= self.y + 100 then | |
if self.callback then | |
self.callback() | |
else | |
emitter.particularMesh.texture = self.imgstr | |
APPSTATE = PARTICLES | |
end | |
end | |
end | |
end | |
end | |
end | |
function setImages(spritepack) | |
local grid = {} | |
local loading = Loading() | |
local list = spriteList(spritepack) | |
local columns = math.floor(WIDTH/110) | |
local rows = math.ceil(#list/columns) | |
local ctr = 1 | |
local x,y = 10,HEIGHT-110 | |
for k=1,rows,1 do | |
grid[k]={} | |
for l=1,columns,1 do | |
if ctr<=#list then | |
local str = spritepack..":"..list[ctr] | |
ctr = ctr+1 | |
local i = ImageFrame(x,y,str) | |
grid[k][l]=i | |
x = x+110 | |
end | |
end | |
loading() | |
y=y-110 | |
x = 10 | |
coroutine.yield() | |
end | |
coroutine.yield(grid) | |
coLoad = nil | |
output.clear() | |
end | |
function loadMenu() | |
local grid = {} | |
local list = {"Cargo Bot","Planet Cute","Platformer Art","Small World","SpaceCute", | |
"Space Art","Tyrian Remastered","Documents"} | |
local icons = {"Cargo Bot:Icon","Planet Cute:Icon","Platformer Art:Icon","Small World:Icon", | |
"SpaceCute:Icon","Space Art:Icon","Tyrian Remastered:Icon", | |
"Cargo Bot:Condition Yellow"} | |
local columns = math.floor(WIDTH/110) | |
local rows = math.ceil(#list/columns) | |
local ctr = 1 | |
local x,y = 10,HEIGHT-110 | |
for k=1,rows,1 do | |
grid[k]={} | |
for l=1,columns,1 do | |
if ctr<=#list then | |
local str = icons[ctr] | |
local i = ImageFrame(x,y,str) | |
local sPack = list[ctr] | |
i.callback = function() | |
output.clear() | |
coLoad = coroutine.create(setImages) | |
coroutine.resume(coLoad,sPack) | |
end | |
grid[k][l]=i | |
x = x+110 | |
ctr = ctr+1 | |
end | |
end | |
y=y-110 | |
x = 10 | |
end | |
return grid | |
end | |
function Loading() | |
i=1 | |
return function() | |
output.clear() | |
if i == 1 then print("Loading.") i = i + 1 | |
elseif i==2 then print("Loading.....") i = i + 1 | |
else print("Loading..........") i=1 | |
end | |
end | |
end | |
----------------------------- | |
--Update Checker Code added by AutoGist | |
----------------------------- | |
VersionUpdateChecker = {} | |
VersionUpdateChecker.gistURL = "https://api.github.com/gists/5816766" | |
VersionUpdateChecker.check = function() | |
local jsonURL = "https://dl.dropboxusercontent.com/s/9e4nvqeu4hsux2q/Json.lua?token_hash=AAFyMB98j4bnt_1gawf9wSke52hsoC7hsIvARcTuZNeOEw&dl=1" | |
local jsonSuccess = function(data) | |
local jsonCode = data | |
if jsonCode then local l = loadstring(jsonCode) l() end | |
local handleSuccess = function(data) | |
local gist = json.decode(data) | |
local version = string.match(gist.description,"%d+%.%d+%.%d+") | |
if VERSION ~= version then | |
alert("New Update Availiable! Click Update.","Update") | |
parameter.action("Update_Project",function() VersionUpdateChecker.GetProject() end) | |
end | |
end | |
http.request(VersionUpdateChecker.gistURL,handleSuccess,function() print("Update Failed") end) | |
end | |
http.request(jsonURL,jsonSuccess,function() print("Check Internet Connection") end) | |
end | |
function VersionUpdateChecker.GetProject() | |
local handleSuccess = function(data,i,j) | |
if listProjectTabs(PROJECTNAME) == nil then | |
error("Check Project Name") | |
end | |
local gist = json.decode(data) | |
local projName = PROJECTNAME | |
if gist.files["1aTabOrder"] then | |
print("***Tab Order Found***") | |
local taborder = gist.files["1aTabOrder"].content | |
local strStart =1 | |
local strEnd =0 | |
strStart = string.find(taborder,"#",strEnd) | |
strEnd = string.find(taborder,"\n",strStart) | |
while strStart do | |
local tmp = string.sub(taborder,strStart+1,strEnd-1) | |
local name = PROJECTNAME..":"..tmp | |
tmp = tmp..".lua" | |
saveProjectTab(name,gist.files[tmp].content) | |
strStart = string.find(taborder,"#",strEnd) | |
strEnd = string.find(taborder,"\n",strStart) | |
end | |
else | |
for k,v in pairs(gist.files) do | |
local name = PROJECTNAME .. ":" .. string.gsub(k,".lua","") | |
saveProjectTab(name, v.content) | |
end | |
end | |
if gist.files["ChangeLog.lua"] then | |
local str = gist.files["ChangeLog.lua"].content | |
alert(str,"Version Notes") | |
end | |
sound(SOUND_PICKUP, 24058) | |
print("Reload Project to finish update!") | |
end | |
http.request(VersionUpdateChecker.gistURL,handleSuccess,function(data) print("Update Failed") end) | |
end | |
--End of Update Checker | |
-------------------------------------------------- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Copyright 2012 Javier Moral | |
-- | |
-- Licensed under the Apache License, Version 2.0 (the "License"); | |
-- you may not use this file except in compliance with the License. | |
-- You may obtain a copy of the License at | |
-- | |
-- http://www.apache.org/licenses/LICENSE-2.0 | |
-- | |
-- Unless required by applicable law or agreed to in writing, software | |
-- distributed under the License is distributed on an "AS IS" BASIS, | |
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
-- See the License for the specific language governing permissions and | |
-- limitations under the License. | |
--Updated and maintained by Briarfox | |
Particular = class() | |
function Particular:init(x,y,settings) | |
self.x = x | |
self.y = y | |
if settings then | |
print("Settings Loaded") | |
self.sizeX = settings.sizeX or 0 | |
self.sizeY = settings.sizeY or 500 | |
self.partPerSec = settings.partPerSec or 2 | |
self.life = settings.life or 30 | |
self.lifeVariation = settings.lifeVariation or 0 | |
self.rotSpd = settings.rotSpd or 0.0 | |
self.rotSpdVariation = settings.rotSpdVariation or 0 | |
self.initPartSize = settings.initPartSize or 35 | |
self.partSizeVariation = settings.partSizeVariation or 0 | |
self.finalPartSize = settings.finalPartSize or -1 | |
self.velocity = settings.velocity or 10 | |
self.velocityVariation = settings.velocityVariation or 0 | |
self.initOpacity = settings.initOpacity or 255 | |
self.opacityVariation = settings.opacityVariation or 0 | |
self.finalOpacity = settings.finalOpacity or -1 | |
self.windX = settings.windX or 0 | |
self.airResistance = settings.airResistance or 0.1 | |
self.gravity = settings.gravity or 0 | |
self.useGravityVector = settings.useGravityVector or 0 | |
self.sizeWiggle = settings.sizeWiggle or 0 | |
self.turbulencePosAffect = settings.turbulencePosAffect or 0 | |
else | |
self.sizeX = 0 | |
self.sizeY = 0 | |
self.partPerSec = 2 | |
self.life = 30 | |
self.lifeVariation = 0 | |
self.rotSpd = 0.0 | |
self.rotSpdVariation = 0 | |
self.initPartSize = 35 | |
self.partSizeVariation = 0 | |
self.finalPartSize = -1 | |
self.velocity = 10 | |
self.velocityVariation = 0 | |
self.initOpacity = 255 | |
self.opacityVariation = 0 | |
self.finalOpacity = -1 | |
self.windX = 0 | |
self.airResistance = 0.1 | |
self.gravity = 0 | |
self.useGravityVector = 0 | |
self.sizeWiggle = 0 | |
self.turbulencePosAffect = 0 | |
end | |
self.rects = {} | |
self.deadRects = {} | |
self.parts = {} | |
self.particularMesh = mesh() | |
self.particularMesh.texture = settings.img or nil | |
self.evo = 0 | |
self.tSinceLast = 0.0 | |
self.particleLimit = 50 | |
end | |
function Particular:draw() | |
self.tSinceLast = self.tSinceLast + DeltaTime | |
local tCreation = 1 / self.partPerSec | |
local partCreated = 0 | |
if self.partPerSec == 0 then | |
self.tSinceLast = 0 | |
end | |
-- Creating new particles | |
while (self.tSinceLast > tCreation) do | |
partCreated = partCreated + 1 | |
if (partCreated<=self.particleLimit)then | |
self.tSinceLast = self.tSinceLast-tCreation | |
else | |
self.tSinceLast = 0 | |
end | |
self:createParticle() | |
end | |
local resistance = 1/(self.airResistance + 1) | |
-- Calculating gravity | |
local g | |
if self.useGravityVector > 0 then | |
if self.gravity == 0 then | |
g = vec2(0,0) | |
else if self.gravity > 0 then | |
g = vec2(Gravity.x,Gravity.y) | |
else | |
g = vec2(-Gravity.x,-Gravity.y) | |
end | |
end | |
else | |
g = vec2(0,-self.gravity) | |
end | |
for k,i in ipairs(self.rects) do | |
local p = self.parts[i] | |
-- Calculating turbulence | |
local nx = 0 | |
local ny = 0 | |
if self.turbulencePosAffect>0 then | |
local n = noise(p.x,p.y,self.evo) | |
if n > 0 then | |
n = n - math.floor(n) | |
else | |
n = n - math.ceil(n) | |
end | |
nx = n * math.cos(self.evo) | |
ny = n * math.sin(self.evo) | |
self.evo = self.evo + 1 | |
if self.evo > 9999 then | |
self.evo = 0 | |
end | |
end | |
if (p.lifeLeft > 0) then | |
-- Calculating position and velocity | |
p.x = p.x + p.v.x + | |
self.windX * 0.1 + | |
self.turbulencePosAffect*nx | |
p.y = p.y + p.v.y + | |
self.turbulencePosAffect*ny | |
p.v = p.v + g | |
p.v = p.v * resistance | |
local lifePercentage = (p.life-p.lifeLeft)/p.life | |
-- Calculating size | |
local size | |
if self.finalPartSize >= 0 then | |
local sizeInc = self.finalPartSize - p.initSize | |
size = (lifePercentage*sizeInc)+p.initSize | |
else | |
size = p.initSize | |
end | |
if ((self.sizeWiggle>0)and(size>1)) then | |
size = math.random(size) | |
end | |
if (size<0) then | |
size = 0 | |
end | |
-- Calculating opacity | |
local opacity | |
if self.finalOpacity >= 0 then | |
local opacityInc = self.finalOpacity - p.initOpacity | |
opacity = (lifePercentage*opacityInc)+p.initOpacity | |
else | |
opacity = p.initOpacity | |
end | |
-- Calculating rotation | |
p.angle = p.angle + p.rotSpd | |
p.lifeLeft = p.lifeLeft - 1 | |
self.particularMesh:setRect(i,p.x,p.y,size,size,p.angle) | |
self.particularMesh:setRectColor(i,255,255,255,opacity) | |
else | |
local deadPart = self.parts[i] | |
if not deadPart.isDead then | |
table.insert(self.deadRects,i) | |
self.particularMesh:setRect(i,0,0,0,0) | |
deadPart.isDead = true | |
end | |
end | |
end | |
self.particularMesh:draw() | |
end | |
function Particular:createParticle() | |
local psize = genNumber(self.initPartSize,self.partSizeVariation) | |
local v = vec2(math.random(-100,100),math.random(-100,100)) | |
v = v:normalize() | |
v = v * genNumber(self.velocity,self.velocityVariation) | |
local partX = self.x + math.random(-self.sizeX,self.sizeX) | |
local partY = self.y + math.random(-self.sizeY,self.sizeY) | |
local particle = Particle(partX, | |
partY, | |
psize, | |
genNumber(self.life,self.lifeVariation), | |
v, | |
0, | |
genNumber(self.initOpacity,self.opacityVariation), | |
genNumber(self.rotSpd,self.rotSpdVariation)) | |
local index | |
if (self.deadRects[1]==nil) then | |
index = self.particularMesh:addRect(self.x, | |
self.y, | |
psize, | |
psize) | |
table.insert(self.rects, index) | |
table.insert(self.parts, particle) | |
else | |
index = self.deadRects[1] | |
table.remove(self.deadRects,1) | |
self.particularMesh:setRect(index, | |
self.x, | |
self.y, | |
psize, | |
psize) | |
self.parts[index] = particle | |
end | |
self.particularMesh:setRectColor(index,255,255,255, | |
particle.initOpacity) | |
end | |
function genNumber(number,variation) | |
if variation == 0.0 then | |
return number | |
end | |
if number == 0 then | |
return number | |
end | |
number = number * 1000 | |
mult = true | |
ret = variation*0.01*math.abs(number) | |
ret = number + math.random(-ret,ret) | |
ret = ret / 1000 | |
return ret | |
end | |
-- | |
-- Particle class | |
-- | |
Particle = class() | |
Particle.DEFAULT_OPACITY = 125 | |
Particle.DEFAULT_ANGLE = 0 | |
Particle.DEFAULT_MASS = 1 | |
function Particle:init(posx,posy,size,life, | |
velocity,angle,opacity,rotSpd) | |
-- position | |
self.x = posx | |
self.y = posy | |
-- size | |
self.initSize = size | |
-- velocity | |
self.v = velocity | |
-- life | |
self.life = life | |
self.lifeLeft= life | |
-- angle | |
if angle == nil then | |
self.angle = self.DEFAULT_ANGLE | |
else | |
self.angle = angle | |
end | |
-- rotation speed | |
if rotSpd==nil then | |
self.rotSpd = 0.0 | |
else | |
self.rotSpd = rotSpd | |
end | |
-- opacity | |
self.initOpacity = opacity | |
self.isDead = false | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--Particular Particle Output | |
--Set LoadParticleTab = true in your project if you want to load this whole tab into your project. | |
--Or just copy the particle class you would like to use. | |
if LoadParticleTab then | |
--Example Saved Particle | |
Example = class(Particular) | |
Example.settings = {} | |
Example.settings.img = "SpaceCute:Planet" --Set Texture Here | |
Example.settings.partPerSec = 67 | |
Example.settings.sizeX = 203 | |
Example.settings.sizeY = 199 | |
Example.settings.life = 70 | |
Example.settings.lifeVariation = 93 | |
Example.settings.initPartSize = 1 | |
Example.settings.partSizeVariation = 54 | |
Example.settings.finalPartSize = 36 | |
Example.settings.velocity = 38.8692 | |
Example.settings.velocityVariation = 37 | |
Example.settings.rotSpd = 0.0806016 | |
Example.settings.rotSpdVariation = 67 | |
Example.settings.initOpacity = 164 | |
Example.settings.opacityVariation = 63 | |
Example.settings.finalOpacity = 213 | |
Example.settings.windX = -48 | |
Example.settings.airResistance = 0.541878 | |
Example.settings.gravity = -3.6593 | |
Example.settings.useGravityVector = 0 | |
Example.settings.sizeWiggle = 1 | |
Example.settings.turbulencePosAffect = 0 | |
function Example:init(x,y) | |
Particular.init(self,x,y,Example.settings) | |
end | |
--Example | |
end --# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment