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

221 lines
18 KiB
HTML
Executable File

<!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">
.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=cF9>I64</span><span class=cF0> sc_1,sc_2;
<a name="l2"></a>
<a name="l3"></a>#</span><span class=cF1>define</span><span class=cF0> DROPS_NUM 0x2000
<a name="l4"></a>
<a name="l5"></a></span><span class=cF1>class</span><span class=cF0> Drop
<a name="l6"></a>{
<a name="l7"></a> </span><span class=cF9>I32</span><span class=cF0> x,y;
<a name="l8"></a>} drops[DROPS_NUM];
<a name="l9"></a>
<a name="l10"></a></span><span class=cF9>CDC</span><span class=cF0> *cur_dc;
<a name="l11"></a>
<a name="l12"></a></span><span class=cF1>U0</span><span class=cF0> DrawFrame(</span><span class=cF9>CTask</span><span class=cF0> *task,</span><span class=cF9>CDC</span><span class=cF0> *dc)
<a name="l13"></a>{
<a name="l14"></a> </span><span class=cF9>I64</span><span class=cF0> w=task-&gt;pix_width,h=task-&gt;pix_height,
<a name="l15"></a> cx=w&gt;&gt;1,cy=h&gt;&gt;1;
<a name="l16"></a>
<a name="l17"></a> dc-&gt;color=</span><span class=cF3>LTRED</span><span class=cF0>;
<a name="l18"></a> </span><span class=cF5>GrLine</span><span class=cF0>(dc,cx-20,cy-50,cx,cy-150);
<a name="l19"></a> </span><span class=cF5>GrLine</span><span class=cF0>(dc,cx+20,cy-50,cx,cy-150);
<a name="l20"></a>
<a name="l21"></a> dc-&gt;color=</span><span class=cF3>LTRED</span><span class=cF0>;
<a name="l22"></a> </span><span class=cF5>GrLine</span><span class=cF0>(dc,cx-100,cy-100,cx,cy);
<a name="l23"></a> </span><span class=cF5>GrLine</span><span class=cF0>(dc,cx+100,cy-100,cx,cy);
<a name="l24"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cFB>kbd</span><span class=cF0>.down_bitmap,sc_1</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l25"></a> dc-&gt;color=</span><span class=cF3>WHITE</span><span class=cF0>;
<a name="l26"></a> </span><span class=cF5>GrRect</span><span class=cF0>(dc,cx-2,cy-2,5,5);
<a name="l27"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l28"></a> dc-&gt;color=</span><span class=cF3>BLACK</span><span class=cF0>;
<a name="l29"></a> </span><span class=cF5>GrPrint</span><span class=cF0>(dc,cx+10,cy,</span><span class=cF6>&quot;Press '1'&quot;</span><span class=cF0>);
<a name="l30"></a>
<a name="l31"></a> dc-&gt;color=</span><span class=cF3>LTRED</span><span class=cF0>;
<a name="l32"></a> </span><span class=cF5>GrRect</span><span class=cF0>(dc,cx-20,cy+60,41,21);
<a name="l33"></a>
<a name="l34"></a> dc-&gt;color=</span><span class=cF3>LTRED</span><span class=cF0>;
<a name="l35"></a> </span><span class=cF5>GrLine</span><span class=cF0>(dc,cx-200,cy,cx,cy+100);
<a name="l36"></a> </span><span class=cF5>GrLine</span><span class=cF0>(dc,cx+200,cy,cx,cy+100);
<a name="l37"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cFB>kbd</span><span class=cF0>.down_bitmap,sc_2</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l38"></a> dc-&gt;color=</span><span class=cF3>WHITE</span><span class=cF0>;
<a name="l39"></a> </span><span class=cF5>GrRect</span><span class=cF0>(dc,cx-2,cy+100-2,5,5);
<a name="l40"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l41"></a> dc-&gt;color=</span><span class=cF3>BLACK</span><span class=cF0>;
<a name="l42"></a> </span><span class=cF5>GrPrint</span><span class=cF0>(dc,cx+10,cy+100,</span><span class=cF6>&quot;Press '2'&quot;</span><span class=cF0>);
<a name="l43"></a>
<a name="l44"></a> dc-&gt;color=</span><span class=cF3>LTRED</span><span class=cF0>;
<a name="l45"></a> </span><span class=cF5>GrLine</span><span class=cF0>(dc,cx+400,cy+100,cx-250,cy+200);
<a name="l46"></a>}
<a name="l47"></a>
<a name="l48"></a></span><span class=cF1>U0</span><span class=cF0> DrawDrops(</span><span class=cF9>CTask</span><span class=cF0> *,</span><span class=cF9>CDC</span><span class=cF0> *dc)
<a name="l49"></a>{
<a name="l50"></a> </span><span class=cF9>I64</span><span class=cF0> i;
<a name="l51"></a> dc-&gt;color=</span><span class=cF3>BLUE</span><span class=cF0>;
<a name="l52"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i&lt;DROPS_NUM;i++)
<a name="l53"></a> </span><span class=cF1>if</span><span class=cF0> (drops[i].y&gt;=0 &amp;&amp; </span><span class=cF5>GrPeek</span><span class=cF7>(</span><span class=cF0>dc,drops[i].x,drops[i].y</span><span class=cF7>)</span><span class=cF0>==</span><span class=cF3>WHITE</span><span class=cF0>)
<a name="l54"></a> </span><span class=cF5>GrPlot</span><span class=cF0>(dc,drops[i].x,drops[i].y);
<a name="l55"></a>}
<a name="l56"></a>
<a name="l57"></a></span><span class=cF1>U0</span><span class=cF0> UpdateCurBase(</span><span class=cF9>CTask</span><span class=cF0> *task,</span><span class=cF9>CDC</span><span class=cF0> *dc)
<a name="l58"></a>{
<a name="l59"></a> cur_dc-&gt;color=</span><span class=cF3>ROP_EQU</span><span class=cF0>;
<a name="l60"></a> dc-&gt;flags|=</span><span class=cF3>DCF_NO_TRANSPARENTS</span><span class=cF0>;
<a name="l61"></a> </span><span class=cF5>GrBlot</span><span class=cF0>(cur_dc,-task-&gt;pix_left-task-&gt;scroll_x,
<a name="l62"></a> -task-&gt;pix_top-task-&gt;scroll_y,dc);
<a name="l63"></a> dc-&gt;flags&amp;=~</span><span class=cF3>DCF_NO_TRANSPARENTS</span><span class=cF0>;
<a name="l64"></a>}
<a name="l65"></a>
<a name="l66"></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="l67"></a>{
<a name="l68"></a> DrawFrame(task,dc);
<a name="l69"></a> DrawDrops(task,dc);
<a name="l70"></a> UpdateCurBase(task,dc);
<a name="l71"></a>}
<a name="l72"></a>
<a name="l73"></a></span><span class=cF1>U0</span><span class=cF0> AnimateTask(</span><span class=cF9>I64</span><span class=cF0>)
<a name="l74"></a>{
<a name="l75"></a> </span><span class=cF9>I64</span><span class=cF0> i,j,cur_drop=0,c1,c2,x0,y0,x1,y1,w,h;
<a name="l76"></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="l77"></a> w=</span><span class=cF5>Fs</span><span class=cF0>-&gt;parent_task-&gt;pix_width;
<a name="l78"></a> h=</span><span class=cF5>Fs</span><span class=cF0>-&gt;parent_task-&gt;pix_height;
<a name="l79"></a>
<a name="l80"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i&lt;2;i++) {
<a name="l81"></a> j=0;
<a name="l82"></a> </span><span class=cF1>do</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
<a name="l83"></a> </span><span class=cF1>if</span><span class=cF0> (++cur_drop&gt;=DROPS_NUM)
<a name="l84"></a> cur_drop=0;
<a name="l85"></a> </span><span class=cF1>if</span><span class=cF0> (drops[cur_drop].y&lt;0)
<a name="l86"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l87"></a> j++;
<a name="l88"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>while</span><span class=cF0> (j&lt;=DROPS_NUM);
<a name="l89"></a>
<a name="l90"></a> drops[cur_drop].x=</span><span class=cF5>RandU32</span><span class=cF0>%w;
<a name="l91"></a> drops[cur_drop].y=0;
<a name="l92"></a> }
<a name="l93"></a>
<a name="l94"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i&lt;DROPS_NUM;i++) {
<a name="l95"></a> </span><span class=cF1>if</span><span class=cF0> (drops[i].y&gt;=0) </span><span class=cF7>{</span><span class=cF0>
<a name="l96"></a> </span><span class=cF1>if</span><span class=cF0> (drops[i].y&gt;=h-1)
<a name="l97"></a> drops[i].y=-</span><span class=cF3>I32_MAX</span><span class=cF0>;
<a name="l98"></a> </span><span class=cF1>else</span><span class=cF0> {
<a name="l99"></a> x0=x1=drops[i].x;
<a name="l100"></a> y0=y1=drops[i].y;
<a name="l101"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>GrPeek</span><span class=cF7>(</span><span class=cF0>cur_dc,x0,y0+1</span><span class=cF7>)</span><span class=cF0>==</span><span class=cF3>WHITE</span><span class=cF0>)
<a name="l102"></a> y1++;
<a name="l103"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
<a name="l104"></a> c1=</span><span class=cF5>GrPeek</span><span class=cF0>(cur_dc,x0+1,y0);
<a name="l105"></a> c2=</span><span class=cF5>GrPeek</span><span class=cF0>(cur_dc,x0-1,y0);
<a name="l106"></a> </span><span class=cF1>if</span><span class=cF0> (c1==</span><span class=cF3>WHITE</span><span class=cF0> &amp;&amp; c2!=</span><span class=cF3>WHITE</span><span class=cF0>)
<a name="l107"></a> x1++;
<a name="l108"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (c2==</span><span class=cF3>WHITE</span><span class=cF0> &amp;&amp; c1!=</span><span class=cF3>WHITE</span><span class=cF0>)
<a name="l109"></a> x1--;
<a name="l110"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (c1==</span><span class=cF3>WHITE</span><span class=cF0> &amp;&amp; c2==</span><span class=cF3>WHITE</span><span class=cF0>) {
<a name="l111"></a> c1=</span><span class=cF5>GrPeek</span><span class=cF0>(cur_dc,x0+1,y0+1);
<a name="l112"></a> c2=</span><span class=cF5>GrPeek</span><span class=cF0>(cur_dc,x0-1,y0+1);
<a name="l113"></a> </span><span class=cF1>if</span><span class=cF0> (c1==</span><span class=cF3>WHITE</span><span class=cF0> &amp;&amp; c2!=</span><span class=cF3>WHITE</span><span class=cF0>)
<a name="l114"></a> x1++;
<a name="l115"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (c2==</span><span class=cF3>WHITE</span><span class=cF0> &amp;&amp; c1!=</span><span class=cF3>WHITE</span><span class=cF0>)
<a name="l116"></a> x1--;
<a name="l117"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>RandI16</span><span class=cF0>&gt;=0)
<a name="l118"></a> x1++;
<a name="l119"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l120"></a> x1--;
<a name="l121"></a> }
<a name="l122"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>GrPeek</span><span class=cF7>(</span><span class=cF0>cur_dc,x1,y1+1</span><span class=cF7>)</span><span class=cF0>==</span><span class=cF3>WHITE</span><span class=cF0>)
<a name="l123"></a> y1++;
<a name="l124"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l125"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>GrPeek</span><span class=cF7>(</span><span class=cF0>cur_dc,x0,y0</span><span class=cF7>)</span><span class=cF0>==</span><span class=cF3>BLUE</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l126"></a> cur_dc-&gt;color=</span><span class=cF3>WHITE</span><span class=cF0>;
<a name="l127"></a> </span><span class=cF5>GrPlot</span><span class=cF0>(cur_dc,x0,y0);
<a name="l128"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l129"></a> cur_dc-&gt;color=</span><span class=cF3>BLUE</span><span class=cF0>;
<a name="l130"></a> </span><span class=cF5>GrPlot</span><span class=cF0>(cur_dc,x1,y1);
<a name="l131"></a> drops[i].x=x1;
<a name="l132"></a> drops[i].y=y1;
<a name="l133"></a> }
<a name="l134"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l135"></a> }
<a name="l136"></a> </span><span class=cF5>Sleep</span><span class=cF0>(10);
<a name="l137"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l138"></a>}
<a name="l139"></a>
<a name="l140"></a></span><span class=cF1>U0</span><span class=cF0> Init()
<a name="l141"></a>{
<a name="l142"></a> </span><span class=cF9>I64</span><span class=cF0> i;
<a name="l143"></a> </span><span class=cF5>MemSet</span><span class=cF0>(drops,0,</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF0>drops</span><span class=cF7>)</span><span class=cF0>);
<a name="l144"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i&lt;DROPS_NUM;i++)
<a name="l145"></a> drops[i].y=-</span><span class=cF3>I32_MAX</span><span class=cF0>;
<a name="l146"></a>}
<a name="l147"></a>
<a name="l148"></a></span><span class=cF1>U0</span><span class=cF0> RainDrops()
<a name="l149"></a>{
<a name="l150"></a> </span><span class=cF9>I64</span><span class=cF0> ch,sc;
<a name="l151"></a> </span><span class=cF5>MenuPush</span><span class=cF0>(
<a name="l152"></a> </span><span class=cF6>&quot;File {&quot;</span><span class=cF0>
<a name="l153"></a> </span><span class=cF6>&quot; Abort(,CH_SHIFT_ESC);&quot;</span><span class=cF0>
<a name="l154"></a> </span><span class=cF6>&quot; Exit(,CH_ESC);&quot;</span><span class=cF0>
<a name="l155"></a> </span><span class=cF6>&quot;}&quot;</span><span class=cF0>
<a name="l156"></a> </span><span class=cF6>&quot;Play {&quot;</span><span class=cF0>
<a name="l157"></a> </span><span class=cF6>&quot; Restart(,'\n');&quot;</span><span class=cF0>
<a name="l158"></a> </span><span class=cF6>&quot; OpenUpper(,'1');&quot;</span><span class=cF0>
<a name="l159"></a> </span><span class=cF6>&quot; OpenLower(,'2');&quot;</span><span class=cF0>
<a name="l160"></a> </span><span class=cF6>&quot;}&quot;</span><span class=cF0>
<a name="l161"></a> );
<a name="l162"></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="l163"></a> </span><span class=cF5>AutoComplete</span><span class=cF0>;
<a name="l164"></a> </span><span class=cF5>WinBorder</span><span class=cF0>;
<a name="l165"></a> </span><span class=cF5>WinMax</span><span class=cF0>;
<a name="l166"></a> </span><span class=cF5>DocCursor</span><span class=cF0>;
<a name="l167"></a> </span><span class=cF5>DocClear</span><span class=cF0>;
<a name="l168"></a> cur_dc=</span><span class=cF5>DCNew</span><span class=cF0>(</span><span class=cF3>GR_WIDTH</span><span class=cF0>,</span><span class=cF3>GR_HEIGHT</span><span class=cF0>);
<a name="l169"></a> sc_1=</span><span class=cF5>Char2ScanCode</span><span class=cF0>(</span><span class=cF6>'1'</span><span class=cF0>);
<a name="l170"></a> sc_2=</span><span class=cF5>Char2ScanCode</span><span class=cF0>(</span><span class=cF6>'2'</span><span class=cF0>);
<a name="l171"></a> Init;
<a name="l172"></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="l173"></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="l174"></a> </span><span class=cF1>try</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
<a name="l175"></a> </span><span class=cF1>do</span><span class=cF0>
<a name="l176"></a> </span><span class=cF1>switch</span><span class=cF0> (ch=</span><span class=cF5>GetKey</span><span class=cF7>(</span><span class=cF0>&amp;sc</span><span class=cF7>)</span><span class=cF0>) {
<a name="l177"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF6>'\n'</span><span class=cF0>:
<a name="l178"></a> Init;
<a name="l179"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l180"></a> }
<a name="l181"></a> </span><span class=cF1>while</span><span class=cF0> (ch!=</span><span class=cF3>CH_ESC</span><span class=cF0> &amp;&amp; ch!=</span><span class=cF3>CH_SHIFT_ESC</span><span class=cF0>);
<a name="l182"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>catch</span><span class=cF0>
<a name="l183"></a> </span><span class=cF5>PutExcept</span><span class=cF0>;
<a name="l184"></a> </span><span class=cF5>SettingsPop</span><span class=cF0>;
<a name="l185"></a> </span><span class=cF5>MenuPop</span><span class=cF0>;
<a name="l186"></a> </span><span class=cF5>DCDel</span><span class=cF0>(cur_dc);
<a name="l187"></a>}
<a name="l188"></a>
<a name="l189"></a>RainDrops;
</span></pre></body>
</html>