ZealOS/docs/Demo/Games/TheDead.CC

236 lines
22 KiB
HolyC
Executable file

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=US-ASCII">
<meta name="generator" content="ZealOS V0.05">
<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>//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 = </span><span class=cFE>0</span><span class=cF0>, y = </span><span class=cF3>GR_HEIGHT</span><span class=cF0> / </span><span class=cFE>2</span><span class=cF0>;
<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.</span><span class=cF0> </span><span class=cF2>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 </span><span class=cFE>32</span><span class=cF0>
<a name="l12"></a></span><span class=cF9>I64</span><span class=cF0> bullets_in = </span><span class=cFE>0</span><span class=cF0>, bullets_out = </span><span class=cFE>0</span><span class=cF0>, 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 </span><span class=cFE>32</span><span class=cF0>
<a name="l16"></a></span><span class=cF9>I64</span><span class=cF0> dead_in = </span><span class=cFE>0</span><span class=cF0>, dead_out = </span><span class=cFE>0</span><span class=cF0>, 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="https://tomawezome.github.io/ZealOS/Doc/DolDocOverview.html#l1"><span class=cF4>DolDoc</span></a><span class=cF0>
<a name="l22"></a></span><span class=cF2>place holder for the sprite.</span><span class=cF0> </span><span class=cF2>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.</span><span class=cF0> </span><span class=cF2>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 60fps.</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="https://tomawezome.github.io/ZealOS/Doc/DolDocOverview.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, </span><span class=cFE>0</span><span class=cF0>, </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)
<a name="l54"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l55"></a> j = i++ &amp; (BULLETS_NUM - </span><span class=cFE>1</span><span class=cF0>);
<a name="l56"></a> </span><span class=cF5>GrLine</span><span class=cF0>(dc, bx[j], by[j], bx[j] - </span><span class=cFE>2</span><span class=cF0>, by[j]);
<a name="l57"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l58"></a> i = dead_out;
<a name="l59"></a> </span><span class=cF1>while</span><span class=cF0> (i != dead_in)
<a name="l60"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l61"></a> j = i++ &amp; (BULLETS_NUM - </span><span class=cFE>1</span><span class=cF0>);
<a name="l62"></a> </span><span class=cF1>if</span><span class=cF0> (!g_dead[j])
<a name="l63"></a> {
<a name="l64"></a> </span><span class=cF1>if</span><span class=cF0> (gx[j] % </span><span class=cFE>10</span><span class=cF0> &gt; </span><span class=cFE>4</span><span class=cF0>)
<a name="l65"></a> </span><span class=cF5>Sprite3</span><span class=cF0>(dc, gx[j], gy[j], </span><span class=cFE>0</span><span class=cF0>, </span><span class=cFA>&lt;2&gt;</span><span class=cF0>);
<a name="l66"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l67"></a> </span><span class=cF5>Sprite3</span><span class=cF0>(dc, gx[j], gy[j], </span><span class=cFE>0</span><span class=cF0>, </span><span class=cFA>&lt;3&gt;</span><span class=cF0>);
<a name="l68"></a> }
<a name="l69"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l70"></a> dc-&gt;color = </span><span class=cF3>BLACK</span><span class=cF0>;
<a name="l71"></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;If you aspire to making games,&quot;</span><span class=cF0>);
<a name="l72"></a> </span><span class=cF5>GrPrint</span><span class=cF0>(dc, </span><span class=cFE>0</span><span class=cF0>, </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="l73"></a>}
<a name="l74"></a>
<a name="l75"></a></span><span class=cF1>U0</span><span class=cF0> SongTask(</span><span class=cF9>I64</span><span class=cF0>)
<a name="l76"></a>{</span><span class=cF2>//Randomly generate (by God :-)</span><span class=cF0>
<a name="l77"></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="l78"></a> </span><span class=cF5>MusicSettingsReset</span><span class=cF0>;
<a name="l79"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF3>TRUE</span><span class=cF0>)
<a name="l80"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l81"></a> </span><span class=cF5>Play</span><span class=cF0>(</span><span class=cF6>&quot;5qDqDsDCDC4etB5C4B5qCqCqCqCqDqDsDCDC4etB5C4B5qCqCqCqCqCqCsCCCCetCCBeBBeBBqBqBqCqCsCCCCetCCBeBBeBBqBqB&quot;</span><span class=cF0>);
<a name="l82"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l83"></a>}
<a name="l84"></a>
<a name="l85"></a></span><span class=cF1>U0</span><span class=cF0> TheDead()
<a name="l86"></a>{
<a name="l87"></a> </span><span class=cF9>I64</span><span class=cF0> i, j, i1, j1, k = </span><span class=cFE>0</span><span class=cF0>, sc = </span><span class=cFE>0</span><span class=cF0>, ch = </span><span class=cFE>0</span><span class=cF0>, message_code, arg1, arg2;
<a name="l88"></a> </span><span class=cF1>Bool</span><span class=cF0> gun_on = </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l89"></a>
<a name="l90"></a> </span><span class=cF5>MenuPush</span><span class=cF0>( </span><span class=cF6>&quot;File {&quot;</span><span class=cF0>
<a name="l91"></a> </span><span class=cF6>&quot; Abort(,CH_SHIFT_ESC);&quot;</span><span class=cF0>
<a name="l92"></a> </span><span class=cF6>&quot; Exit(,CH_ESC);&quot;</span><span class=cF0>
<a name="l93"></a> </span><span class=cF6>&quot;}&quot;</span><span class=cF0>
<a name="l94"></a> </span><span class=cF6>&quot;Play {&quot;</span><span class=cF0>
<a name="l95"></a> </span><span class=cF6>&quot; Fire(,CH_SPACE);&quot;</span><span class=cF0>
<a name="l96"></a> </span><span class=cF6>&quot; Up(,,SC_CURSOR_UP);&quot;</span><span class=cF0>
<a name="l97"></a> </span><span class=cF6>&quot; Down(,,SC_CURSOR_DOWN);&quot;</span><span class=cF0>
<a name="l98"></a> </span><span class=cF6>&quot;}&quot;</span><span class=cF0>
<a name="l99"></a> );
<a name="l100"></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.html#l3"><span class=cF4>SettingsPush</span></a><span class=cF0>
<a name="l101"></a> </span><span class=cF5>AutoComplete</span><span class=cF0>;
<a name="l102"></a> </span><span class=cF5>WinBorder</span><span class=cF0>;
<a name="l103"></a> </span><span class=cF5>WinMax</span><span class=cF0>;
<a name="l104"></a> </span><span class=cF5>DocCursor</span><span class=cF0>;
<a name="l105"></a> </span><span class=cF5>DocClear</span><span class=cF0>;
<a name="l106"></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="l107"></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="l108"></a>
<a name="l109"></a> </span><span class=cF1>try</span><span class=cF0>
<a name="l110"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l111"></a> </span><span class=cF1>do</span><span class=cF0>
<a name="l112"></a> {
<a name="l113"></a> </span><span class=cF1>if</span><span class=cF0> (message_code = </span><span class=cF5>MessageScan</span><span class=cF7>(</span><span class=cF0>&amp;arg1, &amp;arg2, </span><span class=cFE>1</span><span class=cF0> &lt;&lt; </span><span class=cF3>MESSAGE_KEY_DOWN</span><span class=cF0> | </span><span class=cFE>1</span><span class=cF0> &lt;&lt; </span><span class=cF3>MESSAGE_KEY_UP</span><span class=cF7>)</span><span class=cF0>)
<a name="l114"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l115"></a> </span><span class=cF2>//With </span><a href="https://tomawezome.github.io/ZealOS/Doc/CharOverview.html#l1"><span class=cF4>keyboard</span></a><span class=cF2> messages, the two message args</span><span class=cF0>
<a name="l116"></a> </span><span class=cF2>//are the scan code and ascii val for the key.</span><span class=cF0>
<a name="l117"></a> sc = arg2;
<a name="l118"></a> ch = arg1;
<a name="l119"></a>
<a name="l120"></a> </span><span class=cF1>if</span><span class=cF0> (message_code == </span><span class=cF3>MESSAGE_KEY_DOWN</span><span class=cF0>)
<a name="l121"></a> {
<a name="l122"></a> </span><span class=cF2>//The low byte of the scan code identifies the key.</span><span class=cF0>
<a name="l123"></a> </span><span class=cF1>if</span><span class=cF0> (sc.u8[</span><span class=cFE>0</span><span class=cF0>] == </span><span class=cF3>SC_CURSOR_DOWN</span><span class=cF0>)
<a name="l124"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l125"></a> y += </span><span class=cFE>10</span><span class=cF0>;
<a name="l126"></a> </span><span class=cF1>if</span><span class=cF0> (y &gt; </span><span class=cF3>GR_HEIGHT</span><span class=cF0> - </span><span class=cFE>30</span><span class=cF0>)
<a name="l127"></a> y = </span><span class=cF3>GR_HEIGHT</span><span class=cF0> - </span><span class=cFE>30</span><span class=cF0>;
<a name="l128"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l129"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (sc.u8[</span><span class=cFE>0</span><span class=cF0>] == </span><span class=cF3>SC_CURSOR_UP</span><span class=cF0>)
<a name="l130"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l131"></a> y -= </span><span class=cFE>10</span><span class=cF0>;
<a name="l132"></a> </span><span class=cF1>if</span><span class=cF0> (y &lt; </span><span class=cFE>0</span><span class=cF0>)
<a name="l133"></a> y = </span><span class=cFE>0</span><span class=cF0>;
<a name="l134"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l135"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (sc.u8[</span><span class=cFE>0</span><span class=cF0>] == </span><span class=cF3>SC_CURSOR_RIGHT</span><span class=cF0> || ch == </span><span class=cF3>CH_SPACE</span><span class=cF0>)
<a name="l136"></a> gun_on = </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l137"></a> }
<a name="l138"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (message_code == </span><span class=cF3>MESSAGE_KEY_UP</span><span class=cF0>)
<a name="l139"></a> {
<a name="l140"></a> </span><span class=cF1>if</span><span class=cF0> (sc.u8[</span><span class=cFE>0</span><span class=cF0>] == </span><span class=cF3>SC_CURSOR_RIGHT</span><span class=cF0> || ch == </span><span class=cF3>CH_SPACE</span><span class=cF0>)
<a name="l141"></a> gun_on = </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l142"></a> }
<a name="l143"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l144"></a>
<a name="l145"></a> i = bullets_out;
<a name="l146"></a> </span><span class=cF1>while</span><span class=cF0> (i != bullets_in)
<a name="l147"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l148"></a> j = i++ &amp; (BULLETS_NUM - </span><span class=cFE>1</span><span class=cF0>);
<a name="l149"></a> bx[j] += </span><span class=cFE>5</span><span class=cF0>;
<a name="l150"></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="l151"></a> bullets_out++;
<a name="l152"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l153"></a> {
<a name="l154"></a> i1 = dead_out;
<a name="l155"></a> </span><span class=cF1>while</span><span class=cF0> (i1 != dead_in)
<a name="l156"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l157"></a> j1 = i1++ &amp; (DEAD_NUM - </span><span class=cFE>1</span><span class=cF0>);
<a name="l158"></a> </span><span class=cF1>if</span><span class=cF0> (gy[j1] &lt;= by[j] &lt;= gy[j1] + </span><span class=cFE>38</span><span class=cF0> &amp;&amp; gx[j1] &lt;= bx[j] &lt;= gx[j1] + </span><span class=cFE>40</span><span class=cF0>)
<a name="l159"></a> g_dead[j1] = </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l160"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l161"></a> }
<a name="l162"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l163"></a>
<a name="l164"></a> </span><span class=cF1>if</span><span class=cF0> (gun_on)
<a name="l165"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l166"></a> j = bullets_in &amp; (BULLETS_NUM - </span><span class=cFE>1</span><span class=cF0>);
<a name="l167"></a> bx[j] = x + </span><span class=cFE>32</span><span class=cF0>;
<a name="l168"></a> by[j] = y + </span><span class=cFE>14</span><span class=cF0>;
<a name="l169"></a> bullets_in++;
<a name="l170"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l171"></a>
<a name="l172"></a> </span><span class=cF2>//Runs one out of four passes through this loop.</span><span class=cF0>
<a name="l173"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF7>(</span><span class=cF0>k % </span><span class=cFE>4</span><span class=cF7>)</span><span class=cF0>)
<a name="l174"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l175"></a> i = dead_out;
<a name="l176"></a> </span><span class=cF1>while</span><span class=cF0> (i != dead_in)
<a name="l177"></a> {
<a name="l178"></a> j = i++ &amp;(DEAD_NUM - </span><span class=cFE>1</span><span class=cF0>);
<a name="l179"></a> gx[j] -= </span><span class=cFE>1</span><span class=cF0>;
<a name="l180"></a> </span><span class=cF1>if</span><span class=cF0> (gx[j] &lt; </span><span class=cFE>25</span><span class=cF0>)
<a name="l181"></a> dead_out++;
<a name="l182"></a> }
<a name="l183"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l184"></a>
<a name="l185"></a> </span><span class=cF2>//Runs one out of 150 passes through this loop.</span><span class=cF0>
<a name="l186"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF7>(</span><span class=cF0>k % </span><span class=cFE>150</span><span class=cF7>)</span><span class=cF0>)
<a name="l187"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l188"></a> j = dead_in &amp; (DEAD_NUM - </span><span class=cFE>1</span><span class=cF0>);
<a name="l189"></a> gx[j] = </span><span class=cF3>GR_WIDTH</span><span class=cF0> - </span><span class=cFE>30</span><span class=cF0>;
<a name="l190"></a> gy[j] = </span><span class=cF5>RandU32</span><span class=cF0> % (</span><span class=cF3>GR_HEIGHT</span><span class=cF0> - </span><span class=cFE>50</span><span class=cF0>) + </span><span class=cFE>25</span><span class=cF0>;
<a name="l191"></a> g_dead[j] = </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l192"></a> dead_in++;
<a name="l193"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l194"></a> k++;
<a name="l195"></a>
<a name="l196"></a> </span><span class=cF5>Sleep</span><span class=cF0>(</span><span class=cFE>10</span><span class=cF0>); </span><span class=cF2>//Swap this task out for 10 miliseconds.</span><span class=cF0>
<a name="l197"></a> }
<a name="l198"></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="l199"></a>
<a name="l200"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l201"></a> </span><span class=cF1>catch</span><span class=cF0>
<a name="l202"></a> </span><span class=cF5>PutExcept</span><span class=cF0>;
<a name="l203"></a> </span><span class=cF5>SettingsPop</span><span class=cF0>;
<a name="l204"></a> </span><span class=cF5>MenuPop</span><span class=cF0>;
<a name="l205"></a>}
<a name="l206"></a>
<a name="l207"></a>TheDead; </span><span class=cF2>//Run program when #included</span><span class=cF0>
</span></pre></body>
</html>