1 import BearLibTerminal
;
21 abstract class Being
{
25 int xp
, hp
= 30, maxhp
, mp
, maxmp
;
27 RGBColour fgcolour
, bgcolour
;
31 private struct _attr
{ bool reverse
, italic
, bold
, underline
; }
34 pragma(inline
, true) {
35 pure void inchp(int amount
=1) {
36 if ((amount
+ hp
) > maxhp
) {
45 pure bool isfemale() {
54 override Action
getaction() {
55 return rnd(Action
.MoveNorth
, Action
.MoveSouthRight
);
58 fgcolour
= RGBColour(0x00ff00);
59 bgcolour
= RGBColour(0xff00ff);
68 fgcolour
= RGBColour(0xffffff);
69 bgcolour
= RGBColour(0x000000);
73 this.glyph
= Glyph
.at
;
75 override Action
getaction() {
76 static immutable auto vikeys
= set
!dchar('h', 'j', 'k', 'l', 'y', 'u', 'b', 'n', 'q', '.', 'w');
81 while ((c
= graphics
.getch()) !in vikeys
) {}
85 tmp
= Action
.MoveLeft
;
88 tmp
= Action
.MoveRight
;
91 tmp
= Action
.MoveSouth
;
94 tmp
= Action
.MoveNorth
;
97 tmp
= Action
.MoveNorthLeft
;
100 tmp
= Action
.MoveNorthRight
;
103 tmp
= Action
.MoveSouthLeft
;
106 tmp
= Action
.MoveSouthRight
;
111 tmp = Action.AttackLeft;
114 tmp = Action.AttackRight;
117 tmp = Action.AttackSouth;
120 tmp = Action.AttackNorth;
123 tmp = Action.AttackNorthLeft;
126 tmp = Action.AttackNorthRight;
129 tmp = Action.AttackSouthLeft;
132 tmp = Action.AttackSouthRight;
142 case 'w': // (w)here am I?
143 tmp
= Action
.Printloc
;
149 tmp
= Action
.Showinv
;
168 this(string
[] args
) {
169 graphics
= new Default_chargfx
!BLT0("SmugglerRL!");
171 this.map
= genmap(MapType
.caves
);
173 mons
= [u
= new You(graphics
)];
174 foreach (_
; 1 .. 1000) {
180 // If we didn't have this, then if (0, 0) was walkable, then you would automatically get placed there
181 foreach (ref m
; mons
) {
183 m
.loc
.x
= rn1(map_x
+1);
184 m
.loc
.y
= rn1(map_y
+1);
185 } while ((!map
[m
.loc
].walkable
) ||
!mon_at(m
.loc
));
189 foreach (_
; 1 .. 100) {
190 items
~= Item(choice(all_items
));
192 foreach (ref i
; items
) {
194 i
.loc
.x
= rn1(map_x
+1);
195 i
.loc
.y
= rn1(map_y
+1);
196 } while (!map
[i
.loc
].walkable
);
203 void parseargs(string
[] args
) {
204 if (args
.length
== 2) {
205 if (args
[1] == "dumpmap") {
208 } else if (args
[1] == "dumphtmlmap") {
215 // Name credit to lrogue
216 ref Being
mon_at(uint y
, uint x
) {
217 foreach (ref tmpmon
; mons
) {
218 if ((tmpmon
.loc
.y
== y
) && (tmpmon
.loc
.x
== x
)) {
222 // Evil hackery so we can return null
223 static Being tmp
= null;
226 ref Being
mon_at(Vector2n loc
) {
227 return mon_at(loc
.y
, loc
.x
);
233 foreach (row
; map
.get_tiles
) {
234 foreach (tile
; row
) {
235 write(cast(dchar)tile
.glyph
);
244 <html lang="rl"> <!-- RogueLike! -->
246 <meta charset="utf-8">
247 <title>SmuglerRL HTML dump!</title>
249 <body fgcolor="#ffffff" bgcolor="#000000">
250 <div style="font-family: monospace">`);
252 bool clr_changed
, bgclr_changed
;
253 RGBColour fg
, last_fg
, bg
, last_bg
;
254 foreach (row
; map
.get_tiles
) {
255 foreach (tile
; row
) {
265 bgclr_changed
= true;
267 bgclr_changed
= false;
270 if (clr_changed
) write(`</font>`);
271 if (bgclr_changed
) write(`</font>`);
273 with (fg
) writef(`<font color="#%02x%02x%02x">`, r
, g
, b
);
277 with (bg
) writef(`<font bgcolor="#%02x%02x%02x">`, r
, g
, b
);
280 write(cast(dchar)tile
.glyph
);
292 pragma(inline
, true) void refresh() {
293 graphics
.refresh(u
.loc
.y
, u
.loc
.x
, mons
, map
);
295 pragma(inline
, true) void pline(T
...)(T args
) {
296 graphics
.pline(args
);
305 void handlemove(int yshift
, int xshift
, ref Being b
) {
306 if (map
[b
.loc
.y
+yshift
, b
.loc
.x
+xshift
].walkable
&& !mon_at(b
.loc
.y
+yshift
, b
.loc
.x
+xshift
)) {
307 b
.loc
.y
= b
.loc
.y
+ yshift
;
308 b
.loc
.x
= b
.loc
.x
+ xshift
;
310 // only when *you* walk into a wall
311 if (cast(You
)b
) pline("there is a thingy there!");
314 outerloop
: while (true) { foreach (ref Being mon
; mons
) {
315 act
= mon
.getaction();
316 // If we're moving, then move!
317 if ((Action
.MoveNorth
<= act
) && (act
<= Action
.MoveSouthRight
)) {
323 case Action
.MoveNorth
:
326 case Action
.MoveSouth
:
330 case Action
.MoveLeft
:
333 case Action
.MoveRight
:
336 case Action
.MoveNorthLeft
:
337 deltay
= deltax
= -1;
339 case Action
.MoveNorthRight
:
343 case Action
.MoveSouthLeft
:
347 case Action
.MoveSouthRight
:
354 case Action
.Printloc
:
355 pline("(%s, %s)", mon
.loc
.x
, mon
.loc
.y
);
362 handlemove(deltay
, deltax
, mon
);
367 do_fov(map
, u
.loc
.x
, u
.loc
.y
, 1000);