----------------------------- -- Levak ©2014 -------------- -- http://levak.free.fr/ ---- -- levak92@gmail.com -------- ----------------------------- TILE_ANIM = 10 function fillRoundedRect(gc, x, y, w, h, r) if w <= 2*r or h <= 2*r then gc:fillArc(x, y, w, h, 0, 360) else gc:fillRect(r + x- 1, r + y - 1, w - 2*r+2, h - 2*r +2) gc:fillRect(r + x, y, w - 2*r, r) gc:fillRect(x, r + y, r, h - 2*r) gc:fillRect(x + w - r, r + y, r, h - 2*r) gc:fillRect(r + x, y + h - r, w - 2*r, r) gc:fillArc(x, y, 2*r, 2*r, 0, 360) gc:fillArc(x + w - 2*r, y, 2*r, 2*r, 0, 360) gc:fillArc(x, y + h - 2*r, 2*r, 2*r, 0, 360) gc:fillArc(x + w - 2*r, y + h - 2*r, 2*r, 2*r, 0, 360) end end function drawStringOutline(gc, s, x, y) gc:setColorRGB(255, 255, 255) gc:drawString(s, x+1, y) gc:drawString(s, x-1, y) gc:drawString(s, x, y+1) gc:drawString(s, x, y-1) gc:setColorRGB(0, 0, 0) gc:drawString(s, x, y) end best = 0 function on.restore(data) if data then best = data[1] end end function on.save() return {best} end function on.init() game = Game() end function on.resize(w, h) ww, wh = w, h TILE_SIZE = w * 51 / 320 platform.window:invalidate() end function on.draw(gc) game:paint(gc) end function on.paint(gc) on.resize(platform.window:width(), platform.window:height()) on.init() on.paint = on.draw on.draw(gc) end function on.arrowKey(key) game:move(key) platform.window:invalidate() end function on.charIn(ch) if ch == "8" then on.arrowKey("up") elseif ch == "4" then on.arrowKey("left") elseif ch == "6" then on.arrowKey("right") elseif ch == "2" then on.arrowKey("down") elseif ch == " " then on.enterKey() end end function on.enterKey() if game.win then game.win = false else game = Game() end platform.window:invalidate() end if platform.hw then timer.multiplier = platform.hw() < 4 and 4 or 1 else timer.multiplier = 4 end ---------- AnimIt : Timer event function on.timer() local j = 1 while j <= #timer.tasks do -- for each task if timer.tasks[j][2]() then -- delete it if has ended table.remove(timer.tasks, j) else j = j + 1 end end if #timer.tasks <= 0 then timer.stop() end platform.window:invalidate() end