-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.lua
78 lines (67 loc) · 1.87 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
love.filesystem.load('assets/maps/tiledmap.lua')()
love.filesystem.load('lib/TiledMapLoader.lua')()
love.filesystem.load('lib/AnAL.lua')()
Animations_legacy_support = true
function love.load()
love.graphics.setMode(640, 480)
love.graphics.setCaption('PacMan in LOVE')
love.graphics.setBackgroundColor(0,0,0)
love.graphics.clear()
pacmanSheet = love.graphics.newImage('assets/sprites/pacmansheet.png')
pacmanAnim = newAnimation(pacmanSheet, 32, 32, 0.04, 0)
pacmanAnim:setMode("bounce")
TiledMap_Load('assets/maps/tiledmap.tmx')
require('modules.pacman');
end
function love.draw()
pacman.draw();
TiledMap_DrawNearCam(352,272)
end
function love.update(dt)
pacman.update(dt);
pacmanAnim:update(dt)
end
function love.keypressed(key, unicode)
pacman.keypressed(key,unicode);
end
function get_square_position(x, y)
local pos_x = math.ceil(x / 32);
local pos_y = math.ceil(y / 32);
return pos_x, pos_y;
end
function get_tile_index(pos_x, pos_y)
return TiledMap_GetMapTile(pos_x, pos_y, 1);
end
function create_box()
box = {};
for i=1,3 do
box[i] = {};
for j=1,3 do
box[i][j] = {};
end
end
box.update = function (x, y, width, height)
box[1][1] = {x - width / 2, y - height / 2};
box[1][2] = {x - width / 2, y};
box[1][3] = {x - width / 2, y + height / 2};
box[2][1] = {x, y - height / 2};
box[2][2] = {x, y};
box[2][3] = {x, y + height / 2};
box[3][1] = {x + width / 2, y - height / 2};
box[3][2] = {x + width / 2, y};
box[3][3] = {x + width / 2, y + height / 2};
end
return box;
end
function check_colision(box)
local tile;
for i=1,3 do
for j=1,3 do
tile = get_tile_index(get_square_position(box[i][j][1], box[i][j][2]));
if (tile == 85) then
return true;
end
end
end
return false;
end