-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloadSprites.lua
55 lines (53 loc) · 2.04 KB
/
loadSprites.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
GFX = {}
CAMERA = {x=48,y=0,r=0, w=475,h=250 }
function DRAWMAP(objects)
local renderByLayers = {}
local max = 0
local min = 1000
for k,v in pairs(objects) do
renderByLayers[v.position.z] =renderByLayers[v.position.z] or {}
renderByLayers[v.position.z][#renderByLayers[v.position.z]+1] = v
max = math.max(v.position.z, max+GFX[v.texture].slides)
min = math.min(v.position.z, min)
end
local renderObjs = {}
for i=min, max do
atlas.spritebatch:clear()
if(renderByLayers[i]) then
for k,v in ipairs(renderByLayers[i]) do
renderObjs[v] = v
end
end
for k,v in pairs(renderObjs) do
if i >= GFX[v.texture].slides + v.position.z then
renderObjs[k] = nil
else
GFX[v.texture]:draw(v.position.x, v.position.y, v.position.z, i-v.position.z, v.position.r, atlas.spritebatch)
end
end
love.graphics.draw(atlas.spritebatch, 0, 0)
end
end
local function addQuads(format)
format.quads = {}
format.sizeX = format.image:getWidth()/format.slides
format.sizeY = format.image:getHeight()
for i=1, format.slides do
format.quads[#format.quads+1] = love.graphics.newQuad((i-1)*format.image:getWidth()/format.slides+format.UV.x, format.UV.y, format.image:getWidth()/format.slides, format.image:getHeight(), atlas.map:getWidth(), atlas.map:getHeight())
end
end
local function draw(self, x,y, z,layer, r, batch)
local i = layer+1
local XX= x*math.cos(CAMERA.r)+ y*math.sin(CAMERA.r)
local YY= - x*math.sin(CAMERA.r) + y*math.cos(CAMERA.r)
batch:add(self.quads[i], -CAMERA.x +XX+ 0.5*CAMERA.w,-CAMERA.y+ YY -i-z + 0.5*CAMERA.h,r-CAMERA.r,1,1,self.sizeX/2, self.sizeY/2)
end
return function()
local f = require 'sprites.formats'
for _, format in ipairs(f) do
GFX[format.key] = format
format.image = love.graphics.newImage("sprites/"..format.file)
format.addQuads = addQuads
format.draw = draw
end
end