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

194 lines
15 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=cF0>#</span><span class=cF1>define</span><span class=cF0> ROAD_NUM 512
<a name="l2"></a>#</span><span class=cF1>define</span><span class=cF0> ROAD_WIDTH_BY_2 200
<a name="l3"></a>#</span><span class=cF1>define</span><span class=cF0> CAR_WIDTH_BY_2 100
<a name="l4"></a>
<a name="l5"></a></span><span class=cF9>I64</span><span class=cF0> road_x[ROAD_NUM],road_trend;
<a name="l6"></a></span><span class=cF1>F64</span><span class=cF0> speed,distance;
<a name="l7"></a></span><span class=cF9>I64</span><span class=cF0> road_ptr=0,car_x;
<a name="l8"></a></span><span class=cF1>F64</span><span class=cF0> t_last;
<a name="l9"></a></span><span class=cF1>Bool</span><span class=cF0> crash;
<a name="l10"></a>
<a name="l11"></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="l12"></a>{
<a name="l13"></a> </span><span class=cF9>I64</span><span class=cF0> w=task-&gt;pix_width,h=task-&gt;pix_height;
<a name="l14"></a> </span><span class=cF9>I64</span><span class=cF0> i,x,y,xx;
<a name="l15"></a> xx=w&gt;&gt;1-car_x+road_x[road_ptr&amp;(ROAD_NUM-1)];
<a name="l16"></a>
<a name="l17"></a> dc-&gt;color=</span><span class=cF3>LTGRAY</span><span class=cF0>;
<a name="l18"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i&lt;ROAD_NUM;i++) </span><span class=cF7>{</span><span class=cF0>
<a name="l19"></a> x=w&gt;&gt;1-car_x+road_x[(i+road_ptr)&amp;(ROAD_NUM-1)];
<a name="l20"></a> y=h-0.5*i;
<a name="l21"></a> </span><span class=cF1>if</span><span class=cF0> (y&lt;</span><span class=cF7>(</span><span class=cF0>h+</span><span class=cF3>FONT_HEIGHT</span><span class=cF7>)</span><span class=cF0>&gt;&gt;1) </span><span class=cF1>break</span><span class=cF0>;
<a name="l22"></a> </span><span class=cF5>GrPlot</span><span class=cF0>(dc,x+ROAD_WIDTH_BY_2-0.4*i,y);
<a name="l23"></a> </span><span class=cF5>GrPlot</span><span class=cF0>(dc,x-ROAD_WIDTH_BY_2+0.4*i,y);
<a name="l24"></a> </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>
<a name="l27"></a> x=w&gt;&gt;1-CAR_WIDTH_BY_2;
<a name="l28"></a> </span><span class=cF1>if</span><span class=cF0> (x&lt;xx-ROAD_WIDTH_BY_2)
<a name="l29"></a> crash=</span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l30"></a> </span><span class=cF5>GrLine</span><span class=cF0>(dc,x-10,h,x-40,h-100);
<a name="l31"></a> </span><span class=cF5>GrLine</span><span class=cF0>(dc,x+10,h,x+40,h-100);
<a name="l32"></a>
<a name="l33"></a> x=w&gt;&gt;1+CAR_WIDTH_BY_2;
<a name="l34"></a> </span><span class=cF1>if</span><span class=cF0> (x&gt;xx+ROAD_WIDTH_BY_2)
<a name="l35"></a> crash=</span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l36"></a> </span><span class=cF5>GrLine</span><span class=cF0>(dc,x-10,h,x-40,h-100);
<a name="l37"></a> </span><span class=cF5>GrLine</span><span class=cF0>(dc,x+10,h,x+40,h-100);
<a name="l38"></a>
<a name="l39"></a> dc-&gt;color=</span><span class=cF3>YELLOW</span><span class=cF0>;
<a name="l40"></a> </span><span class=cF1>if</span><span class=cF0> (crash)
<a name="l41"></a> </span><span class=cF5>GrPrint</span><span class=cF0>(dc,w&gt;&gt;1-</span><span class=cF3>FONT_WIDTH</span><span class=cF0>*4,</span><span class=cF7>(</span><span class=cF0>h-</span><span class=cF3>FONT_HEIGHT</span><span class=cF7>)</span><span class=cF0>&gt;&gt;1,</span><span class=cF6>&quot;Game Over&quot;</span><span class=cF0>);
<a name="l42"></a>}
<a name="l43"></a>
<a name="l44"></a></span><span class=cF1>U0</span><span class=cF0> UpdateRoad()
<a name="l45"></a>{
<a name="l46"></a> </span><span class=cF1>F64</span><span class=cF0> t0=</span><span class=cF5>tS</span><span class=cF0>;
<a name="l47"></a> distance+=speed*(t0-t_last);
<a name="l48"></a> t_last=t0;
<a name="l49"></a> </span><span class=cF1>while</span><span class=cF0> (distance&gt;1.0) </span><span class=cF7>{</span><span class=cF0>
<a name="l50"></a> road_trend=</span><span class=cF5>ClampI64</span><span class=cF0>(road_trend+</span><span class=cF5>SignI64</span><span class=cF7>(</span><span class=cF5>RandU16</span><span class=cF0>%3-1</span><span class=cF7>)</span><span class=cF0>,-5,5);
<a name="l51"></a> road_x[road_ptr&amp;(ROAD_NUM-1)]=
<a name="l52"></a> road_x[(road_ptr-1)&amp;(ROAD_NUM-1)]+=road_trend/3;
<a name="l53"></a> road_ptr++;
<a name="l54"></a> distance-=1.0;
<a name="l55"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l56"></a>}
<a name="l57"></a>
<a name="l58"></a></span><span class=cF1>U0</span><span class=cF0> Init()
<a name="l59"></a>{
<a name="l60"></a> </span><span class=cF9>I64</span><span class=cF0> i,x=0;
<a name="l61"></a> </span><span class=cF5>DocClear</span><span class=cF0>;
<a name="l62"></a> </span><span class=cF6>&quot;$BG,DKGRAY$%h*c&quot;</span><span class=cF0>,(</span><span class=cF3>TEXT_ROWS</span><span class=cF0>-1)/2,</span><span class=cF6>'\n'</span><span class=cF0>;
<a name="l63"></a> speed=0;
<a name="l64"></a> distance=0;
<a name="l65"></a> road_trend=0;
<a name="l66"></a> road_ptr=0;
<a name="l67"></a> car_x=0;
<a name="l68"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i&lt;ROAD_NUM;i++) </span><span class=cF7>{</span><span class=cF0>
<a name="l69"></a> road_x[i]=x;
<a name="l70"></a> road_trend=</span><span class=cF5>ClampI64</span><span class=cF0>(road_trend+</span><span class=cF5>SignI64</span><span class=cF7>(</span><span class=cF5>RandU16</span><span class=cF0>%3-1</span><span class=cF7>)</span><span class=cF0>,-5,5);
<a name="l71"></a> x+=road_trend/3;
<a name="l72"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l73"></a> t_last=</span><span class=cF5>tS</span><span class=cF0>;
<a name="l74"></a> crash=</span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l75"></a>}
<a name="l76"></a>
<a name="l77"></a></span><span class=cF1>U0</span><span class=cF0> Halogen()
<a name="l78"></a>{
<a name="l79"></a> </span><span class=cF9>I64</span><span class=cF0> arg1,arg2,ch=0,sc=0;
<a name="l80"></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="l81"></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="l82"></a> </span><span class=cF5>MenuPush</span><span class=cF0>(
<a name="l83"></a> </span><span class=cF6>&quot;File {&quot;</span><span class=cF0>
<a name="l84"></a> </span><span class=cF6>&quot; Abort(,CH_SHIFT_ESC);&quot;</span><span class=cF0>
<a name="l85"></a> </span><span class=cF6>&quot; Exit(,CH_ESC);&quot;</span><span class=cF0>
<a name="l86"></a> </span><span class=cF6>&quot;}&quot;</span><span class=cF0>
<a name="l87"></a> </span><span class=cF6>&quot;Play {&quot;</span><span class=cF0>
<a name="l88"></a> </span><span class=cF6>&quot; Restart(,'\n');&quot;</span><span class=cF0>
<a name="l89"></a> </span><span class=cF6>&quot; Accelerate(,,SC_CURSOR_UP);&quot;</span><span class=cF0>
<a name="l90"></a> </span><span class=cF6>&quot; Deccellerate(,,SC_CURSOR_DOWN);&quot;</span><span class=cF0>
<a name="l91"></a> </span><span class=cF6>&quot; Left(,,SC_CURSOR_LEFT);&quot;</span><span class=cF0>
<a name="l92"></a> </span><span class=cF6>&quot; Right(,,SC_CURSOR_RIGHT);&quot;</span><span class=cF0>
<a name="l93"></a> </span><span class=cF6>&quot;}&quot;</span><span class=cF0>
<a name="l94"></a> );
<a name="l95"></a> </span><span class=cF5>AutoComplete</span><span class=cF0>;
<a name="l96"></a> </span><span class=cF5>WinBorder</span><span class=cF0>;
<a name="l97"></a> </span><span class=cF5>WinMax</span><span class=cF0>;
<a name="l98"></a> </span><span class=cF5>DocCursor</span><span class=cF0>;
<a name="l99"></a> Init;
<a name="l100"></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="l101"></a> </span><span class=cF1>try</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
<a name="l102"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF3>TRUE</span><span class=cF0>) {
<a name="l103"></a> </span><span class=cF1>switch</span><span class=cF0> (</span><span class=cF5>ScanMsg</span><span class=cF7>(</span><span class=cF0>&amp;arg1,&amp;arg2,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="l104"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>MSG_KEY_DOWN</span><span class=cF0>:
<a name="l105"></a> ch=arg1;sc=arg2;
<a name="l106"></a> </span><span class=cF1>switch</span><span class=cF0> (ch) {
<a name="l107"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF6>'\n'</span><span class=cF0>:
<a name="l108"></a> Init;
<a name="l109"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l110"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>CH_ESC</span><span class=cF0>:
<a name="l111"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>CH_SHIFT_ESC</span><span class=cF0>:
<a name="l112"></a> </span><span class=cF1>goto</span><span class=cF0> ha_done;
<a name="l113"></a> }
<a name="l114"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l115"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>MSG_KEY_UP</span><span class=cF0>:
<a name="l116"></a> ch=arg1;sc=arg2;
<a name="l117"></a> </span><span class=cF1>if</span><span class=cF0> (!ch)
<a name="l118"></a> </span><span class=cF1>switch</span><span class=cF0> (sc.u8[0]) {
<a name="l119"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>SC_CURSOR_RIGHT</span><span class=cF0>:
<a name="l120"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>SC_CURSOR_LEFT</span><span class=cF0>:
<a name="l121"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>SC_CURSOR_UP</span><span class=cF0>:
<a name="l122"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>SC_CURSOR_DOWN</span><span class=cF0>:
<a name="l123"></a> sc=0;
<a name="l124"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l125"></a> }
<a name="l126"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l127"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l128"></a> </span><span class=cF1>switch</span><span class=cF0> (sc.u8[0]) </span><span class=cF7>{</span><span class=cF0>
<a name="l129"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>SC_CURSOR_RIGHT</span><span class=cF0>:
<a name="l130"></a> car_x++;
<a name="l131"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l132"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>SC_CURSOR_LEFT</span><span class=cF0>:
<a name="l133"></a> car_x--;
<a name="l134"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l135"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>SC_CURSOR_UP</span><span class=cF0>:
<a name="l136"></a> </span><span class=cF1>if</span><span class=cF0> (++speed&gt;200) speed=200;
<a name="l137"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l138"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>SC_CURSOR_DOWN</span><span class=cF0>:
<a name="l139"></a> </span><span class=cF1>if</span><span class=cF0> (--speed&lt;0) speed=0;
<a name="l140"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l141"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l142"></a> </span><span class=cF1>if</span><span class=cF0> (crash)
<a name="l143"></a> </span><span class=cF5>Snd</span><span class=cF0>;
<a name="l144"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
<a name="l145"></a> </span><span class=cF1>if</span><span class=cF0> (speed)
<a name="l146"></a> </span><span class=cF5>Snd</span><span class=cF0>(</span><span class=cF5>Freq2Ona</span><span class=cF7>(</span><span class=cF0>speed+10</span><span class=cF7>)</span><span class=cF0>);
<a name="l147"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l148"></a> </span><span class=cF5>Snd</span><span class=cF0>;
<a name="l149"></a> UpdateRoad;
<a name="l150"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l151"></a> </span><span class=cF5>Sleep</span><span class=cF0>(10);
<a name="l152"></a> }
<a name="l153"></a>ha_done:
<a name="l154"></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="l155"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>catch</span><span class=cF0>
<a name="l156"></a> </span><span class=cF5>PutExcept</span><span class=cF0>;
<a name="l157"></a> </span><span class=cF5>MenuPop</span><span class=cF0>;
<a name="l158"></a> </span><span class=cF5>DocClear</span><span class=cF0>;
<a name="l159"></a> </span><span class=cF5>SettingsPop</span><span class=cF0>;
<a name="l160"></a>}
<a name="l161"></a>
<a name="l162"></a>Halogen;
</span></pre></body>
</html>