gdritter repos animaltransiro / ebab62a
Add some new sprites and also character facing Getty Ritter 7 years ago
15 changed file(s) with 77 addition(s) and 12 deletion(s). Collapse all Expand all
1 {
2 pass = true,
3 name = 'character',
4 sprites = {
5 down = 'character_down',
6 left = 'character_left',
7 right = 'character_right',
8 up = 'character_up',
9 }
10 }
11 local consts = require 'constants'
2 local tile = require 'tile'
23
34 local Entity = {}
45 Entity.__index = Entity
56
6 function Entity:new(board, x, y, s)
7 function Entity:new(board, x, y, name)
8 local file = io.open('entities/' .. name .. '.lua')
9 local char_data = loadstring('return' .. file:read('*all'))()
10
11 local sprites = {}
12 for name, sprite in pairs(char_data.sprites) do
13 sprites[name] = tile.getTile(sprite)
14 end
15
716 local t = {
817 board = board,
918 x = x,
1019 y = y,
1120 dx = 0,
1221 dy = 0,
13 sprite = s,
22 sprites = sprites,
1423 direction = {0, 1},
24 facing = 'down',
1525 }
26
1627 return setmetatable(t, Entity)
1728 end
1829
5768
5869 if self.dx > 0 then
5970 self.direction[1] = 1
71 self.facing = 'right'
6072 elseif self.dx < 0 then
6173 self.direction[1] = -1
74 self.facing = 'left'
6275 elseif self.dy ~= 0 then
6376 self.direction[1] = 0
6477 end
6578
6679 if self.dy > 0 then
6780 self.direction[2] = 1
81 self.facing = 'down'
6882 elseif self.dy < 0 then
6983 self.direction[2] = -1
84 self.facing = 'up'
7085 elseif self.dx ~= 0 then
7186 self.direction[2] = 0
7287 end
106121 end
107122
108123 function Entity:draw()
109 self.sprite:drawPx(self.x, self.y)
124 self.sprites[self.facing]:drawPx(self.x, self.y)
110125 end
111126
112127 function Entity:gameCoords()
1919 debug = ''
2020
2121 state.board = board.loadBoard('sample.map')
22 state.char = entity.Entity:new(state.board, 3 * 24, 3 * 24, tile.getTile('character'))
22 state.char = entity.Entity:new(
23 state.board, 3 * 24, 3 * 24, 'character')
2324
2425 state.canvas = love.graphics.newCanvas(
2526 consts.boardWidth * consts.tileSize,
11 {
22 {"grass"}, {"grass"}, {"grass"}, {"stonepath"}, {"grass"}, {"water"}, {"water"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"},
33 {"grass"}, {"grass"}, {"water"}, {"stonepath"}, {"water"}, {"water"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"},
4 {"grass"}, {"water"}, {"water"}, {"stonepath"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"},
5 {"grass"}, {"water"}, {"grass"}, {"stonepath"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"},
4 {"grass"}, {"water"}, {"water", "pine_upper"}, {"stonepath"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"},
5 {"grass"}, {"water"}, {"grass", "pine_lower"}, {"stonepath"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"},
66 {"grass"}, {"water"}, {"grass"}, {"stonepath"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"},
77 {"grass"}, {"water"}, {"grass"}, {"stonepath"}, {"grass"}, {"grass"}, {"grass", "sign"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"},
88 {"water"}, {"water"}, {"grass"}, {"stonepath"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass", "sign", signText="This is an example of entity-specific\ninformation contained in the map file."}, {"grass"}, {"grass"}, {"grass", "tree_upper"}, {"grass"}, {"grass"}, {"grass"},
9 {"water"}, {"grass"}, {"grass"}, {"stonepath"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass", "tree_lower"}, {"grass"}, {"grass"}, {"grass"},
10 {"water"}, {"grass"}, {"grass"}, {"stonepath"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"},
9 {"water"}, {"grass"}, {"grass"}, {"stonepath"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass", "tree_lower"}, {"grass", "tree_upper"}, {"grass"}, {"grass"},
10 {"water"}, {"grass"}, {"grass"}, {"stonepath"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass", "tree_lower"}, {"grass"}, {"grass"},
1111 {"grass"}, {"stonepath"}, {"stonepath", "lamp_upper"}, {"stonepath"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"},
12 {"grass"}, {"stonepath"}, {"stonepath", "lamp_lower"}, {"stonepath"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"},
12 {"grass"}, {"stonepath"}, {"stonepath", "lamp_lower" }, {"stonepath"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"},
1313 {"grass"}, {"stonepath"}, {"stonepath"}, {"stonepath"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"},
1414 }
6969 end
7070
7171 function Tile:drawPx(x, y)
72 love.graphics.draw(self.sprite, x, y)
72 love.graphics.draw(spritesheet,
73 self.quad,
74 x,
75 y)
7376 end
7477
7578 local tileCache = {}
1 {
2 pass = true,
3 name = 'character',
4 spriteX = 8,
5 spriteY = 0,
6 }
1 {
2 pass = true,
3 name = 'character',
4 spriteX = 9,
5 spriteY = 0,
6 }
1 {
2 pass = true,
3 name = 'character',
4 spriteX = 10,
5 spriteY = 0,
6 }
1 {
2 pass = true,
3 name = 'character',
4 spriteX = 11,
5 spriteY = 0,
6 }
1 {
2 pass = false,
3 name = 'pine_lower',
4 spriteX = 4,
5 spriteY = 1,
6 }
1 {
2 pass = true,
3 name = 'pine_upper',
4 spriteX = 4,
5 spriteY = 0,
6 }
Binary diff not shown
Binary diff not shown
11 {
22 pass = false,
33 name = 'tree_lower',
4 spriteX = 4,
4 spriteX = 2,
55 spriteY = 1,
66 }
11 {
22 pass = true,
33 name = 'tree_upper',
4 spriteX = 4,
4 spriteX = 2,
55 spriteY = 0,
66 }