local scrn = view.newscreen(0, 2) local player = { x = 40, y = 22, dx = 1, dy = 0, len = 8, tail = {} } function _init() image.pointer(image.new()) gfx.cls() local w,h = view.size(scrn) gfx.palette(1, 15, 15, 15) gfx.palette(2, 15, 0, 0) gfx.fgcolor(1) gfx.line(0,0, w-1,0) gfx.line(w-1,0, w-1,h-1) gfx.line(w-1,h-1, 0, h-1) gfx.line(0, h-1, 0,0) gfx.fgcolor(2) gfx.plot(math.random(w-4), math.random(h-4)) player.x = math.floor(w/2) player.y = math.floor(h/2) player.len = 1 sys.stepinterval(1000/(w/8)) end function _step(t) local btn = input.gamepad() if btn & 1 > 0 and player.dx == 0 then player.dx = 1 player.dy = 0 end if btn & 2 > 0 and player.dx == 0 then player.dx = -1 player.dy = 0 end if btn & 4 > 0 and player.dy == 0 then player.dx = 0 player.dy = -1 end if btn & 8 > 0 and player.dy == 0 then player.dx = 0 player.dy = 1 end player.x = player.x + player.dx player.y = player.y + player.dy if gfx.pixel(player.x, player.y) == 1 then _init() end if gfx.pixel(player.x, player.y) == 2 then player.len = player.len + 2 local w,h = view.size(scrn) gfx.fgcolor(2) gfx.plot(math.random(w-4), math.random(h-4)) end table.insert(player.tail, { x=player.x, y=player.y }) gfx.fgcolor(1) gfx.plot(player.x, player.y) while #player.tail > player.len do local tailend = table.remove(player.tail, 1) if gfx.pixel(tailend.x, tailend.y) == 1 then gfx.fgcolor(0) gfx.plot(tailend.x, tailend.y) end end if input.hotkey() == "\x1b" then sys.exit() end end