-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMap.rb
68 lines (57 loc) · 1.23 KB
/
Map.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
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
# $Id$
#
# Shade: A science-fiction computer roleplaying game.
# Copyright (C) 2002 Greg McIntyre
#
# Shade is licensed under the GNU General Public License as published
# by the Free Software Foundation. For more information, please refer
# to gpl.txt.
require 'Tile'
require 'Debug'
require 'External'
class Map < External::Map
def allocate(width, height)
Debug.print "Allocating #{width}x#{height} map..."
@blank = Empty.new(self)
alloc(self, width, height)
end
def free
dealloc
end
def set_unit(x, y, unit)
t = tile(x, y)
t.unit = unit
unit.location = t
end
def make_demo
puts "Making demo map..."
allocate(50, 50)
# Walls
for i in 5..10
t = Wall::new(self)
set_tile(i, 5, t)
t.colour = 0x808080
end
for i in 5..10
t = Wall::new(self)
set_tile(5, i, t)
t.colour = 0x808080
end
# Door
t = Door::new(self)
set_tile(5, 7, t)
t.colour = 0xFF8040
end
# Attempt moving a unit from one tile to another.
# If there are any problems, do nothing.
def move_unit(unit, tile_old, tile_new)
if tile_new and not tile_new.unit and tile_new.passable
tile_old.unit = nil
tile_new.unit = unit
unit.location = tile_new
end
end
def new_tile(type)
return eval(type).new(self)
end
end