-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathbehavior.rb
31 lines (24 loc) · 932 Bytes
/
behavior.rb
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
class Rubyhave::Behavior
def blocked_move?(move)
x = move.x == 0 ? 0 : move.x > 0 ? 1 : -1
y = move.y == 0 ? 0 : move.y > 0 ? 1 : -1
blocked = entity.blocked?(x, y) || (x != 0 && entity.blocked?(x, 0)) || (y != 0 && entity.blocked?(0, y))
if entity.size.x > 1
additional_width = entity.size.x - 1
blocked = blocked || entity.blocked?(x+additional_width, y) || (x != 0 && entity.blocked?(x+additional_width, 0)) || (y != 0 && entity.blocked?(additional_width, y))
end
if entity.size.y > 1
additional_height = entity.size.y - 1
blocked = blocked || entity.blocked?(x, y-additional_height) || (x != 0 && entity.blocked?(x, -additional_height)) || (y != 0 && entity.blocked?(0, y-additional_height))
end
blocked
end
def zone
@zone ||= entity.zone
end
def complete_block!(block)
if blocks = get(:directed_blocks)
blocks.delete block
end
end
end