-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.lua
48 lines (40 loc) · 978 Bytes
/
player.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
require "objects"
Player = Entity:extend()
function Player:new(normal_state, x, y)
Player.super.new(self, x, y, "@", {1, 0.7, 0.5})
self.normal_state = normal_state
end
function Player:keypressed(key)
local nx = self.x
local ny = self.y
if key == "up" then
ny = ny - 1
elseif key == "down" then
ny = ny + 1
elseif key == "left" then
nx = nx - 1
elseif key == "right" then
nx = nx + 1
else
return false
end
local map = self.normal_state.map
if map:out_range(nx, ny) then
return true
end
local unit = map:find_unit_at(nx, ny)
if unit then
console:print("you try to hit " .. unit.char)
return true
end
local tile = map:get_tile(nx, ny)
if tile.block_move then
console:print("you can't move this way")
return true
end
self.x = nx
self.y = ny
map:update_fov(self.x, self.y)
return true
end
return Player