-- Snake on love2d function love.load() love.graphics.setDefaultFilter("nearest", "nearest") img = love.graphics.newImage("circle01_96x96_32col.png") x = love.graphics.getWidth() / 2 y = love.graphics.getHeight() / 2 pos_buf = {} for i = 1, 128 do pos_buf[i] = {x, y} end idx = #pos_buf end function love.update(dt) -- move head mx, my = love.mouse.getPosition() local dx = (mx - x) * 0.1 local dy = (my - y) * 0.1 x = x + dx y = y + dy -- Updated index to record head position idx = idx - 1 if idx <= 0 then idx = #pos_buf end -- record head position pos_buf[idx] = {x, y} end function love.draw() -- fill window background love.graphics.clear(0.4, 0.7, 0.8, 1.0) -- draw snake local ox, oy = img:getWidth() / 2, img:getHeight() / 2 love.graphics.setColor(1.0, 1.0, 1.0, 1.0) for i = 16, 0, -1 do local n = ((idx + i * 4) % #pos_buf) + 1 local px = pos_buf[n][1] local py = pos_buf[n][2] love.graphics.draw(img, px, py, 0, 1.0, 1.0, ox, oy) end -- draw FPS txet love.graphics.print("FPS: " .. tostring(love.timer.getFPS()), 2, 2) end function love.keypressed(key, isrepeat) if key == "escape" then -- ESC key to exit love.event.quit() end end