`,]']>S}Wup8d%qy)6o;]AsVl3S}Wup8d%qy)6o;]AsVl3?;33)""933#"""BDDDDygffZUUUUwZUDDDD"""DDD̜ywxwwffffffffUQUUUU333""933#"""DDDDDffUUUUUuwZDDDD$"""DDY̙ywxwhfffffffIDTQUU33""33#""BDDDDDDiU9ZUUUUUUwZDDDDD"""wwywwhfffffffXIDDDUUUU33#""DDDDDDDIDD3UUUUUUUuwJDDDDD"""wwwwwxwwxffffffXDDDDUU[UU"JD93#""DDDDDDD3UUUUUQJDDDDDDD""ywwwwwwxwwwwhfffffXIDDDDU[UU%"DDD33"BDDDIDD33ZUUUUDDDDDDTUwwwwwwwwwwffffUDDDDDU_UU""JDDD;3"BDDDDDD33ZUUUZJDDDDDUwwwwxwwwwwwffUEDDDDDUSUU""XJDDD1#BDDDDD33ZUUUUDDDDTxwwwwwwwwww8XUDDDDD?SU%""UDDDBDDIDD93cZUUUDDwwwwwwwwww8UUI333SU%""XUzwwDHDDIDDD93CZUUZUxWUUwwwwwwww8SXUUID333U+""XUzwwwwDIDDD̈3DUU\UUXUUUUwwwwwww(RUXUUUD933+"""UUwwwwwD33UUIDDĎ94UUUUUUUUUuwwwwww""UUUUUUDD33+"""UUywwwwwwH3333SUU:3IDDD̈3[U\UUZHDDXUUUUUUwwwwww""RUUUUUDD33"""UUwwwwwww433333UUU:3CDDD̈93UUUUZUHDDDDUUUUUUUuwwwww(""UUUUDD3"""UUwwwwwwwy333333SUU33wǦ"";33([TUUUUUŻDDDDD%""UUUUuwwww&""UUDD3+""UUUywwwwwwww93333333UUU:3swl"""333|ww|UUUUUŻHDDDD$""""UUUUwwwwh"""IDD3""RUUuwwwwwww73333333UUU33wwl&""333(|wWUUUƯDDDDD"""""RUUUwwwwhf""IDD3+"RUUuwwwwwww33333333SUU33wwlf"c3333rwwXUU̙DDDD$""""""UUUywwwfFD̜DDD8+"UUuwwwwwww33333SUU:3swwaf2c3333w|wXU̙HDDDD33#""""RUUwwwLDD̙IDDD̙3[Uuwwwwww333QU:3swwf6c33333Kww̜BDDD3333#"""RUUywwLDD̜DDDD̜3UUwwwwww33;U:3swwaFk633333Dwxw3""23""""UywwDDD̜DDDD̙3cUwwwwwwJ3Q:3swwKd6333333K|w:|""""33#""Uw'DDDFDDDDD̙33;cfvwwww9:3swwf333333D|zww""!"""3333#"UwIffDDDD̜333cffwwww933wwwf633333V|qwww"""""23333̜w̙ZafffffDD̜33333cffvwww*""DD33wwwkf3333cU{|www'""!+3333̜̙Uaffffff&"̜<3333333cfffqww*""""DDDD:3swwwff33cVUewqww""";33̙̜YUqfffffff""""̜33333333fff("""KDDDDD33wwwwlffff[Ue{̬ww)""ff6̜̜yUw&"ffff&"""̜33333333fff(""DDDDDD13swww;kff[Uefww)BDffff̹̙ywg"""ff&""""̙<333333 self.radius*0.75 then goTo(self.pos, self.target, self.vel, self.speed) end end elseif self.type == "head" then self.update = function() self.angleVel = self.vel.getDir() --When the cursor is out of the --screen, the snake goes to the --center. mouseX, mouseY = mouse() if mouseX > WIDTH*1.05 or mouseY > HEIGHT*1.05 then mouseX = WIDTH*0.5 mouseY = HEIGHT*0.5 end --Choose the target behavior if getDist() <= self.minDist then moveCircle(Vector(mouseX, mouseY), self.target, self.minDist, self.speed*2) else posCirc(Vector(mouseX, mouseY), self.target, self.minDist, self.angleVel) end goTo(self.pos, self.target, self.vel, self.speed) end end --render() self.render = function() end self.renderBody = function() circ( self.pos.x, self.pos.y, self.radius, self.color[1] ) end if self.type == "head" then self.renderTongue = function() local posTongue = Vector( self.pos.x+(self.radius*1.5)*math.cos(self.angleVel), self.pos.y+(self.radius*1.5)*math.sin(self.angleVel) ) line( self.pos.x, self.pos.y, posTongue.x, posTongue.y, self.color[2] ) for i=-1,1,2 do line( posTongue.x, posTongue.y, posTongue.x+2*math.cos(self.angleVel+math.pi*i/4), posTongue.y+2*math.sin(self.angleVel+math.pi*i/4), self.color[2] ) end end self.renderEyes = function() for i=-1,1,2 do pix( self.pos.x+self.radius/2*math.cos(self.angleVel+math.pi*i/3), self.pos.y+self.radius/2*math.sin(self.angleVel+math.pi*i/3), self.color[3] ) end end self.render = function() self.renderTongue() self.renderBody() self.renderEyes() end elseif self.type == "body" then self.render = function() self.renderBody() end elseif self.type == "tail" then self.renderTail = function() for r=2,3 do local color = self.color[4] local posTail = Vector( self.pos.x+(self.radius+(3-r)*r)*math.cos(self.angleVel+math.pi), self.pos.y+(self.radius+(3-r)*r)*math.sin(self.angleVel+math.pi) ) circ( posTail.x, posTail.y, r, color ) end end self.render = function() self.renderTail() self.renderBody() end end self.paint = function() local c = self.palette[math.random(1, #self.palette)] if time()%700 < 20 then circ( self.pos.x, self.pos.y, self.radius, c ) end end return self end ----Snake Table---- --[[ Here, a table manages different body parts to form the complete snake. ]]-- --Snake attributes snake = {} snakeLenght = 16 snakeWeight = 8 --radius snakePos = Vector(-8, HEIGHT/2) snakePalette = {1,2,3,4,5,6,7,8,9,10,11,12} --Initialize the snake for i=snakeLenght,1,-1 do local type = i==1 and "head" or (i==snakeLenght and "tail" or "body") local color = {7-(i%3), 2, 0, 4}--{body, tongue, eyes, tail} local b = Body({ pos = Vector(snakePos.x-i*snakeWeight, snakePos.y), speed = 1.5, type = type, minDist = snakeLenght*(snakeWeight/2), color = color, radius = snakeWeight, palette = snakePalette }) table.insert(snake, b) end cls(BG_COLOR) function TIC() --Update the target of each body part for k, b in pairs(snake) do if b.type == "body" or b.type == "tail" then b.target = snake[k+1].pos end end --Move all the body parts for k, b in pairs(snake) do b.update() end --The snake paints the background layer. vbank(0) for k, b in pairs(snake) do b.paint() end --Render over layer renderOVR() end ----renderOVR()---- --[[ It renders the snake on the over layer. ]]-- function renderOVR() vbank(1) --Set ovr transparence poke(OVR_ADDR, BG_COLOR) cls(BG_COLOR) --Render the snake for k, b in pairs(snake) do b.render() end end