@@ -5,6 +5,7 @@ const Vec2i = math.Vec(2, i64);
55const vec2i = Vec2i .init ;
66const Map = @import ("./map.zig" ).Map ;
77const platform = @import ("platform" );
8+ const component = @import ("./component.zig" );
89
910const Room = struct {
1011 pos : Vec2i ,
@@ -27,6 +28,7 @@ pub const Options = struct {
2728 min : i64 ,
2829 max : i64 ,
2930 },
31+ max_monsters_per_room : u64 ,
3032};
3133
3234pub fn generateMap (allocator : * std.mem.Allocator , opts : Options ) ! Map {
@@ -130,6 +132,16 @@ pub fn generateMap(allocator: *std.mem.Allocator, opts: Options) !Map {
130132 map .set (pos , .Floor );
131133 }
132134 }
135+
136+ // Place monsters in room
137+ const num_monsters = rand .intRangeAtMostBiased (u64 , 0 , opts .max_monsters_per_room );
138+ var c : u64 = 0 ;
139+ while (c < num_monsters ) : (c += 1 ) {
140+ createRatEntity (& map , Vec2i {
141+ .x = room .pos .x + rand .intRangeAtMostBiased (i64 , 0 , room .size .x ),
142+ .y = room .pos .y + rand .intRangeAtMostBiased (i64 , 0 , room .size .y ),
143+ });
144+ }
133145 }
134146
135147 map .spawn = rooms .items [0 ].pos .addv (rooms .items [0 ].size .scaleDivFloor (2 ));
@@ -182,3 +194,9 @@ fn create_v_tunnel(map: *Map, y0: i64, y1: i64, x: i64) void {
182194 }
183195 }
184196}
197+
198+ pub fn createRatEntity (map : * Map , pos : Vec2i ) void {
199+ var e = map .registry .create ();
200+ map .registry .add (e , component.Position { .pos = pos });
201+ map .registry .add (e , component.Render { .tid = 415 });
202+ }
0 commit comments