templeos-info/public/Wb/Demo/Games/DunGen.HC.HTML

479 lines
40 KiB
Plaintext
Raw Normal View History

2024-03-24 21:24:44 +00:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="generator" content="TempleOS V5.03">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="/style/templeos.css">
<script src="/script/templeos.js"></script>
<style type="text/css">
.c00{color:#000000;background-color:#000000;}
.c0A{color:#55ff55;background-color:#000000;}
.cF0{color:#000000;background-color:#ffffff;}
.cF1{color:#0000aa;background-color:#ffffff;}
.cF2{color:#00aa00;background-color:#ffffff;}
.cF3{color:#00aaaa;background-color:#ffffff;}
.cF4{color:#aa0000;background-color:#ffffff;}
.cF5{color:#aa00aa;background-color:#ffffff;}
.cF6{color:#aa5500;background-color:#ffffff;}
.cF7{color:#aaaaaa;background-color:#ffffff;}
.cF8{color:#555555;background-color:#ffffff;}
.cF9{color:#5555ff;background-color:#ffffff;}
.cFA{color:#55ff55;background-color:#ffffff;}
.cFB{color:#55ffff;background-color:#ffffff;}
.cFC{color:#ff5555;background-color:#ffffff;}
.cFD{color:#ff55ff;background-color:#ffffff;}
.cFE{color:#ffff55;background-color:#ffffff;}
.cFF{color:#ffffff;background-color:#ffffff;}
</style>
</head>
<body>
<pre id="content">
<a name="l1"></a><span class=cF5>RegDft</span><span class=cF0>(</span><span class=cF6>&quot;TempleOS/DunGen&quot;</span><span class=cF0>,</span><span class=cF6>&quot;F64 best_score=9999;\n&quot;</span><span class=cF0>);
<a name="l2"></a></span><span class=cF5>RegExe</span><span class=cF0>(</span><span class=cF6>&quot;TempleOS/DunGen&quot;</span><span class=cF0>);
<a name="l3"></a>
<a name="l4"></a></span><span class=cF2>//Set snap to 4 and width to 4</span><span class=cF0>
<a name="l5"></a></span><span class=cF2>//if you edit this map.</span><span class=cF0>
<a name="l6"></a>
<a name="l7"></a></span><span class=cF2>//Don't forget to change the</span><span class=cF0>
<a name="l8"></a></span><span class=cF2>//starting pos.</span><span class=cF0>
<a name="l9"></a></span><span class=c00>
<a name="l10"></a></span><span class=c0A>
<a name="l11"></a>&lt;1&gt;/* Graphics Not Rendered in HTML */</span><span class=c00>
<a name="l12"></a>
<a name="l13"></a>
<a name="l14"></a>
<a name="l15"></a>
<a name="l16"></a>
<a name="l17"></a>
<a name="l18"></a>
<a name="l19"></a>
<a name="l20"></a></span><span class=c0A>
<a name="l21"></a>&lt;2&gt;/* Graphics Not Rendered in HTML */</span><span class=c00>
<a name="l22"></a>
<a name="l23"></a>
<a name="l24"></a></span><span class=c0A>
<a name="l25"></a>&lt;3&gt;/* Graphics Not Rendered in HTML */</span><span class=c00>
<a name="l26"></a>
<a name="l27"></a> </span><span class=c0A>
<a name="l28"></a>&lt;4&gt;/* Graphics Not Rendered in HTML */</span><span class=c00>
<a name="l29"></a></span><span class=c0A>
<a name="l30"></a>&lt;5&gt;/* Graphics Not Rendered in HTML */</span><span class=c00>
<a name="l31"></a></span><span class=c0A>
<a name="l32"></a>&lt;6&gt;/* Graphics Not Rendered in HTML */</span><span class=c00>
<a name="l33"></a></span><span class=c0A>
<a name="l34"></a>&lt;7&gt;/* Graphics Not Rendered in HTML */</span><span class=c00>
<a name="l35"></a></span><span class=c0A>
<a name="l36"></a>&lt;8&gt;/* Graphics Not Rendered in HTML */</span><span class=c00>
<a name="l37"></a></span><span class=c0A>
<a name="l38"></a>&lt;9&gt;/* Graphics Not Rendered in HTML */</span><span class=c00>
<a name="l39"></a></span><span class=c0A>
<a name="l40"></a>&lt;10&gt;/* Graphics Not Rendered in HTML */</span><span class=c00>
<a name="l41"></a>
<a name="l42"></a>
<a name="l43"></a></span><span class=cF2>//These are indexed by color #.</span><span class=cF0>
<a name="l44"></a></span><span class=cF2>//See </span><a href="/Wb/Kernel/KernelA.HH.HTML#l2918"><span class=cF4>COLORS</span></a><span class=cF2>.</span><span class=cF0>
<a name="l45"></a>
<a name="l46"></a></span><span class=cF1>U8</span><span class=cF0> *tiles1[16]={</span><span class=cF3>NULL</span><span class=cF0>,</span><span class=cFA>&lt;7&gt;</span><span class=cF0> ,</span><span class=cFA>&lt;5&gt;</span><span class=cF0> ,</span><span class=cF3>NULL</span><span class=cF0>,</span><span class=cF3>NULL</span><span class=cF0>,</span><span class=cF3>NULL</span><span class=cF0>,</span><span class=cF3>NULL</span><span class=cF0>,</span><span class=cF3>NULL</span><span class=cF0>,
<a name="l47"></a> </span><span class=cFA>&lt;6&gt;</span><span class=cF0> ,</span><span class=cF3>NULL</span><span class=cF0>,</span><span class=cF3>NULL</span><span class=cF0>,</span><span class=cF3>NULL</span><span class=cF0>,</span><span class=cF3>NULL</span><span class=cF0>,</span><span class=cF3>NULL</span><span class=cF0>,</span><span class=cF3>NULL</span><span class=cF0>,</span><span class=cF3>NULL</span><span class=cF0>};
<a name="l48"></a>
<a name="l49"></a></span><span class=cF1>U8</span><span class=cF0> *tiles2[16]={</span><span class=cF3>NULL</span><span class=cF0>,</span><span class=cFA>&lt;8&gt;</span><span class=cF0> ,</span><span class=cFA>&lt;5&gt;</span><span class=cF0> ,</span><span class=cF3>NULL</span><span class=cF0>,</span><span class=cF3>NULL</span><span class=cF0>,</span><span class=cF3>NULL</span><span class=cF0>,</span><span class=cF3>NULL</span><span class=cF0>,</span><span class=cF3>NULL</span><span class=cF0>,
<a name="l50"></a> </span><span class=cFA>&lt;6&gt;</span><span class=cF0> ,</span><span class=cF3>NULL</span><span class=cF0>,</span><span class=cF3>NULL</span><span class=cF0>,</span><span class=cF3>NULL</span><span class=cF0>,</span><span class=cF3>NULL</span><span class=cF0>,</span><span class=cF3>NULL</span><span class=cF0>,</span><span class=cF3>NULL</span><span class=cF0>,</span><span class=cF3>NULL</span><span class=cF0>};
<a name="l51"></a>
<a name="l52"></a>#</span><span class=cF1>define</span><span class=cF0> SCRN_SCALE 24
<a name="l53"></a>#</span><span class=cF1>define</span><span class=cF0> SCRN_WIDTH 24
<a name="l54"></a>#</span><span class=cF1>define</span><span class=cF0> SCRN_HEIGHT 24
<a name="l55"></a></span><span class=cF9>I64</span><span class=cF0> scrn_x,scrn_y;
<a name="l56"></a>
<a name="l57"></a>#</span><span class=cF1>define</span><span class=cF0> MAP_SCALE 4
<a name="l58"></a></span><span class=cF9>I64</span><span class=cF0> map_width,map_height;
<a name="l59"></a></span><span class=cF1>U8</span><span class=cF0> *map=</span><span class=cF3>NULL</span><span class=cF0>;
<a name="l60"></a>
<a name="l61"></a></span><span class=cF9>I64</span><span class=cF0> man_x,man_y,man_dx,man_dy;
<a name="l62"></a></span><span class=cF1>Bool</span><span class=cF0> man_attack;
<a name="l63"></a></span><span class=cF1>F64</span><span class=cF0> man_attack_t0;
<a name="l64"></a>
<a name="l65"></a>#</span><span class=cF1>define</span><span class=cF0> MONSTERS_NUM 10
<a name="l66"></a></span><span class=cF9>I64</span><span class=cF0> monsters_left;
<a name="l67"></a></span><span class=cF1>class</span><span class=cF0> Monster
<a name="l68"></a>{
<a name="l69"></a> </span><span class=cF9>I64</span><span class=cF0> x,y,dx,dy;
<a name="l70"></a> </span><span class=cF1>Bool</span><span class=cF0> dead,pad[7];
<a name="l71"></a>} monsters[MONSTERS_NUM];
<a name="l72"></a>
<a name="l73"></a></span><span class=cF1>F64</span><span class=cF0> t0,tf;
<a name="l74"></a>
<a name="l75"></a>#</span><span class=cF1>define</span><span class=cF0> LOS_SCALE 4
<a name="l76"></a>
<a name="l77"></a></span><span class=cF1>Bool</span><span class=cF0> LOSPlot(</span><span class=cF1>U8</span><span class=cF0> *,</span><span class=cF9>I64</span><span class=cF0> x,</span><span class=cF9>I64</span><span class=cF0> y,</span><span class=cF9>I64</span><span class=cF0>)
<a name="l78"></a>{
<a name="l79"></a> </span><span class=cF1>if</span><span class=cF0> (!map[</span><span class=cF7>(</span><span class=cF0>y/LOS_SCALE</span><span class=cF7>)</span><span class=cF0>*map_width+</span><span class=cF7>(</span><span class=cF0>x/LOS_SCALE</span><span class=cF7>)</span><span class=cF0>])
<a name="l80"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l81"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l82"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l83"></a>}
<a name="l84"></a>
<a name="l85"></a></span><span class=cF1>Bool</span><span class=cF0> LOS(</span><span class=cF9>I64</span><span class=cF0> x1,</span><span class=cF9>I64</span><span class=cF0> y1,</span><span class=cF9>I64</span><span class=cF0> x2,</span><span class=cF9>I64</span><span class=cF0> y2)
<a name="l86"></a>{</span><span class=cF2>//Line of sight</span><span class=cF0>
<a name="l87"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF5>Line</span><span class=cF0>(</span><span class=cF3>NULL</span><span class=cF0>,x1*LOS_SCALE+LOS_SCALE/2,y1*LOS_SCALE+LOS_SCALE/2,0,
<a name="l88"></a> x2*LOS_SCALE+LOS_SCALE/2,y2*LOS_SCALE+LOS_SCALE/2,0,&amp;LOSPlot);
<a name="l89"></a>}
<a name="l90"></a>
<a name="l91"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>DrawIt</span><span class=cF0>(</span><span class=cF9>CTask</span><span class=cF0> *task,</span><span class=cF9>CDC</span><span class=cF0> *dc)
<a name="l92"></a>{
<a name="l93"></a> </span><span class=cF9>CDC</span><span class=cF0> *dc_t=</span><span class=cF5>DCAlias</span><span class=cF0>(</span><span class=cFB>gr</span><span class=cF0>.dc2,task);
<a name="l94"></a> </span><span class=cF9>I64</span><span class=cF0> i,x,y,xx,yy,x1,y1,z1,color,
<a name="l95"></a> cx=task-&gt;pix_width/2,
<a name="l96"></a> cy=task-&gt;pix_height/2;
<a name="l97"></a> </span><span class=cF9>CD3I32</span><span class=cF0> poly[4];
<a name="l98"></a> </span><span class=cF1>U8</span><span class=cF0> **_tiles;
<a name="l99"></a> </span><span class=cF1>F64</span><span class=cF0> tt;
<a name="l100"></a> Monster *tmpm;
<a name="l101"></a>
<a name="l102"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>Blink</span><span class=cF7>(</span><span class=cF0>5</span><span class=cF7>)</span><span class=cF0>)
<a name="l103"></a> _tiles=tiles1;
<a name="l104"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l105"></a> _tiles=tiles2;
<a name="l106"></a>
<a name="l107"></a> </span><span class=cF5>Mat4x4RotX</span><span class=cF0>(dc_t-&gt;r,60*2*</span><span class=cF3>pi</span><span class=cF0>/360);
<a name="l108"></a> </span><span class=cF5>Mat4x4RotZ</span><span class=cF0>(dc_t-&gt;r,15*2*</span><span class=cF3>pi</span><span class=cF0>/360);
<a name="l109"></a> </span><span class=cF5>DCMat4x4Set</span><span class=cF0>(dc_t,dc_t-&gt;r);
<a name="l110"></a> dc_t-&gt;x=task-&gt;pix_width/2;
<a name="l111"></a> dc_t-&gt;y=task-&gt;pix_height/2;
<a name="l112"></a> dc_t-&gt;flags|=</span><span class=cF3>DCF_TRANSFORMATION</span><span class=cF0>;
<a name="l113"></a>
<a name="l114"></a> </span><span class=cF2>//You could make it much more efficient</span><span class=cF0>
<a name="l115"></a> </span><span class=cF2>//if you did it like </span><a href="/Wb/Demo/Games/BigGuns.HC.HTML#l1"><span class=cF4>::/Demo/Games/BigGuns.HC</span></a><span class=cF0>
<a name="l116"></a> </span><span class=cF2>//with a </span><a href="/Wb/Kernel/KernelA.HH.HTML#l3599"><span class=cF4>CDC</span></a><span class=cF2>.</span><span class=cF0>
<a name="l117"></a>
<a name="l118"></a> </span><span class=cF1>for</span><span class=cF0> (y=-SCRN_HEIGHT/2;y&lt;SCRN_HEIGHT/2;y++) </span><span class=cF7>{</span><span class=cF0>
<a name="l119"></a> yy=y+scrn_y;
<a name="l120"></a> </span><span class=cF1>if</span><span class=cF0> (0&lt;=yy&lt;map_height)
<a name="l121"></a> </span><span class=cF1>for</span><span class=cF0> (x=-SCRN_WIDTH/2;x&lt;SCRN_WIDTH/2;x++) {
<a name="l122"></a> xx=x+scrn_x;
<a name="l123"></a> </span><span class=cF1>if</span><span class=cF0> (0&lt;=xx&lt;map_width) </span><span class=cF7>{</span><span class=cF0>
<a name="l124"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF7>(</span><span class=cF0>color=map[yy*map_width+xx]</span><span class=cF7>)</span><span class=cF0> &amp;&amp;
<a name="l125"></a> LOS</span><span class=cF7>(</span><span class=cF0>xx,yy,man_x,man_y</span><span class=cF7>)</span><span class=cF0>) {
<a name="l126"></a> </span><span class=cF1>if</span><span class=cF0> (_tiles[color]) </span><span class=cF7>{</span><span class=cF0>
<a name="l127"></a> x1=x*SCRN_SCALE;
<a name="l128"></a> y1=y*SCRN_SCALE;
<a name="l129"></a> z1=0;
<a name="l130"></a> </span><span class=cF5>DCTransform</span><span class=cF0>(dc_t,&amp;x1,&amp;y1,&amp;z1);
<a name="l131"></a> </span><span class=cF5>Sprite3</span><span class=cF0>(dc,x1,y1,z1,_tiles[color]);
<a name="l132"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF7>{</span><span class=cF2>//If no tile defined, do solid color.</span><span class=cF0>
<a name="l133"></a> poly[0].x=x*SCRN_SCALE;
<a name="l134"></a> poly[0].y=y*SCRN_SCALE;
<a name="l135"></a> poly[0].z=0;
<a name="l136"></a> poly[1].x=(x+1)*SCRN_SCALE-1;
<a name="l137"></a> poly[1].y=y*SCRN_SCALE;
<a name="l138"></a> poly[1].z=0;
<a name="l139"></a> poly[2].x=(x+1)*SCRN_SCALE;
<a name="l140"></a> poly[2].y=(y+1)*SCRN_SCALE-1;
<a name="l141"></a> poly[2].z=0;
<a name="l142"></a> poly[3].x=x*SCRN_SCALE-1;
<a name="l143"></a> poly[3].y=(y+1)*SCRN_SCALE-1;
<a name="l144"></a> poly[3].z=0;
<a name="l145"></a> dc_t-&gt;color=color;
<a name="l146"></a> </span><span class=cF5>GrFillPoly3</span><span class=cF0>(dc_t,4,poly);
<a name="l147"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l148"></a> }
<a name="l149"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l150"></a> }
<a name="l151"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l152"></a>
<a name="l153"></a> </span><span class=cF1>for</span><span class=cF0> (y=-SCRN_HEIGHT/2;y&lt;SCRN_HEIGHT/2;y++) </span><span class=cF7>{</span><span class=cF0>
<a name="l154"></a> yy=y+scrn_y;
<a name="l155"></a> </span><span class=cF1>if</span><span class=cF0> (0&lt;=yy&lt;map_height)
<a name="l156"></a> </span><span class=cF1>for</span><span class=cF0> (x=-SCRN_WIDTH/2;x&lt;SCRN_WIDTH/2;x++) {
<a name="l157"></a> xx=x+scrn_x;
<a name="l158"></a> </span><span class=cF1>if</span><span class=cF0> (0&lt;=xx&lt;map_width) </span><span class=cF7>{</span><span class=cF0>
<a name="l159"></a> </span><span class=cF1>if</span><span class=cF0> (!map[yy*map_width+xx]) {
<a name="l160"></a> </span><span class=cF1>if</span><span class=cF0> (yy+1&lt;map_height &amp;&amp; LOS</span><span class=cF7>(</span><span class=cF0>xx,yy+1,man_x,man_y</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l161"></a> x1=x*SCRN_SCALE;
<a name="l162"></a> y1=y*SCRN_SCALE;
<a name="l163"></a> z1=0;
<a name="l164"></a> </span><span class=cF5>DCTransform</span><span class=cF0>(dc_t,&amp;x1,&amp;y1,&amp;z1);
<a name="l165"></a> </span><span class=cF5>Sprite3</span><span class=cF0>(dc,x1,y1,z1,</span><span class=cFA>&lt;9&gt;</span><span class=cF0>);
<a name="l166"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l167"></a> </span><span class=cF1>if</span><span class=cF0> (xx+1&lt;map_width &amp;&amp; LOS</span><span class=cF7>(</span><span class=cF0>xx+1,yy,man_x,man_y</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l168"></a> x1=x*SCRN_SCALE;
<a name="l169"></a> y1=y*SCRN_SCALE;
<a name="l170"></a> z1=0;
<a name="l171"></a> </span><span class=cF5>DCTransform</span><span class=cF0>(dc_t,&amp;x1,&amp;y1,&amp;z1);
<a name="l172"></a> </span><span class=cF5>Sprite3</span><span class=cF0>(dc,x1,y1,z1,</span><span class=cFA>&lt;10&gt;</span><span class=cF0>);
<a name="l173"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l174"></a> }
<a name="l175"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l176"></a> }
<a name="l177"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l178"></a>
<a name="l179"></a> </span><span class=cF1>for</span><span class=cF0> (i=0,tmpm=monsters;i&lt;MONSTERS_NUM;i++,tmpm++)
<a name="l180"></a> </span><span class=cF1>if</span><span class=cF0> (!tmpm-&gt;dead &amp;&amp; LOS</span><span class=cF7>(</span><span class=cF0>tmpm-&gt;x,tmpm-&gt;y,man_x,man_y</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l181"></a> x1=(tmpm-&gt;x-scrn_x)*SCRN_SCALE+SCRN_SCALE/2;
<a name="l182"></a> y1=(tmpm-&gt;y-scrn_y)*SCRN_SCALE+SCRN_SCALE/2;
<a name="l183"></a> z1=0;
<a name="l184"></a> </span><span class=cF5>DCTransform</span><span class=cF0>(dc_t,&amp;x1,&amp;y1,&amp;z1);
<a name="l185"></a> </span><span class=cF1>if</span><span class=cF0> (tmpm-&gt;dx&lt;0) {
<a name="l186"></a> dc-&gt;flags|=</span><span class=cF3>DCF_SYMMETRY</span><span class=cF0>|</span><span class=cF3>DCF_JUST_MIRROR</span><span class=cF0>;
<a name="l187"></a> </span><span class=cF5>DCSymmetrySet</span><span class=cF0>(dc,x1,y1,x1,y1+1);
<a name="l188"></a> } </span><span class=cF1>else</span><span class=cF0>
<a name="l189"></a> dc-&gt;flags&amp;=~(</span><span class=cF3>DCF_SYMMETRY</span><span class=cF0>|</span><span class=cF3>DCF_JUST_MIRROR</span><span class=cF0>);
<a name="l190"></a> </span><span class=cF5>Sprite3</span><span class=cF0>(dc,x1,y1,z1,</span><span class=cFA>&lt;4&gt;</span><span class=cF0>);
<a name="l191"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l192"></a>
<a name="l193"></a> x1=(man_x-scrn_x)*SCRN_SCALE+SCRN_SCALE/2;
<a name="l194"></a> y1=(man_y-scrn_y)*SCRN_SCALE+SCRN_SCALE/2;
<a name="l195"></a> z1=0;
<a name="l196"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>tS</span><span class=cF0>-man_attack_t0&lt;0.2) </span><span class=cF7>{</span><span class=cF0>
<a name="l197"></a> x1+=</span><span class=cF5>Tri</span><span class=cF0>(</span><span class=cF5>tS</span><span class=cF0>-man_attack_t0,0.2)*SCRN_SCALE*man_dx;
<a name="l198"></a> y1+=</span><span class=cF5>Tri</span><span class=cF0>(</span><span class=cF5>tS</span><span class=cF0>-man_attack_t0,0.2)*SCRN_SCALE*man_dy;
<a name="l199"></a> </span><span class=cF1>if</span><span class=cF0> (man_dy!=1)
<a name="l200"></a> y1-=</span><span class=cF5>Saw</span><span class=cF0>(</span><span class=cF5>tS</span><span class=cF0>-man_attack_t0,0.2)*SCRN_SCALE;
<a name="l201"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l202"></a> </span><span class=cF5>DCTransform</span><span class=cF0>(dc_t,&amp;x1,&amp;y1,&amp;z1);
<a name="l203"></a> </span><span class=cF1>if</span><span class=cF0> (man_dx&lt;0) </span><span class=cF7>{</span><span class=cF0>
<a name="l204"></a> dc-&gt;flags|=</span><span class=cF3>DCF_SYMMETRY</span><span class=cF0>|</span><span class=cF3>DCF_JUST_MIRROR</span><span class=cF0>;
<a name="l205"></a> </span><span class=cF5>DCSymmetrySet</span><span class=cF0>(dc,x1,y1,x1,y1+1);
<a name="l206"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>else</span><span class=cF0>
<a name="l207"></a> dc-&gt;flags&amp;=~(</span><span class=cF3>DCF_SYMMETRY</span><span class=cF0>|</span><span class=cF3>DCF_JUST_MIRROR</span><span class=cF0>);
<a name="l208"></a>
<a name="l209"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>tS</span><span class=cF0>-man_attack_t0&lt;0.2)
<a name="l210"></a> </span><span class=cF5>Sprite3</span><span class=cF0>(dc,x1,y1,z1,</span><span class=cFA>&lt;3&gt;</span><span class=cF0>);
<a name="l211"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l212"></a> </span><span class=cF5>Sprite3</span><span class=cF0>(dc,x1,y1,z1,</span><span class=cFA>&lt;2&gt;</span><span class=cF0>);
<a name="l213"></a>
<a name="l214"></a> </span><span class=cF5>DCDel</span><span class=cF0>(dc_t);
<a name="l215"></a>
<a name="l216"></a> </span><span class=cF1>if</span><span class=cF0> (tf) </span><span class=cF7>{</span><span class=cF0>
<a name="l217"></a> dc-&gt;color=</span><span class=cF3>LTRED</span><span class=cF0>;
<a name="l218"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>Blink</span><span class=cF0>)
<a name="l219"></a> </span><span class=cF5>GrPrint</span><span class=cF0>(dc,cx-</span><span class=cF7>(</span><span class=cF3>FONT_WIDTH</span><span class=cF0>*14</span><span class=cF7>)</span><span class=cF0>/2,cy-</span><span class=cF3>FONT_HEIGHT</span><span class=cF0>/2,</span><span class=cF6>&quot;Game Completed&quot;</span><span class=cF0>);
<a name="l220"></a> tt=tf;
<a name="l221"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
<a name="l222"></a> dc-&gt;color=</span><span class=cF3>LTGREEN</span><span class=cF0>;
<a name="l223"></a> tt=</span><span class=cF5>tS</span><span class=cF0>;
<a name="l224"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l225"></a> </span><span class=cF5>GrPrint</span><span class=cF0>(dc,0,0,</span><span class=cF6>&quot;Enemy:%d Time:%3.2f Best:%3.2f&quot;</span><span class=cF0>,
<a name="l226"></a> monsters_left,tt-t0,best_score);
<a name="l227"></a>}
<a name="l228"></a>
<a name="l229"></a></span><span class=cF1>U0</span><span class=cF0> Attack()
<a name="l230"></a>{
<a name="l231"></a> </span><span class=cF9>I64</span><span class=cF0> i;
<a name="l232"></a> Monster *tmpm;
<a name="l233"></a>
<a name="l234"></a> man_attack_t0=</span><span class=cF5>tS</span><span class=cF0>;
<a name="l235"></a> </span><span class=cF5>Noise</span><span class=cF0>(100,53,74);
<a name="l236"></a> </span><span class=cF1>for</span><span class=cF0> (i=0,tmpm=monsters;i&lt;MONSTERS_NUM;i++,tmpm++) </span><span class=cF7>{</span><span class=cF0>
<a name="l237"></a> </span><span class=cF1>if</span><span class=cF0> (!tmpm-&gt;dead &amp;&amp;
<a name="l238"></a> man_x+man_dx==tmpm-&gt;x &amp;&amp; man_y+man_dy==tmpm-&gt;y) {
<a name="l239"></a> tmpm-&gt;dead=</span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l240"></a> </span><span class=cF1>if</span><span class=cF0> (!--monsters_left) </span><span class=cF7>{</span><span class=cF0>
<a name="l241"></a> tf=</span><span class=cF5>tS</span><span class=cF0>;
<a name="l242"></a> </span><span class=cF1>if</span><span class=cF0> (tf-t0&lt;best_score)
<a name="l243"></a> best_score=tf-t0;
<a name="l244"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l245"></a> }
<a name="l246"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l247"></a>}
<a name="l248"></a>
<a name="l249"></a></span><span class=cF1>U0</span><span class=cF0> Init()
<a name="l250"></a>{
<a name="l251"></a> </span><span class=cF9>I64</span><span class=cF0> i,x,y;
<a name="l252"></a> </span><span class=cF9>CDC</span><span class=cF0> *dc;
<a name="l253"></a> Monster *tmpm;
<a name="l254"></a>
<a name="l255"></a> dc=</span><span class=cF5>Sprite2DC</span><span class=cF0>(</span><span class=cFA>&lt;1&gt;</span><span class=cF0>);
<a name="l256"></a> map_width =dc-&gt;width/MAP_SCALE;
<a name="l257"></a> map_height=dc-&gt;height/MAP_SCALE;
<a name="l258"></a> </span><span class=cF5>Free</span><span class=cF0>(map);
<a name="l259"></a> map=</span><span class=cF5>MAlloc</span><span class=cF0>(map_width*map_height*</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF1>U8</span><span class=cF7>)</span><span class=cF0>);
<a name="l260"></a> </span><span class=cF1>for</span><span class=cF0> (y=0;y&lt;map_height;y++)
<a name="l261"></a> </span><span class=cF1>for</span><span class=cF0> (x=0;x&lt;map_width;x++)
<a name="l262"></a> map[y*map_width+x]=</span><span class=cF5>GrPeek</span><span class=cF0>(dc,x*MAP_SCALE,y*MAP_SCALE);
<a name="l263"></a> </span><span class=cF5>DCDel</span><span class=cF0>(dc);
<a name="l264"></a>
<a name="l265"></a> man_attack_t0=0;
<a name="l266"></a> man_attack=</span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l267"></a> man_x=0;
<a name="l268"></a> man_y=4;
<a name="l269"></a> man_dx=0;
<a name="l270"></a> man_dy=0;
<a name="l271"></a> scrn_x=0;
<a name="l272"></a> scrn_y=0;
<a name="l273"></a> </span><span class=cF1>for</span><span class=cF0> (i=0,tmpm=monsters;i&lt;MONSTERS_NUM;i++,tmpm++) </span><span class=cF7>{</span><span class=cF0>
<a name="l274"></a> tmpm-&gt;dead=</span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l275"></a> tmpm-&gt;dx=0;
<a name="l276"></a> tmpm-&gt;dy=0;
<a name="l277"></a> </span><span class=cF1>do</span><span class=cF0> {
<a name="l278"></a> tmpm-&gt;x=</span><span class=cF5>RandU64</span><span class=cF0>%(map_width-2)+1;
<a name="l279"></a> tmpm-&gt;y=</span><span class=cF5>RandU64</span><span class=cF0>%(map_height-2)+1;
<a name="l280"></a> } </span><span class=cF1>while</span><span class=cF0> (!map[</span><span class=cF7>(</span><span class=cF0>tmpm-&gt;y</span><span class=cF7>)</span><span class=cF0>*map_width+tmpm-&gt;x]);
<a name="l281"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l282"></a> monsters_left=MONSTERS_NUM;
<a name="l283"></a> tf=0;
<a name="l284"></a> t0=</span><span class=cF5>tS</span><span class=cF0>;
<a name="l285"></a>}
<a name="l286"></a>
<a name="l287"></a></span><span class=cF1>U0</span><span class=cF0> CleanUp()
<a name="l288"></a>{
<a name="l289"></a> </span><span class=cF5>Free</span><span class=cF0>(map);
<a name="l290"></a> map=</span><span class=cF3>NULL</span><span class=cF0>;
<a name="l291"></a>}
<a name="l292"></a>
<a name="l293"></a></span><span class=cF1>U0</span><span class=cF0> AnimateTask(</span><span class=cF9>I64</span><span class=cF0>)
<a name="l294"></a>{
<a name="l295"></a> </span><span class=cF9>I64</span><span class=cF0> i,x,y,dx,dy;
<a name="l296"></a> Monster *tmpm;
<a name="l297"></a>
<a name="l298"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF3>TRUE</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l299"></a> </span><span class=cF1>for</span><span class=cF0> (i=0,tmpm=monsters;i&lt;MONSTERS_NUM;i++,tmpm++)
<a name="l300"></a> </span><span class=cF1>if</span><span class=cF0> (!tmpm-&gt;dead) {
<a name="l301"></a> dx=</span><span class=cF5>RandU16</span><span class=cF0>%3-1;
<a name="l302"></a> dy=</span><span class=cF5>RandU16</span><span class=cF0>%3-1;
<a name="l303"></a> x=tmpm-&gt;x+dx;
<a name="l304"></a> y=tmpm-&gt;y+dy;
<a name="l305"></a> </span><span class=cF1>if</span><span class=cF0> (0&lt;=x&lt;map_width &amp;&amp; 0&lt;=y&lt;map_height &amp;&amp; map[y*map_width+x]) </span><span class=cF7>{</span><span class=cF0>
<a name="l306"></a> tmpm-&gt;x=x;
<a name="l307"></a> tmpm-&gt;y=y;
<a name="l308"></a> tmpm-&gt;dx=dx;
<a name="l309"></a> tmpm-&gt;dy=dy;
<a name="l310"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l311"></a> }
<a name="l312"></a> </span><span class=cF5>Sleep</span><span class=cF0>(1000);
<a name="l313"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l314"></a>}
<a name="l315"></a>
<a name="l316"></a></span><span class=cF1>U0</span><span class=cF0> DunGen()
<a name="l317"></a>{
<a name="l318"></a> </span><span class=cF9>I64</span><span class=cF0> ch,sc;
<a name="l319"></a>
<a name="l320"></a> </span><span class=cF5>MenuPush</span><span class=cF0>(
<a name="l321"></a> </span><span class=cF6>&quot;File {&quot;</span><span class=cF0>
<a name="l322"></a> </span><span class=cF6>&quot; Abort(,CH_SHIFT_ESC);&quot;</span><span class=cF0>
<a name="l323"></a> </span><span class=cF6>&quot; Exit(,CH_ESC);&quot;</span><span class=cF0>
<a name="l324"></a> </span><span class=cF6>&quot;}&quot;</span><span class=cF0>
<a name="l325"></a> </span><span class=cF6>&quot;Play {&quot;</span><span class=cF0>
<a name="l326"></a> </span><span class=cF6>&quot; Restart(,'\n');&quot;</span><span class=cF0>
<a name="l327"></a> </span><span class=cF6>&quot; Up(,,SC_CURSOR_UP);&quot;</span><span class=cF0>
<a name="l328"></a> </span><span class=cF6>&quot; Down(,,SC_CURSOR_DOWN);&quot;</span><span class=cF0>
<a name="l329"></a> </span><span class=cF6>&quot; Left(,,SC_CURSOR_LEFT);&quot;</span><span class=cF0>
<a name="l330"></a> </span><span class=cF6>&quot; Right(,,SC_CURSOR_RIGHT);&quot;</span><span class=cF0>
<a name="l331"></a> </span><span class=cF6>&quot; Attack(,CH_SPACE);&quot;</span><span class=cF0>
<a name="l332"></a> </span><span class=cF6>&quot;}&quot;</span><span class=cF0>
<a name="l333"></a> );
<a name="l334"></a>
<a name="l335"></a> </span><span class=cF5>SettingsPush</span><span class=cF0>; </span><span class=cF2>//See </span><a href="/Wb/Adam/TaskSettings.HC.HTML#l3"><span class=cF4>SettingsPush</span></a><span class=cF0>
<a name="l336"></a> </span><span class=cF5>Fs</span><span class=cF0>-&gt;text_attr=</span><span class=cF3>BLACK</span><span class=cF0>&lt;&lt;4+</span><span class=cF3>WHITE</span><span class=cF0>;
<a name="l337"></a> </span><span class=cF5>AutoComplete</span><span class=cF0>;
<a name="l338"></a> </span><span class=cF5>WinBorder</span><span class=cF0>;
<a name="l339"></a> </span><span class=cF5>WinMax</span><span class=cF0>;
<a name="l340"></a> </span><span class=cF5>DocCursor</span><span class=cF0>;
<a name="l341"></a> </span><span class=cF5>DocClear</span><span class=cF0>;
<a name="l342"></a> Init;
<a name="l343"></a> </span><span class=cF5>Fs</span><span class=cF0>-&gt;animate_task=</span><span class=cF5>Spawn</span><span class=cF0>(&amp;AnimateTask,</span><span class=cF3>NULL</span><span class=cF0>,</span><span class=cF6>&quot;Animate&quot;</span><span class=cF0>,,</span><span class=cF5>Fs</span><span class=cF0>);
<a name="l344"></a> </span><span class=cF5>Fs</span><span class=cF0>-&gt;draw_it=&amp;</span><span class=cF5>DrawIt</span><span class=cF0>;
<a name="l345"></a>
<a name="l346"></a> </span><span class=cF1>try</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
<a name="l347"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF3>TRUE</span><span class=cF0>) {
<a name="l348"></a> </span><span class=cF1>switch</span><span class=cF0> (</span><span class=cF5>GetMsg</span><span class=cF7>(</span><span class=cF0>&amp;ch,&amp;sc,1&lt;&lt;</span><span class=cF3>MSG_KEY_DOWN</span><span class=cF0>|1&lt;&lt;</span><span class=cF3>MSG_KEY_UP</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l349"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>MSG_KEY_DOWN</span><span class=cF0>:
<a name="l350"></a> </span><span class=cF1>switch</span><span class=cF0> (ch) {
<a name="l351"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF6>'\n'</span><span class=cF0>:
<a name="l352"></a> Init;
<a name="l353"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l354"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>CH_SPACE</span><span class=cF0>:
<a name="l355"></a> man_attack=</span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l356"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l357"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>CH_ESC</span><span class=cF0>:
<a name="l358"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>CH_SHIFT_ESC</span><span class=cF0>:
<a name="l359"></a> </span><span class=cF1>goto</span><span class=cF0> dg_done;
<a name="l360"></a> </span><span class=cF1>case</span><span class=cF0> 0:
<a name="l361"></a> </span><span class=cF1>switch</span><span class=cF0> (sc.u8[0]) </span><span class=cF7>{</span><span class=cF0>
<a name="l362"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>SC_CURSOR_RIGHT</span><span class=cF0>:
<a name="l363"></a> </span><span class=cF1>if</span><span class=cF0> (man_attack) {
<a name="l364"></a> man_dx=1;
<a name="l365"></a> man_dy=0;
<a name="l366"></a> Attack;
<a name="l367"></a> } </span><span class=cF1>else</span><span class=cF0>
<a name="l368"></a> </span><span class=cF1>if</span><span class=cF0> (man_x+1&lt;map_width &amp;&amp;
<a name="l369"></a> map[man_y*map_width+</span><span class=cF7>(</span><span class=cF0>man_x+1</span><span class=cF7>)</span><span class=cF0>]==</span><span class=cF3>DKGRAY</span><span class=cF0>) {
<a name="l370"></a> man_x++;
<a name="l371"></a> </span><span class=cF1>if</span><span class=cF0> (man_x-scrn_x&gt;SCRN_WIDTH/2-3) </span><span class=cF7>{</span><span class=cF0>
<a name="l372"></a> scrn_x+=SCRN_WIDTH/2;
<a name="l373"></a> </span><span class=cF1>if</span><span class=cF0> (scrn_x+SCRN_WIDTH/2&gt;map_width)
<a name="l374"></a> scrn_x=map_width-SCRN_WIDTH/2;
<a name="l375"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l376"></a> }
<a name="l377"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l378"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>SC_CURSOR_LEFT</span><span class=cF0>:
<a name="l379"></a> </span><span class=cF1>if</span><span class=cF0> (man_attack) {
<a name="l380"></a> man_dx=-1;
<a name="l381"></a> man_dy=0;
<a name="l382"></a> Attack;
<a name="l383"></a> } </span><span class=cF1>else</span><span class=cF0>
<a name="l384"></a> </span><span class=cF1>if</span><span class=cF0> (man_x-1&gt;=0 &amp;&amp;
<a name="l385"></a> map[man_y*map_width+</span><span class=cF7>(</span><span class=cF0>man_x-1</span><span class=cF7>)</span><span class=cF0>]==</span><span class=cF3>DKGRAY</span><span class=cF0>) {
<a name="l386"></a> man_x--;
<a name="l387"></a> </span><span class=cF1>if</span><span class=cF0> (man_x-scrn_x&lt;-SCRN_WIDTH/2+3) </span><span class=cF7>{</span><span class=cF0>
<a name="l388"></a> scrn_x-=SCRN_WIDTH/2;
<a name="l389"></a> </span><span class=cF1>if</span><span class=cF0> (scrn_x-SCRN_WIDTH/2&lt;0)
<a name="l390"></a> scrn_x=SCRN_WIDTH/2;
<a name="l391"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l392"></a> }
<a name="l393"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l394"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>SC_CURSOR_UP</span><span class=cF0>:
<a name="l395"></a> </span><span class=cF1>if</span><span class=cF0> (man_attack) {
<a name="l396"></a> man_dx=0;
<a name="l397"></a> man_dy=-1;
<a name="l398"></a> Attack;
<a name="l399"></a> } </span><span class=cF1>else</span><span class=cF0>
<a name="l400"></a> </span><span class=cF1>if</span><span class=cF0> (man_y-1&gt;=0 &amp;&amp;
<a name="l401"></a> map[</span><span class=cF7>(</span><span class=cF0>man_y-1</span><span class=cF7>)</span><span class=cF0>*map_width+man_x]==</span><span class=cF3>DKGRAY</span><span class=cF0>) {
<a name="l402"></a> man_y--;
<a name="l403"></a> </span><span class=cF1>if</span><span class=cF0> (man_y-scrn_y&lt;-SCRN_HEIGHT/2+3) </span><span class=cF7>{</span><span class=cF0>
<a name="l404"></a> scrn_y-=SCRN_HEIGHT/2;
<a name="l405"></a> </span><span class=cF1>if</span><span class=cF0> (scrn_y-SCRN_HEIGHT/2&lt;0)
<a name="l406"></a> scrn_y=SCRN_HEIGHT/2;
<a name="l407"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l408"></a> }
<a name="l409"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l410"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>SC_CURSOR_DOWN</span><span class=cF0>:
<a name="l411"></a> </span><span class=cF1>if</span><span class=cF0> (man_attack) {
<a name="l412"></a> man_dx=0;
<a name="l413"></a> man_dy=1;
<a name="l414"></a> Attack;
<a name="l415"></a> } </span><span class=cF1>else</span><span class=cF0>
<a name="l416"></a> </span><span class=cF1>if</span><span class=cF0> (man_y+1&lt;map_height &amp;&amp;
<a name="l417"></a> map[</span><span class=cF7>(</span><span class=cF0>man_y+1</span><span class=cF7>)</span><span class=cF0>*map_width+man_x]==</span><span class=cF3>DKGRAY</span><span class=cF0>) {
<a name="l418"></a> man_y++;
<a name="l419"></a> </span><span class=cF1>if</span><span class=cF0> (man_y-scrn_y&gt;SCRN_HEIGHT/2-3) </span><span class=cF7>{</span><span class=cF0>
<a name="l420"></a> scrn_y+=SCRN_HEIGHT/2;
<a name="l421"></a> </span><span class=cF1>if</span><span class=cF0> (scrn_y+SCRN_HEIGHT/2&gt;map_height)
<a name="l422"></a> scrn_y=map_height-SCRN_HEIGHT/2;
<a name="l423"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l424"></a> }
<a name="l425"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l426"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l427"></a> }
<a name="l428"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l429"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>MSG_KEY_UP</span><span class=cF0>:
<a name="l430"></a> </span><span class=cF1>if</span><span class=cF0> (ch==</span><span class=cF3>CH_SPACE</span><span class=cF0>)
<a name="l431"></a> man_attack=</span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l432"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l433"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l434"></a> }
<a name="l435"></a>dg_done:
<a name="l436"></a> </span><span class=cF5>GetMsg</span><span class=cF0>(,,1&lt;&lt;</span><span class=cF3>MSG_KEY_UP</span><span class=cF0>);
<a name="l437"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>catch</span><span class=cF0>
<a name="l438"></a> </span><span class=cF5>PutExcept</span><span class=cF0>;
<a name="l439"></a> </span><span class=cF5>SettingsPop</span><span class=cF0>;
<a name="l440"></a> CleanUp;
<a name="l441"></a> </span><span class=cF5>MenuPop</span><span class=cF0>;
<a name="l442"></a> </span><span class=cF5>RegWrite</span><span class=cF0>(</span><span class=cF6>&quot;TempleOS/DunGen&quot;</span><span class=cF0>,</span><span class=cF6>&quot;F64 best_score=%5.4f;\n&quot;</span><span class=cF0>,best_score);
<a name="l443"></a>}
<a name="l444"></a>
<a name="l445"></a>DunGen;
</span></pre></body>
</html>