1 import BearLibTerminal
;
22 abstract class Being
{
26 int xp
, hp
= 30, maxhp
, mp
, maxmp
;
28 RGBColour fgcolour
, bgcolour
;
31 int fov_dist
, light_dist
;
36 private struct _attr
{ bool reverse
, italic
, bold
, underline
; }
39 pragma(inline
, true) {
40 pure void inchp(int amount
=1) {
41 if ((amount
+ hp
) > maxhp
) {
50 pure bool isfemale() {
58 lightmap
= new Lightmap(&loc
, fov_dist
*2 + 1);
63 override Action
getaction() {
64 return rnd(Action
.MoveNorth
, Action
.MoveSouthRight
);
67 fgcolour
= RGBColour(0x00ff00);
68 bgcolour
= RGBColour(0xff00ff);
72 this.light_source
= true;
76 this.lightclr
= RGBColour(0x008800);
85 fgcolour
= RGBColour(0xffffff);
86 bgcolour
= RGBColour(0x000000);
90 this.glyph
= Glyph
.at
;
92 this.light_source
= true;
96 //this.lightclr = RGBColour(0xee9933);
97 this.lightclr
= RGBColour(0xff0000);
101 override Action
getaction() {
102 static immutable auto vikeys
= set
!dchar('h', 'j', 'k', 'l', 'y', 'u', 'b', 'n', 'q', '.', 'w');
107 while ((c
= graphics
.getch()) !in vikeys
) {}
111 tmp
= Action
.MoveLeft
;
114 tmp
= Action
.MoveRight
;
117 tmp
= Action
.MoveSouth
;
120 tmp
= Action
.MoveNorth
;
123 tmp
= Action
.MoveNorthLeft
;
126 tmp
= Action
.MoveNorthRight
;
129 tmp
= Action
.MoveSouthLeft
;
132 tmp
= Action
.MoveSouthRight
;
137 tmp = Action.AttackLeft;
140 tmp = Action.AttackRight;
143 tmp = Action.AttackSouth;
146 tmp = Action.AttackNorth;
149 tmp = Action.AttackNorthLeft;
152 tmp = Action.AttackNorthRight;
155 tmp = Action.AttackSouthLeft;
158 tmp = Action.AttackSouthRight;
168 case 'w': // (w)here am I?
169 tmp
= Action
.Printloc
;
175 tmp
= Action
.Showinv
;
194 this(string
[] args
) {
195 graphics
= new Default_chargfx
!BLT0("SmugglerRL!");
197 this.map
= genmap(MapType
.caves
);
199 mons
= [u
= new You(graphics
)];
200 foreach (_
; 1 .. 1000) {
206 // If we didn't have this, then if (0, 0) was walkable, then you would automatically get placed there
207 foreach (ref m
; mons
) {
209 m
.loc
.x
= rn1(map_x
+1);
210 m
.loc
.y
= rn1(map_y
+1);
211 } while ((!map
[m
.loc
].walkable
) ||
!mon_at(m
.loc
));
215 foreach (_
; 1 .. 100) {
216 items
~= Item(choice(all_items
));
218 foreach (ref i
; items
) {
220 i
.loc
.x
= rn1(map_x
+1);
221 i
.loc
.y
= rn1(map_y
+1);
222 } while (!map
[i
.loc
].walkable
);
229 void parseargs(string
[] args
) {
230 if (args
.length
== 2) {
231 if (args
[1] == "dumpmap") {
234 } else if (args
[1] == "dumphtmlmap") {
241 // Name credit to lrogue
242 ref Being
mon_at(uint y
, uint x
) {
243 foreach (ref tmpmon
; mons
) {
244 if ((tmpmon
.loc
.y
== y
) && (tmpmon
.loc
.x
== x
)) {
248 // Evil hackery so we can return null
249 static Being tmp
= null;
252 ref Being
mon_at(Vector2n loc
) {
253 return mon_at(loc
.y
, loc
.x
);
259 foreach (row
; map
.get_tiles
) {
260 foreach (tile
; row
) {
261 write(cast(dchar)tile
.glyph
);
270 <html lang="rl"> <!-- RogueLike! -->
272 <meta charset="utf-8">
273 <title>SmuglerRL HTML dump!</title>
275 <body fgcolor="#ffffff" bgcolor="#000000">
276 <div style="font-family: monospace">`);
278 bool clr_changed
, bgclr_changed
;
279 RGBColour fg
, last_fg
, bg
, last_bg
;
280 foreach (row
; map
.get_tiles
) {
281 foreach (tile
; row
) {
291 bgclr_changed
= true;
293 bgclr_changed
= false;
296 if (clr_changed
) write(`</font>`);
297 if (bgclr_changed
) write(`</font>`);
299 with (fg
) writef(`<font color="#%02x%02x%02x">`, r
, g
, b
);
303 with (bg
) writef(`<font bgcolor="#%02x%02x%02x">`, r
, g
, b
);
306 write(cast(dchar)tile
.glyph
);
318 pragma(inline
, true) void refresh() {
319 graphics
.refresh(u
.loc
.y
, u
.loc
.x
, mons
, map
);
321 pragma(inline
, true) void pline(T
...)(T args
) {
322 graphics
.pline(args
);
329 foreach (ref mon
; mons
) {
330 do_fov(map
, mon
.lightmap
, mon
.loc
.x
, mon
.loc
.y
, mon
.fov_dist
* mon
.fov_dist
, mon
.light_dist
* mon
.light_dist
);
332 do_colour(map
, mons
);
335 void handlemove(int yshift
, int xshift
, ref Being b
) {
336 if (map
[b
.loc
.y
+yshift
, b
.loc
.x
+xshift
].walkable
&& !mon_at(b
.loc
.y
+yshift
, b
.loc
.x
+xshift
)) {
337 b
.loc
.y
= b
.loc
.y
+ yshift
;
338 b
.loc
.x
= b
.loc
.x
+ xshift
;
340 // only when *you* walk into a wall
341 if (cast(You
)b
) pline("there is a thingy there!");
344 outerloop
: while (true) { foreach (ref Being mon
; mons
) {
345 act
= mon
.getaction();
346 // If we're moving, then move!
347 if ((Action
.MoveNorth
<= act
) && (act
<= Action
.MoveSouthRight
)) {
353 case Action
.MoveNorth
:
356 case Action
.MoveSouth
:
360 case Action
.MoveLeft
:
363 case Action
.MoveRight
:
366 case Action
.MoveNorthLeft
:
367 deltay
= deltax
= -1;
369 case Action
.MoveNorthRight
:
373 case Action
.MoveSouthLeft
:
377 case Action
.MoveSouthRight
:
384 case Action
.Printloc
:
385 pline("(%s, %s)", mon
.loc
.x
, mon
.loc
.y
);
392 handlemove(deltay
, deltax
, mon
);
397 foreach (ref mon
; mons
) {
398 do_fov(map
, mon
.lightmap
, mon
.loc
.x
, mon
.loc
.y
, mon
.fov_dist
* mon
.fov_dist
, mon
.light_dist
* mon
.light_dist
);
400 do_colour(map
, mons
);