118 lines
9.2 KiB
Plaintext
118 lines
9.2 KiB
Plaintext
|
<!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=cFA>
|
||
|
<a name="l2"></a><1>/* Graphics Not Rendered in HTML */</span><span class=cF0>
|
||
|
<a name="l3"></a>
|
||
|
<a name="l4"></a>#</span><span class=cF1>define</span><span class=cF0> APPLES_NUM 128
|
||
|
<a name="l5"></a>
|
||
|
<a name="l6"></a></span><span class=cF9>I64</span><span class=cF0> x[APPLES_NUM],y[APPLES_NUM],
|
||
|
<a name="l7"></a> cur_apple,cur_dist;
|
||
|
<a name="l8"></a></span><span class=cF1>Bool</span><span class=cF0> trigger;
|
||
|
<a name="l9"></a>
|
||
|
<a name="l10"></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> *,</span><span class=cF9>CDC</span><span class=cF0> *dc)
|
||
|
<a name="l11"></a>{
|
||
|
<a name="l12"></a> </span><span class=cF9>I64</span><span class=cF0> i,best_dist=</span><span class=cF3>I64_MAX</span><span class=cF0>,best_apple=0;
|
||
|
<a name="l13"></a>
|
||
|
<a name="l14"></a> dc->flags|=</span><span class=cF3>DCF_LOCATE_NEAREST</span><span class=cF0>;
|
||
|
<a name="l15"></a> dc->cur_x=</span><span class=cFB>ms</span><span class=cF0>.pos.x;
|
||
|
<a name="l16"></a> dc->cur_y=</span><span class=cFB>ms</span><span class=cF0>.pos.y;
|
||
|
<a name="l17"></a> dc->cur_z=0;
|
||
|
<a name="l18"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i<APPLES_NUM;i++) </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l19"></a> </span><span class=cF5>Sprite3</span><span class=cF0>(dc,x[i],y[i],0,</span><span class=cFA><1></span><span class=cF0>);
|
||
|
<a name="l20"></a> </span><span class=cF1>if</span><span class=cF0> (dc->nearest_dist<=best_dist) {
|
||
|
<a name="l21"></a></span><span class=cF2>//Distance to nearest pix, squared</span><span class=cF0>
|
||
|
<a name="l22"></a> </span><span class=cF2>//</span><a href="/Wb/Kernel/KernelB.HH.HTML#l109"><span class=cF4>Sqrt</span></a><span class=cF2>() is expensive so we work with distance squared.</span><span class=cF0>
|
||
|
<a name="l23"></a> best_dist=dc->nearest_dist;
|
||
|
<a name="l24"></a> best_apple=i;
|
||
|
<a name="l25"></a> }
|
||
|
<a name="l26"></a> </span><span class=cF7>}</span><span class=cF0>
|
||
|
<a name="l27"></a> </span><span class=cF1>if</span><span class=cF0> (trigger) </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l28"></a> cur_apple=best_apple;
|
||
|
<a name="l29"></a> cur_dist=best_dist;
|
||
|
<a name="l30"></a> trigger=</span><span class=cF3>FALSE</span><span class=cF0>;
|
||
|
<a name="l31"></a> </span><span class=cF7>}</span><span class=cF0>
|
||
|
<a name="l32"></a> </span><span class=cF5>GrPrint</span><span class=cF0>(dc,</span><span class=cF3>FONT_WIDTH</span><span class=cF0>,</span><span class=cF3>FONT_HEIGHT</span><span class=cF0>,</span><span class=cF6>"Dist Squared:%d"</span><span class=cF0>,cur_dist);
|
||
|
<a name="l33"></a>}
|
||
|
<a name="l34"></a>
|
||
|
<a name="l35"></a></span><span class=cF1>U0</span><span class=cF0> Pick()
|
||
|
<a name="l36"></a>{
|
||
|
<a name="l37"></a> </span><span class=cF9>I64</span><span class=cF0> i,msg_code,arg1,arg2,delta_x,delta_y;
|
||
|
<a name="l38"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i<APPLES_NUM;i++) </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l39"></a> x[i]=</span><span class=cF5>RandU16</span><span class=cF0>%</span><span class=cF3>GR_WIDTH</span><span class=cF0>;
|
||
|
<a name="l40"></a> y[i]=</span><span class=cF5>RandU16</span><span class=cF0>%(</span><span class=cF3>GR_HEIGHT</span><span class=cF0>-</span><span class=cF3>FONT_HEIGHT</span><span class=cF0>*3)+</span><span class=cF3>FONT_HEIGHT</span><span class=cF0>*3;
|
||
|
<a name="l41"></a> </span><span class=cF7>}</span><span class=cF0>
|
||
|
<a name="l42"></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="l43"></a> </span><span class=cF5>AutoComplete</span><span class=cF0>;
|
||
|
<a name="l44"></a> </span><span class=cF5>DocCursor</span><span class=cF0>;
|
||
|
<a name="l45"></a> </span><span class=cF5>DocClear</span><span class=cF0>;
|
||
|
<a name="l46"></a>
|
||
|
<a name="l47"></a> trigger=</span><span class=cF3>FALSE</span><span class=cF0>;
|
||
|
<a name="l48"></a> cur_apple=cur_dist=0;
|
||
|
<a name="l49"></a>
|
||
|
<a name="l50"></a> </span><span class=cF5>Fs</span><span class=cF0>->draw_it=&</span><span class=cF5>DrawIt</span><span class=cF0>;
|
||
|
<a name="l51"></a> </span><span class=cF5>Fs</span><span class=cF0>->win_inhibit=</span><span class=cF3>WIG_TASK_DFT</span><span class=cF0>-</span><span class=cF3>WIF_SELF_FOCUS</span><span class=cF0>-</span><span class=cF3>WIF_SELF_BORDER</span><span class=cF0>;
|
||
|
<a name="l52"></a>
|
||
|
<a name="l53"></a> </span><span class=cF1>try</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l54"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF3>TRUE</span><span class=cF0>) {
|
||
|
<a name="l55"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>GetMsg</span><span class=cF7>(</span><span class=cF0>&arg1,&arg2,1<<</span><span class=cF3>MSG_KEY_DOWN</span><span class=cF0>|1<<</span><span class=cF3>MSG_MS_L_DOWN</span><span class=cF7>)</span><span class=cF0>==</span><span class=cF3>MSG_KEY_DOWN</span><span class=cF0>)
|
||
|
<a name="l56"></a> </span><span class=cF1>goto</span><span class=cF0> pi_done;
|
||
|
<a name="l57"></a>
|
||
|
<a name="l58"></a> </span><span class=cF2>//Wait for window mgr to call DrawIt()</span><span class=cF0>
|
||
|
<a name="l59"></a> trigger=</span><span class=cF3>TRUE</span><span class=cF0>;
|
||
|
<a name="l60"></a> </span><span class=cF1>do</span><span class=cF0> </span><span class=cF5>Refresh</span><span class=cF0>;
|
||
|
<a name="l61"></a> </span><span class=cF1>while</span><span class=cF0> (trigger);
|
||
|
<a name="l62"></a>
|
||
|
<a name="l63"></a> </span><span class=cF2>//Use scrn coordinates, not window (arg1,arg2)</span><span class=cF0>
|
||
|
<a name="l64"></a> </span><span class=cF2>//</span><a href="/Wb/Kernel/KGlbls.HC.HTML#l25"><span class=cF4>ms.pos.x</span></a><span class=cF2> and </span><a href="/Wb/Kernel/KGlbls.HC.HTML#l25"><span class=cF4>ms.pos.y</span></a><span class=cF2> are global vars updated</span><span class=cF0>
|
||
|
<a name="l65"></a> </span><span class=cF2>//updated by the window mgr to hold the</span><span class=cF0>
|
||
|
<a name="l66"></a> </span><span class=cF2>//scrn coordinates of the mouse.</span><span class=cF0>
|
||
|
<a name="l67"></a> delta_x=x[cur_apple]-</span><span class=cFB>ms</span><span class=cF0>.pos.x;
|
||
|
<a name="l68"></a> delta_y=y[cur_apple]-</span><span class=cFB>ms</span><span class=cF0>.pos.y;
|
||
|
<a name="l69"></a>
|
||
|
<a name="l70"></a> </span><span class=cF1>do</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l71"></a> msg_code=</span><span class=cF5>GetMsg</span><span class=cF0>(&arg1,&arg2,
|
||
|
<a name="l72"></a> 1<<</span><span class=cF3>MSG_KEY_DOWN</span><span class=cF0>|1<<</span><span class=cF3>MSG_MS_MOVE</span><span class=cF0>|1<<</span><span class=cF3>MSG_MS_L_UP</span><span class=cF0>);
|
||
|
<a name="l73"></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="l74"></a> </span><span class=cF1>goto</span><span class=cF0> pi_done;
|
||
|
<a name="l75"></a> x[cur_apple]=</span><span class=cFB>ms</span><span class=cF0>.pos.x+delta_x;
|
||
|
<a name="l76"></a> y[cur_apple]=</span><span class=cFB>ms</span><span class=cF0>.pos.y+delta_y;
|
||
|
<a name="l77"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>while</span><span class=cF0> (msg_code!=</span><span class=cF3>MSG_MS_L_UP</span><span class=cF0>);
|
||
|
<a name="l78"></a> }
|
||
|
<a name="l79"></a>pi_done:
|
||
|
<a name="l80"></a> </span><span class=cF5>GetMsg</span><span class=cF0>(,,1<<</span><span class=cF3>MSG_KEY_UP</span><span class=cF0>);
|
||
|
<a name="l81"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>catch</span><span class=cF0>
|
||
|
<a name="l82"></a> </span><span class=cF5>PutExcept</span><span class=cF0>;
|
||
|
<a name="l83"></a> </span><span class=cF5>SettingsPop</span><span class=cF0>;
|
||
|
<a name="l84"></a>}
|
||
|
<a name="l85"></a>
|
||
|
<a name="l86"></a>Pick;
|
||
|
</span></pre></body>
|
||
|
</html>
|