--# Main --# Main MENU = 0 PLAY = 1 CRED = 2 ACHIEVE = 3 HIDE = 4 STATS = 5 SETT = 6 state = MENU displayMode(FULLSCREEN) supportedOrientations(LANDSCAPE_ANY) EE = { PC = {code = "YDMLR TAYAB SKEDX EWXKE YESDS PYPSP DWAAA VE",hint = "Lies. and Cake."}, B1 = {code = "RKAA TFOB JCSN JJAI VMBR PQ",hint = "Would you kindly?"}, AC = {code = "PFXLLPXMWWTLIEQFVZIUAKLMQIZWTHTDMXWGU",hint = "Assasins live by this, do you?"}, } function setup() -- print((WIDTH/2)..":"..(WIDTH-300)) InitialSetup() Dissolve = false UseTimeDelay = Switch(WIDTH/2,HEIGHT/3,true,function()end) pos = {Alpha = 255} MakeLogo() Title = {px = WIDTH/2,py = HEIGHT*2/3+100} Small_Rotate = {a = 15} tween(1.5,Small_Rotate,{a = 10},{ease = tween.easing.linear, loop = tween.loop.pingpong}) music("Game Music One:Jungle Rampage",true) hitESD = false useTouch = true Alert = AlertBox("Reset?","Do you really want to reset all the Achievements?\n\nThis will also lock Hardcore Mode again!",black,white) newPos = false esdPosX,esdPosY = WIDTH*2/3,HEIGHT/3 --math.random(WIDTH),math.random(HEIGHT) TrophyCabinet:init() gotParts = 0 ESDHits = 0 music.volume =1 PartGoal = 45 isDead = false newPart = false guyX,guyY = WIDTH/2,HEIGHT/2 guyW,guyH = spriteSize(guy) X,Y = WIDTH*2/3,HEIGHT*2/3 parameter.watch("TotalGames") W, H = textSize(Battery) esdW,esdH = spriteSize(ESD) PlayTween = {x = WIDTH/2,y = HEIGHT/2, w = 200, h = 100} MusVol = Slider(WIDTH/2,HEIGHT*2/3,10,300,"Music Volume") makeImages() Play = Button(PlayTween.x,PlayTween.y,PlayTween.w,PlayTween.h,Trans,white,"Play",function()state=PLAY guyX,guyY = WIDTH/2,HEIGHT/2 saveLocalData("TotalGames",readLocalData("TotalGames") +1) end) Reset = Button(WIDTH-100,HEIGHT-50,200,100,Trans,white,"Reset\nAchievements",function()isShowing=true end) Credits = Button(WIDTH/2-125,HEIGHT/2-125,200,100,Trans,white,"Stats",function()state=STATS end) Settings = Button(WIDTH-100,50,200,100,Trans,white,"Settings",function()state=SETT end) Achieve = Button(WIDTH/2+125,HEIGHT/2-125,200,100,Trans,white,"Achievements",function()state=ACHIEVE end) Stat = Button(WIDTH-100,HEIGHT-50,200,100,Trans,white,"Credits",function()state=CRED end) Back = Button(100,HEIGHT-50,200,100,Trans,white,"Back",function()state=MENU end) Hide = Button(100,50,200,100,Trans,white,"Hi!!!",function() state = HIDE end) Tweet = Button(WIDTH/2,HEIGHT/2-250,200,100,Trans,white,"Tweet this\ngame!",tweetthis) Record = Button(50,HEIGHT-50,100,100,Trans,white,"[]<",handleRecord) --nfo = Button() --alert(How2Play) readText("Project:Trophy_Info") if readLocalData("TotalGames") == nil then saveLocalData("TotalGames",0) end addGame = false end function draw() textAlign(CENTER) music.volume = MusVol.Value/10 Hour = os.date("%H") DayNum = os.date("%d") WeekDay = os.date("%A") AchieveReq = WeekDay..":"..DayNum..":"..Hour if AchieveReq == "Friday:13:23" then TrophyCabinet.trophies.Master:setAchieved(true) end TotalGames = readLocalData("TotalGames") if newPart then if UseTimeDelay.Value then tween.delay(3,function()X,Y = math.random(WIDTH-100),math.random(HEIGHT-100)end) end X,Y = math.random(WIDTH-100),math.random(HEIGHT-300) esdPosX,esdPosY = math.random(WIDTH),math.random(200,HEIGHT-200) gotParts = gotParts + 1 newPart = false hitESD = false end if loseCharge then esdPosX,esdPosY = math.random(WIDTH-100),math.random(HEIGHT-100) gotParts = gotParts - 1 ESDHits = ESDHits + 1 saveLocalData("ESD_HITS",readLocalData("ESD_HITS") + 1) loseCharge = false hitESD = true if gotParts <= 0 then gotParts = 0 end end background(0, 0, 0, 255) sprite("Project:Star_Background",WIDTH/2,HEIGHT/2,WIDTH,HEIGHT) font("Inconsolata") if state == MENU then gotParts = 0 pushStyle() fontSize(80) fill(0, 255, 0, 255) font("CourierNewPS-BoldMT") pushMatrix() translate(Title.px,Title.py) rotate(Small_Rotate.a) text(TITLE,0,0) fontSize(35) text(SMALL_TITLE,100,-70) popMatrix() fontSize(30) Play:draw() Credits:draw() Tweet:draw() Achieve:draw() -- text(AchieveReq,300,300) Record:draw() popStyle() end if state == PLAY then guyX = guyX + gotParts addGame = true pushStyle() fill(green) textAlign(CENTER) fontSize(30) text("āš”ļø Charge: "..math.floor((gotParts/PartGoal)*100).."% āš”ļø",WIDTH/2,HEIGHT-25) fill(0,255,0,pos.Alpha) text(DESC,WIDTH/2,HEIGHT/2+100) fill(green) text("Coordinates: "..math.floor(X)..":"..math.floor(Y),170,50) stroke(0,255,0,pos.Alpha) fill(0,0,0,0) strokeWidth(4) ellipse(X,Y,W+50,H+50) sprite(guy,guyX,guyY) pushStyle() fill(255) text(Battery, X, Y) stroke(255,0,0,pos.Alpha) fill(255,0,0,pos.Alpha) --line(esdPosX-esdW/2,esdPosY,WIDTH,HEIGHT) fill(0,0,0,0) strokeWidth(4) ellipse(esdPosX,esdPosY,esdW+50,esdH+50) fill(255) sprite(ESD,esdPosX,esdPosY) fill(255,0,0,pos.Alpha) fontSize(100) --line(esdPosX-esdW/2,esdPosY,WIDTH,HEIGHT) text("X",esdPosX,esdPosY) popStyle() checkHit() checkESD() popStyle() if guyX >= WIDTH + 50 then isDead = true if isDead then tween(.1,pos,{Alpha = 255}) alert("\nYou got a charge of "..math.floor((gotParts/PartGoal)*100).."%\n\nYou hit "..ESDHits.." ESD's.","You Died!") if gotParts <= 0 and not hitESD and ESDHits == 0 then TrophyCabinet.trophies.Houston:setAchieved(true) end if gotParts == 19 then TrophyCabinet.trophies.Answer:setAchieved(true) end if gotParts >= 23 then TrophyCabinet.trophies.Charger:setAchieved(true) end if gotParts >= 45 then TrophyCabinet.trophies.Recharge:setAchieved(true) if not readLocalData("CanUseHardcore") then saveLocalData("CanUseHardcore",true) sound("Game Sounds One:Pop 2") alert("Hardcore Mode Unlocked!") end end if gotParts >= 135 then TrophyCabinet.trophies.God:setAchieved(true) if UseTimeDelay.Value then TrophyCabinet.trophies.God2:setAchieved(true) end end if gotParts == PartGoal-1 and hitESD and ESDHits == 1 then TrophyCabinet.trophies.Shock:setAchieved(true) end if ESDHits == 25 then if not readLocalData("CanUseHardcore") then saveLocalData("CanUseHardcore",true) alert("Hardcore mode unlocked!\nIt can be found in settings!") end end if math.floor((gotParts/PartGoal)*100) > readLocalData("Highscore") then saveLocalData("Highscore",math.floor((gotParts/PartGoal)*100)) alert("New Highscore!") sound("Game Sounds One:Crowd Cheer") end if math.floor((gotParts/PartGoal)*100) > readLocalData("HARD_HISCORE") and UseTimeDelay.Value then saveLocalData("HARD_HISCORE",math.floor((gotParts/PartGoal)*100)) alert("New Hardcore Highscore!") sound("Game Sounds One:Crowd Cheer") end state = MENU X,Y = WIDTH*2/3,HEIGHT*2/3 hitESD = false esdPosX,esdPosY = WIDTH*2/3,HEIGHT/3 ESDHits = 0 SMALL_TITLE = Messages[math.random(1,#Messages)] isDead = false --alert(EE[math.random(1,3)].code.."\nThe hint is: "..EE[math.random(1,3)].hint) end end if guyY >= 5000 then state = HIDE end end if state == CRED then pushStyle() Back:draw() textWrapWidth(WIDTH-50) fill(green) fontSize(50) textAlign(CENTER) text(CREDS,WIDTH/2,HEIGHT/2) popStyle() end if state == ACHIEVE then pushStyle() Back:draw() TrophyCabinet:draw() Reset:draw() if isShowing then Alert:draw() end fill(green) fontSize(30) font("CourierNewPS-BoldMT") text("Achievement Score:\n"..math.floor(readLocalData("AH:SCORE_TOTAL")).." G / 691 G\n"..percent(readLocalData("AH:SCORE_TOTAL"),691).."% completed",WIDTH/2,HEIGHT-50) popStyle() end if state == HIDE then pushStyle() Back:draw() fontSize(60) fill(green) textAlign(CENTER) textWrapWidth(WIDTH-50) text("Congrats! You found a secret!!\n\nšŸ°šŸ°šŸ°šŸ°šŸ°šŸ°\n\n(The cake is a lie!) :)\n\nEaster Egg! The working title for this game was 'Project: Frosted Flakes'!",WIDTH/2,HEIGHT/2) TrophyCabinet.trophies.Two:setAchieved(true) popStyle() end if state == STATS then pushStyle() fill(green) fontSize(65) text("STATS\nā€¢ā€¢ā€¢ā€¢ā€¢ā€¢",WIDTH/2,HEIGHT-75) Back:draw() Stat:draw() Settings:draw() fontSize(50) text("Highest Charge: "..math.floor(readLocalData("Highscore")).."%",WIDTH/2,HEIGHT*4/5) text("ESD's Hit: "..math.floor(readLocalData("ESD_HITS")),WIDTH/2,HEIGHT*3/5) text("Highest Charge w/ Hardcore: "..math.floor(readLocalData("HARD_HISCORE")).."%",WIDTH/2,HEIGHT*2/5) text("Total Games: "..math.floor(readLocalData("TotalGames")),WIDTH/2,HEIGHT/5) popStyle() end if state == SETT then MusVol:draw() Back:draw() if readLocalData("CanUseHardcore") then fontSize(20) fill(green) text("Use Hardcore?",WIDTH/2,HEIGHT/3+60) end if readLocalData("CanUseHardcore") then UseTimeDelay:draw() end end end function touched(t) if state == MENU then Play:touched(t) Credits:touched(t) Achieve:touched(t) Tweet:touched(t) Record:touched(t) if t.tapCount == 5 and t.state == ENDED then clearAssets() end end if state == PLAY then if t.state == BEGAN then Dissolve = true if Dissolve then tween(1,pos,{Alpha = 0}) end else guyX = guyX + t.deltaX guyY = guyY + t.deltaY end end if state == CRED then Back:touched(t) Hide:touched(t) Stat:touched(t) end if state == ACHIEVE then if useTouch then Back:touched(t) Reset:touched(t) TrophyCabinet:touched(t) elseif isShowing then Alert:touched(t) end end if state == HIDE then Back:touched(t) if t.tapCount == 4 and t.state == ENDED then alert(NEW,"What's new in Version "..VERSION.."?\n\n"..NEW) end end if state == STATS then Back:touched(t) Stat:touched(t) Settings:touched(t) end if state == SETT then Back:touched(t) MusVol:touched(t) if readLocalData("CanUseHardcore") then UseTimeDelay:touched(t) end end end function checkHit() if guyX + guyW/2 >= X - W/2 and guyX - guyW/2 <= X + W/2 and guyY + guyH/2 >= Y - H/2 and guyY - guyH/2 <= Y + H/2 then newPart = true end end function checkESD() if guyX + guyW/2 >= esdPosX - esdW/2 and guyX - guyW/2 <= esdPosX + esdW/2 and guyY + guyH/2 >= esdPosY - esdH/2 and guyY - guyH/2 <= esdPosY + esdH/2 then loseCharge = true end end --# Buttonc Button = class() function Button:init(x,y,w,h,c,sc,name,func) -- you can accept and set parameters here self.x = x self.y = y self.w = w self.h = h self.c = c self.sc = sc self.name = name self.func = func end function Button:draw() pushStyle() stroke(self.sc) strokeWidth(3) font("Inconsolata") fill(self.c) rectMode(CENTER) fontSize(25) rect(self.x,self.y,self.w,self.h) fill(self.sc) text(self.name,self.x,self.y) popStyle() -- Codea does not automatically call this method end function Button:touched(t) if t.x > self.x-self.w/2 and t.x < self.x+self.w/2 and t.y > self.y-self.h/2 and t.y < self.y+self.h/2 and t.state == ENDED then self.func() end -- Codea does not automatically call this method end --# Trophy Trophy = class() TROPHY_PREFIX = "TROPHY_" TROPHY_SECRET_TITLE = "Secret" TROPHY_SECRET_DESC = "Unlock this achievement to learn more about it." TROPHY_SECRET_SCORE = "--" function Trophy:init(x,y,name,desc,score,isSecret,Col) self:InitialSetup() --Just don't make the color Red. self.AHx = x self.AHy = y self.AHname = name self.AHshowName = self.AHname self.AHname2 = TROPHY_SECRET_TITLE self.AHdesc = desc self.AHshowDesc = self.AHdesc self.AHdesc2 = TROPHY_SECRET_DESC self.AHscore = score self.AHshowScore = self.AHscore self.AHscore2 = TROPHY_SECRET_SCORE self.Col = Col self.w,self.h = textSize(self.AHname) self.w = self.w + 125 self.h = self.h + 100 self.completed = readLocalData(TROPHY_PREFIX..self.AHname) if isSecret then self.AHshowName = self.AHname2 self.AHshowDesc = self.AHdesc2 self.AHshowScore = self.AHscore2 end end function Trophy:draw() --self:ScoreReset() pushStyle() smooth() textAlign(CENTER) rectMode(CENTER) stroke(255) strokeWidth(3) fill(0, 0, 0, 255) ellipse(self.AHx,self.AHy,self.w,self.h) fill(255, 255, 255, 255) text(self.AHshowName.."\n\n"..self.AHshowScore.." G",self.AHx,self.AHy) popStyle() if self.completed then self.AHshowName = self.AHname self.AHshowDesc = self.AHdesc self.AHshowScore = self.AHscore else pushMatrix() pushStyle() translate(self.AHx,self.AHy) rotate(10) fill(255, 0, 0, 255) text("[ Incomplete ]",0,0) popStyle() popMatrix() end end function Trophy:touched(touch) if touch.x > self.AHx - self.w/2 and touch.x < self.AHx + self.w/2 and touch.y > self.AHy - self.h/2 and touch.y < self.AHy + self.h/2 and touch.state == ENDED then alert("\n"..self.AHshowDesc,self.AHshowName) end end function Trophy:setAchieved(ach) if self.completed ~= ach then saveLocalData(TROPHY_PREFIX..self.AHname,ach) if ach == true then sound("Game Sounds One:Pop 1") alert("\n'"..self.AHname.."' - "..self.AHscore.." G","Achievement Unlocked!") self.completed = ach saveLocalData("AH:SCORE_TOTAL",readLocalData("AH:SCORE_TOTAL") + self.AHscore) end end end function Trophy:InitialSetup() if readLocalData("AH:SCORE_TOTAL") == nil then saveLocalData("AH:SCORE_TOTAL",0) end end function Trophy:ScoreReset() --Rests Total Score to 0, and locks all achievements, useful for debugging saveLocalData("AH:SCORE_TOTAL",0) TrophyCabinet:resetAll() saveLocalData("TotalGames",0) end --# TrophyCabinet TrophyCabinet = class() function TrophyCabinet:init() self.trophies = { Charger = Trophy(851,252,"51% Charged","Get a charge of 51% or more in one run.",25,true,white), Recharge = Trophy(WIDTH/5,HEIGHT/3,"Ever heard of rechargable?","Get a charge of 100% or more in one run.",50,true,black), Houston = Trophy(682,604,"Houston, we have a problem.","Die with a charge of 0% without getting an ESD.",5,false,white), Two = Trophy(283,533,"Easter Eggs in SPAAACCCEEE!", "Find the hidden submenu!\n(There are 2 ways!)",50,false,black), God = Trophy(WIDTH/2+123,167,"A god-like feat!","Achieve a 300% or more charge in one run",150,true,white), Master = Trophy(227,HEIGHT/2+20,"Bad Luck!","Play 'Space Flight!' during the witching hour on Friday the 13th!",1,false,black), King = Trophy(WIDTH-153,HEIGHT/2,"Platinum Status","Unlock all other achievements.",75,false,Plat), Shock = Trophy(WIDTH/2-73,HEIGHT/2-38,"System Shock!","Achieve a charge of exactly 100% without hitting an ESD, then hit an ESD.",10,false,black), Socialite = Trophy(200,123,"Socialite!","Tweet about this game!\n(From inside the game)",10,false,black), Hello = Trophy(842,103,"Hello YouTube!","Record a game of 'Space Flight!'",5,false,black), Answer = Trophy(WIDTH/2+116,HEIGHT/2+78,"Answer to the Universe!","What is 6 X 9?",10,false,black), God2 = Trophy(WIDTH/2-78,HEIGHT/2-312,"God-like feat 2.0","Achieve a 300%+ charge in one run. on Hardcore mode.",300,true,black) } end function TrophyCabinet:draw() for a,b in pairs(self.trophies) do b:draw() self:checkTimeAchievements() self:checkOtherAchievements() end end function TrophyCabinet:touched(touch) for k,v in pairs(self.trophies) do v:touched(touch) self:checkTouchAchievements(touch) end end function TrophyCabinet:checkTouchAchievements(t) --Put touch achievements here end function TrophyCabinet:checkTimeAchievements() -- Put time-based achievements here end function TrophyCabinet:checkOtherAchievements() -- Put assorted achievements here if readLocalData("AH:SCORE_TOTAL") == 615 and TrophyCabinet.trophies.Master.completed then TrophyCabinet.trophies.King:setAchieved(true) end end function TrophyCabinet:checkPlatinum() end function TrophyCabinet:keyboard(key) --Put keyboard related Achievements here end function TrophyCabinet:resetAll() --Resets all achievements, useful for debugging for c,z in pairs(self.trophies) do z:setAchieved(false) end end --# Colour_Palette Trans = color(0,0,0,0) black = color(0) white = color(255) green = color(0,255,0) red = color(255, 0, 0, 255) grey = color(127,127,127,255) --# Text TITLE = "Space Flight!" DESC = "Drag to move!" Battery = "āš”ļø" ESD = readImage("Space Art:Green Explosion") guy = readImage("Platformer Art:Guy Jump") VERSION = "1.1.1 BETA" How2Play = readText("Project:How_To_Play") CREDS = "Developed by: Lonely Alien Studios\n(CodeaNoob)\n\nVersion "..VERSION.."\n\nArt by: kenney.nl & Daniel Cook\n\nCodea Game Jam 2015!!" NEW = "" Messages = { "An adventure in Space!!!", "Better than Space Invaders!", "Try dragging with 2+ fingers!", "Can you get all the achievements?", "Life ruiningly Awesome!", "Twitter: @LonelyAlienDev", "FOR NARNIA!!!!!", "Story mode? Maybe in the future... ;)", "Have you found the hidden menu yet?", "Tweet me any features you want to see!", "Many more easter eggs coming!", "^^vvLRLRBA!", "Is it black & blue?\nor white & gold?", "Chuck Norris Approved!", "Qwertyuiop!!", "All about that bass!", "Trollololol", "if not ok then return end", "twenty wun" } SMALL_TITLE = Messages[math.random(1,#Messages)] Logs = { } --# AlertBox AlertBox = class() function AlertBox:init(title,message,col,col2) self.title = title self.message = message self.col = col self.col2 = col2 self.TITLE_FONT = "ArialRoundedMTBold" self.MESSAGE_FONT = "ArialMT" self:setup() end function AlertBox:setup() pushStyle() isShowing = false No = Button(WIDTH/3,HEIGHT/3,200,100,color(255,0,0,255),color(0),"No",self.noFunc) Yes = Button(WIDTH*2/3,HEIGHT/3,200,100,color(0,255,0,255),color(0),"Yes",self.yesFunc) popStyle() end function AlertBox:draw() pushStyle() stroke(self.col2) strokeWidth(5) if isShowing then useTouch = false rectMode(CENTER) textWrapWidth(WIDTH-200) textAlign(CENTER) fill(self.col) rect(WIDTH/2,HEIGHT/2,WIDTH-300,HEIGHT-300) fill(self.col2) font(self.TITLE_FONT) fontSize(30) text(self.title,WIDTH/2,HEIGHT-200) font(self.MESSAGE_FONT) text(self.message,WIDTH/2,HEIGHT/2+50) No:draw() Yes:draw() popStyle() end end function AlertBox:touched(t) if isShowing then No:touched(t) Yes:touched(t) end end function AlertBox:yesFunc() isShowing = false Trophy:ScoreReset() --lert2:draw() state = MENU saveLocalData("CanUseHardcore",false) tween.delay(0.35,restart) useTouch = true end function AlertBox:noFunc() isShowing = false useTouch = true end function AlertBox:RectRound(Rw,Rh,Rr,Rc) local Round = image(Rw,Rh) pushStyle() fill(Rc) rectMode(CENTER) rect(Rw,Rh,Rw,Rh-Rr) rect(Rw,Rh,Rw-Rr,Rh) ellipse(Rr/2,Rr/2) popStyle() return Round end --# AssetFunctions moonPhase = { "šŸŒ‘", "šŸŒ’", "šŸŒ“", "šŸŒ”", "šŸŒ™" } moon = math.random(1,#moonPhase) function makeImages() Star_Background = image(WIDTH,HEIGHT) randS = math.random(10,25) setContext(Star_Background) for i = 1,250 do pushStyle() fill(255) ellipse(math.random(WIDTH),math.random(HEIGHT),3) end text(moonPhase[moon],math.random(WIDTH),math.random(HEIGHT)) sprite("Tyrian Remastered:Eggstroid",math.random(WIDTH),math.random(HEIGHT)) text("šŸŒŽ",math.random(WIDTH),math.random(HEIGHT)) for q = 1,30 do sprite("Space Art:Asteroid Small",math.random(WIDTH),math.random(HEIGHT),12,12) end setContext() saveImage("Project:Star_Background",Star_Background) end function resetST() saveLocalData("Highscore",0) saveLocalData("ESD_HITS",0) saveLocalData("HARD_HISCORE",0) end function MakeLogo() Logo = image(512,512) setContext(Logo) pushStyle() rectMode(CENTER) fill(black) rect(256,256,512,512) for z = 1,200 do fill(white) ellipse(math.random(1,512),math.random(1,512),3) end fontSize(50) sprite("Platformer Art:Guy Jump",(512)/3,(512*2/3)) text("āš”ļø",(512)*2/3,(512/3)) pushMatrix() fill(green) fontSize(85) translate(256,256) rotate(15) text(TITLE,0,0) popMatrix() popStyle() setContext() saveImage("Project:Icon",Logo) end function InitialSetup() if readLocalData("CanUseHardcore") == nil then saveLocalData("CanUseHardcore",false) end if readLocalData("Highscore") == nil then saveLocalData("Highscore",0) end if readLocalData("ESD_HITS") == nil then saveLocalData("ESD_HITS",0) end if readLocalData("HARD_HISCORE") == nil then saveLocalData("HARD_HISCORE",0) end end function percent(a,b) return math.ceil((a/b)*100) end function checkHit() if guyX + guyW/2 >= X - W/2 and guyX - guyW/2 <= X + W/2 and guyY + guyH/2 >= Y - H/2 and guyY - guyH/2 <= Y + W/2 then newPart = true end end function clearAssets() saveImage("Project:Icon",nil) saveImage("Project:Star_Background",nil) alert("Assets Cleared. closing game. You can now delete.") tween.delay(0.1,close) end function getInteger(val) return math.tointeger(val) end function tweetthis() openURL("http://ctt.ec/pZ3qc",true) TrophyCabinet.trophies.Socialite:setAchieved(true) end function handleRecord() if isRecording() then stopRecording() TrophyCabinet.trophies.Hello:setAchieved(true) elseif not isRecording() then startRecording() end end Switch = class() function Switch:init(x,y,initVal,func) self.SwitchX = x self.y = y self.w = 25 self.h = 50 self.initVal = initVal self.func = func self.BackCol = {r = 255, g = 255, b = 255} self.Pos = {TrueX = self.SwitchX+self.w/2,FalseX = self.SwitchX-self.w/2} self.Current = {Pos=self.Pos.FalseX,Val = false} self.Value = self.Current.Val end function Switch:draw() pushStyle() smooth() stroke(self.BackCol.r,self.BackCol.g,self.BackCol.b,255) strokeWidth(self.h) lineCapMode(ROUND) line(self.Pos.FalseX,self.y,self.Pos.TrueX,self.y) strokeWidth(.25) fill(255) stroke(0) ellipse(self.Current.Pos,self.y,47) popStyle() end function Switch:touched(t) if t.x > self.SwitchX-self.w and t.x < self.SwitchX+self.w and t.y > self.y-self.h/2 and t.y < self.y+self.h/2 and t.state == ENDED then if not self.Value then tween(.1,self.Current,{Pos=self.Pos.TrueX}) tween(.2,self.BackCol,{r = 0, g = 255, b = 0}) self.Value = true self.func() print(self.Value) else tween(.1,self.Current,{Pos=self.Pos.FalseX}) tween(.2,self.BackCol,{r = 255,g = 255, b = 255}) self.Value = false print(self.Value) end end end function Switch:ChangeValOutside() if self.Value then tween(.1,self.Current,{Pos=self.Pos.FalseX}) tween(.1,self.BackCol,{r = 255,g = 255, b = 255}) self.Value = false elseif not self.Value then tween(.1,self.Current,{Pos=self.Pos.TrueX}) tween(.1,self.BackCol,{r = 0, g = 255, b = 0}) self.Value = true end end --# Slider Slider = class() function Slider:init(X,Y,max,w,label) -- you can accept and set parameters here self.posX = X self.posY = Y self.max = max self.min = 1 self.endX = 1 self.w = w self.h = 75 self.minX = self.posX-self.w/2 self.maxX = self.posX+self.w/2 self.Value = 1 self.CurrentX = {Spot = self.maxX} self.interval = (self.w//self.max) self.label = label end function Slider:draw() -- Codea does not automatically call this method pushStyle() lineCapMode(ROUND) stroke(255, 255, 255, 255) fill(0,0,0,0) strokeWidth(4) rectMode(CENTER) rect(self.posX,self.posY,self.w+50,self.h+40) self.Algo = ((self.CurrentX.Spot-(WIDTH-self.w)/2)/self.interval) strokeWidth(5) line(self.posX-self.w/2,self.posY,self.posX+self.w/2,self.posY) stroke(green) line(self.posX-self.w/2,self.posY,self.CurrentX.Spot,self.posY) self.Value = math.floor(self.Algo) if self.Value >= self.max then self.Value = self.max elseif self.Value <= self.min then self.Value = self.min end stroke(0) strokeWidth(2) fill(255, 255, 255, 255) ellipse(self.CurrentX.Spot,self.posY,25) text(self.Value,self.posX,self.posY+25) text(self.label,self.posX,self.posY+75) end function Slider:touched(t) -- Codea does not automatically call this method if t.x > self.posX-self.w+50 and t.x < self.posX+self.w-50 and t.y > self.posY-self.h+50 and t.y < self.posY+self.h-50 and t.state == MOVING then self.CurrentX.Spot = self.CurrentX.Spot + t.deltaX if self.CurrentX.Spot <= self.minX then self.CurrentX.Spot = self.minX elseif self.CurrentX.Spot >= self.maxX then self.CurrentX.Spot = self.maxX end end end --# Codes