-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.lua
executable file
·142 lines (124 loc) · 3.38 KB
/
main.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
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
lights = require('monocle')
local _lg = love.graphics
local _mouse = love.mouse
pi = math.pi
function love.load()
map_height = 12
map_width = 18
tileSize = 40
player = require('player')
level = GenerateMap(map_width,map_height)
sprite_canvas = _lg.newCanvas()
DEBUG = false
draw_monocle = true
end
function love.update(dt)
player:update(dt, level)
end
function love.draw()
_lg.setBlendMode('alpha')
for i = 1, #level do
for j = 1, #level[i] do
if level[i][j].solid then
_lg.setColor(50,50,200)
else
_lg.setColor(100,100,100)
end
_lg.rectangle('fill', j*tileSize, i*tileSize, tileSize, tileSize)
end
end
player:draw()
_lg.setCanvas()
_lg.draw(sprite_canvas)
_lg.setCanvas()
lights:draw(player.x,player.y,level,tileSize, DEBUG, draw_monocle)
_lg.setBlendMode('multiplicative')
if draw_monocle then
_lg.draw(lights.canvas)
end
_lg.setBlendMode('alpha')
_lg.setColor(255,255,255)
_lg.print('X:' .. player.x .. ';Y:' .. player.y, 0,0)
_lg.print('Press "b" to toggle debug mode',0,12)
_lg.print('Press "n" to toggle Monocle mode',0,24)
_lg.print('Press "t" to teleport player to (3,3)',0,36)
end
function love.keypressed(key,code)
if key == 'b' then
DEBUG = not DEBUG
elseif key == 'n'then
draw_monocle = not draw_monocle
elseif key == 't' then
player.x=3
player.y=3
end
end
function love.mousepressed(x,y,button)
end
function CheckTileCollisions(map, rectx, recty, rectw, recth, tileSize)
local firstTileX = math.floor(rectx / tileSize)
local firstTileY = math.floor(recty / tileSize)
local lastTileX = math.floor((rectx + rectw) / tileSize)
local lastTileY = math.floor((recty + recth) / tileSize)
local noCollision = true
for i = firstTileY, lastTileY do
for j = firstTileX, lastTileX do
if map[i] then
if map[i][j] then
if map[i][j].solid then
noCollision = false
return noCollision
end
end
end
end
end
return noCollision
end
function GenerateMap(w,h)
local map = {}
for i = 1,math.ceil(h) do
map[i] = {}
for j = 1,math.ceil(w) do
map[i][j] = {}
if this_level[i][j] == 1 then
map[i][j].solid = true
else
map[i][j].solid = false
end
end
end
return map
end
function round(num, idp)
local mult = 10^(idp or 0)
return math.floor(num * mult + 0.5) / mult
end
--[[this_level2 = {
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1},
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
}]]
this_level = {
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,1,0,0,0,1,0,1,1,0,1},
{1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,1},
{1,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,1},
{1,0,0,1,1,1,0,0,0,0,1,0,1,0,1,0,0,1},
{1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,1,1,1,0,0,0,0,1,0,1,0,1,0,0,1},
{1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,1,0,1,0,1,0,0,1},
{1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1},
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
}