-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTile.lua
More file actions
92 lines (76 loc) · 1.92 KB
/
Copy pathTile.lua
File metadata and controls
92 lines (76 loc) · 1.92 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
require "oop"
require "color"
require "camera"
Tile = class() do
local base = Tile
function base:init() end
function base:draw(info)
love.graphics.scale(info.dist / screen.height, 1)
love.graphics.translate(0, - 1 - info.z + camera.pos.z)
self:shader(info)
end
function base:shader(info)
error("tile without shader:", self, "render info: ", info)
end
end
ColorTile = subclass(Tile) do
local base = ColorTile
function base:init(xcolor, ycolor)
base.super.init(self)
self.xcolor = xcolor or color.white
self.ycolor = ycolor or self.xcolor
end
function base:shader(info)
if info.axis == "x" then
love.graphics.setColor(self.xcolor)
else
love.graphics.setColor(self.ycolor)
end
love.graphics.rectangle("fill", 0, 0, 1, 1)
end
end
TextureTile = subclass(Tile) do
local base = TextureTile
function base:init(xtex, ytex)
base.super.init(self)
if type(xtex) == "string" then
xtex = love.graphics.newImage(xtex, format)
end
if type(ytex) == "string" then
ytex = love.graphics.newImage(ytex, format)
end
self.xtex = xtex
local xw = xtex:getWidth()
self.xquadcount = xw
self.xquads = {}
for i = 0, xw - 1 do
self.xquads[i] = love.graphics.newQuad(i, 0, 1, 1, xw, 1)
end
if (ytex) then
self.ytex = ytex
local yw = ytex:getWidth()
self.yquadcount = yw
self.yquads = {}
for i = 0, yw - 1 do
self.yquads[i] = love.graphics.newQuad(i, 0, 1, 1, yw, 1)
end
else
self.ytex = xtex
self.yquadcount = self.xquadcount
self.yquads = self.xquads
end
end
function base:shader(info)
if info.axis == "x" then
local u = info.y - info.j
if info.sign < 0 then u = 1 - u end
local quad = self.xquads[math.floor(u * self.xquadcount)]
love.graphics.draw(self.xtex, quad)
else
local u = info.x - info.i
if info.sign > 0 then u = 1 - u end
local quad = self.yquads[math.floor(u * self.yquadcount)]
love.graphics.draw(self.ytex, quad)
end
end
end