1 import BearLibTerminal
;
20 abstract class Being
{
24 int xp
, hp
= 30, maxhp
, mp
, maxmp
;
26 RGBColour fgcolour
, bgcolour
;
30 private struct _attr
{ bool reverse
, italic
, bold
, underline
; }
33 pragma(inline
, true) {
34 pure void inchp(int amount
=1) {
35 if ((amount
+ hp
) > maxhp
) {
44 pure bool isfemale() {
53 override Action
getaction() {
54 return rnd(Action
.MoveNorth
, Action
.MoveSouthRight
);
57 fgcolour
= RGBColour(0x00ff00);
58 bgcolour
= RGBColour(0xff00ff);
67 fgcolour
= RGBColour(0xffffff);
68 bgcolour
= RGBColour(0x000000);
72 this.glyph
= Glyph
.at
;
74 override Action
getaction() {
75 static immutable auto vikeys
= set
!dchar('h', 'j', 'k', 'l', 'y', 'u', 'b', 'n', 'q', '.', 'w');
80 while ((c
= graphics
.getch()) !in vikeys
) {}
84 tmp
= Action
.MoveLeft
;
87 tmp
= Action
.MoveRight
;
90 tmp
= Action
.MoveSouth
;
93 tmp
= Action
.MoveNorth
;
96 tmp
= Action
.MoveNorthLeft
;
99 tmp
= Action
.MoveNorthRight
;
102 tmp
= Action
.MoveSouthLeft
;
105 tmp
= Action
.MoveSouthRight
;
110 tmp = Action.AttackLeft;
113 tmp = Action.AttackRight;
116 tmp = Action.AttackSouth;
119 tmp = Action.AttackNorth;
122 tmp = Action.AttackNorthLeft;
125 tmp = Action.AttackNorthRight;
128 tmp = Action.AttackSouthLeft;
131 tmp = Action.AttackSouthRight;
141 case 'w': // (w)here am I?
142 tmp
= Action
.Printloc
;
148 tmp
= Action
.Showinv
;
167 this(string
[] args
) {
168 graphics
= new Default_chargfx
!BLT0("SmugglerRL!");
170 this.map
= genmap(MapType
.caves
);
172 mons
= [u
= new You(graphics
)];
173 foreach (_
; 1 .. 1000) {
178 map
.for_all((ref Tile x
) => x
.setdefglyph());
182 // If we didn't have this, then if (0, 0) was walkable, then you would automatically get placed there
183 foreach (ref m
; mons
) {
185 m
.loc
.x
= rn1(map_x
+1);
186 m
.loc
.y
= rn1(map_y
+1);
187 } while ((!map
[m
.loc
].walkable
) ||
!mon_at(m
.loc
));
191 foreach (_
; 1 .. 100) {
192 items
~= Item(choice(all_items
));
194 foreach (ref i
; items
) {
196 i
.loc
.x
= rn1(map_x
+1);
197 i
.loc
.y
= rn1(map_y
+1);
198 } while (!map
[i
.loc
].walkable
);
205 void parseargs(string
[] args
) {
206 if (args
.length
== 2) {
207 if (args
[1] == "dumpmap") {
210 } else if (args
[1] == "dumphtmlmap") {
217 // Name credit to lrogue
218 ref Being
mon_at(uint y
, uint x
) {
219 foreach (ref tmpmon
; mons
) {
220 if ((tmpmon
.loc
.y
== y
) && (tmpmon
.loc
.x
== x
)) {
224 // Evil hackery so we can return null
225 static Being tmp
= null;
228 ref Being
mon_at(Vector2n loc
) {
229 return mon_at(loc
.y
, loc
.x
);
235 foreach (row
; map
.get_tiles
) {
236 foreach (tile
; row
) {
237 write(cast(dchar)tile
.glyph
);
246 <html lang="rl"> <!-- RogueLike! -->
248 <meta charset="utf-8">
249 <title>SmuglerRL HTML dump!</title>
251 <body fgcolor="#ffffff" bgcolor="#000000">
252 <div style="font-family: monospace">`);
254 bool clr_changed
, bgclr_changed
;
255 RGBColour fg
, last_fg
, bg
, last_bg
;
256 foreach (row
; map
.get_tiles
) {
257 foreach (tile
; row
) {
267 bgclr_changed
= true;
269 bgclr_changed
= false;
272 if (clr_changed
) write(`</font>`);
273 if (bgclr_changed
) write(`</font>`);
275 with (fg
) writef(`<font color="#%02x%02x%02x">`, r
, g
, b
);
279 with (bg
) writef(`<font bgcolor="#%02x%02x%02x">`, r
, g
, b
);
282 write(cast(dchar)tile
.glyph
);
294 pragma(inline
, true) void refresh() {
295 graphics
.refresh(u
.loc
.y
, u
.loc
.x
, mons
, map
);
297 pragma(inline
, true) void pline(T
...)(T args
) {
298 graphics
.pline(args
);
307 void handlemove(int yshift
, int xshift
, ref Being b
) {
308 if (map
[b
.loc
.y
+yshift
, b
.loc
.x
+xshift
].walkable
&& !mon_at(b
.loc
.y
+yshift
, b
.loc
.x
+xshift
)) {
309 map
[b
.loc
.y
, b
.loc
.x
].setdefglyph();
310 b
.loc
.y
= b
.loc
.y
+ yshift
;
311 b
.loc
.x
= b
.loc
.x
+ xshift
;
313 // only when *you* walk into a wall
314 if (cast(You
)b
) pline("there is a thingy there!");
317 outerloop
: while (true) { foreach (ref Being mon
; mons
) {
318 act
= mon
.getaction();
319 // If we're moving, then move!
320 if ((Action
.MoveNorth
<= act
) && (act
<= Action
.MoveSouthRight
)) {
326 case Action
.MoveNorth
:
329 case Action
.MoveSouth
:
333 case Action
.MoveLeft
:
336 case Action
.MoveRight
:
339 case Action
.MoveNorthLeft
:
340 deltay
= deltax
= -1;
342 case Action
.MoveNorthRight
:
346 case Action
.MoveSouthLeft
:
350 case Action
.MoveSouthRight
:
357 case Action
.Printloc
:
358 pline("(%s, %s)", mon
.loc
.x
, mon
.loc
.y
);
365 handlemove(deltay
, deltax
, mon
);
367 //if (cast(You)mon) { refresh(); }
371 do_fov(map
, u
.loc
.x
, u
.loc
.y
, 100);