----------------------------- -- Levak ©2014 -------------- -- http://levak.free.fr/ ---- -- levak92@gmail.com -------- ----------------------------- Tile = class(Object) function Tile:init(x, y, value) Object.init(self, { x = (x-1) * TILE_SIZE / ww, y = (y-1) * TILE_SIZE / ww, scale=1 }) self.data = {x=x, y=y, value=value} self.dead = false self:setValue(value) end local ColorSkin = { [0]= {r=204, g=192, b=179, w=0, s=1}, [2]= {r=238, g=224, b=218, w=0, s=1}, [4]= {r=237, g=224, b=200, w=0, s=1}, [8]= {r=242, g=177, b=121, w=1, s=1}, [16]= {r=245, g=149, b=83, w=1, s=1}, [32]= {r=246, g=124, b=95, w=1, s=1}, [64]= {r=246, g=94, b=59, w=1, s=1}, [128]= {r=237, g=127, b=114, w=1, s=.75}, [256]= {r=237, g=204, b=97, w=1, s=.75}, [512]= {r=237, g=200, b=80, w=1, s=.75}, [1024]={r=237, g=197, b=63, w=1, s=.7}, [2048]={r=237, g=194, b=46, w=1, s=.7}, } function Tile:setValue(value) self.value = value self.c = ColorSkin[self.value] if not self.c then self.c = ColorSkin[0] end end local math_max = math.max function Tile:paint(gc, ox, oy) local c = self.c local x = self.x * ww + ox local y = self.y * ww + oy local m = 3 / 320 * ww local scale = self.scale local size = (TILE_SIZE - 2*m) gc:setColorRGB(c.r, c.g, c.b) fillRoundedRect(gc, x + m + size/2 * (1 - scale), y + m + size/2 * (1 - scale), size * scale, size * scale, m) if self.value > 0 then if c.w == 1 then gc:setColorRGB(249, 246, 242) else gc:setColorRGB(119, 110, 101) end if scale > .2 then local s = tostring(self.value) local fs = math_max(TILE_SIZE/#s*scale*.9, 6) gc:setFont("sansserif", "b", fs) local sw, sh = gc:getStringWidth(s), gc:getStringHeight(s) gc:drawString(s, x + (TILE_SIZE - sw) / 2, y + (TILE_SIZE - sh) / 2 - 3, "top") end end end