ZealOS/docs/Demo/Games/Squirt.html
2021-07-03 02:51:43 -04:00

444 lines
41 KiB
HTML
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;}
.cB0{color:#ffffff;background-color:#34e2e2;}
.cBA{color:#82bc49;background-color:#34e2e2;}
.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:courier;font-size:10pt">
<a name="l1"></a><span class=cF0>#</span><span class=cF1>define</span><span class=cF0> MT_HOSE </span><span class=cFE>1</span><span class=cF0>
<a name="l2"></a>#</span><span class=cF1>define</span><span class=cF0> MT_DROPLET </span><span class=cFE>2</span><span class=cF0>
<a name="l3"></a></span><span class=cF1>class</span><span class=cF0> MyMass:</span><span class=cF9>CMass</span><span class=cF0>
<a name="l4"></a>{
<a name="l5"></a> </span><span class=cF9>I64</span><span class=cF0> type;
<a name="l6"></a> </span><span class=cF1>F64</span><span class=cF0> radius;
<a name="l7"></a>};
<a name="l8"></a>
<a name="l9"></a>#</span><span class=cF1>define</span><span class=cF0> ST_HOSE </span><span class=cFE>1</span><span class=cF0>
<a name="l10"></a></span><span class=cF1>class</span><span class=cF0> MySpring:</span><span class=cF9>CSpring</span><span class=cF0>
<a name="l11"></a>{
<a name="l12"></a> </span><span class=cF9>I64</span><span class=cF0> type;
<a name="l13"></a>};
<a name="l14"></a></span><span class=cB0>
<a name="l15"></a>
<a name="l16"></a>
<a name="l17"></a> </span><span class=cBA>&lt;1&gt;/* Graphics Not Rendered in HTML */</span><span class=cB0>
<a name="l18"></a>
<a name="l19"></a> </span><span class=cBA>&lt;2&gt;/* Graphics Not Rendered in HTML */</span><span class=cB0>
<a name="l20"></a>
<a name="l21"></a> </span><span class=cBA>&lt;3&gt;/* Graphics Not Rendered in HTML */</span><span class=cB0>
<a name="l22"></a></span><span class=cF0>
<a name="l23"></a>
<a name="l24"></a>
<a name="l25"></a>
<a name="l26"></a>
<a name="l27"></a>
<a name="l28"></a>
<a name="l29"></a>
<a name="l30"></a>
<a name="l31"></a>
<a name="l32"></a>
<a name="l33"></a>
<a name="l34"></a>
<a name="l35"></a>
<a name="l36"></a></span><span class=cFA>
<a name="l37"></a>/* Graphics Not Rendered in HTML */</span><span class=cF0>
<a name="l38"></a>
<a name="l39"></a>#</span><span class=cF1>define</span><span class=cF0> HOSE_RADIUS </span><span class=cFE>3</span><span class=cF0>
<a name="l40"></a>#</span><span class=cF1>define</span><span class=cF0> LINK_SIZE </span><span class=cFE>6</span><span class=cF0>
<a name="l41"></a>#</span><span class=cF1>define</span><span class=cF0> NOZZLE_START_Y (</span><span class=cF3>GR_HEIGHT</span><span class=cF0> - </span><span class=cFE>15</span><span class=cF0> * </span><span class=cF3>FONT_HEIGHT</span><span class=cF0>)
<a name="l42"></a>#</span><span class=cF1>define</span><span class=cF0> NOZZLE_LEN </span><span class=cFE>18</span><span class=cF0>
<a name="l43"></a>#</span><span class=cF1>define</span><span class=cF0> FAUCET_X (</span><span class=cFE>5</span><span class=cF0> * HOSE_RADIUS)
<a name="l44"></a>#</span><span class=cF1>define</span><span class=cF0> FAUCET_Y (</span><span class=cF3>GR_HEIGHT</span><span class=cF0> - </span><span class=cFE>12</span><span class=cF0> * </span><span class=cF3>FONT_HEIGHT</span><span class=cF0>)
<a name="l45"></a>#</span><span class=cF1>define</span><span class=cF0> GROUND_Y (</span><span class=cF3>GR_HEIGHT</span><span class=cF0> - </span><span class=cFE>3</span><span class=cF0> * </span><span class=cF3>FONT_HEIGHT</span><span class=cF0>)
<a name="l46"></a>MyMass *faucet, *nozzle;
<a name="l47"></a></span><span class=cF1>F64</span><span class=cF0> nozzle_theta;
<a name="l48"></a>
<a name="l49"></a></span><span class=cF9>CMathODE</span><span class=cF0> *ode = </span><span class=cF3>NULL</span><span class=cF0>;
<a name="l50"></a></span><span class=cF1>F64</span><span class=cF0> start_up_timeout;
<a name="l51"></a>
<a name="l52"></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="l53"></a>{
<a name="l54"></a> </span><span class=cF1>Bool</span><span class=cF0> first;
<a name="l55"></a> </span><span class=cF1>F64</span><span class=cF0> dx, dy, d;
<a name="l56"></a> </span><span class=cF9>I64</span><span class=cF0> x1b, y1b, x2b, y2b, x1a, y1a, x2a, y2a;
<a name="l57"></a> MyMass *tmpm, *tmpm1;
<a name="l58"></a> MySpring *tmps;
<a name="l59"></a> </span><span class=cF9>CD3I32</span><span class=cF0> poly[</span><span class=cFE>4</span><span class=cF0>];
<a name="l60"></a>
<a name="l61"></a> </span><span class=cF5>Sprite3</span><span class=cF0>(dc, </span><span class=cFE>0</span><span class=cF0>, GROUND_Y, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cFA>&lt;4&gt;</span><span class=cF0>);
<a name="l62"></a> </span><span class=cF1>if</span><span class=cF0> (start_up_timeout &gt; </span><span class=cF5>tS</span><span class=cF0>)
<a name="l63"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l64"></a> ode-&gt;drag_v2 = </span><span class=cFE>0</span><span class=cF0>.</span><span class=cFE>01</span><span class=cF0>; </span><span class=cF2>//Let hose settle during start-up</span><span class=cF0>
<a name="l65"></a> ode-&gt;drag_v3 = </span><span class=cFE>0</span><span class=cF0>.</span><span class=cFE>0001</span><span class=cF0>;
<a name="l66"></a> dc-&gt;color = </span><span class=cF3>RED</span><span class=cF0>;
<a name="l67"></a> </span><span class=cF5>GrPrint</span><span class=cF0>(dc, </span><span class=cF7>(</span><span class=cF3>GR_WIDTH</span><span class=cF0> - </span><span class=cF3>FONT_WIDTH</span><span class=cF0> * </span><span class=cFE>6</span><span class=cF7>)</span><span class=cF0> &gt;&gt; </span><span class=cFE>1</span><span class=cF0>, </span><span class=cF3>GR_HEIGHT</span><span class=cF0> &gt;&gt; </span><span class=cFE>1</span><span class=cF0>, </span><span class=cF6>&quot;Squirt&quot;</span><span class=cF0>);
<a name="l68"></a> </span><span class=cF1>return</span><span class=cF0>;
<a name="l69"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l70"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l71"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l72"></a> ode-&gt;drag_v2 = </span><span class=cFE>0</span><span class=cF0>.</span><span class=cFE>0005</span><span class=cF0>;
<a name="l73"></a> ode-&gt;drag_v3 = </span><span class=cFE>0</span><span class=cF0>.</span><span class=cFE>0000025</span><span class=cF0>;
<a name="l74"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l75"></a>
<a name="l76"></a> tmpm = faucet;
<a name="l77"></a> dc-&gt;color = </span><span class=cF3>BLACK</span><span class=cF0>;
<a name="l78"></a> </span><span class=cF5>GrRect</span><span class=cF0>(dc, tmpm-&gt;x + </span><span class=cFE>8</span><span class=cF0>, tmpm-&gt;y, </span><span class=cFE>8</span><span class=cF0>, GROUND_Y - FAUCET_Y);
<a name="l79"></a> </span><span class=cF5>Sprite3</span><span class=cF0>(dc, tmpm-&gt;x, tmpm-&gt;y, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cFA>&lt;1&gt;</span><span class=cF0>);
<a name="l80"></a> dc-&gt;color = </span><span class=cF3>BLACK</span><span class=cF0>;
<a name="l81"></a> </span><span class=cF5>GrCircle</span><span class=cF0>(dc, tmpm-&gt;x, tmpm-&gt;y, tmpm-&gt;radius);
<a name="l82"></a> dc-&gt;color = </span><span class=cF3>GREEN</span><span class=cF0>;
<a name="l83"></a> </span><span class=cF5>GrFloodFill</span><span class=cF0>(dc, tmpm-&gt;x, tmpm-&gt;y);
<a name="l84"></a>
<a name="l85"></a> tmpm = nozzle;
<a name="l86"></a> tmpm1 = nozzle-&gt;last;
<a name="l87"></a> dx = tmpm-&gt;x - tmpm1-&gt;x;
<a name="l88"></a> dy = tmpm-&gt;y - tmpm1-&gt;y;
<a name="l89"></a> nozzle_theta = </span><span class=cF5>Wrap</span><span class=cF0>(</span><span class=cF5>Arg</span><span class=cF7>(</span><span class=cF0>dx, dy</span><span class=cF7>)</span><span class=cF0>);
<a name="l90"></a> </span><span class=cF5>Sprite3ZB</span><span class=cF0>(dc, tmpm-&gt;x, tmpm-&gt;y, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cFA>&lt;2&gt;</span><span class=cF0>, nozzle_theta);
<a name="l91"></a> dc-&gt;color = </span><span class=cF3>BLACK</span><span class=cF0>;
<a name="l92"></a> </span><span class=cF5>GrCircle</span><span class=cF0>(dc, tmpm-&gt;x, tmpm-&gt;y, tmpm-&gt;radius);
<a name="l93"></a> dc-&gt;color = </span><span class=cF3>GREEN</span><span class=cF0>;
<a name="l94"></a> </span><span class=cF5>GrFloodFill</span><span class=cF0>(dc, tmpm-&gt;x, tmpm-&gt;y);
<a name="l95"></a>
<a name="l96"></a> first = </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l97"></a> tmpm = ode-&gt;next_mass;
<a name="l98"></a> </span><span class=cF1>while</span><span class=cF0> (tmpm != &amp;ode-&gt;next_mass)
<a name="l99"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l100"></a> </span><span class=cF1>if</span><span class=cF0> (tmpm-&gt;type == MT_HOSE)
<a name="l101"></a> {
<a name="l102"></a> tmpm1 = tmpm-&gt;last;
<a name="l103"></a> dx = tmpm-&gt;x - tmpm1-&gt;x;
<a name="l104"></a> dy = tmpm-&gt;y - tmpm1-&gt;y;
<a name="l105"></a> d = HOSE_RADIUS / </span><span class=cF5>Max</span><span class=cF0>(</span><span class=cF5>Sqrt</span><span class=cF7>(</span><span class=cF0>dx * dx + dy * dy</span><span class=cF7>)</span><span class=cF0>, </span><span class=cFE>0</span><span class=cF0>.</span><span class=cFE>001</span><span class=cF0>);
<a name="l106"></a> dx *= d;
<a name="l107"></a> dy *= d;
<a name="l108"></a> x2a = tmpm-&gt;x - dy;
<a name="l109"></a> y2a = tmpm-&gt;y + dx;
<a name="l110"></a> x2b = tmpm-&gt;x + dy;
<a name="l111"></a> y2b = tmpm-&gt;y - dx;
<a name="l112"></a>
<a name="l113"></a> </span><span class=cF1>if</span><span class=cF0> (first)
<a name="l114"></a> first = </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l115"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l116"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l117"></a> dc-&gt;color = </span><span class=cF3>GREEN</span><span class=cF0>;
<a name="l118"></a> poly[</span><span class=cFE>0</span><span class=cF0>].x = x1a;
<a name="l119"></a> poly[</span><span class=cFE>0</span><span class=cF0>].y = y1a;
<a name="l120"></a> poly[</span><span class=cFE>0</span><span class=cF0>].z = </span><span class=cFE>0</span><span class=cF0>;
<a name="l121"></a> poly[</span><span class=cFE>1</span><span class=cF0>].x = x2a;
<a name="l122"></a> poly[</span><span class=cFE>1</span><span class=cF0>].y = y2a;
<a name="l123"></a> poly[</span><span class=cFE>1</span><span class=cF0>].z = </span><span class=cFE>0</span><span class=cF0>;
<a name="l124"></a> poly[</span><span class=cFE>2</span><span class=cF0>].x = x2b;
<a name="l125"></a> poly[</span><span class=cFE>2</span><span class=cF0>].y = y2b;
<a name="l126"></a> poly[</span><span class=cFE>2</span><span class=cF0>].z = </span><span class=cFE>0</span><span class=cF0>;
<a name="l127"></a> poly[</span><span class=cFE>3</span><span class=cF0>].x = x1b;
<a name="l128"></a> poly[</span><span class=cFE>3</span><span class=cF0>].y = y1b;
<a name="l129"></a> poly[</span><span class=cFE>3</span><span class=cF0>].z = </span><span class=cFE>0</span><span class=cF0>;
<a name="l130"></a> </span><span class=cF5>GrFillPoly3</span><span class=cF0>(dc, </span><span class=cFE>4</span><span class=cF0>, poly);
<a name="l131"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l132"></a>
<a name="l133"></a> </span><span class=cF2>//Fill gaps</span><span class=cF0>
<a name="l134"></a> </span><span class=cF5>GrLine</span><span class=cF0>(dc, x2a, y2a, x2b, y2b);
<a name="l135"></a>
<a name="l136"></a> x1a = x2a;
<a name="l137"></a> y1a = y2a;
<a name="l138"></a> x1b = x2b;
<a name="l139"></a> y1b = y2b;
<a name="l140"></a> }
<a name="l141"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (tmpm-&gt;type == MT_DROPLET)
<a name="l142"></a> </span><span class=cF5>Sprite3</span><span class=cF0>(dc, tmpm-&gt;x, tmpm-&gt;y, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cFA>&lt;3&gt;</span><span class=cF0>);
<a name="l143"></a> tmpm = tmpm-&gt;next;
<a name="l144"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l145"></a>
<a name="l146"></a> tmps = ode-&gt;next_spring;
<a name="l147"></a> </span><span class=cF1>while</span><span class=cF0> (tmps != &amp;ode-&gt;next_spring)
<a name="l148"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l149"></a> </span><span class=cF1>if</span><span class=cF0> (tmps-&gt;type == ST_HOSE)
<a name="l150"></a> {
<a name="l151"></a> dx = tmps-&gt;end1-&gt;x - tmps-&gt;end2-&gt;x;
<a name="l152"></a> dy = tmps-&gt;end1-&gt;y - tmps-&gt;end2-&gt;y;
<a name="l153"></a> d = HOSE_RADIUS / </span><span class=cF5>Max</span><span class=cF0>(</span><span class=cF5>Sqrt</span><span class=cF7>(</span><span class=cF0>dx * dx + dy * dy</span><span class=cF7>)</span><span class=cF0>, </span><span class=cFE>0</span><span class=cF0>.</span><span class=cFE>001</span><span class=cF0>);
<a name="l154"></a> dx *= d;
<a name="l155"></a> dy *= d;
<a name="l156"></a> dc-&gt;color = </span><span class=cF3>BLACK</span><span class=cF0>;
<a name="l157"></a> </span><span class=cF5>GrLine</span><span class=cF0>(dc, tmps-&gt;end1-&gt;x - dy, tmps-&gt;end1-&gt;y + dx, tmps-&gt;end2-&gt;x - dy, tmps-&gt;end2-&gt;y + dx);
<a name="l158"></a> </span><span class=cF5>GrLine</span><span class=cF0>(dc, tmps-&gt;end1-&gt;x + dy, tmps-&gt;end1-&gt;y - dx, tmps-&gt;end2-&gt;x + dy, tmps-&gt;end2-&gt;y - dx);
<a name="l159"></a> }
<a name="l160"></a> tmps = tmps-&gt;next;
<a name="l161"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l162"></a>}
<a name="l163"></a>
<a name="l164"></a></span><span class=cF1>U0</span><span class=cF0> MyDerivative(</span><span class=cF9>CMathODE</span><span class=cF0> *ode, </span><span class=cF1>F64</span><span class=cF0> t, </span><span class=cF9>COrder2D3</span><span class=cF0> *state, </span><span class=cF9>COrder2D3</span><span class=cF0> *DstateDt)
<a name="l165"></a>{</span><span class=cF2>//The forces due to springs and drag are</span><span class=cF0>
<a name="l166"></a></span><span class=cF2>//automatically handled by the</span><span class=cF0>
<a name="l167"></a> </span><span class=cF2>//ode code. We can add new forces</span><span class=cF0>
<a name="l168"></a> </span><span class=cF2>//here.</span><span class=cF0>
<a name="l169"></a> </span><span class=cF1>no_warn</span><span class=cF0> t, state, DstateDt;
<a name="l170"></a> MyMass *tmpm1 = ode-&gt;next_mass;
<a name="l171"></a>
<a name="l172"></a> </span><span class=cF1>while</span><span class=cF0> (tmpm1 != &amp;ode-&gt;next_mass)
<a name="l173"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l174"></a> </span><span class=cF1>if</span><span class=cF0> (tmpm1-&gt;type == MT_HOSE)
<a name="l175"></a> {
<a name="l176"></a> </span><span class=cF1>if</span><span class=cF0> (tmpm1-&gt;state-&gt;y + tmpm1-&gt;radius &gt; GROUND_Y)
<a name="l177"></a> tmpm1-&gt;DstateDt-&gt;DyDt -= </span><span class=cF5>Sqr</span><span class=cF0>(</span><span class=cF5>Sqr</span><span class=cF7>(</span><span class=cF0>tmpm1-&gt;state-&gt;y + tmpm1-&gt;radius - GROUND_Y</span><span class=cF7>)</span><span class=cF0>) * tmpm1-&gt;mass;
<a name="l178"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l179"></a> tmpm1-&gt;DstateDt-&gt;DyDt += </span><span class=cFE>500</span><span class=cF0> * tmpm1-&gt;mass;
<a name="l180"></a> </span><span class=cF1>if</span><span class=cF0> (tmpm1 == nozzle || tmpm1 == faucet)
<a name="l181"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l182"></a> tmpm1-&gt;DstateDt-&gt;DxDt = </span><span class=cFE>0</span><span class=cF0>;
<a name="l183"></a> tmpm1-&gt;DstateDt-&gt;DyDt = </span><span class=cFE>0</span><span class=cF0>;
<a name="l184"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l185"></a> }
<a name="l186"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (tmpm1-&gt;type == MT_DROPLET)
<a name="l187"></a> tmpm1-&gt;DstateDt-&gt;DyDt = </span><span class=cFE>500</span><span class=cF0> * tmpm1-&gt;mass;
<a name="l188"></a> tmpm1 = tmpm1-&gt;next;
<a name="l189"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l190"></a>}
<a name="l191"></a>
<a name="l192"></a>MyMass *PlaceMass(</span><span class=cF9>I64</span><span class=cF0> type, </span><span class=cF9>I64</span><span class=cF0> x, </span><span class=cF9>I64</span><span class=cF0> y, </span><span class=cF1>F64</span><span class=cF0> r, </span><span class=cF1>F64</span><span class=cF0> dx, </span><span class=cF1>F64</span><span class=cF0> dy, </span><span class=cF1>F64</span><span class=cF0> mass, </span><span class=cF9>CTask</span><span class=cF0> *mem_task)
<a name="l193"></a>{
<a name="l194"></a> MyMass *tmpm = </span><span class=cF5>CAlloc</span><span class=cF0>(</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF0>MyMass</span><span class=cF7>)</span><span class=cF0>, mem_task);
<a name="l195"></a>
<a name="l196"></a> tmpm-&gt;type = type;
<a name="l197"></a> tmpm-&gt;mass = mass;
<a name="l198"></a> tmpm-&gt;drag_profile_factor = </span><span class=cFE>250</span><span class=cF0>.</span><span class=cFE>0</span><span class=cF0>;
<a name="l199"></a> tmpm-&gt;x = x;
<a name="l200"></a> tmpm-&gt;y = y;
<a name="l201"></a> tmpm-&gt;DxDt = dx;
<a name="l202"></a> tmpm-&gt;DyDt = dy;
<a name="l203"></a> tmpm-&gt;radius = r;
<a name="l204"></a> </span><span class=cF5>QueueInsert</span><span class=cF0>(tmpm, ode-&gt;last_mass);
<a name="l205"></a>
<a name="l206"></a> </span><span class=cF1>return</span><span class=cF0> tmpm;
<a name="l207"></a>}
<a name="l208"></a>
<a name="l209"></a>MySpring PlaceSpring(MyMass *tmpm1, MyMass *tmpm2)
<a name="l210"></a>{
<a name="l211"></a> MySpring *tmps = </span><span class=cF5>CAlloc</span><span class=cF0>(</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF0>MySpring</span><span class=cF7>)</span><span class=cF0>);
<a name="l212"></a>
<a name="l213"></a> tmps-&gt;end1 = tmpm1;
<a name="l214"></a> tmps-&gt;end2 = tmpm2;
<a name="l215"></a> tmps-&gt;const = </span><span class=cFE>20000</span><span class=cF0>;
<a name="l216"></a> </span><span class=cF5>QueueInsert</span><span class=cF0>(tmps, ode-&gt;last_spring);
<a name="l217"></a>
<a name="l218"></a> </span><span class=cF1>return</span><span class=cF0> tmps;
<a name="l219"></a>}
<a name="l220"></a>
<a name="l221"></a></span><span class=cF1>U0</span><span class=cF0> HoseNew()
<a name="l222"></a>{
<a name="l223"></a> </span><span class=cF9>I64</span><span class=cF0> i;
<a name="l224"></a> MyMass *tmpm1 = </span><span class=cF3>NULL</span><span class=cF0>, *tmpm;
<a name="l225"></a> MySpring *tmps;
<a name="l226"></a>
<a name="l227"></a> </span><span class=cF1>for</span><span class=cF0> (i = FAUCET_X; i &lt; </span><span class=cF3>GR_WIDTH</span><span class=cF0>; i += LINK_SIZE)
<a name="l228"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l229"></a> tmpm = PlaceMass(MT_HOSE, i / </span><span class=cFE>2</span><span class=cF0>, GROUND_Y - HOSE_RADIUS, HOSE_RADIUS, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cFE>1</span><span class=cF0>.</span><span class=cFE>0</span><span class=cF0>, </span><span class=cF5>Fs</span><span class=cF0>);
<a name="l230"></a> </span><span class=cF1>if</span><span class=cF0> (tmpm1)
<a name="l231"></a> {
<a name="l232"></a> tmps = PlaceSpring(tmpm, tmpm1);
<a name="l233"></a> tmps-&gt;rest_len = LINK_SIZE;
<a name="l234"></a> tmps-&gt;type = ST_HOSE;
<a name="l235"></a> nozzle = tmpm;
<a name="l236"></a> }
<a name="l237"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l238"></a> faucet = tmpm;
<a name="l239"></a> tmpm1 = tmpm;
<a name="l240"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l241"></a> faucet-&gt;y = FAUCET_Y;
<a name="l242"></a> nozzle-&gt;y = NOZZLE_START_Y;
<a name="l243"></a> nozzle_theta = </span><span class=cFE>0</span><span class=cF0>;
<a name="l244"></a>}
<a name="l245"></a>
<a name="l246"></a></span><span class=cF1>U0</span><span class=cF0> AnimateTask(</span><span class=cF9>I64</span><span class=cF0>)
<a name="l247"></a>{
<a name="l248"></a> MyMass *tmpm, *tmpm1;
<a name="l249"></a> </span><span class=cF1>F64</span><span class=cF0> dx, dy;
<a name="l250"></a>
<a name="l251"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF3>TRUE</span><span class=cF0>)
<a name="l252"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l253"></a> dx = </span><span class=cF5>Cos</span><span class=cF0>(nozzle_theta);
<a name="l254"></a> dy = </span><span class=cF5>Sin</span><span class=cF0>(nozzle_theta);
<a name="l255"></a> PlaceMass(MT_DROPLET, nozzle-&gt;x + NOZZLE_LEN * dx,
<a name="l256"></a> nozzle-&gt;y + NOZZLE_LEN * dy, HOSE_RADIUS, </span><span class=cFE>500</span><span class=cF0> * dx, </span><span class=cFE>500</span><span class=cF0> * dy, </span><span class=cFE>100</span><span class=cF0>.</span><span class=cFE>0</span><span class=cF0>, </span><span class=cF5>Fs</span><span class=cF0>-&gt;parent_task);
<a name="l257"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>Rand</span><span class=cF0> &lt; </span><span class=cFE>0</span><span class=cF0>.</span><span class=cFE>05</span><span class=cF0>) </span><span class=cF2>//faucet drip</span><span class=cF0>
<a name="l258"></a> PlaceMass(MT_DROPLET, faucet-&gt;x, faucet-&gt;y, HOSE_RADIUS, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cFE>100</span><span class=cF0>.</span><span class=cFE>0</span><span class=cF0>, </span><span class=cF5>Fs</span><span class=cF0>-&gt;parent_task);
<a name="l259"></a>
<a name="l260"></a> tmpm = ode-&gt;next_mass;
<a name="l261"></a> </span><span class=cF1>while</span><span class=cF0> (tmpm != &amp;ode-&gt;next_mass)
<a name="l262"></a> {
<a name="l263"></a> tmpm1 = tmpm-&gt;next;
<a name="l264"></a> </span><span class=cF1>if</span><span class=cF0> (tmpm-&gt;type == MT_DROPLET &amp;&amp; tmpm-&gt;y + tmpm-&gt;radius &gt; GROUND_Y)
<a name="l265"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l266"></a> </span><span class=cF5>QueueRemove</span><span class=cF0>(tmpm);
<a name="l267"></a> </span><span class=cF5>Free</span><span class=cF0>(tmpm);
<a name="l268"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l269"></a> tmpm = tmpm1;
<a name="l270"></a> }
<a name="l271"></a> </span><span class=cF5>Refresh</span><span class=cF0>;
<a name="l272"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l273"></a>}
<a name="l274"></a>
<a name="l275"></a>#</span><span class=cF1>define</span><span class=cF0> NOZZLE_MOVE_STEPS </span><span class=cFE>5</span><span class=cF0>
<a name="l276"></a>#</span><span class=cF1>define</span><span class=cF0> NOZZLE_MOVE </span><span class=cFE>15</span><span class=cF0>.</span><span class=cFE>0</span><span class=cF0>
<a name="l277"></a></span><span class=cF1>U0</span><span class=cF0> MoveNozzleTaskX(</span><span class=cF9>I64</span><span class=cF0> sign)
<a name="l278"></a>{
<a name="l279"></a> </span><span class=cF9>I64</span><span class=cF0> i;
<a name="l280"></a>
<a name="l281"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>; i &lt; NOZZLE_MOVE_STEPS; i++)
<a name="l282"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l283"></a> nozzle-&gt;x = </span><span class=cF5>Clamp</span><span class=cF0>(nozzle-&gt;x + sign * NOZZLE_MOVE / NOZZLE_MOVE_STEPS, HOSE_RADIUS * </span><span class=cFE>3</span><span class=cF0>, </span><span class=cF3>GR_WIDTH</span><span class=cF0> - HOSE_RADIUS * </span><span class=cFE>3</span><span class=cF0>);
<a name="l284"></a> </span><span class=cF5>Refresh</span><span class=cF0>;
<a name="l285"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l286"></a>}
<a name="l287"></a>
<a name="l288"></a></span><span class=cF1>U0</span><span class=cF0> MoveNozzleTaskY(</span><span class=cF9>I64</span><span class=cF0> sign)
<a name="l289"></a>{
<a name="l290"></a> </span><span class=cF9>I64</span><span class=cF0> i;
<a name="l291"></a>
<a name="l292"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>; i &lt; NOZZLE_MOVE_STEPS; i++)
<a name="l293"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l294"></a> nozzle-&gt;y = </span><span class=cF5>Clamp</span><span class=cF0>(nozzle-&gt;y + sign * NOZZLE_MOVE / NOZZLE_MOVE_STEPS, HOSE_RADIUS * </span><span class=cFE>3</span><span class=cF0>, GROUND_Y);
<a name="l295"></a> </span><span class=cF5>Refresh</span><span class=cF0>;
<a name="l296"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l297"></a>}
<a name="l298"></a>
<a name="l299"></a></span><span class=cF1>U0</span><span class=cF0> Init()
<a name="l300"></a>{
<a name="l301"></a> </span><span class=cF5>DocClear</span><span class=cF0>;
<a name="l302"></a> </span><span class=cF6>&quot;$BG, LTCYAN$%h*c&quot;</span><span class=cF0>, </span><span class=cF5>ToI64</span><span class=cF0>(GROUND_Y / </span><span class=cF3>FONT_HEIGHT</span><span class=cF0>), </span><span class=cF6>'\n'</span><span class=cF0>;
<a name="l303"></a>
<a name="l304"></a> </span><span class=cF2>//Allow hose to settle.</span><span class=cF0>
<a name="l305"></a> start_up_timeout = </span><span class=cF5>tS</span><span class=cF0> + </span><span class=cFE>0</span><span class=cF0>.</span><span class=cFE>5</span><span class=cF0>;
<a name="l306"></a>
<a name="l307"></a> ode = </span><span class=cF5>ODENew</span><span class=cF0>(</span><span class=cFE>0</span><span class=cF0>, </span><span class=cFE>5</span><span class=cF0>e-</span><span class=cFE>2</span><span class=cF0>, </span><span class=cF3>ODEF_HAS_MASSES</span><span class=cF0>);
<a name="l308"></a> ode-&gt;derive = &amp;MyDerivative;
<a name="l309"></a> ode-&gt;acceleration_limit = </span><span class=cFE>5</span><span class=cF0>e3;
<a name="l310"></a>
<a name="l311"></a> HoseNew;
<a name="l312"></a> </span><span class=cF5>QueueInsert</span><span class=cF0>(ode, </span><span class=cF5>Fs</span><span class=cF0>-&gt;last_ode);
<a name="l313"></a>}
<a name="l314"></a>
<a name="l315"></a></span><span class=cF1>U0</span><span class=cF0> CleanUp()
<a name="l316"></a>{
<a name="l317"></a> </span><span class=cF5>Refresh</span><span class=cF0>(NOZZLE_MOVE_STEPS); </span><span class=cF2>//Let nozzle move tasks die</span><span class=cF0>
<a name="l318"></a> </span><span class=cF5>QueueRemove</span><span class=cF0>(ode);
<a name="l319"></a> </span><span class=cF5>QueueDel</span><span class=cF0>(&amp;ode-&gt;next_mass, </span><span class=cF3>TRUE</span><span class=cF0>);
<a name="l320"></a> </span><span class=cF5>QueueDel</span><span class=cF0>(&amp;ode-&gt;next_spring, </span><span class=cF3>TRUE</span><span class=cF0>);
<a name="l321"></a> </span><span class=cF5>ODEDel</span><span class=cF0>(ode);
<a name="l322"></a> </span><span class=cF5>DocClear</span><span class=cF0>;
<a name="l323"></a>}
<a name="l324"></a>
<a name="l325"></a></span><span class=cF1>U0</span><span class=cF0> SongTask(</span><span class=cF9>I64</span><span class=cF0>)
<a name="l326"></a>{
<a name="l327"></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="l328"></a> </span><span class=cF5>MusicSettingsReset</span><span class=cF0>;
<a name="l329"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF3>TRUE</span><span class=cF0>)
<a name="l330"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l331"></a> </span><span class=cF5>Play</span><span class=cF0>(</span><span class=cF6>&quot;5sDCDC4qA5DetDFFeDG4etA5EF4qG5eFC&quot;</span><span class=cF0>);
<a name="l332"></a> </span><span class=cF5>Play</span><span class=cF0>(</span><span class=cF6>&quot;5sDCDC4qA5DetDFFeDG4etA5EF4qG5eFC&quot;</span><span class=cF0>);
<a name="l333"></a> </span><span class=cF5>Play</span><span class=cF0>(</span><span class=cF6>&quot;5DCsG4A5G4AqBeBA5qEE4B5eC4B&quot;</span><span class=cF0>);
<a name="l334"></a> </span><span class=cF5>Play</span><span class=cF0>(</span><span class=cF6>&quot;5DCsG4A5G4AqBeBA5qEE4B5eC4B&quot;</span><span class=cF0>);
<a name="l335"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l336"></a>}
<a name="l337"></a>
<a name="l338"></a></span><span class=cF1>U0</span><span class=cF0> Squirt()
<a name="l339"></a>{
<a name="l340"></a> </span><span class=cF9>I64</span><span class=cF0> sc;
<a name="l341"></a>
<a name="l342"></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="l343"></a> </span><span class=cF5>Fs</span><span class=cF0>-&gt;text_attr = </span><span class=cF3>YELLOW</span><span class=cF0> &lt;&lt; </span><span class=cFE>4</span><span class=cF0> + </span><span class=cF3>BLUE</span><span class=cF0>;
<a name="l344"></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="l345"></a> </span><span class=cF5>AutoComplete</span><span class=cF0>;
<a name="l346"></a> </span><span class=cF5>WinBorder</span><span class=cF0>;
<a name="l347"></a> </span><span class=cF5>WinMax</span><span class=cF0>;
<a name="l348"></a> </span><span class=cF5>DocCursor</span><span class=cF0>;
<a name="l349"></a>
<a name="l350"></a> </span><span class=cF5>MenuPush</span><span class=cF0>( </span><span class=cF6>&quot;File {&quot;</span><span class=cF0>
<a name="l351"></a> </span><span class=cF6>&quot; Abort(,CH_SHIFT_ESC);&quot;</span><span class=cF0>
<a name="l352"></a> </span><span class=cF6>&quot; Exit(,CH_ESC);&quot;</span><span class=cF0>
<a name="l353"></a> </span><span class=cF6>&quot;}&quot;</span><span class=cF0>
<a name="l354"></a> </span><span class=cF6>&quot;Play {&quot;</span><span class=cF0>
<a name="l355"></a> </span><span class=cF6>&quot; Restart(,'\n');&quot;</span><span class=cF0>
<a name="l356"></a> </span><span class=cF6>&quot; Left(,,SC_CURSOR_LEFT);&quot;</span><span class=cF0>
<a name="l357"></a> </span><span class=cF6>&quot; Right(,,SC_CURSOR_RIGHT);&quot;</span><span class=cF0>
<a name="l358"></a> </span><span class=cF6>&quot; Up(,,SC_CURSOR_UP);&quot;</span><span class=cF0>
<a name="l359"></a> </span><span class=cF6>&quot; Down(,,SC_CURSOR_DOWN);&quot;</span><span class=cF0>
<a name="l360"></a> </span><span class=cF6>&quot;}&quot;</span><span class=cF0>
<a name="l361"></a> );
<a name="l362"></a>
<a name="l363"></a> Init;
<a name="l364"></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="l365"></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="l366"></a>
<a name="l367"></a> </span><span class=cF1>try</span><span class=cF0>
<a name="l368"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l369"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF3>TRUE</span><span class=cF0>)
<a name="l370"></a> {
<a name="l371"></a> </span><span class=cF1>switch</span><span class=cF0> (</span><span class=cF5>KeyGet</span><span class=cF7>(</span><span class=cF0>&amp;sc</span><span class=cF7>)</span><span class=cF0>)
<a name="l372"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l373"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cFE>0</span><span class=cF0>:
<a name="l374"></a> </span><span class=cF1>switch</span><span class=cF0> (sc.u8[</span><span class=cFE>0</span><span class=cF0>])
<a name="l375"></a> {
<a name="l376"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>SC_CURSOR_LEFT</span><span class=cF0>:
<a name="l377"></a> </span><span class=cF5>Spawn</span><span class=cF0>(&amp;MoveNozzleTaskX, -</span><span class=cFE>1</span><span class=cF0>, </span><span class=cF6>&quot;Move Nozzle&quot;</span><span class=cF0>,, </span><span class=cF5>Fs</span><span class=cF0>);
<a name="l378"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l379"></a>
<a name="l380"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>SC_CURSOR_RIGHT</span><span class=cF0>:
<a name="l381"></a> </span><span class=cF5>Spawn</span><span class=cF0>(&amp;MoveNozzleTaskX, </span><span class=cFE>1</span><span class=cF0>, </span><span class=cF6>&quot;Move Nozzle&quot;</span><span class=cF0>,, </span><span class=cF5>Fs</span><span class=cF0>);
<a name="l382"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l383"></a>
<a name="l384"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>SC_CURSOR_UP</span><span class=cF0>:
<a name="l385"></a> </span><span class=cF5>Spawn</span><span class=cF0>(&amp;MoveNozzleTaskY, -</span><span class=cFE>1</span><span class=cF0>, </span><span class=cF6>&quot;Move Nozzle&quot;</span><span class=cF0>,, </span><span class=cF5>Fs</span><span class=cF0>);
<a name="l386"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l387"></a>
<a name="l388"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>SC_CURSOR_DOWN</span><span class=cF0>:
<a name="l389"></a> </span><span class=cF5>Spawn</span><span class=cF0>(&amp;MoveNozzleTaskY, </span><span class=cFE>1</span><span class=cF0>, </span><span class=cF6>&quot;Move Nozzle&quot;</span><span class=cF0>,, </span><span class=cF5>Fs</span><span class=cF0>);
<a name="l390"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l391"></a> }
<a name="l392"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l393"></a>
<a name="l394"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF6>'\n'</span><span class=cF0>:
<a name="l395"></a> CleanUp;
<a name="l396"></a> Init;
<a name="l397"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l398"></a>
<a name="l399"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>CH_SHIFT_ESC</span><span class=cF0>:
<a name="l400"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>CH_ESC</span><span class=cF0>:
<a name="l401"></a> </span><span class=cF1>goto</span><span class=cF0> sq_done;
<a name="l402"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l403"></a> }
<a name="l404"></a>sq_done: </span><span class=cF2>//Don't goto out of try</span><span class=cF0>
<a name="l405"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l406"></a> </span><span class=cF1>catch</span><span class=cF0>
<a name="l407"></a> </span><span class=cF5>PutExcept</span><span class=cF0>;
<a name="l408"></a> </span><span class=cF5>SettingsPop</span><span class=cF0>;
<a name="l409"></a> CleanUp;
<a name="l410"></a> </span><span class=cF5>MenuPop</span><span class=cF0>;
<a name="l411"></a>}
<a name="l412"></a>
<a name="l413"></a>Squirt;
</span></pre></body>
</html>