Instantly share code, notes, and snippets.

# Saurabh96jun/Line riderLast active Dec 17, 2015

Line rider
 --# Splines Spline = class() function Spline:init(x1,y1) self.px = {} self.py = {} self.splines={} self.x1 = x1 or 100 self.y1 = y1 or 100 self.x2 = self.x1+100 self.y2 = self.y1-100 self.x3 = self.x2+100 self.y3 = self.y2 self.x4 = self.x3+100 self.y4 = self.y3+100 self.n=40 end function Spline:draw() if PhysicsPaused then pushStyle() fill(127, 127, 127, 255) ellipse(self.x1,self.y1,15) ellipse(self.x2,self.y2,15) ellipse(self.x3,self.y3,15) ellipse(self.x4,self.y4,15) popStyle() pushStyle() stroke(73, 73, 73, 80) strokeWidth(7) line(self.x1,self.y1,self.x2,self.y2) line(self.x2,self.y2,self.x3,self.y3) line(self.x3,self.y3,self.x4,self.y4) popStyle() end local t=0 for i=1,self.n do self.px[i] = (1-t)^3 * (self.x1) + 3*(1-t)^2 *t * (self.x2) + 3*(1-t)* t^2 *(self.x3)+ t^3*(self.x4) self.py[i] = (1-t)^3 * (self.y1) + 3*(1-t)^2 *t * (self.y2) + 3*(1-t)* t^2 *(self.y3)+ t^3*(self.y4) t=t+1/(self.n-1) end for i=1,self.n-1 do pushMatrix() pushStyle() stroke(0, 0, 0, 255) strokeWidth(5) line(self.px[i],self.py[i],self.px[i+1],self.py[i+1]) popStyle() popMatrix() end end function Spline:touched(touch) if tx>self.x1-40 and txself.y1-40 and tyself.x2-40 and txself.y2-40 and tyself.x3-40 and txself.y3-40 and tyself.x4-40 and txself.y4-40 and ty=self.x - self.l/2 and ty>=self.y - self.h/2 and ty<=self.y + self.h/2 then if touch.state==BEGAN then self.colour=color(31, 64, 104, 100) elseif touch.state == ENDED then self.colour=color(31,64,104,0) self.funct() end end if touch.state==ENDED then self.colour=color(31,64,104,0) end end --# Main function setup() displayMode(FULLSCREEN_NO_BUTTONS) supportedOrientations(LANDSCAPE_ANY) GameState="PhysicsPausedPlay" PhysicsPausedPlayInit() end function draw() if GameState=="PhysicsPausedPlay" then PhysicsPausedPlayDraw() elseif GameState=="PhysicsResumePlay" then PhysicsResumePlayDraw() end end function touched(touch) if GameState=="PhysicsPausedPlay" then PhysicsPausedPlayTouched(touch) elseif GameState=="PhysicsResumePlay" then PhysicsResumePlayTouched(touch) end if touch.x>WIDTH-10 and touch.y>HEIGHT-10 then close() end end