1
+ set mapSize 16;
2
+ set random $utils.random;
3
+
4
+ set global.br $this;
5
+
6
+ set Vector2 from function {x y}
7
+ {
8
+ return (obj x $x y $y);
9
+ };
10
+
11
+ lua.eval {br.push = function(t, v) table.insert(t, v) end};
12
+
13
+ set roomMaxSize (Vector2 32 32);
14
+ set roomAmount 128;
15
+
16
+ set Creature from function {name position}
17
+ {
18
+ set tempcreature (obj name $name position $position);
19
+ set tempcreature.globalPosition 1;
20
+ set tempcreature.needs (obj hunger 100 thirst 100 health 100);
21
+ set tempcreature.stats (obj strength 10 dexterity 10 intelligence 10);
22
+ set tempcreature.inventory [];
23
+ set tempcreature.equipment (obj head nil body nil legs nil hands nil feet nil);
24
+ set tempcreature.room 1;
25
+ return $tempcreature;
26
+ };
27
+
28
+ set Room from function {w h}
29
+ {
30
+ set temproom (obj w $w h $h);
31
+ set temproom.map (utils.matrix.new $w $h 46);
32
+
33
+ set iy (random 2 (- $h 2));
34
+ set oy (random 2 (- $h 2));
35
+ set ix (random 2 (- $w 2));
36
+ set ox (random 2 (- $w 2));
37
+
38
+ set tmpw (- $w 1);
39
+ set tmph (- $h 1);
40
+ // create the walls on the limits
41
+ //print $w $h;
42
+ for {set i 1} {< $i $w} {set i (+ $i 1)}
43
+ {
44
+ //print $i;
45
+ set temproom.map.$i.1 35;
46
+ set temproom.map.$i.$tmph 35;
47
+ };
48
+
49
+ for {set i 1} {< $i $h} {set i (+ $i 1)}
50
+ {
51
+ set temproom.map.1.$i 35;
52
+ set temproom.map.$tmpw.$i 35;
53
+ };
54
+
55
+ set doorbyte 32;
56
+
57
+ set tmpx (random 2 (- $w 2));
58
+ set temproom.map.$tmpx.1 $doorbyte;
59
+ set tmpx (random 2 (- $w 2));
60
+ set tmph (- $h 1);
61
+ set temproom.map.$tmpx.$tmph $doorbyte;
62
+ set tmpx nil;
63
+ set tmph nil;
64
+ set tmpy (random 2 (- $h 2));
65
+ set temproom.map.1.$tmpy $doorbyte;
66
+ set tmpy (random 2 (- $h 2));
67
+ set tmpw (- $w 1);
68
+ set temproom.map.$tmpw.$tmpy $doorbyte;
69
+ set tmpy nil;
70
+ set tmpw nil;
71
+
72
+ return $temproom;
73
+ };
74
+
75
+ set genRooms from function {}
76
+ {
77
+ set rooms from [];
78
+ for {set x 1} {< $x (/ $roomAmount 2)} {set x (+ $x 1)}
79
+ {
80
+ set rooms.$x from [];
81
+ for {set y 1} {< $y (/ $roomAmount 2)} {set y (+ $y 1)}
82
+ {
83
+ set rooms.$x.$y (Room (random 7 $roomMaxSize.x) (random 7 $roomMaxSize.y ));
84
+ };
85
+ };
86
+ return $rooms;
87
+ };
88
+
89
+ set world from [];
90
+ set world.rooms (genRooms);
91
+ set world.creatures ([]);
92
+ set tmpx (random 5 (len $world.rooms.1));
93
+ set tmpy (random 5 (len $world.rooms));
94
+ push $world.creatures (Creature `player` (Vector2 (random 5 $tmpx ) (random 5 $tmpy)));
95
+ set player $world.creatures.1;
96
+ lua.eval {br["rawprint"] = io.write;};
97
+
98
+ set printmaptile from function {_map _x _y}
99
+ {
100
+ lua.eval (string `io.write("" .. string.char(br._map[` $_x `][` $_y `]));`);
101
+ };
102
+
103
+ lua.eval {br["io"] = io};
104
+
105
+ set printroom from function {_map}
106
+ {
107
+ for {set i 1} {< $i (len $_map.1)} {set i (+ $i 1)}
108
+ {
109
+ for {set j 1} {< $j (len $_map)} {set j (+ $j 1)}
110
+ {
111
+ if {and (== $j $player.position.x) (== $i $player.position.y)}
112
+ {
113
+ io.write {@};
114
+ }
115
+ else
116
+ {
117
+ printmaptile $_map $j $i;
118
+ };
119
+ };
120
+ print {};
121
+ };
122
+ };
123
+
124
+ printroom $world.rooms.1.1.map;
0 commit comments