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

223 lines
20 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>/*</span><span class=cF0>
<a name="l2"></a></span><span class=cF2>Char graphics are how games on the C64 were made. You don't need to do it</span><span class=cF0>
<a name="l3"></a></span><span class=cF2>this way, unless for fun. You can just make device context bigger than</span><span class=cF0>
<a name="l4"></a></span><span class=cF2>the scrn and scroll around.</span><span class=cF0>
<a name="l5"></a>
<a name="l6"></a></span><span class=cF2>See </span><a href="/Wb/Demo/Games/RawHide.HC.HTML#l1"><span class=cF4>::/Demo/Games/RawHide.HC</span></a><span class=cF2> or </span><a href="/Wb/Demo/Games/BigGuns.HC.HTML#l1"><span class=cF4>::/Demo/Games/BigGuns.HC</span></a><span class=cF2>.</span><span class=cF0>
<a name="l7"></a>
<a name="l8"></a></span><span class=cF2>The nice thing about character graphics are the animations.</span><span class=cF0>
<a name="l9"></a></span><span class=cF2>*/</span><span class=cF0>
<a name="l10"></a>
<a name="l11"></a>#</span><span class=cF1>define</span><span class=cF0> MAP_WIDTH (</span><span class=cF3>TEXT_COLS</span><span class=cF0>*2)
<a name="l12"></a>#</span><span class=cF1>define</span><span class=cF0> MAP_HEIGHT (</span><span class=cF3>TEXT_ROWS</span><span class=cF0>*2)
<a name="l13"></a>
<a name="l14"></a>#</span><span class=cF1>define</span><span class=cF0> CH_WATER </span><span class=cF6>'^'</span><span class=cF0>
<a name="l15"></a>#</span><span class=cF1>define</span><span class=cF0> CH_LAND </span><span class=cF3>CH_SPACE</span><span class=cF0>
<a name="l16"></a>#</span><span class=cF1>define</span><span class=cF0> CH_TREE </span><span class=cF6>'*'</span><span class=cF0>
<a name="l17"></a>
<a name="l18"></a></span><span class=cF9>U16</span><span class=cF0> map[MAP_HEIGHT][MAP_WIDTH];
<a name="l19"></a>
<a name="l20"></a></span><span class=cF9>I64</span><span class=cF0> scrn_pix_x,scrn_pix_y;
<a name="l21"></a>
<a name="l22"></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> *)
<a name="l23"></a>{
<a name="l24"></a> </span><span class=cF9>U16</span><span class=cF0> *ptr;
<a name="l25"></a> </span><span class=cF9>I64</span><span class=cF0> i,j,y=scrn_pix_y&gt;&gt;3;
<a name="l26"></a> </span><span class=cFB>gr</span><span class=cF0>.hide_col=</span><span class=cFB>gr</span><span class=cF0>.hide_row=</span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l27"></a> </span><span class=cFB>gr</span><span class=cF0>.pan_text_x=7-scrn_pix_x&amp;7;
<a name="l28"></a> </span><span class=cFB>gr</span><span class=cF0>.pan_text_y=7-scrn_pix_y&amp;7;
<a name="l29"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i&lt;task-&gt;win_height;i++) </span><span class=cF7>{</span><span class=cF0>
<a name="l30"></a> ptr=&amp;map[y++][scrn_pix_x&gt;&gt;3];
<a name="l31"></a> </span><span class=cF1>for</span><span class=cF0> (j=0;j&lt;task-&gt;win_width;j++)
<a name="l32"></a> </span><span class=cF2>//By the time you clip to window and handle Fs-&gt;scroll_x,Fs-&gt;scroll_y,</span><span class=cF0>
<a name="l33"></a> </span><span class=cF2>//it is too much trouble to do raw access to gr.text_base like we do</span><span class=cF0>
<a name="l34"></a> </span><span class=cF2>//in </span><a href="/Wb/Demo/Games/Maze.HC.HTML#l1"><span class=cF4>::/Demo/Games/Maze.HC</span></a><span class=cF2>.</span><span class=cF0>
<a name="l35"></a> </span><span class=cF5>TextChar</span><span class=cF0>(task,</span><span class=cF3>FALSE</span><span class=cF0>,j,i,*ptr++);
<a name="l36"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l37"></a>}
<a name="l38"></a>
<a name="l39"></a></span><span class=cF1>U8</span><span class=cF0> *old_font=</span><span class=cFB>text</span><span class=cF0>.font;
<a name="l40"></a></span><span class=cF9>U64</span><span class=cF0> waves[4]={
<a name="l41"></a>0x0011AA440011AA44,0x0022558800225588,
<a name="l42"></a>0x0044AA110044AA11,0x0088552200885522};
<a name="l43"></a>
<a name="l44"></a></span><span class=cF1>U0</span><span class=cF0> AnimateEndCB()
<a name="l45"></a>{
<a name="l46"></a> </span><span class=cFB>text</span><span class=cF0>.font=old_font;
<a name="l47"></a> </span><span class=cF5>Exit</span><span class=cF0>;
<a name="l48"></a>}
<a name="l49"></a>
<a name="l50"></a></span><span class=cF1>U0</span><span class=cF0> AnimateTask(</span><span class=cF9>I64</span><span class=cF0>)
<a name="l51"></a>{
<a name="l52"></a> </span><span class=cF9>I64</span><span class=cF0> i;
<a name="l53"></a> </span><span class=cF9>U64</span><span class=cF0> *font=</span><span class=cF5>MAlloc</span><span class=cF0>(256*8);
<a name="l54"></a> </span><span class=cF5>Fs</span><span class=cF0>-&gt;task_end_cb=&amp;AnimateEndCB;
<a name="l55"></a> </span><span class=cF5>MemCpy</span><span class=cF0>(font,</span><span class=cFB>text</span><span class=cF0>.font,256*8);
<a name="l56"></a> </span><span class=cFB>text</span><span class=cF0>.font=font;
<a name="l57"></a> font[CH_TREE]=0x18187E7E3C3C18;
<a name="l58"></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="l59"></a> font[CH_WATER]=waves[i++&amp;0x3];
<a name="l60"></a> </span><span class=cF5>Sleep</span><span class=cF0>(200);
<a name="l61"></a> </span><span class=cF5>Refresh</span><span class=cF0>;
<a name="l62"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l63"></a>}
<a name="l64"></a>
<a name="l65"></a></span><span class=cF1>U0</span><span class=cF0> ScrollTaskX(</span><span class=cF9>I64</span><span class=cF0> sign)
<a name="l66"></a>{
<a name="l67"></a> </span><span class=cF9>I64</span><span class=cF0> i;
<a name="l68"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i&lt;32;i++) </span><span class=cF7>{</span><span class=cF0>
<a name="l69"></a> scrn_pix_x=</span><span class=cF5>ClampI64</span><span class=cF0>(scrn_pix_x+sign,0,
<a name="l70"></a> </span><span class=cF7>(</span><span class=cF0>MAP_WIDTH-</span><span class=cF3>TEXT_COLS</span><span class=cF0>+1</span><span class=cF7>)</span><span class=cF0>*</span><span class=cF3>FONT_WIDTH</span><span class=cF0>);
<a name="l71"></a> </span><span class=cF5>Refresh</span><span class=cF0>;
<a name="l72"></a> </span><span class=cF7>}</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> ScrollTaskY(</span><span class=cF9>I64</span><span class=cF0> sign)
<a name="l76"></a>{
<a name="l77"></a> </span><span class=cF9>I64</span><span class=cF0> i;
<a name="l78"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i&lt;32;i++) </span><span class=cF7>{</span><span class=cF0>
<a name="l79"></a> scrn_pix_y=</span><span class=cF5>ClampI64</span><span class=cF0>(scrn_pix_y+sign,0,
<a name="l80"></a> </span><span class=cF7>(</span><span class=cF0>MAP_HEIGHT-</span><span class=cF3>TEXT_ROWS</span><span class=cF0>+2</span><span class=cF7>)</span><span class=cF0>*</span><span class=cF3>FONT_HEIGHT</span><span class=cF0>);
<a name="l81"></a> </span><span class=cF5>Refresh</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> Init()
<a name="l86"></a>{
<a name="l87"></a> </span><span class=cF9>I64</span><span class=cF0> i,j,x,y;
<a name="l88"></a> scrn_pix_x=(MAP_WIDTH-</span><span class=cF3>TEXT_COLS</span><span class=cF0>)&gt;&gt;1*</span><span class=cF3>FONT_WIDTH</span><span class=cF0>;
<a name="l89"></a> scrn_pix_y=(MAP_HEIGHT-</span><span class=cF3>TEXT_ROWS</span><span class=cF0>)&gt;&gt;1*</span><span class=cF3>FONT_HEIGHT</span><span class=cF0>;
<a name="l90"></a>
<a name="l91"></a> </span><span class=cF5>MemSetU16</span><span class=cF0>(map,CH_WATER+</span><span class=cF7>(</span><span class=cF3>BLUE</span><span class=cF0>&lt;&lt;4+</span><span class=cF3>LTBLUE</span><span class=cF7>)</span><span class=cF0>&lt;&lt;8,MAP_WIDTH*MAP_HEIGHT);
<a name="l92"></a> </span><span class=cF1>for</span><span class=cF0> (i=1;i&lt;MAP_WIDTH-1;i++)
<a name="l93"></a> map[0][i]=map[MAP_HEIGHT-1][i]=</span><span class=cF6>'.'</span><span class=cF0>+(</span><span class=cF3>BLUE</span><span class=cF0>&lt;&lt;4+</span><span class=cF3>RED</span><span class=cF0>)&lt;&lt;8;
<a name="l94"></a> </span><span class=cF1>for</span><span class=cF0> (i=1;i&lt;MAP_HEIGHT-1;i++)
<a name="l95"></a> map[i][0]=map[i][MAP_WIDTH-1]=</span><span class=cF6>'.'</span><span class=cF0>+(</span><span class=cF3>BLUE</span><span class=cF0>&lt;&lt;4+</span><span class=cF3>RED</span><span class=cF0>)&lt;&lt;8;
<a name="l96"></a> map[0][0] =</span><span class=cF6>'.'</span><span class=cF0>+(</span><span class=cF3>BLUE</span><span class=cF0>&lt;&lt;4+</span><span class=cF3>RED</span><span class=cF0>)&lt;&lt;8;
<a name="l97"></a> map[0][MAP_WIDTH-1] =</span><span class=cF6>'.'</span><span class=cF0>+(</span><span class=cF3>BLUE</span><span class=cF0>&lt;&lt;4+</span><span class=cF3>RED</span><span class=cF0>)&lt;&lt;8;
<a name="l98"></a> map[MAP_HEIGHT-1][0] =</span><span class=cF6>'.'</span><span class=cF0>+(</span><span class=cF3>BLUE</span><span class=cF0>&lt;&lt;4+</span><span class=cF3>RED</span><span class=cF0>)&lt;&lt;8;
<a name="l99"></a> map[MAP_HEIGHT-1][MAP_WIDTH-1]=</span><span class=cF6>'.'</span><span class=cF0>+(</span><span class=cF3>BLUE</span><span class=cF0>&lt;&lt;4+</span><span class=cF3>RED</span><span class=cF0>)&lt;&lt;8;
<a name="l100"></a>
<a name="l101"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i&lt;20;i++) </span><span class=cF7>{</span><span class=cF0>
<a name="l102"></a> x=MAP_WIDTH*</span><span class=cF5>Rand</span><span class=cF0>;
<a name="l103"></a> y=MAP_HEIGHT*</span><span class=cF5>Rand</span><span class=cF0>;
<a name="l104"></a> </span><span class=cF1>for</span><span class=cF0> (j=0;j&lt;1000;j++) {
<a name="l105"></a> map[y][x]=CH_LAND+(</span><span class=cF3>YELLOW</span><span class=cF0>&lt;&lt;4+</span><span class=cF3>BLACK</span><span class=cF0>)&lt;&lt;8;
<a name="l106"></a> x=</span><span class=cF5>ClampI64</span><span class=cF0>(x+</span><span class=cF5>RandU16</span><span class=cF0>%3-1,0,MAP_WIDTH-1);
<a name="l107"></a> y=</span><span class=cF5>ClampI64</span><span class=cF0>(y+</span><span class=cF5>RandU16</span><span class=cF0>%3-1,0,MAP_HEIGHT-1);
<a name="l108"></a> }
<a name="l109"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l110"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i&lt;100;i++) </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> x=MAP_WIDTH*</span><span class=cF5>Rand</span><span class=cF0>;
<a name="l113"></a> y=MAP_HEIGHT*</span><span class=cF5>Rand</span><span class=cF0>;
<a name="l114"></a> } </span><span class=cF1>while</span><span class=cF0> (map[y][x].u8[0]!=CH_LAND);
<a name="l115"></a> </span><span class=cF1>for</span><span class=cF0> (j=0;j&lt;100;j++) {
<a name="l116"></a> map[y][x]=CH_TREE+(</span><span class=cF3>YELLOW</span><span class=cF0>&lt;&lt;4+</span><span class=cF3>GREEN</span><span class=cF0>)&lt;&lt;8;
<a name="l117"></a> x=</span><span class=cF5>ClampI64</span><span class=cF0>(x+</span><span class=cF5>RandU16</span><span class=cF0>%3-1,0,MAP_WIDTH-1);
<a name="l118"></a> y=</span><span class=cF5>ClampI64</span><span class=cF0>(y+</span><span class=cF5>RandU16</span><span class=cF0>%3-1,0,MAP_HEIGHT-1);
<a name="l119"></a> }
<a name="l120"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l121"></a>}
<a name="l122"></a>
<a name="l123"></a></span><span class=cF1>U0</span><span class=cF0> CleanUp()
<a name="l124"></a>{
<a name="l125"></a> </span><span class=cFB>gr</span><span class=cF0>.pan_text_x=</span><span class=cFB>gr</span><span class=cF0>.pan_text_y=0;
<a name="l126"></a> </span><span class=cFB>gr</span><span class=cF0>.hide_col=</span><span class=cFB>gr</span><span class=cF0>.hide_row=</span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l127"></a>}
<a name="l128"></a>
<a name="l129"></a></span><span class=cF1>U0</span><span class=cF0> CharDemo()
<a name="l130"></a>{
<a name="l131"></a> </span><span class=cF9>I64</span><span class=cF0> sc;
<a name="l132"></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="l133"></a> </span><span class=cF5>Fs</span><span class=cF0>-&gt;text_attr=</span><span class=cF3>YELLOW</span><span class=cF0>&lt;&lt;4+</span><span class=cF3>BLUE</span><span class=cF0>;
<a name="l134"></a> </span><span class=cF5>AutoComplete</span><span class=cF0>;
<a name="l135"></a> </span><span class=cF5>WinBorder</span><span class=cF0>;
<a name="l136"></a> </span><span class=cF5>WinMax</span><span class=cF0>;
<a name="l137"></a> </span><span class=cF5>DocCursor</span><span class=cF0>;
<a name="l138"></a>
<a name="l139"></a> </span><span class=cF5>MenuPush</span><span class=cF0>(
<a name="l140"></a> </span><span class=cF6>&quot;File {&quot;</span><span class=cF0>
<a name="l141"></a> </span><span class=cF6>&quot; Abort(,CH_SHIFT_ESC);&quot;</span><span class=cF0>
<a name="l142"></a> </span><span class=cF6>&quot; Exit(,CH_ESC);&quot;</span><span class=cF0>
<a name="l143"></a> </span><span class=cF6>&quot;}&quot;</span><span class=cF0>
<a name="l144"></a> </span><span class=cF6>&quot;Play {&quot;</span><span class=cF0>
<a name="l145"></a> </span><span class=cF6>&quot; Restart(,'\n');&quot;</span><span class=cF0>
<a name="l146"></a> </span><span class=cF6>&quot; Left(,,SC_CURSOR_LEFT);&quot;</span><span class=cF0>
<a name="l147"></a> </span><span class=cF6>&quot; Right(,,SC_CURSOR_RIGHT);&quot;</span><span class=cF0>
<a name="l148"></a> </span><span class=cF6>&quot; Up(,,SC_CURSOR_UP);&quot;</span><span class=cF0>
<a name="l149"></a> </span><span class=cF6>&quot; Down(,,SC_CURSOR_DOWN);&quot;</span><span class=cF0>
<a name="l150"></a> </span><span class=cF6>&quot;}&quot;</span><span class=cF0>
<a name="l151"></a> );
<a name="l152"></a> Init;
<a name="l153"></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="l154"></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="l155"></a> </span><span class=cF1>try</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
<a name="l156"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF3>TRUE</span><span class=cF0>) {
<a name="l157"></a> </span><span class=cF1>switch</span><span class=cF0> (</span><span class=cF5>GetKey</span><span class=cF7>(</span><span class=cF0>&amp;sc</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l158"></a> </span><span class=cF1>case</span><span class=cF0> 0:
<a name="l159"></a> </span><span class=cF1>switch</span><span class=cF0> (sc.u8[0]) {
<a name="l160"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>SC_CURSOR_LEFT</span><span class=cF0>:
<a name="l161"></a> </span><span class=cF5>Spawn</span><span class=cF0>(&amp;ScrollTaskX,-1,</span><span class=cF6>&quot;Scroll&quot;</span><span class=cF0>,,</span><span class=cF5>Fs</span><span class=cF0>);
<a name="l162"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l163"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>SC_CURSOR_RIGHT</span><span class=cF0>:
<a name="l164"></a> </span><span class=cF5>Spawn</span><span class=cF0>(&amp;ScrollTaskX,1,</span><span class=cF6>&quot;Scroll&quot;</span><span class=cF0>,,</span><span class=cF5>Fs</span><span class=cF0>);
<a name="l165"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l166"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>SC_CURSOR_UP</span><span class=cF0>:
<a name="l167"></a> </span><span class=cF5>Spawn</span><span class=cF0>(&amp;ScrollTaskY,-1,</span><span class=cF6>&quot;Scroll&quot;</span><span class=cF0>,,</span><span class=cF5>Fs</span><span class=cF0>);
<a name="l168"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l169"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>SC_CURSOR_DOWN</span><span class=cF0>:
<a name="l170"></a> </span><span class=cF5>Spawn</span><span class=cF0>(&amp;ScrollTaskY,1,</span><span class=cF6>&quot;Scroll&quot;</span><span class=cF0>,,</span><span class=cF5>Fs</span><span class=cF0>);
<a name="l171"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l172"></a> }
<a name="l173"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l174"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF6>'\n'</span><span class=cF0>:
<a name="l175"></a> CleanUp;
<a name="l176"></a> Init;
<a name="l177"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l178"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>CH_SHIFT_ESC</span><span class=cF0>:
<a name="l179"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>CH_ESC</span><span class=cF0>:
<a name="l180"></a> </span><span class=cF1>goto</span><span class=cF0> sq_done;
<a name="l181"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l182"></a> }
<a name="l183"></a>sq_done: </span><span class=cF2>//Don't goto out of try</span><span class=cF0>
<a name="l184"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>catch</span><span class=cF0>
<a name="l185"></a> </span><span class=cF5>PutExcept</span><span class=cF0>;
<a name="l186"></a> </span><span class=cF5>SettingsPop</span><span class=cF0>;
<a name="l187"></a> CleanUp;
<a name="l188"></a> </span><span class=cF5>MenuPop</span><span class=cF0>;
<a name="l189"></a>}
<a name="l190"></a>
<a name="l191"></a>CharDemo;
</span></pre></body>
</html>