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

219 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=cF2>//These are the coordinates of the player.</span><span class=cF0>
<a name="l2"></a></span><span class=cF9>I64</span><span class=cF0> x=0,y=</span><span class=cF3>GR_HEIGHT</span><span class=cF0>/2;
<a name="l3"></a>
<a name="l4"></a></span><span class=cF2>/*This is a FIFO (first-in first-out) data structure</span><span class=cF0>
<a name="l5"></a></span><span class=cF2>which keeps track of bullets. When a new bullet is</span><span class=cF0>
<a name="l6"></a></span><span class=cF2>fired, the bullets_in val is increased by one.</span><span class=cF0>
<a name="l7"></a></span><span class=cF2>When a bullet expires, the bullets_out val is increased</span><span class=cF0>
<a name="l8"></a></span><span class=cF2>by one. The in and out vals loop-around, back to</span><span class=cF0>
<a name="l9"></a></span><span class=cF2>the start of the arrays. It is known as a ring-buffer.</span><span class=cF0>
<a name="l10"></a></span><span class=cF2>*/</span><span class=cF0>
<a name="l11"></a>#</span><span class=cF1>define</span><span class=cF0> BULLETS_NUM 32
<a name="l12"></a></span><span class=cF9>I64</span><span class=cF0> bullets_in=0,bullets_out=0,bx[BULLETS_NUM],by[BULLETS_NUM];
<a name="l13"></a>
<a name="l14"></a></span><span class=cF2>//This is a fifo which keeps track of the bad guys.</span><span class=cF0>
<a name="l15"></a>#</span><span class=cF1>define</span><span class=cF0> DEAD_NUM 32
<a name="l16"></a></span><span class=cF9>I64</span><span class=cF0> dead_in=0,dead_out=0,gx[DEAD_NUM],gy[DEAD_NUM];
<a name="l17"></a></span><span class=cF1>Bool</span><span class=cF0> g_dead[DEAD_NUM];
<a name="l18"></a>
<a name="l19"></a></span><span class=cF2>/*This is a sprite created and edited by pressing</span><span class=cF0>
<a name="l20"></a></span><span class=cF2>&lt;CTRL-r&gt;. When created, they are assigned</span><span class=cF0>
<a name="l21"></a></span><span class=cF2>a num.</span><span class=cF0> </span><span class=cF2>Press &lt;CTRL-t&gt;, to see the hidden </span><a href="/Wb/Doc/DolDocOverview.DD.HTML#l1"><span class=cF4>DolDoc</span></a><span class=cF0>
<a name="l22"></a></span><span class=cF2>place holder for the sprite. The text in quotes</span><span class=cF0>
<a name="l23"></a></span><span class=cF2>can be set to whatever you want or nothing,</span><span class=cF0>
<a name="l24"></a></span><span class=cF2>but the ending num can't be changed. It</span><span class=cF0>
<a name="l25"></a></span><span class=cF2>is controled by the editor.</span><span class=cF0>
<a name="l26"></a></span><span class=cF2>*/</span><span class=cFA>
<a name="l27"></a>&lt;1&gt;/* Graphics Not Rendered in HTML */</span><span class=cF0>
<a name="l28"></a>
<a name="l29"></a>
<a name="l30"></a>
<a name="l31"></a> </span><span class=cFA>
<a name="l32"></a>&lt;2&gt;/* Graphics Not Rendered in HTML */</span><span class=cF0>
<a name="l33"></a>
<a name="l34"></a>
<a name="l35"></a>
<a name="l36"></a></span><span class=cFA>
<a name="l37"></a>&lt;3&gt;/* Graphics Not Rendered in HTML */</span><span class=cF0>
<a name="l38"></a>
<a name="l39"></a>
<a name="l40"></a>
<a name="l41"></a>
<a name="l42"></a></span><span class=cF2>//Called by the Window Mgr system task 30fps.</span><span class=cF0>
<a name="l43"></a></span><span class=cF2>//The task arg is the task owning the window.</span><span class=cF0>
<a name="l44"></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="l45"></a>{
<a name="l46"></a> </span><span class=cF9>I64</span><span class=cF0> i,j;
<a name="l47"></a></span><span class=cF2>//&lt;CTRL-t&gt; now to see the </span><a href="/Wb/Doc/DolDocOverview.DD.HTML#l1"><span class=cF4>DolDoc</span></a><span class=cF2> place holder</span><span class=cF0>
<a name="l48"></a> </span><span class=cF2>//where the sprite num is encoded. $IB...$ stands</span><span class=cF0>
<a name="l49"></a> </span><span class=cF2>//for &quot;insert ptr to binary object&quot;.</span><span class=cF0>
<a name="l50"></a> </span><span class=cF5>Sprite3</span><span class=cF0>(dc,x,y,0,</span><span class=cFA>&lt;1&gt;</span><span class=cF0>);
<a name="l51"></a>
<a name="l52"></a> i=bullets_out;
<a name="l53"></a> </span><span class=cF1>while</span><span class=cF0> (i!=bullets_in) </span><span class=cF7>{</span><span class=cF0>
<a name="l54"></a> j=i++ &amp;(BULLETS_NUM-1);
<a name="l55"></a> </span><span class=cF5>GrLine</span><span class=cF0>(dc,bx[j],by[j],bx[j]-2,by[j]);
<a name="l56"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l57"></a> i=dead_out;
<a name="l58"></a> </span><span class=cF1>while</span><span class=cF0> (i!=dead_in) </span><span class=cF7>{</span><span class=cF0>
<a name="l59"></a> j=i++ &amp;(BULLETS_NUM-1);
<a name="l60"></a> </span><span class=cF1>if</span><span class=cF0> (!g_dead[j]) {
<a name="l61"></a> </span><span class=cF1>if</span><span class=cF0> (gx[j]%10&gt;4)
<a name="l62"></a> </span><span class=cF5>Sprite3</span><span class=cF0>(dc,gx[j],gy[j],0,</span><span class=cFA>&lt;2&gt;</span><span class=cF0>);
<a name="l63"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l64"></a> </span><span class=cF5>Sprite3</span><span class=cF0>(dc,gx[j],gy[j],0,</span><span class=cFA>&lt;3&gt;</span><span class=cF0>);
<a name="l65"></a> }
<a name="l66"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l67"></a> dc-&gt;color=</span><span class=cF3>BLACK</span><span class=cF0>;
<a name="l68"></a> </span><span class=cF5>GrPrint</span><span class=cF0>(dc,0,0,</span><span class=cF6>&quot;If you aspire to making games,&quot;</span><span class=cF0>);
<a name="l69"></a> </span><span class=cF5>GrPrint</span><span class=cF0>(dc,0,</span><span class=cF3>FONT_HEIGHT</span><span class=cF0>,</span><span class=cF6>&quot;you must learn to make-up rules.&quot;</span><span class=cF0>);
<a name="l70"></a>}
<a name="l71"></a>
<a name="l72"></a></span><span class=cF1>U0</span><span class=cF0> SongTask(</span><span class=cF9>I64</span><span class=cF0>)
<a name="l73"></a>{</span><span class=cF2>//Randomly generate (by God :-)</span><span class=cF0>
<a name="l74"></a> </span><span class=cF5>Fs</span><span class=cF0>-&gt;task_end_cb=&amp;</span><span class=cF5>SndTaskEndCB</span><span class=cF0>;
<a name="l75"></a> </span><span class=cF5>MusicSettingsRst</span><span class=cF0>;
<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> </span><span class=cF5>Play</span><span class=cF0>(</span><span class=cF6>&quot;5qDqDsDCDC4etB5C4B5qCqCqCqCqDqDsDCDC4etB5C4B5qCqCqCqCqCq&quot;</span><span class=cF0>
<a name="l78"></a> </span><span class=cF6>&quot;CsCCCCetCCBeBBeBBqBqBqCqCsCCCCetCCBeBBeBBqBqB&quot;</span><span class=cF0>);
<a name="l79"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l80"></a>}
<a name="l81"></a>
<a name="l82"></a></span><span class=cF1>U0</span><span class=cF0> TheDead()
<a name="l83"></a>{
<a name="l84"></a> </span><span class=cF9>I64</span><span class=cF0> i,j,i1,j1,k=0,sc=0,ch=0,msg_code,arg1,arg2;
<a name="l85"></a> </span><span class=cF1>Bool</span><span class=cF0> gun_on=</span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l86"></a>
<a name="l87"></a> </span><span class=cF5>MenuPush</span><span class=cF0>(
<a name="l88"></a> </span><span class=cF6>&quot;File {&quot;</span><span class=cF0>
<a name="l89"></a> </span><span class=cF6>&quot; Abort(,CH_SHIFT_ESC);&quot;</span><span class=cF0>
<a name="l90"></a> </span><span class=cF6>&quot; Exit(,CH_ESC);&quot;</span><span class=cF0>
<a name="l91"></a> </span><span class=cF6>&quot;}&quot;</span><span class=cF0>
<a name="l92"></a> </span><span class=cF6>&quot;Play {&quot;</span><span class=cF0>
<a name="l93"></a> </span><span class=cF6>&quot; Fire(,CH_SPACE);&quot;</span><span class=cF0>
<a name="l94"></a> </span><span class=cF6>&quot; Up(,,SC_CURSOR_UP);&quot;</span><span class=cF0>
<a name="l95"></a> </span><span class=cF6>&quot; Down(,,SC_CURSOR_DOWN);&quot;</span><span class=cF0>
<a name="l96"></a> </span><span class=cF6>&quot;}&quot;</span><span class=cF0>
<a name="l97"></a> );
<a name="l98"></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="l99"></a> </span><span class=cF5>AutoComplete</span><span class=cF0>;
<a name="l100"></a> </span><span class=cF5>WinBorder</span><span class=cF0>;
<a name="l101"></a> </span><span class=cF5>WinMax</span><span class=cF0>;
<a name="l102"></a> </span><span class=cF5>DocCursor</span><span class=cF0>;
<a name="l103"></a> </span><span class=cF5>DocClear</span><span class=cF0>;
<a name="l104"></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="l105"></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="l106"></a>
<a name="l107"></a> </span><span class=cF1>try</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
<a name="l108"></a> </span><span class=cF1>do</span><span class=cF0> {
<a name="l109"></a> </span><span class=cF1>if</span><span class=cF0> (msg_code=</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="l110"></a></span><span class=cF2>//With </span><a href="/Wb/Doc/CharOverview.DD.HTML#l1"><span class=cF4>keyboard</span></a><span class=cF2> msgs, the two msg args</span><span class=cF0>
<a name="l111"></a> </span><span class=cF2>//are the scan code and ascii val for the key.</span><span class=cF0>
<a name="l112"></a> sc=arg2; ch=arg1;
<a name="l113"></a>
<a name="l114"></a> </span><span class=cF1>if</span><span class=cF0> (msg_code==</span><span class=cF3>MSG_KEY_DOWN</span><span class=cF0>) {
<a name="l115"></a></span><span class=cF2>//The low byte of the scan code identifies the key.</span><span class=cF0>
<a name="l116"></a> </span><span class=cF1>if</span><span class=cF0> (sc.u8[0]==</span><span class=cF3>SC_CURSOR_DOWN</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l117"></a> y+=10;
<a name="l118"></a> </span><span class=cF1>if</span><span class=cF0> (y&gt;</span><span class=cF3>GR_HEIGHT</span><span class=cF0>-30)
<a name="l119"></a> y=</span><span class=cF3>GR_HEIGHT</span><span class=cF0>-30;
<a name="l120"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (sc.u8[0]==</span><span class=cF3>SC_CURSOR_UP</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l121"></a> y-=10;
<a name="l122"></a> </span><span class=cF1>if</span><span class=cF0> (y&lt;0)
<a name="l123"></a> y=0;
<a name="l124"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (sc.u8[0]==</span><span class=cF3>SC_CURSOR_RIGHT</span><span class=cF0> ||
<a name="l125"></a> ch==</span><span class=cF3>CH_SPACE</span><span class=cF0>)
<a name="l126"></a> gun_on=</span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l127"></a> } </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (msg_code==</span><span class=cF3>MSG_KEY_UP</span><span class=cF0>) {
<a name="l128"></a> </span><span class=cF1>if</span><span class=cF0> (sc.u8[0]==</span><span class=cF3>SC_CURSOR_RIGHT</span><span class=cF0> ||
<a name="l129"></a> ch==</span><span class=cF3>CH_SPACE</span><span class=cF0>)
<a name="l130"></a> gun_on=</span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l131"></a> }
<a name="l132"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l133"></a>
<a name="l134"></a> i=bullets_out;
<a name="l135"></a> </span><span class=cF1>while</span><span class=cF0> (i!=bullets_in) </span><span class=cF7>{</span><span class=cF0>
<a name="l136"></a> j=i++ &amp;(BULLETS_NUM-1);
<a name="l137"></a> bx[j]+=5;
<a name="l138"></a> </span><span class=cF1>if</span><span class=cF0> (bx[j]&gt;</span><span class=cF3>GR_WIDTH</span><span class=cF0>)
<a name="l139"></a> bullets_out++;
<a name="l140"></a> </span><span class=cF1>else</span><span class=cF0> {
<a name="l141"></a> i1=dead_out;
<a name="l142"></a> </span><span class=cF1>while</span><span class=cF0> (i1!=dead_in) </span><span class=cF7>{</span><span class=cF0>
<a name="l143"></a> j1=i1++ &amp;(DEAD_NUM-1);
<a name="l144"></a> </span><span class=cF1>if</span><span class=cF0> (gy[j1]&lt;=by[j]&lt;=gy[j1]+38 &amp;&amp;
<a name="l145"></a> gx[j1]&lt;=bx[j]&lt;=gx[j1]+40)
<a name="l146"></a> g_dead[j1]=</span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l147"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l148"></a> }
<a name="l149"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l150"></a>
<a name="l151"></a> </span><span class=cF1>if</span><span class=cF0> (gun_on) </span><span class=cF7>{</span><span class=cF0>
<a name="l152"></a> j=bullets_in&amp;(BULLETS_NUM-1);
<a name="l153"></a> bx[j]=x+32;
<a name="l154"></a> by[j]=y+14;
<a name="l155"></a> bullets_in++;
<a name="l156"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l157"></a>
<a name="l158"></a> </span><span class=cF2>//Runs one out of four passes through this loop.</span><span class=cF0>
<a name="l159"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF7>(</span><span class=cF0>k % 4</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l160"></a> i=dead_out;
<a name="l161"></a> </span><span class=cF1>while</span><span class=cF0> (i!=dead_in) {
<a name="l162"></a> j=i++ &amp;(DEAD_NUM-1);
<a name="l163"></a> gx[j]-=1;
<a name="l164"></a> </span><span class=cF1>if</span><span class=cF0> (gx[j]&lt;25)
<a name="l165"></a> dead_out++;
<a name="l166"></a> }
<a name="l167"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l168"></a>
<a name="l169"></a> </span><span class=cF2>//Runs one out of 150 passes through this loop.</span><span class=cF0>
<a name="l170"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF7>(</span><span class=cF0>k%150</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l171"></a> j=dead_in&amp;(DEAD_NUM-1);
<a name="l172"></a> gx[j]=</span><span class=cF3>GR_WIDTH</span><span class=cF0>-30;
<a name="l173"></a> gy[j]=</span><span class=cF5>RandU32</span><span class=cF0>%(</span><span class=cF3>GR_HEIGHT</span><span class=cF0>-50)+25;
<a name="l174"></a> g_dead[j]=</span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l175"></a> dead_in++;
<a name="l176"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l177"></a> k++;
<a name="l178"></a>
<a name="l179"></a> </span><span class=cF5>Sleep</span><span class=cF0>(10); </span><span class=cF2>//Swap this task out for 10 miliseconds.</span><span class=cF0>
<a name="l180"></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="l181"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>catch</span><span class=cF0>
<a name="l182"></a> </span><span class=cF5>PutExcept</span><span class=cF0>;
<a name="l183"></a> </span><span class=cF5>SettingsPop</span><span class=cF0>;
<a name="l184"></a> </span><span class=cF5>MenuPop</span><span class=cF0>;
<a name="l185"></a>}
<a name="l186"></a>
<a name="l187"></a>TheDead; </span><span class=cF2>//Run program when #included</span><span class=cF0>
</span></pre></body>
</html>