Basic ambient animation
Getty Ritter
8 years ago
| 40 | 40 | end |
| 41 | 41 | |
| 42 | 42 | function love.update() |
| 43 | state.t = state.t + 1 | |
| 43 | 44 | state.char:move() |
| 44 | 45 | end |
| 45 | 46 | |
| 46 | 47 | function love.mousepressed(x, y) |
| 47 |
local gx, gy = fromScreen(x |
|
| 48 | local gx, gy = fromScreen(x / 2, y / 2) | |
| 48 | 49 | state.board:set(gx, gy, tile.getTile('stonepath')) |
| 49 | 50 | end |
| 50 | 51 | |
| 74 | 75 | |
| 75 | 76 | for x = 0, consts.boardWidth, 1 do |
| 76 | 77 | for y = 0, consts.boardHeight, 1 do |
| 77 |
state.board:lookup(x, y):draw(x, y |
|
| 78 | state.board:lookup(x, y):draw(x, y, state.t) | |
| 78 | 79 | end |
| 79 | 80 | end |
| 80 | 81 | |
| 81 | 82 | for x = 0, consts.boardWidth, 1 do |
| 82 | 83 | for y = 0, consts.boardHeight, 1 do |
| 83 | 84 | local e = state.board:lookupEntity(x, y) |
| 84 |
if e then e:draw(x, y |
|
| 85 | if e then e:draw(x, y, state.t) end | |
| 85 | 86 | end |
| 86 | 87 | end |
| 87 | 88 | |
| 15 | 15 | if f then |
| 16 | 16 | t = loadstring('return' .. f:read('*all'))() |
| 17 | 17 | f:close() |
| 18 | t.quad = love.graphics.newQuad( | |
| 19 | t.spriteX * consts.tileSize, | |
| 20 | t.spriteY * consts.tileSize, | |
| 21 | consts.tileSize, | |
| 22 | consts.tileSize, | |
| 23 | spritesheet:getDimensions()) | |
| 18 | if t.animation then | |
| 19 | t.totalFrames = table.getn(t.animation) | |
| 20 | t.quads = {} | |
| 21 | for i = 1, t.totalFrames do | |
| 22 | t.quads[i] = love.graphics.newQuad( | |
| 23 | t.animation[i][1] * consts.tileSize, | |
| 24 | t.animation[i][2] * consts.tileSize, | |
| 25 | consts.tileSize, | |
| 26 | consts.tileSize, | |
| 27 | spritesheet:getDimensions()) | |
| 28 | end | |
| 29 | t.draw = tileAnimation | |
| 30 | else | |
| 31 | t.quad = love.graphics.newQuad( | |
| 32 | t.spriteX * consts.tileSize, | |
| 33 | t.spriteY * consts.tileSize, | |
| 34 | consts.tileSize, | |
| 35 | consts.tileSize, | |
| 36 | spritesheet:getDimensions()) | |
| 37 | end | |
| 24 | 38 | else |
| 25 | 39 | t = { |
| 26 | 40 | name = name, |
| 35 | 49 | end |
| 36 | 50 | |
| 37 | 51 | function Tile:action() |
| 52 | end | |
| 53 | ||
| 54 | function tileAnimation(self, x, y, t) | |
| 55 | local tM = math.floor(t / 40) % self.totalFrames | |
| 56 | ||
| 57 | love.graphics.draw( | |
| 58 | spritesheet, | |
| 59 | self.quads[tM + 1], | |
| 60 | x * consts.tileSize, | |
| 61 | y * consts.tileSize) | |
| 38 | 62 | end |
| 39 | 63 | |
| 40 | 64 | function Tile:draw(x, y) |
| 4 | 4 | spriteX = 3, |
| 5 | 5 | spriteY = 0, |
| 6 | 6 | action = function(self, state) state.message = self.signText end, |
| 7 |
signText = 'Bonvolu al Animaltransiron! |
|
| 7 | signText = 'Bonvolu al Animaltransiron!\nKiel vi fartas, mia amiko?' | |
| 8 | 8 | } |
Binary diff not shown
Binary diff not shown