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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161 | function love.update(dt)
local mc = maze[playerCell]
if love.keyboard.isDown('left') and x==xT and yT==y
and ((not onVbridge and mc.linked.left) or onHbridge) then
xT=xT-dx
playerCell = playerCell - 1
onHbridge = (mc.linked.left ~= mc.left) and (not onHbridge)
elseif love.keyboard.isDown('right') and x==xT and yT==y
and ((not onVbridge and mc.linked.right) or onHbridge) then
xT=xT+dx
playerCell = playerCell + 1
onHbridge = (mc.linked.right ~= mc.right) and (not onHbridge)
elseif love.keyboard.isDown('up') and y==yT and xT==x
and ((not onHbridge and mc.linked.up) or onVbridge) then
yT=yT-dy
playerCell = playerCell - nx
onVbridge = (mc.linked.up ~= mc.up) and (not onVbridge)
elseif love.keyboard.isDown('down') and y==yT and xT==x
and ((not onHbridge and mc.linked.down) or onVbridge) then
yT=yT+dy
playerCell = playerCell + nx
onVbridge = (mc.linked.down ~= mc.down) and (not onVbridge)
end
if math.abs(x-xT)<1 and math.abs(y-yT)<1 then
x=xT
y=yT
else
x=x+(xT-x)*30*dt
y=y+(yT-y)*30*dt
end
if onVbridge or onHbridge then
plate:set(idh, hero, 0, 0, 0, 0, 0)
plate:set(idhb, hero, x, y)
else
plate:set(idhb, hero, 0, 0, 0, 0, 0)
plate:set(idh, hero, x, y)
end
if playerCell == nx * nz then finished = true end
end
function love.load()
require('Maze')
love.window.setTitle('Amazing maze')
love.mouse.setVisible(false)
local sprites = love.graphics.newImage('sprites/digital.png')
local spSize = sprites:getDimensions() / 5
local sp = {}
for x = 0, 4 do
for y = 0, 2 do
sp[(x+1)+y*5] = love.graphics.newQuad(x*spSize, y*spSize,
spSize, spSize, sprites:getDimensions())
end
end
hero = love.graphics.newQuad(2*spSize, 3*spSize, spSize, spSize,
sprites:getDimensions())
local bridgeH = love.graphics.newQuad(0, 3*spSize, spSize, spSize,
sprites:getDimensions())
local bridgeV = love.graphics.newQuad(spSize, 3*spSize, spSize, spSize,
sprites:getDimensions())
local width = 10
local height = 10
function initMaze(w, h)
nx = w or 10
nz = h or 10
love.window.setMode(nx*spSize, nz*spSize)
maze = Maze:new(nx,nz)
finished = false
tLastVisit = {}
for i = 1, nx*nz do
tLastVisit[i]=0
end
x=0
y=0
xT=0
yT=0
dx=spSize
dy=spSize
playerCell = 1
plate = love.graphics.newSpriteBatch(sprites)
plate:setBufferSize(2*nx*nz)
for cell = 1, nx * nz do
local cellScore = 0
local mc = maze[cell]
if mc.linked.left then
cellScore = 1 end
if mc.linked.down then
cellScore = cellScore + 2 end
if mc.linked.right then
cellScore = cellScore + 4 end
if mc.linked.up then
cellScore = cellScore + 8 end
local x = (cell - 1) % nx
local y = (cell - x - 1) / nx
plate:add(sp[cellScore], x*spSize, y*spSize)
end
idh = plate:add(hero, 0, 0)
for cell = 1, nx * nz do
local mc = maze[cell]
local x = (cell - 1) % nx
local y = (cell - x - 1) / nx
if mc.up and mc.down and mc.up.linked.down == mc.down then
plate:add(bridgeV, x*spSize, y*spSize)
elseif mc.left and mc.right and mc.left.linked.right == mc.right then
plate:add(bridgeH, x*spSize, y*spSize)
end
end
idhb = plate:add(hero, 0, 0)
onVbridge = false
onHbridge = false
end
function love.resize(w, h)
love.window.setMode(nx*spSize, nz*spSize, {resizable=false})
end
function love.keyreleased(key)
if key=='h' and width>10 then
width = width-5
initMaze(width, height)
elseif key=='l' and width<50 then
width = width+5
initMaze(width, height)
elseif key=='k' and height>10 then
height = height-5
initMaze(width, height)
elseif key=='j' and height<50 then
height = height+5
initMaze(width, height)
end
if key=='right' and finished then initMaze(width, height) end
end
function mask(x, y, trsp)
love.graphics.setColor(0, 0, 0, trsp)
love.graphics.rectangle('fill', x*spSize, y*spSize, spSize, spSize)
love.graphics.setColor(255, 255, 255, 255)
end
initMaze(width, height)
end
function love.draw()
love.graphics.draw(plate)
time = love.timer.getTime()
tLastVisit[playerCell] = time
for i = 1, nx*nz do
local x = (i - 1) % nx
local y = (i - x - 1) / nx
etrsp = (time-tLastVisit[i])*255/10
mask(x, y, (etrsp < 255 and etrsp or 255 ))
end
end
|