ZealOS/docs/Demo/Games/CastleFrankenstein.CC.html
TomAwezome dbf8647d59 Fixed non-writable drive throw on F5 and Ctrl-S.
Added top & right borders to RawDr.
Improved spacing in some debug and compiler reporting.
Fixed RawPutChar and EdLite tab width.
Fixed Ui missing '0x' prefix syntax highlighter bug.
Added 32BitPaint demo.
2021-07-14 18:38:02 -04:00

695 lines
64 KiB
HTML
Executable file

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=US-ASCII">
<meta name="generator" content="ZealOS V0.08">
<style type="text/css">
body {background-color:#000000;}
.cF0{color:#ffffff;background-color:#000000;}
.cF1{color:#3465a4;background-color:#000000;}
.cF2{color:#4e9a06;background-color:#000000;}
.cF3{color:#06989a;background-color:#000000;}
.cF4{color:#a24444;background-color:#000000;}
.cF5{color:#75507b;background-color:#000000;}
.cF6{color:#ce982f;background-color:#000000;}
.cF7{color:#bcc0b9;background-color:#000000;}
.cF8{color:#555753;background-color:#000000;}
.cF9{color:#729fcf;background-color:#000000;}
.cFA{color:#82bc49;background-color:#000000;}
.cFB{color:#34e2e2;background-color:#000000;}
.cFC{color:#ac3535;background-color:#000000;}
.cFD{color:#ad7fa8;background-color:#000000;}
.cFE{color:#fce94f;background-color:#000000;}
.cFF{color:#000000;background-color:#000000;}
</style>
</head>
<body>
<pre style="font-family:monospace;font-size:12pt">
<a name="l1"></a><span class=cF2>//Uses </span><a href="https://tomawezome.github.io/ZealOS/Demo/Lectures/FixedPoint.CC.html#l1"><span class=cF4>fixed-point</span></a><span class=cF2>.</span><span class=cF0>
<a name="l2"></a>
<a name="l3"></a></span><span class=cF5>RegDefault</span><span class=cF0>(</span><span class=cF6>&quot;ZealOS/CastleFrankenstein&quot;</span><span class=cF0>, </span><span class=cF6>&quot;F64 best_score=9999;\n&quot;</span><span class=cF0>);
<a name="l4"></a></span><span class=cF5>RegExe</span><span class=cF0>(</span><span class=cF6>&quot;ZealOS/CastleFrankenstein&quot;</span><span class=cF0>);
<a name="l5"></a>
<a name="l6"></a></span><span class=cF2>//Set snap to 4 and width to 4</span><span class=cF0>
<a name="l7"></a></span><span class=cF2>//if you edit this map.</span><span class=cF0>
<a name="l8"></a>
<a name="l9"></a></span><span class=cF2>//Don't forget to change the</span><span class=cF0>
<a name="l10"></a></span><span class=cF2>//starting pos.</span><span class=cF0>
<a name="l11"></a>#</span><span class=cF1>define</span><span class=cF0> MAN_START_X </span><span class=cFE>0</span><span class=cF0>
<a name="l12"></a>#</span><span class=cF1>define</span><span class=cF0> MAN_START_Y </span><span class=cFE>4</span><span class=cF0>.</span><span class=cFE>5</span><span class=cF0>
<a name="l13"></a></span><span class=cFA>
<a name="l14"></a>&lt;1&gt;/* Graphics Not Rendered in HTML */</span><span class=cF0>
<a name="l15"></a>
<a name="l16"></a>
<a name="l17"></a>
<a name="l18"></a>
<a name="l19"></a>
<a name="l20"></a>
<a name="l21"></a>
<a name="l22"></a>
<a name="l23"></a>
<a name="l24"></a>
<a name="l25"></a>
<a name="l26"></a>
<a name="l27"></a>
<a name="l28"></a>
<a name="l29"></a>#</span><span class=cF1>define</span><span class=cF0> MONSTER_SCALE </span><span class=cFE>2</span><span class=cF0>.</span><span class=cFE>0</span><span class=cF0>
<a name="l30"></a>
<a name="l31"></a> </span><span class=cFA>&lt;2&gt;/* Graphics Not Rendered in HTML */</span><span class=cF0>
<a name="l32"></a>
<a name="l33"></a>
<a name="l34"></a>
<a name="l35"></a>
<a name="l36"></a>
<a name="l37"></a>
<a name="l38"></a>
<a name="l39"></a>
<a name="l40"></a>
<a name="l41"></a>
<a name="l42"></a> </span><span class=cFA>&lt;3&gt;/* Graphics Not Rendered in HTML */</span><span class=cF0>
<a name="l43"></a>
<a name="l44"></a>
<a name="l45"></a>
<a name="l46"></a>
<a name="l47"></a>
<a name="l48"></a>
<a name="l49"></a>
<a name="l50"></a>
<a name="l51"></a>
<a name="l52"></a> </span><span class=cFA>&lt;4&gt;/* Graphics Not Rendered in HTML */</span><span class=cF0>
<a name="l53"></a>
<a name="l54"></a>
<a name="l55"></a>
<a name="l56"></a>
<a name="l57"></a>
<a name="l58"></a>
<a name="l59"></a>
<a name="l60"></a>#</span><span class=cF1>define</span><span class=cF0> PLANT_SCALE </span><span class=cFE>2</span><span class=cF0>.</span><span class=cFE>0</span><span class=cF0>
<a name="l61"></a>
<a name="l62"></a>
<a name="l63"></a>
<a name="l64"></a> </span><span class=cFA>&lt;5&gt;/* Graphics Not Rendered in HTML */</span><span class=cF0>
<a name="l65"></a>
<a name="l66"></a>
<a name="l67"></a>
<a name="l68"></a>
<a name="l69"></a>
<a name="l70"></a>
<a name="l71"></a>
<a name="l72"></a>
<a name="l73"></a>
<a name="l74"></a>
<a name="l75"></a>
<a name="l76"></a>
<a name="l77"></a>
<a name="l78"></a> </span><span class=cFA>&lt;6&gt;/* Graphics Not Rendered in HTML */</span><span class=cF0>
<a name="l79"></a>
<a name="l80"></a>
<a name="l81"></a>
<a name="l82"></a>
<a name="l83"></a>
<a name="l84"></a>
<a name="l85"></a>
<a name="l86"></a>
<a name="l87"></a>
<a name="l88"></a>
<a name="l89"></a>
<a name="l90"></a>
<a name="l91"></a>
<a name="l92"></a>
<a name="l93"></a>#</span><span class=cF1>define</span><span class=cF0> SCREEN_SCALE </span><span class=cFE>512</span><span class=cF0>
<a name="l94"></a>#</span><span class=cF1>define</span><span class=cF0> PLOT_GRID_WIDTH </span><span class=cFE>24</span><span class=cF0>
<a name="l95"></a>#</span><span class=cF1>define</span><span class=cF0> PLOT_GRID_HEIGHT </span><span class=cFE>24</span><span class=cF0>
<a name="l96"></a>#</span><span class=cF1>define</span><span class=cF0> MAN_HEIGHT </span><span class=cFE>125</span><span class=cF0>
<a name="l97"></a>
<a name="l98"></a>#</span><span class=cF1>define</span><span class=cF0> MAP_SCALE </span><span class=cFE>4</span><span class=cF0>
<a name="l99"></a></span><span class=cF9>I64</span><span class=cF0> map_width, map_height;
<a name="l100"></a></span><span class=cF1>U8</span><span class=cF0> *map = </span><span class=cF3>NULL</span><span class=cF0>, *panels_processed_bitmap = </span><span class=cF3>NULL</span><span class=cF0>;
<a name="l101"></a>
<a name="l102"></a></span><span class=cF9>I64</span><span class=cF0> man_xx, man_yy;
<a name="l103"></a></span><span class=cF1>F64</span><span class=cF0> man_theta;
<a name="l104"></a>
<a name="l105"></a></span><span class=cF1>F64</span><span class=cF0> t0, tf;
<a name="l106"></a>
<a name="l107"></a>#</span><span class=cF1>define</span><span class=cF0> MONSTERS_NUM </span><span class=cFE>10</span><span class=cF0>
<a name="l108"></a></span><span class=cF9>I64</span><span class=cF0> monsters_left;
<a name="l109"></a></span><span class=cF1>class</span><span class=cF0> Monster
<a name="l110"></a>{
<a name="l111"></a> </span><span class=cF9>I64</span><span class=cF0> x, y;
<a name="l112"></a> </span><span class=cF1>Bool</span><span class=cF0> dead, pad[</span><span class=cFE>7</span><span class=cF0>];
<a name="l113"></a>
<a name="l114"></a>} monsters[MONSTERS_NUM];
<a name="l115"></a>
<a name="l116"></a></span><span class=cF1>U0</span><span class=cF0> CFTransform(</span><span class=cF9>CDC</span><span class=cF0> *dc, </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> *z)
<a name="l117"></a>{
<a name="l118"></a> </span><span class=cF9>I64</span><span class=cF0> zz;
<a name="l119"></a>
<a name="l120"></a> </span><span class=cF5>Mat4x4MulXYZ</span><span class=cF0>(dc-&gt;r, x, y, z);
<a name="l121"></a> zz = SCREEN_SCALE / </span><span class=cFE>3</span><span class=cF0> + *z;
<a name="l122"></a> </span><span class=cF1>if</span><span class=cF0> (zz &lt; </span><span class=cFE>1</span><span class=cF0>)
<a name="l123"></a> zz = </span><span class=cFE>1</span><span class=cF0>;
<a name="l124"></a> *x = SCREEN_SCALE / </span><span class=cFE>2</span><span class=cF0> * *x / zz;
<a name="l125"></a> *y = SCREEN_SCALE / </span><span class=cFE>2</span><span class=cF0> * (*y + MAN_HEIGHT) / zz;
<a name="l126"></a> *x += dc-&gt;x;
<a name="l127"></a> *y += dc-&gt;y;
<a name="l128"></a> *z += dc-&gt;z;
<a name="l129"></a>}
<a name="l130"></a>
<a name="l131"></a>#</span><span class=cF1>define</span><span class=cF0> LOS_SCALE </span><span class=cFE>4</span><span class=cF0>
<a name="l132"></a>
<a name="l133"></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="l134"></a>{
<a name="l135"></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="l136"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l137"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l138"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l139"></a>}
<a name="l140"></a>
<a name="l141"></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="l142"></a>{</span><span class=cF2>//Line of sight</span><span class=cF0>
<a name="l143"></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 / SCREEN_SCALE, y1 * LOS_SCALE / SCREEN_SCALE, </span><span class=cFE>0</span><span class=cF0>,
<a name="l144"></a> x2 * LOS_SCALE / SCREEN_SCALE, y2 * LOS_SCALE / SCREEN_SCALE, </span><span class=cFE>0</span><span class=cF0>, &amp;LOSPlot);
<a name="l145"></a>}
<a name="l146"></a>
<a name="l147"></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="l148"></a>{
<a name="l149"></a> </span><span class=cF9>I64</span><span class=cF0> i, j, *r1, *r2, *r3, *s2w, xx, yy, zz, x, y, x1, y1, z1, c, x1w, y1w, x1h, y1h, xh, yh, zh,
<a name="l150"></a> cx = task-&gt;pix_width / </span><span class=cFE>2</span><span class=cF0>,
<a name="l151"></a> cy = task-&gt;pix_height / </span><span class=cFE>2</span><span class=cF0>;
<a name="l152"></a> </span><span class=cF1>U8</span><span class=cF0> *tmps;
<a name="l153"></a> </span><span class=cF1>F64</span><span class=cF0> tt;
<a name="l154"></a> </span><span class=cF9>CD3I32</span><span class=cF0> poly[</span><span class=cFE>4</span><span class=cF0>];
<a name="l155"></a> Monster *tmpm;
<a name="l156"></a>
<a name="l157"></a> </span><span class=cF5>DCDepthBufAlloc</span><span class=cF0>(dc);
<a name="l158"></a> </span><span class=cF5>MemSet</span><span class=cF0>(panels_processed_bitmap, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cF7>(</span><span class=cF0>map_width * map_height + </span><span class=cFE>7</span><span class=cF7>)</span><span class=cF0> &gt;&gt; </span><span class=cFE>3</span><span class=cF0>);
<a name="l159"></a>
<a name="l160"></a> </span><span class=cF2>//World to screen</span><span class=cF0>
<a name="l161"></a> </span><span class=cF5>Mat4x4RotZ</span><span class=cF0>(dc-&gt;r, man_theta + </span><span class=cF3>pi</span><span class=cF0> / </span><span class=cFE>2</span><span class=cF0>);
<a name="l162"></a> </span><span class=cF5>Mat4x4RotX</span><span class=cF0>(dc-&gt;r, </span><span class=cF3>pi</span><span class=cF0> / </span><span class=cFE>2</span><span class=cF0>);
<a name="l163"></a> </span><span class=cF5>DCMat4x4Set</span><span class=cF0>(dc, dc-&gt;r);
<a name="l164"></a>
<a name="l165"></a> xh = -man_xx / SCREEN_SCALE;
<a name="l166"></a> yh = -man_yy / SCREEN_SCALE;
<a name="l167"></a> zh = </span><span class=cFE>0</span><span class=cF0>;
<a name="l168"></a> </span><span class=cF5>Mat4x4MulXYZ</span><span class=cF0>(dc-&gt;r, &amp;xh, &amp;yh, &amp;zh);
<a name="l169"></a> </span><span class=cF5>Mat4x4TranslationEqu</span><span class=cF0>(dc-&gt;r, xh, yh, zh);
<a name="l170"></a>
<a name="l171"></a> </span><span class=cF2>//Screen to world</span><span class=cF0>
<a name="l172"></a> s2w = </span><span class=cF5>Mat4x4IdentNew</span><span class=cF0>(task);
<a name="l173"></a> </span><span class=cF5>Mat4x4RotX</span><span class=cF0>(s2w, -</span><span class=cF3>pi</span><span class=cF0> / </span><span class=cFE>2</span><span class=cF0>);
<a name="l174"></a> </span><span class=cF5>Mat4x4RotZ</span><span class=cF0>(s2w, -man_theta - </span><span class=cF3>pi</span><span class=cF0> / </span><span class=cFE>2</span><span class=cF0>);
<a name="l175"></a> xh = </span><span class=cFE>0</span><span class=cF0>;
<a name="l176"></a> yh = </span><span class=cFE>0</span><span class=cF0>;
<a name="l177"></a> zh = SCREEN_SCALE;
<a name="l178"></a> </span><span class=cF5>Mat4x4MulXYZ</span><span class=cF0>(s2w, &amp;xh, &amp;yh, &amp;zh);
<a name="l179"></a>
<a name="l180"></a> </span><span class=cF2>//Rotate light source</span><span class=cF0>
<a name="l181"></a> xx = dc-&gt;ls.x;
<a name="l182"></a> yy = dc-&gt;ls.y;
<a name="l183"></a> zz = -dc-&gt;ls.z;
<a name="l184"></a> (*dc-&gt;transform)(dc, &amp;xx, &amp;yy, &amp;zz);
<a name="l185"></a> dc-&gt;ls.x = xx;
<a name="l186"></a> dc-&gt;ls.y = yy;
<a name="l187"></a> dc-&gt;ls.z = zz;
<a name="l188"></a>
<a name="l189"></a> dc-&gt;flags |= </span><span class=cF3>DCF_TRANSFORMATION</span><span class=cF0>;
<a name="l190"></a> dc-&gt;transform = &amp;CFTransform;
<a name="l191"></a> dc-&gt;x = cx;
<a name="l192"></a> dc-&gt;y = cy;
<a name="l193"></a> r1 = </span><span class=cF5>Mat4x4IdentNew</span><span class=cF0>(task);
<a name="l194"></a> </span><span class=cF5>Mat4x4RotX</span><span class=cF0>(r1, -</span><span class=cF3>pi</span><span class=cF0> / </span><span class=cFE>2</span><span class=cF0>);
<a name="l195"></a> </span><span class=cF5>Mat4x4RotZ</span><span class=cF0>(r1, </span><span class=cF5>tS</span><span class=cF0>);
<a name="l196"></a> </span><span class=cF5>Mat4x4Scale</span><span class=cF0>(r1, MONSTER_SCALE);
<a name="l197"></a>
<a name="l198"></a> r2 = </span><span class=cF5>Mat4x4IdentNew</span><span class=cF0>(task);
<a name="l199"></a> </span><span class=cF5>Mat4x4Scale</span><span class=cF0>(r2, MONSTER_SCALE);
<a name="l200"></a>
<a name="l201"></a> r3 = </span><span class=cF5>Mat4x4IdentNew</span><span class=cF0>(task);
<a name="l202"></a> </span><span class=cF5>Mat4x4RotX</span><span class=cF0>(r3, -</span><span class=cF3>pi</span><span class=cF0> / </span><span class=cFE>2</span><span class=cF0>);
<a name="l203"></a> </span><span class=cF5>Mat4x4Scale</span><span class=cF0>(r3, PLANT_SCALE);
<a name="l204"></a>
<a name="l205"></a> </span><span class=cF5>Seed</span><span class=cF0>(</span><span class=cFE>1</span><span class=cF0>);
<a name="l206"></a> x1h = man_xx + yh * PLOT_GRID_WIDTH / </span><span class=cFE>2</span><span class=cF0> + xh * (PLOT_GRID_HEIGHT - </span><span class=cFE>1</span><span class=cF0>);
<a name="l207"></a> y1h = man_yy - xh * PLOT_GRID_WIDTH / </span><span class=cFE>2</span><span class=cF0> + yh * (PLOT_GRID_HEIGHT - </span><span class=cFE>1</span><span class=cF0>);
<a name="l208"></a> xh &gt;&gt;= </span><span class=cFE>1</span><span class=cF0>;
<a name="l209"></a> yh &gt;&gt;= </span><span class=cFE>1</span><span class=cF0>;
<a name="l210"></a> </span><span class=cF1>for</span><span class=cF0> (j = </span><span class=cFE>0</span><span class=cF0>; j &lt; PLOT_GRID_HEIGHT * </span><span class=cFE>2</span><span class=cF0>; j++)
<a name="l211"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l212"></a> x1w = x1h;
<a name="l213"></a> y1w = y1h;
<a name="l214"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>; i &lt; PLOT_GRID_WIDTH * </span><span class=cFE>4</span><span class=cF0>; i++)
<a name="l215"></a> {
<a name="l216"></a> xx = x1w / SCREEN_SCALE;
<a name="l217"></a> yy = y1w / SCREEN_SCALE;
<a name="l218"></a> x = xx * SCREEN_SCALE - man_xx;
<a name="l219"></a> y = yy * SCREEN_SCALE - man_yy;
<a name="l220"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFE>1</span><span class=cF0> &lt;= xx &lt; map_width - </span><span class=cFE>1</span><span class=cF0> &amp;&amp; </span><span class=cFE>1</span><span class=cF0> &lt;= yy &lt; map_height - </span><span class=cFE>1</span><span class=cF0> &amp;&amp; !</span><span class=cF5>LBts</span><span class=cF7>(</span><span class=cF0>panels_processed_bitmap, yy * map_width + xx</span><span class=cF7>)</span><span class=cF0>)
<a name="l221"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l222"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF7>(</span><span class=cF0>c = map[yy * map_width + xx]</span><span class=cF7>)</span><span class=cF0> &amp;&amp;
<a name="l223"></a> LOS</span><span class=cF7>(</span><span class=cF0>xx * SCREEN_SCALE + SCREEN_SCALE / </span><span class=cFE>2</span><span class=cF0>, yy * SCREEN_SCALE + SCREEN_SCALE / </span><span class=cFE>2</span><span class=cF0>, man_xx, man_yy</span><span class=cF7>)</span><span class=cF0>)
<a name="l224"></a> {
<a name="l225"></a> </span><span class=cF1>if</span><span class=cF0> (c == </span><span class=cF3>YELLOW</span><span class=cF0>)
<a name="l226"></a> dc-&gt;color = </span><span class=cF3>DKGRAY</span><span class=cF0>;
<a name="l227"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l228"></a> dc-&gt;color = c;
<a name="l229"></a> poly[</span><span class=cFE>0</span><span class=cF0>].x = x;
<a name="l230"></a> poly[</span><span class=cFE>0</span><span class=cF0>].y = y;
<a name="l231"></a> poly[</span><span class=cFE>0</span><span class=cF0>].z = </span><span class=cFE>0</span><span class=cF0>;
<a name="l232"></a> poly[</span><span class=cFE>1</span><span class=cF0>].x = x + SCREEN_SCALE;
<a name="l233"></a> poly[</span><span class=cFE>1</span><span class=cF0>].y = y;
<a name="l234"></a> poly[</span><span class=cFE>1</span><span class=cF0>].z = </span><span class=cFE>0</span><span class=cF0>;
<a name="l235"></a> poly[</span><span class=cFE>2</span><span class=cF0>].x = x + SCREEN_SCALE;
<a name="l236"></a> poly[</span><span class=cFE>2</span><span class=cF0>].y = y + SCREEN_SCALE;
<a name="l237"></a> poly[</span><span class=cFE>2</span><span class=cF0>].z = </span><span class=cFE>0</span><span class=cF0>;
<a name="l238"></a> poly[</span><span class=cFE>3</span><span class=cF0>].x = x;
<a name="l239"></a> poly[</span><span class=cFE>3</span><span class=cF0>].y = y + SCREEN_SCALE;
<a name="l240"></a> poly[</span><span class=cFE>3</span><span class=cF0>].z = </span><span class=cFE>0</span><span class=cF0>;
<a name="l241"></a> </span><span class=cF5>GrFillPoly3</span><span class=cF0>(dc, </span><span class=cFE>4</span><span class=cF0>, poly);
<a name="l242"></a> </span><span class=cF1>if</span><span class=cF0> (c == </span><span class=cF3>GREEN</span><span class=cF0>)
<a name="l243"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l244"></a> x1 = x + SCREEN_SCALE / </span><span class=cFE>2</span><span class=cF0>;
<a name="l245"></a> y1 = y + SCREEN_SCALE / </span><span class=cFE>2</span><span class=cF0>;
<a name="l246"></a> z1 = </span><span class=cFE>0</span><span class=cF0>;
<a name="l247"></a> </span><span class=cF5>DCTransform</span><span class=cF0>(dc, &amp;x1, &amp;y1, &amp;z1);
<a name="l248"></a> </span><span class=cF1>if</span><span class=cF0> (z1 &gt; </span><span class=cFE>0</span><span class=cF0>)
<a name="l249"></a> </span><span class=cF5>Sprite3Mat4x4B</span><span class=cF0>(dc, x + SCREEN_SCALE / </span><span class=cFE>2</span><span class=cF0>, y + SCREEN_SCALE / </span><span class=cFE>2</span><span class=cF0>, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cFA>&lt;5&gt;</span><span class=cF0>, r3);
<a name="l250"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l251"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (c == </span><span class=cF3>YELLOW</span><span class=cF0>)
<a name="l252"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l253"></a> x1 = x + SCREEN_SCALE / </span><span class=cFE>2</span><span class=cF0>;
<a name="l254"></a> y1 = y + SCREEN_SCALE / </span><span class=cFE>2</span><span class=cF0>;
<a name="l255"></a> z1 = </span><span class=cFE>0</span><span class=cF0>;
<a name="l256"></a> </span><span class=cF5>DCTransform</span><span class=cF0>(dc, &amp;x1, &amp;y1, &amp;z1);
<a name="l257"></a> </span><span class=cF1>if</span><span class=cF0> (z1 &gt; </span><span class=cFE>0</span><span class=cF0>)
<a name="l258"></a> </span><span class=cF5>Sprite3Mat4x4B</span><span class=cF0>(dc, x + SCREEN_SCALE / </span><span class=cFE>2</span><span class=cF0>, y + SCREEN_SCALE / </span><span class=cFE>2</span><span class=cF0>, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cFA>&lt;6&gt;</span><span class=cF0>, r3);
<a name="l259"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l260"></a>
<a name="l261"></a> </span><span class=cF1>if</span><span class=cF0> (!map[</span><span class=cF7>(</span><span class=cF0>yy + </span><span class=cFE>1</span><span class=cF7>)</span><span class=cF0> * map_width + xx])
<a name="l262"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l263"></a> dc-&gt;color = </span><span class=cF3>LTGRAY</span><span class=cF0>;
<a name="l264"></a> poly[</span><span class=cFE>0</span><span class=cF0>].x = x;
<a name="l265"></a> poly[</span><span class=cFE>0</span><span class=cF0>].y = y + SCREEN_SCALE;
<a name="l266"></a> poly[</span><span class=cFE>0</span><span class=cF0>].z = </span><span class=cFE>0</span><span class=cF0>;
<a name="l267"></a> poly[</span><span class=cFE>1</span><span class=cF0>].x = x + SCREEN_SCALE;
<a name="l268"></a> poly[</span><span class=cFE>1</span><span class=cF0>].y = y + SCREEN_SCALE;
<a name="l269"></a> poly[</span><span class=cFE>1</span><span class=cF0>].z = </span><span class=cFE>0</span><span class=cF0>;
<a name="l270"></a> poly[</span><span class=cFE>2</span><span class=cF0>].x = x + SCREEN_SCALE;
<a name="l271"></a> poly[</span><span class=cFE>2</span><span class=cF0>].y = y + SCREEN_SCALE;
<a name="l272"></a> poly[</span><span class=cFE>2</span><span class=cF0>].z = SCREEN_SCALE;
<a name="l273"></a> poly[</span><span class=cFE>3</span><span class=cF0>].x = x;
<a name="l274"></a> poly[</span><span class=cFE>3</span><span class=cF0>].y = y + SCREEN_SCALE;
<a name="l275"></a> poly[</span><span class=cFE>3</span><span class=cF0>].z = SCREEN_SCALE;
<a name="l276"></a> </span><span class=cF5>GrFillPoly3</span><span class=cF0>(dc, </span><span class=cFE>4</span><span class=cF0>, poly);
<a name="l277"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l278"></a> </span><span class=cF1>if</span><span class=cF0> (!map[yy * map_width + xx + </span><span class=cFE>1</span><span class=cF0>])
<a name="l279"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l280"></a> dc-&gt;color = </span><span class=cF3>WHITE</span><span class=cF0>;
<a name="l281"></a> poly[</span><span class=cFE>0</span><span class=cF0>].x = x + SCREEN_SCALE;
<a name="l282"></a> poly[</span><span class=cFE>0</span><span class=cF0>].y = y;
<a name="l283"></a> poly[</span><span class=cFE>0</span><span class=cF0>].z = </span><span class=cFE>0</span><span class=cF0>;
<a name="l284"></a> poly[</span><span class=cFE>1</span><span class=cF0>].x = x + SCREEN_SCALE;
<a name="l285"></a> poly[</span><span class=cFE>1</span><span class=cF0>].y = y + SCREEN_SCALE;
<a name="l286"></a> poly[</span><span class=cFE>1</span><span class=cF0>].z = </span><span class=cFE>0</span><span class=cF0>;
<a name="l287"></a> poly[</span><span class=cFE>2</span><span class=cF0>].x = x + SCREEN_SCALE;
<a name="l288"></a> poly[</span><span class=cFE>2</span><span class=cF0>].y = y + SCREEN_SCALE;
<a name="l289"></a> poly[</span><span class=cFE>2</span><span class=cF0>].z = SCREEN_SCALE;
<a name="l290"></a> poly[</span><span class=cFE>3</span><span class=cF0>].x = x + SCREEN_SCALE;
<a name="l291"></a> poly[</span><span class=cFE>3</span><span class=cF0>].y = y;
<a name="l292"></a> poly[</span><span class=cFE>3</span><span class=cF0>].z = SCREEN_SCALE;
<a name="l293"></a> </span><span class=cF5>GrFillPoly3</span><span class=cF0>(dc, </span><span class=cFE>4</span><span class=cF0>, poly);
<a name="l294"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l295"></a> </span><span class=cF1>if</span><span class=cF0> (!map[</span><span class=cF7>(</span><span class=cF0>yy - </span><span class=cFE>1</span><span class=cF7>)</span><span class=cF0> * map_width + xx])
<a name="l296"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l297"></a> dc-&gt;color =</span><span class=cF3>LTGRAY</span><span class=cF0>;
<a name="l298"></a> poly[</span><span class=cFE>0</span><span class=cF0>].x = x;
<a name="l299"></a> poly[</span><span class=cFE>0</span><span class=cF0>].y = y;
<a name="l300"></a> poly[</span><span class=cFE>0</span><span class=cF0>].z = </span><span class=cFE>0</span><span class=cF0>;
<a name="l301"></a> poly[</span><span class=cFE>1</span><span class=cF0>].x = x + SCREEN_SCALE;
<a name="l302"></a> poly[</span><span class=cFE>1</span><span class=cF0>].y = y;
<a name="l303"></a> poly[</span><span class=cFE>1</span><span class=cF0>].z = </span><span class=cFE>0</span><span class=cF0>;
<a name="l304"></a> poly[</span><span class=cFE>2</span><span class=cF0>].x = x + SCREEN_SCALE;
<a name="l305"></a> poly[</span><span class=cFE>2</span><span class=cF0>].y = y;
<a name="l306"></a> poly[</span><span class=cFE>2</span><span class=cF0>].z = SCREEN_SCALE;
<a name="l307"></a> poly[</span><span class=cFE>3</span><span class=cF0>].x = x;
<a name="l308"></a> poly[</span><span class=cFE>3</span><span class=cF0>].y = y;
<a name="l309"></a> poly[</span><span class=cFE>3</span><span class=cF0>].z = SCREEN_SCALE;
<a name="l310"></a> </span><span class=cF5>GrFillPoly3</span><span class=cF0>(dc, </span><span class=cFE>4</span><span class=cF0>, poly);
<a name="l311"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l312"></a> </span><span class=cF1>if</span><span class=cF0> (!map[yy * map_width + xx - </span><span class=cFE>1</span><span class=cF0>])
<a name="l313"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l314"></a> dc-&gt;color =</span><span class=cF3>WHITE</span><span class=cF0>;
<a name="l315"></a> poly[</span><span class=cFE>0</span><span class=cF0>].x = x;
<a name="l316"></a> poly[</span><span class=cFE>0</span><span class=cF0>].y = y;
<a name="l317"></a> poly[</span><span class=cFE>0</span><span class=cF0>].z = </span><span class=cFE>0</span><span class=cF0>;
<a name="l318"></a> poly[</span><span class=cFE>1</span><span class=cF0>].x = x;
<a name="l319"></a> poly[</span><span class=cFE>1</span><span class=cF0>].y = y + SCREEN_SCALE;
<a name="l320"></a> poly[</span><span class=cFE>1</span><span class=cF0>].z = </span><span class=cFE>0</span><span class=cF0>;
<a name="l321"></a> poly[</span><span class=cFE>2</span><span class=cF0>].x = x;
<a name="l322"></a> poly[</span><span class=cFE>2</span><span class=cF0>].y = y + SCREEN_SCALE;
<a name="l323"></a> poly[</span><span class=cFE>2</span><span class=cF0>].z = SCREEN_SCALE;
<a name="l324"></a> poly[</span><span class=cFE>3</span><span class=cF0>].x = x;
<a name="l325"></a> poly[</span><span class=cFE>3</span><span class=cF0>].y = y;
<a name="l326"></a> poly[</span><span class=cFE>3</span><span class=cF0>].z = SCREEN_SCALE;
<a name="l327"></a> </span><span class=cF5>GrFillPoly3</span><span class=cF0>(dc, </span><span class=cFE>4</span><span class=cF0>, poly);
<a name="l328"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l329"></a> }
<a name="l330"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l331"></a> x1w -= yh;
<a name="l332"></a> y1w += xh;
<a name="l333"></a> }
<a name="l334"></a> x1h -= xh;
<a name="l335"></a> y1h -= yh;
<a name="l336"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l337"></a>
<a name="l338"></a> </span><span class=cF2>//Draw Monsters</span><span class=cF0>
<a name="l339"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>, tmpm = monsters; i &lt; MONSTERS_NUM; i++, tmpm++)
<a name="l340"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l341"></a> x = tmpm-&gt;x;
<a name="l342"></a> y = tmpm-&gt;y;
<a name="l343"></a> </span><span class=cF1>if</span><span class=cF0> (LOS</span><span class=cF7>(</span><span class=cF0>x, y, man_xx, man_yy</span><span class=cF7>)</span><span class=cF0>)
<a name="l344"></a> {
<a name="l345"></a> x -= man_xx;
<a name="l346"></a> y -= man_yy;
<a name="l347"></a> xx = x;
<a name="l348"></a> yy = y;
<a name="l349"></a> zz = </span><span class=cFE>0</span><span class=cF0>;
<a name="l350"></a> </span><span class=cF5>DCTransform</span><span class=cF0>(dc, &amp;xx, &amp;yy, &amp;zz);
<a name="l351"></a> </span><span class=cF1>if</span><span class=cF0> (zz &gt; </span><span class=cFE>0</span><span class=cF0>)
<a name="l352"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l353"></a> </span><span class=cF1>if</span><span class=cF0> (tmpm-&gt;dead)
<a name="l354"></a> </span><span class=cF5>Sprite3Mat4x4B</span><span class=cF0>(dc, x, y, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cFA>&lt;2&gt;</span><span class=cF0>, r2);
<a name="l355"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l356"></a> {
<a name="l357"></a> tt = </span><span class=cF5>Tri</span><span class=cF0>(</span><span class=cF5>tS</span><span class=cF0>, </span><span class=cFE>1</span><span class=cF0>.</span><span class=cFE>0</span><span class=cF0>);
<a name="l358"></a> tmps = </span><span class=cF5>SpriteInterpolate</span><span class=cF0>(tt, </span><span class=cFA>&lt;3&gt;</span><span class=cF0>, </span><span class=cFA>&lt;4&gt;</span><span class=cF0>);
<a name="l359"></a> </span><span class=cF5>Sprite3Mat4x4B</span><span class=cF0>(dc, x, y, </span><span class=cFE>0</span><span class=cF0>, tmps, r1);
<a name="l360"></a> </span><span class=cF5>Free</span><span class=cF0>(tmps);
<a name="l361"></a> }
<a name="l362"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l363"></a> }
<a name="l364"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l365"></a> </span><span class=cF5>Free</span><span class=cF0>(r1);
<a name="l366"></a> </span><span class=cF5>Free</span><span class=cF0>(r2);
<a name="l367"></a> </span><span class=cF5>Free</span><span class=cF0>(r3);
<a name="l368"></a>
<a name="l369"></a> </span><span class=cF2>//Draw Map heads-up display, scaled 2 pixs</span><span class=cF0>
<a name="l370"></a> </span><span class=cF5>Free</span><span class=cF0>(dc-&gt;r);
<a name="l371"></a> </span><span class=cF5>DCMat4x4Set</span><span class=cF0>(dc, </span><span class=cF5>Mat4x4IdentNew</span><span class=cF7>(</span><span class=cF0>task</span><span class=cF7>)</span><span class=cF0>);
<a name="l372"></a> dc-&gt;x = task-&gt;pix_width - </span><span class=cFE>2</span><span class=cF0> * map_width;
<a name="l373"></a> dc-&gt;y = task-&gt;pix_height - </span><span class=cFE>2</span><span class=cF0> * map_height;
<a name="l374"></a> dc-&gt;z = </span><span class=cFE>0</span><span class=cF0>;
<a name="l375"></a> dc-&gt;transform = &amp;</span><span class=cF5>DCTransform</span><span class=cF0>;
<a name="l376"></a> dc-&gt;thick = </span><span class=cFE>2</span><span class=cF0>;
<a name="l377"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>; i &lt; map_height; i++)
<a name="l378"></a> </span><span class=cF1>for</span><span class=cF0> (j = </span><span class=cFE>0</span><span class=cF0>; j &lt; map_width; j++)
<a name="l379"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l380"></a> dc-&gt;color = map[(map_height - </span><span class=cFE>1</span><span class=cF0> - i) * map_width + j];
<a name="l381"></a> </span><span class=cF5>GrPlot3</span><span class=cF0>(dc, </span><span class=cFE>2</span><span class=cF0> * j, </span><span class=cFE>2</span><span class=cF0> * i, </span><span class=cFE>0</span><span class=cF0>);
<a name="l382"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l383"></a>
<a name="l384"></a> </span><span class=cF2>//Draw Things on heads-up Map</span><span class=cF0>
<a name="l385"></a> dc-&gt;color = </span><span class=cF3>LTPURPLE</span><span class=cF0>;
<a name="l386"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>, tmpm = monsters; i &lt; MONSTERS_NUM; i++, tmpm++)
<a name="l387"></a> </span><span class=cF1>if</span><span class=cF0> (!tmpm-&gt;dead)
<a name="l388"></a> </span><span class=cF5>GrPlot3</span><span class=cF0>(dc, </span><span class=cFE>2</span><span class=cF0> * </span><span class=cF7>(</span><span class=cF0>tmpm-&gt;x / SCREEN_SCALE</span><span class=cF7>)</span><span class=cF0>,
<a name="l389"></a> </span><span class=cFE>2</span><span class=cF0> * </span><span class=cF7>(</span><span class=cF0>map_height - </span><span class=cFE>1</span><span class=cF0> - tmpm-&gt;y / SCREEN_SCALE</span><span class=cF7>)</span><span class=cF0>, </span><span class=cFE>0</span><span class=cF0>);
<a name="l390"></a> dc-&gt;color = </span><span class=cF3>LTCYAN</span><span class=cF0>;
<a name="l391"></a> </span><span class=cF5>GrPlot3</span><span class=cF0>(dc, </span><span class=cFE>2</span><span class=cF0> * </span><span class=cF7>(</span><span class=cF0>man_xx / SCREEN_SCALE</span><span class=cF7>)</span><span class=cF0>, </span><span class=cFE>2</span><span class=cF0> * </span><span class=cF7>(</span><span class=cF0>map_height - </span><span class=cFE>1</span><span class=cF0> - man_yy / SCREEN_SCALE</span><span class=cF7>)</span><span class=cF0>, </span><span class=cFE>0</span><span class=cF0>);
<a name="l392"></a>
<a name="l393"></a> </span><span class=cF1>if</span><span class=cF0> (tf)
<a name="l394"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l395"></a> dc-&gt;color = </span><span class=cF3>LTRED</span><span class=cF0>;
<a name="l396"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>Blink</span><span class=cF0>)
<a name="l397"></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> * </span><span class=cFE>14</span><span class=cF7>)</span><span class=cF0> / </span><span class=cFE>2</span><span class=cF0>, cy - </span><span class=cF3>FONT_HEIGHT</span><span class=cF0> / </span><span class=cFE>2</span><span class=cF0>, </span><span class=cF6>&quot;Game Completed&quot;</span><span class=cF0>);
<a name="l398"></a> tt = tf;
<a name="l399"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l400"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l401"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l402"></a> dc-&gt;color = </span><span class=cF3>LTGREEN</span><span class=cF0>;
<a name="l403"></a> </span><span class=cF5>GrLine</span><span class=cF0>(dc, cx - </span><span class=cFE>5</span><span class=cF0>, cy, cx + </span><span class=cFE>5</span><span class=cF0>, cy);
<a name="l404"></a> </span><span class=cF5>GrLine</span><span class=cF0>(dc, cx, cy - </span><span class=cFE>5</span><span class=cF0>, cx, cy + </span><span class=cFE>5</span><span class=cF0>);
<a name="l405"></a> tt = </span><span class=cF5>tS</span><span class=cF0>;
<a name="l406"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l407"></a> </span><span class=cF5>GrPrint</span><span class=cF0>(dc, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cF6>&quot;Enemy:%d Time:%3.2f Best:%3.2f&quot;</span><span class=cF0>, monsters_left, tt - t0, best_score);
<a name="l408"></a> </span><span class=cF5>Free</span><span class=cF0>(s2w);
<a name="l409"></a> </span><span class=cF5>Seed</span><span class=cF0>(</span><span class=cFE>0</span><span class=cF0>);
<a name="l410"></a>}
<a name="l411"></a>
<a name="l412"></a></span><span class=cF1>U0</span><span class=cF0> Fire()
<a name="l413"></a>{
<a name="l414"></a> </span><span class=cF9>I64</span><span class=cF0> i, x, y;
<a name="l415"></a> </span><span class=cF1>F64</span><span class=cF0> d, dx, dy, xx = </span><span class=cF5>Cos</span><span class=cF0>(man_theta), yy = </span><span class=cF5>Sin</span><span class=cF0>(man_theta);
<a name="l416"></a> Monster *tmpm;
<a name="l417"></a>
<a name="l418"></a> </span><span class=cF5>Noise</span><span class=cF0>(</span><span class=cFE>100</span><span class=cF0>, </span><span class=cFE>53</span><span class=cF0>, </span><span class=cFE>74</span><span class=cF0>);
<a name="l419"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>, tmpm = monsters; i &lt; MONSTERS_NUM; i++, tmpm++)
<a name="l420"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l421"></a> x = tmpm-&gt;x;
<a name="l422"></a> y = tmpm-&gt;y;
<a name="l423"></a> </span><span class=cF1>if</span><span class=cF0> (!tmpm-&gt;dead &amp;&amp; LOS</span><span class=cF7>(</span><span class=cF0>x, y, man_xx, man_yy</span><span class=cF7>)</span><span class=cF0>)
<a name="l424"></a> {
<a name="l425"></a> dx = x - man_xx;
<a name="l426"></a> dy = man_yy - y;
<a name="l427"></a> </span><span class=cF1>if</span><span class=cF0> (d = </span><span class=cF5>Sqrt</span><span class=cF7>(</span><span class=cF0>dx * dx + dy * dy</span><span class=cF7>)</span><span class=cF0>)
<a name="l428"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l429"></a> dx /= d;
<a name="l430"></a> dy /= d;
<a name="l431"></a> </span><span class=cF1>if</span><span class=cF0> (dx * xx + dy * yy &gt; </span><span class=cFE>0</span><span class=cF0>.</span><span class=cFE>995</span><span class=cF0>)
<a name="l432"></a> {
<a name="l433"></a> tmpm-&gt;dead = </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l434"></a> </span><span class=cF1>if</span><span class=cF0> (!--monsters_left)
<a name="l435"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l436"></a> tf = </span><span class=cF5>tS</span><span class=cF0>;
<a name="l437"></a> </span><span class=cF1>if</span><span class=cF0> (tf - t0 &lt; best_score)
<a name="l438"></a> best_score = tf - t0;
<a name="l439"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l440"></a> }
<a name="l441"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l442"></a> }
<a name="l443"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l444"></a>}
<a name="l445"></a>
<a name="l446"></a></span><span class=cF1>U0</span><span class=cF0> Init()
<a name="l447"></a>{
<a name="l448"></a> </span><span class=cF9>I64</span><span class=cF0> i, x, y;
<a name="l449"></a> </span><span class=cF9>CDC</span><span class=cF0> *dc;
<a name="l450"></a> Monster *tmpm;
<a name="l451"></a>
<a name="l452"></a> </span><span class=cF5>DocClear</span><span class=cF0>;
<a name="l453"></a> </span><span class=cF6>&quot;$BG,BLACK$%h*c&quot;</span><span class=cF0>, </span><span class=cF3>TEXT_ROWS</span><span class=cF0> / </span><span class=cFE>2</span><span class=cF0>, </span><span class=cF6>'\n'</span><span class=cF0>;
<a name="l454"></a>
<a name="l455"></a> dc = </span><span class=cF5>Sprite2DC</span><span class=cF0>(</span><span class=cFA>&lt;1&gt;</span><span class=cF0>);
<a name="l456"></a> map_width = dc-&gt;width / MAP_SCALE + </span><span class=cFE>2</span><span class=cF0>;
<a name="l457"></a> map_height = dc-&gt;height / MAP_SCALE + </span><span class=cFE>2</span><span class=cF0>;
<a name="l458"></a> </span><span class=cF5>Free</span><span class=cF0>(map);
<a name="l459"></a> </span><span class=cF5>Free</span><span class=cF0>(panels_processed_bitmap);
<a name="l460"></a> map = </span><span class=cF5>CAlloc</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="l461"></a> panels_processed_bitmap = </span><span class=cF5>MAlloc</span><span class=cF0>(</span><span class=cF7>(</span><span class=cF0>map_width * map_height + </span><span class=cFE>7</span><span class=cF7>)</span><span class=cF0> &gt;&gt; </span><span class=cFE>3</span><span class=cF0>);
<a name="l462"></a> </span><span class=cF1>for</span><span class=cF0> (y = </span><span class=cFE>0</span><span class=cF0>; y &lt; map_height - </span><span class=cFE>2</span><span class=cF0>; y++)
<a name="l463"></a> </span><span class=cF1>for</span><span class=cF0> (x = </span><span class=cFE>0</span><span class=cF0>; x &lt; map_width - </span><span class=cFE>2</span><span class=cF0>; x++)
<a name="l464"></a> map[(map_height - </span><span class=cFE>2</span><span class=cF0> - y) * map_width + x + </span><span class=cFE>1</span><span class=cF0>] = </span><span class=cF5>GrPeek</span><span class=cF0>(dc, x * MAP_SCALE, y * MAP_SCALE);
<a name="l465"></a> </span><span class=cF5>DCDel</span><span class=cF0>(dc);
<a name="l466"></a> man_xx = (</span><span class=cFE>1</span><span class=cF0> + MAN_START_X) * SCREEN_SCALE;
<a name="l467"></a> man_yy = (map_height - </span><span class=cFE>1</span><span class=cF0> - MAN_START_Y) * SCREEN_SCALE;
<a name="l468"></a> man_theta = </span><span class=cFE>0</span><span class=cF0>;
<a name="l469"></a>
<a name="l470"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>, tmpm = monsters; i &lt; MONSTERS_NUM; i++, tmpm++)
<a name="l471"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l472"></a> tmpm-&gt;dead = </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l473"></a> </span><span class=cF1>do</span><span class=cF0>
<a name="l474"></a> {
<a name="l475"></a> tmpm-&gt;x = </span><span class=cF5>RandU64</span><span class=cF0> % (</span><span class=cF7>(</span><span class=cF0>map_width - </span><span class=cFE>2</span><span class=cF7>)</span><span class=cF0> * SCREEN_SCALE) + SCREEN_SCALE;
<a name="l476"></a> tmpm-&gt;y = </span><span class=cF5>RandU64</span><span class=cF0> % (</span><span class=cF7>(</span><span class=cF0>map_height - </span><span class=cFE>2</span><span class=cF7>)</span><span class=cF0> * SCREEN_SCALE) + SCREEN_SCALE;
<a name="l477"></a> }
<a name="l478"></a> </span><span class=cF1>while</span><span class=cF0> (!map[</span><span class=cF7>(</span><span class=cF0>tmpm-&gt;y / SCREEN_SCALE</span><span class=cF7>)</span><span class=cF0> * map_width + tmpm-&gt;x / SCREEN_SCALE]);
<a name="l479"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l480"></a> monsters_left = MONSTERS_NUM;
<a name="l481"></a> tf = </span><span class=cFE>0</span><span class=cF0>;
<a name="l482"></a> t0 = </span><span class=cF5>tS</span><span class=cF0>;
<a name="l483"></a>}
<a name="l484"></a>
<a name="l485"></a></span><span class=cF1>U0</span><span class=cF0> AnimateTask(</span><span class=cF9>I64</span><span class=cF0>)
<a name="l486"></a>{
<a name="l487"></a> </span><span class=cF9>I64</span><span class=cF0> i, x, y, dd;
<a name="l488"></a> Monster *tmpm;
<a name="l489"></a>
<a name="l490"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF3>TRUE</span><span class=cF0>)
<a name="l491"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l492"></a> dd = </span><span class=cFE>0</span><span class=cF0>.</span><span class=cFE>25</span><span class=cF0> * SCREEN_SCALE * </span><span class=cF5>Sin</span><span class=cF0>(</span><span class=cF5>tS</span><span class=cF0> / </span><span class=cFE>2</span><span class=cF0>);
<a name="l493"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>, tmpm = monsters; i &lt; MONSTERS_NUM; i++, tmpm++)
<a name="l494"></a> </span><span class=cF1>if</span><span class=cF0> (!tmpm-&gt;dead)
<a name="l495"></a> {
<a name="l496"></a> x = tmpm-&gt;x;
<a name="l497"></a> y = tmpm-&gt;y;
<a name="l498"></a> </span><span class=cF1>if</span><span class=cF0> (i &amp; </span><span class=cFE>1</span><span class=cF0>)
<a name="l499"></a> x += dd;
<a name="l500"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l501"></a> y += dd;
<a name="l502"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFE>0</span><span class=cF0> &lt;= x &lt;= map_width * SCREEN_SCALE &amp;&amp;
<a name="l503"></a> </span><span class=cFE>0</span><span class=cF0> &lt;= y &lt;= map_height * SCREEN_SCALE &amp;&amp;
<a name="l504"></a> map[</span><span class=cF7>(</span><span class=cF0>y / SCREEN_SCALE</span><span class=cF7>)</span><span class=cF0> * map_width + x / SCREEN_SCALE])
<a name="l505"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l506"></a> </span><span class=cF1>if</span><span class=cF0> (!map[</span><span class=cF7>(</span><span class=cF0>y / SCREEN_SCALE</span><span class=cF7>)</span><span class=cF0> * map_width + x / SCREEN_SCALE + </span><span class=cFE>1</span><span class=cF0>] &amp;&amp;
<a name="l507"></a> x - </span><span class=cF5>RoundI64</span><span class=cF7>(</span><span class=cF0>x, SCREEN_SCALE</span><span class=cF7>)</span><span class=cF0> &gt; SCREEN_SCALE / </span><span class=cFE>2</span><span class=cF0> ||
<a name="l508"></a> !map[</span><span class=cF7>(</span><span class=cF0>y / SCREEN_SCALE</span><span class=cF7>)</span><span class=cF0> * map_width + x / SCREEN_SCALE - </span><span class=cFE>1</span><span class=cF0>] &amp;&amp;
<a name="l509"></a> x - </span><span class=cF5>RoundI64</span><span class=cF7>(</span><span class=cF0>x, SCREEN_SCALE</span><span class=cF7>)</span><span class=cF0> &lt; SCREEN_SCALE / </span><span class=cFE>2</span><span class=cF0>)
<a name="l510"></a> x = </span><span class=cF5>RoundI64</span><span class=cF0>(x, SCREEN_SCALE) + SCREEN_SCALE / </span><span class=cFE>2</span><span class=cF0>;
<a name="l511"></a>
<a name="l512"></a> </span><span class=cF1>if</span><span class=cF0> (!map[</span><span class=cF7>(</span><span class=cF0>y / SCREEN_SCALE + </span><span class=cFE>1</span><span class=cF7>)</span><span class=cF0> * map_width + x / SCREEN_SCALE] &amp;&amp;
<a name="l513"></a> y - </span><span class=cF5>RoundI64</span><span class=cF7>(</span><span class=cF0>y, SCREEN_SCALE</span><span class=cF7>)</span><span class=cF0> &gt; SCREEN_SCALE / </span><span class=cFE>2</span><span class=cF0> ||
<a name="l514"></a> !map[</span><span class=cF7>(</span><span class=cF0>y / SCREEN_SCALE - </span><span class=cFE>1</span><span class=cF7>)</span><span class=cF0> * map_width + x / SCREEN_SCALE] &amp;&amp;
<a name="l515"></a> y - </span><span class=cF5>RoundI64</span><span class=cF7>(</span><span class=cF0>y, SCREEN_SCALE</span><span class=cF7>)</span><span class=cF0> &lt; SCREEN_SCALE / </span><span class=cFE>2</span><span class=cF0>)
<a name="l516"></a> y = </span><span class=cF5>RoundI64</span><span class=cF0>(y, SCREEN_SCALE) + SCREEN_SCALE / </span><span class=cFE>2</span><span class=cF0>;
<a name="l517"></a> tmpm-&gt;x = x;
<a name="l518"></a> tmpm-&gt;y = y;
<a name="l519"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l520"></a> }
<a name="l521"></a> </span><span class=cF5>Sleep</span><span class=cF0>(</span><span class=cFE>20</span><span class=cF0>);
<a name="l522"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l523"></a>}
<a name="l524"></a>
<a name="l525"></a></span><span class=cF1>U0</span><span class=cF0> CleanUp()
<a name="l526"></a>{
<a name="l527"></a> </span><span class=cF5>Free</span><span class=cF0>(map);
<a name="l528"></a> </span><span class=cF5>Free</span><span class=cF0>(panels_processed_bitmap);
<a name="l529"></a> map = </span><span class=cF3>NULL</span><span class=cF0>;
<a name="l530"></a> panels_processed_bitmap = </span><span class=cF3>NULL</span><span class=cF0>;
<a name="l531"></a>}
<a name="l532"></a>
<a name="l533"></a></span><span class=cF1>U0</span><span class=cF0> SongTask(</span><span class=cF9>I64</span><span class=cF0>)
<a name="l534"></a>{</span><span class=cF2>//Song by Terry A. Davis</span><span class=cF0>
<a name="l535"></a> </span><span class=cF5>Fs</span><span class=cF0>-&gt;task_end_cb = &amp;</span><span class=cF5>SoundTaskEndCB</span><span class=cF0>;
<a name="l536"></a> </span><span class=cF5>MusicSettingsReset</span><span class=cF0>;
<a name="l537"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF3>TRUE</span><span class=cF0>)
<a name="l538"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l539"></a> </span><span class=cF5>Play</span><span class=cF0>(</span><span class=cF6>&quot;3q.A#eGAeA#qAq.A#eGeAeA#qA&quot;</span><span class=cF0>);
<a name="l540"></a> </span><span class=cF5>Play</span><span class=cF0>(</span><span class=cF6>&quot;3q.A#eGA#AqGq.A#eGA#AqG&quot;</span><span class=cF0>);
<a name="l541"></a> </span><span class=cF5>Play</span><span class=cF0>(</span><span class=cF6>&quot;4eA#AqGeA#AqGeA#AGAA#AqG&quot;</span><span class=cF0>);
<a name="l542"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l543"></a>}
<a name="l544"></a>
<a name="l545"></a></span><span class=cF1>U0</span><span class=cF0> MoveMan(</span><span class=cF1>F64</span><span class=cF0> theta)
<a name="l546"></a>{
<a name="l547"></a> </span><span class=cF9>I64</span><span class=cF0> x, y, color, step=SCREEN_SCALE / </span><span class=cFE>2</span><span class=cF0>;
<a name="l548"></a>
<a name="l549"></a> </span><span class=cF1>do</span><span class=cF0>
<a name="l550"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l551"></a> x = man_xx + step * </span><span class=cF5>Cos</span><span class=cF0>(theta);
<a name="l552"></a> y = man_yy - step * </span><span class=cF5>Sin</span><span class=cF0>(theta);
<a name="l553"></a> x = </span><span class=cF5>Clamp</span><span class=cF0>(x, </span><span class=cFE>0</span><span class=cF0>, map_width * SCREEN_SCALE);
<a name="l554"></a> y = </span><span class=cF5>Clamp</span><span class=cF0>(y, </span><span class=cFE>0</span><span class=cF0>, map_height * SCREEN_SCALE);
<a name="l555"></a> color = map[y / SCREEN_SCALE * map_width + x / SCREEN_SCALE];
<a name="l556"></a> </span><span class=cF1>if</span><span class=cF0> (color == </span><span class=cF3>DKGRAY</span><span class=cF0> || color == </span><span class=cF3>GREEN</span><span class=cF0>) {
<a name="l557"></a> man_xx = x;
<a name="l558"></a> man_yy = y;
<a name="l559"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l560"></a> }
<a name="l561"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l562"></a> step &gt;&gt;= </span><span class=cFE>1</span><span class=cF0>;
<a name="l563"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l564"></a> </span><span class=cF1>while</span><span class=cF0> (step);
<a name="l565"></a>}
<a name="l566"></a>
<a name="l567"></a></span><span class=cF2>//#define MICRO_STEPS </span><span class=cF0> </span><span class=cF2>4</span><span class=cF0>
<a name="l568"></a>#</span><span class=cF1>define</span><span class=cF0> MICRO_STEPS </span><span class=cFE>32</span><span class=cF0>
<a name="l569"></a></span><span class=cF1>U0</span><span class=cF0> RotateMan(</span><span class=cF1>F64</span><span class=cF0> d)
<a name="l570"></a>{
<a name="l571"></a> </span><span class=cF9>I64</span><span class=cF0> i;
<a name="l572"></a>
<a name="l573"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>; i &lt; MICRO_STEPS; i++)
<a name="l574"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l575"></a> man_theta += d / MICRO_STEPS;
<a name="l576"></a></span><span class=cF2>//</span><span class=cF0> </span><span class=cF2>Sleep(15);</span><span class=cF0>
<a name="l577"></a> </span><span class=cF5>Sleep</span><span class=cF0>(</span><span class=cFE>1</span><span class=cF0>);
<a name="l578"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l579"></a>}
<a name="l580"></a>
<a name="l581"></a></span><span class=cF1>U0</span><span class=cF0> CastleFrankenstein()
<a name="l582"></a>{
<a name="l583"></a> </span><span class=cF9>I64</span><span class=cF0> sc;
<a name="l584"></a>
<a name="l585"></a> </span><span class=cF5>MenuPush</span><span class=cF0>(
<a name="l586"></a> </span><span class=cF6>&quot;File {&quot;</span><span class=cF0>
<a name="l587"></a> </span><span class=cF6>&quot; Abort(,CH_SHIFT_ESC);&quot;</span><span class=cF0>
<a name="l588"></a> </span><span class=cF6>&quot; Exit(,CH_ESC);&quot;</span><span class=cF0>
<a name="l589"></a> </span><span class=cF6>&quot;}&quot;</span><span class=cF0>
<a name="l590"></a> </span><span class=cF6>&quot;Play {&quot;</span><span class=cF0>
<a name="l591"></a> </span><span class=cF6>&quot; Restart(,'\n');&quot;</span><span class=cF0>
<a name="l592"></a> </span><span class=cF6>&quot; Fwd(,,SC_CURSOR_UP);&quot;</span><span class=cF0>
<a name="l593"></a> </span><span class=cF6>&quot; Bwd(,,SC_CURSOR_DOWN);&quot;</span><span class=cF0>
<a name="l594"></a> </span><span class=cF6>&quot; Left(,,SC_CURSOR_LEFT);&quot;</span><span class=cF0>
<a name="l595"></a> </span><span class=cF6>&quot; Right(,,SC_CURSOR_RIGHT);&quot;</span><span class=cF0>
<a name="l596"></a> </span><span class=cF6>&quot; Fire(,CH_SPACE);&quot;</span><span class=cF0>
<a name="l597"></a> </span><span class=cF6>&quot;}&quot;</span><span class=cF0>
<a name="l598"></a> );
<a name="l599"></a>
<a name="l600"></a> </span><span class=cF5>SettingsPush</span><span class=cF0>; </span><span class=cF2>//See </span><a href="https://tomawezome.github.io/ZealOS/System/TaskSettings.CC.html#l3"><span class=cF4>SettingsPush</span></a><span class=cF0>
<a name="l601"></a> </span><span class=cF5>Fs</span><span class=cF0>-&gt;text_attr = </span><span class=cF3>DKGRAY</span><span class=cF0> &lt;&lt; </span><span class=cFE>4</span><span class=cF0> + </span><span class=cF3>WHITE</span><span class=cF0>;
<a name="l602"></a> </span><span class=cF5>AutoComplete</span><span class=cF0>;
<a name="l603"></a> </span><span class=cF5>WinBorder</span><span class=cF0>;
<a name="l604"></a> </span><span class=cF5>WinMax</span><span class=cF0>;
<a name="l605"></a> </span><span class=cF5>DocCursor</span><span class=cF0>;
<a name="l606"></a> Init;
<a name="l607"></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="l608"></a> </span><span class=cF5>Fs</span><span class=cF0>-&gt;song_task = </span><span class=cF5>Spawn</span><span class=cF0>(&amp;SongTask, </span><span class=cF3>NULL</span><span class=cF0>, </span><span class=cF6>&quot;Song&quot;</span><span class=cF0>,, </span><span class=cF5>Fs</span><span class=cF0>);
<a name="l609"></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="l610"></a>
<a name="l611"></a> </span><span class=cF1>try</span><span class=cF0>
<a name="l612"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l613"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF3>TRUE</span><span class=cF0>)
<a name="l614"></a> {
<a name="l615"></a> </span><span class=cF1>switch</span><span class=cF0> (</span><span class=cF5>KeyGet</span><span class=cF7>(</span><span class=cF0>&amp;sc</span><span class=cF7>)</span><span class=cF0>)
<a name="l616"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l617"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>CH_SPACE</span><span class=cF0>:
<a name="l618"></a> Fire;
<a name="l619"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l620"></a>
<a name="l621"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF6>'\n'</span><span class=cF0>:
<a name="l622"></a> Init;
<a name="l623"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l624"></a>
<a name="l625"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>CH_ESC</span><span class=cF0>:
<a name="l626"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>CH_SHIFT_ESC</span><span class=cF0>:
<a name="l627"></a> </span><span class=cF1>goto</span><span class=cF0> fs_done;
<a name="l628"></a>
<a name="l629"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cFE>0</span><span class=cF0>:
<a name="l630"></a> </span><span class=cF1>switch</span><span class=cF0> (sc.u8[</span><span class=cFE>0</span><span class=cF0>])
<a name="l631"></a> {
<a name="l632"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>SC_CURSOR_RIGHT</span><span class=cF0>:
<a name="l633"></a></span><span class=cF2>//</span><span class=cF0> </span><span class=cF2>Spawn(&amp;RotateMan, (pi / 32)(I64));</span><span class=cF0>
<a name="l634"></a> RotateMan(</span><span class=cF3>pi</span><span class=cF0> / </span><span class=cFE>32</span><span class=cF0>);
<a name="l635"></a> </span><span class=cF5>FlushMessages</span><span class=cF0>;
<a name="l636"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l637"></a>
<a name="l638"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>SC_CURSOR_LEFT</span><span class=cF0>:
<a name="l639"></a></span><span class=cF2>//</span><span class=cF0> </span><span class=cF2>Spawn(&amp;RotateMan, (-pi / 32)(I64));</span><span class=cF0>
<a name="l640"></a> RotateMan(-</span><span class=cF3>pi</span><span class=cF0> / </span><span class=cFE>32</span><span class=cF0>);
<a name="l641"></a> </span><span class=cF5>FlushMessages</span><span class=cF0>;
<a name="l642"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l643"></a>
<a name="l644"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>SC_CURSOR_UP</span><span class=cF0>:
<a name="l645"></a> MoveMan(man_theta);
<a name="l646"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l647"></a>
<a name="l648"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>SC_CURSOR_DOWN</span><span class=cF0>:
<a name="l649"></a> MoveMan(man_theta + </span><span class=cF3>pi</span><span class=cF0>);
<a name="l650"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l651"></a> }
<a name="l652"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l653"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l654"></a> }
<a name="l655"></a>fs_done:
<a name="l656"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l657"></a> </span><span class=cF1>catch</span><span class=cF0>
<a name="l658"></a> </span><span class=cF5>PutExcept</span><span class=cF0>;
<a name="l659"></a> </span><span class=cF5>DocClear</span><span class=cF0>;
<a name="l660"></a> </span><span class=cF5>SettingsPop</span><span class=cF0>;
<a name="l661"></a> CleanUp;
<a name="l662"></a> </span><span class=cF5>MenuPop</span><span class=cF0>;
<a name="l663"></a> </span><span class=cF5>RegWrite</span><span class=cF0>(</span><span class=cF6>&quot;ZealOS/CastleFrankenstein&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="l664"></a>}
<a name="l665"></a>
<a name="l666"></a>CastleFrankenstein;
</span></pre></body>
</html>