-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.lua
62 lines (48 loc) · 1.4 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
ROT = require "vendor/rotLove/rotLove"
require "utils"
require "classes/thing"
require "classes/map"
SCREEN_WIDTH = 37
SCREEN_HEIGHT = 37
LEVEL_WIDTH = 23
LEVEL_HEIGHT = 21
function love.load()
love.keyboard.setKeyRepeat(true)
display = ROT.Display:new(LEVEL_WIDTH, LEVEL_HEIGHT)
player = Thing:new{character='@', color="yellow", xpos=1, ypos=1}
player.score = 0
map = Map:new("data/level1.txt")
end
function love.draw()
display:draw()
end
function love.update(dt)
map:draw()
display:write("score: " .. player.score, 1, LEVEL_HEIGHT)
player:draw()
-- TODO: for ghost in map.ghosts or something, do things
-- TODO: will need to make a ghosts table somewhere
end
function love.keypressed(key)
-- clear everything that moves before changing the position of anything
player:clear()
local potential_move = {}
if key == 'j' then
potential_move = {player.xpos, player.ypos + 1}
elseif key == 'k' then
potential_move = {player.xpos, player.ypos - 1}
elseif key == 'l' then
potential_move = {player.xpos + 1, player.ypos}
elseif key == 'h' then
potential_move = {player.xpos - 1, player.ypos}
else
return
end
if not map:is_blocked(potential_move) then
player:move(potential_move)
local collectibles = map:get_collectibles(potential_move)
for i, collectible in ipairs(collectibles) do
player.score = player.score + collectible.points
end
end
end