<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>trail</title>
		<link>http://www.allegro.cc/forums/view/586149</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Wed, 28 Jun 2006 20:47:23 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>In my pong game. I want to have the ball leave a trail of putpixels. The only problem with this is that I am clearing the buffer every loop so the putpixel from the previous loop does not stay. Anyone have an idea to get around this.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (neil dwyer)</author>
		<pubDate>Wed, 28 Jun 2006 06:33:05 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Make a particle class and use it to leave a trail, that way it gets treated like every other object and is redrawn.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SonShadowCat)</author>
		<pubDate>Wed, 28 Jun 2006 06:38:32 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The old pixels would still be cleared from the buffer, no?</p><p>Edit: is there a way to clear certain objects from a bitmap without clearing the whole bitmap.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (neil dwyer)</author>
		<pubDate>Wed, 28 Jun 2006 07:31:08 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yes, the &quot;old&quot; pixels will be cleared when you clear your frame buffer, but you will be redrawing. What you could do is record the last 10 frames&#39; (x,y) coordinates for the ball. Then, in your drawing, you would redraw all 10 frames using the ball&#39;s bitmap, but you could also add alpha blending. Here is an example of what I&#39;m talking about.</p><p>Our point structure, so we can easily manage 2D points
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">typedef</span> <span class="k1">struct</span> Point2D
<span class="k2">{</span>
  <span class="k1">int</span> x<span class="k2">;</span>
  <span class="k1">int</span> y<span class="k2">;</span>
<span class="k2">}</span><span class="k2">;</span>
</pre></div></div><p>

Declare our array of trails
</p><div class="source-code snippet"><div class="inner"><pre>  <span class="p">#define MAX_TRAILS     10</span>
  Point2D BallTrail<span class="k2">[</span>MAX_TRAILS<span class="k3">+</span><span class="n">1</span><span class="k2">]</span><span class="k2">;</span>
</pre></div></div><p>


Our drawing method for ball
</p><div class="source-code"><div class="toolbar"></div><div class="inner"><table width="100%"><tbody><tr><td class="number">1</td><td><span class="k1">void</span> Ball::Draw<span class="k2">(</span><a href="http://www.allegro.cc/manual/BITMAP" target="_blank"><span class="a">BITMAP</span></a> <span class="k3">*</span>dest<span class="k2">)</span></td></tr><tr><td class="number">2</td><td><span class="k2">{</span></td></tr><tr><td class="number">3</td><td>    <span class="k1">for</span><span class="k2">(</span><span class="k1">int</span> i <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span> i <span class="k3">&lt;</span> MAX_TRAILS<span class="k2">;</span> i<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span></td></tr><tr><td class="number">4</td><td>    <span class="k2">{</span></td></tr><tr><td class="number">5</td><td>      <span class="k1">int</span> per <span class="k3">=</span> <span class="k2">(</span> <span class="n">128</span> <span class="k3">*</span> <span class="k2">(</span><span class="k2">(</span><span class="k1">float</span><span class="k2">)</span>i<span class="k3">/</span>MAX_TRAILS<span class="k2">)</span> <span class="k2">)</span><span class="k2">;</span> <span class="c">// calculate the percentage</span></td></tr><tr><td class="number">6</td><td>                                          <span class="c">// which is used in the alpha</span></td></tr><tr><td class="number">7</td><td>      <a href="http://www.allegro.cc/manual/set_trans_blender" target="_blank"><span class="a">set_trans_blender</span></a><span class="k2">(</span>per, per, per, per<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">8</td><td>      <a href="http://www.allegro.cc/manual/draw_trans_sprite" target="_blank"><span class="a">draw_trans_sprite</span></a><span class="k2">(</span>dest, sprBall, BallTrail<span class="k3">&lt;</span>i&gt;.x, BallTrail<span class="k3">&lt;</span>i&gt;.y<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">9</td><td>    <span class="k2">}</span></td></tr><tr><td class="number">10</td><td>  </td></tr><tr><td class="number">11</td><td>    <span class="c">// turn off trans blending, draw our REAL ball</span></td></tr><tr><td class="number">12</td><td>    <a href="http://www.allegro.cc/manual/set_trans_blender" target="_blank"><span class="a">set_trans_blender</span></a><span class="k2">(</span><span class="n">255</span>, <span class="n">255</span>, <span class="n">255</span>, <span class="n">255</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">13</td><td>    <a href="http://www.allegro.cc/manual/draw_sprite" target="_blank"><span class="a">draw_sprite</span></a><span class="k2">(</span>dest, sprBall, x, y<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">14</td><td>&#160;</td></tr><tr><td class="number">15</td><td>    <span class="c">// update our trails</span></td></tr><tr><td class="number">16</td><td>    BallTrail<span class="k2">[</span>MAX_TRAILS<span class="k2">]</span>.x <span class="k3">=</span> x<span class="k2">;</span></td></tr><tr><td class="number">17</td><td>    BallTrail<span class="k2">[</span>MAX_TRAILS<span class="k2">]</span>.y <span class="k3">=</span> y<span class="k2">;</span></td></tr><tr><td class="number">18</td><td>    <span class="k1">for</span><span class="k2">(</span><span class="k1">int</span> i <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span> i <span class="k3">&lt;</span> MAX_TRAILS<span class="k2">;</span> i<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span> <span class="k2">{</span></td></tr><tr><td class="number">19</td><td>      BallTrail<span class="k3">&lt;</span>i&gt;.x <span class="k3">=</span> BallTrail<span class="k2">[</span>i<span class="k3">+</span><span class="n">1</span><span class="k2">]</span>.x<span class="k2">;</span></td></tr><tr><td class="number">20</td><td>      BallTrail<span class="k3">&lt;</span>i&gt;.y <span class="k3">=</span> BallTrail<span class="k2">[</span>i<span class="k3">+</span><span class="n">1</span><span class="k2">]</span>.y<span class="k2">;</span> <span class="k2">}</span></td></tr><tr><td class="number">21</td><td><span class="k2">}</span></td></tr></tbody></table></div></div><p>

You will need to go through and pound out a few of the minor things (such as fully initialising the array), and this code is untested, but at least it gives you the idea.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elverion)</author>
		<pubDate>Wed, 28 Jun 2006 14:19:47 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I don&#39;t know if either explaination makes it clear or not, but the goal is to keep in memory enough information to redraw the trail.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
is there a way to clear certain objects from a bitmap without clearing the whole bitmap.
</p></div></div><p>
The dirty rectangle system (DRS) is a programming technique to do it. The Allegro demo game has an implementation.<br />It works by making a small copy of the background BITMAP, <u>before</u> putting any sprite there. So you can later &quot;remove&quot; the sprite by overwriting it with the stored copy.<br />It&#39;s mostly intended for sprites and such, so in your case (pixel-size particles), it should work but is probably quite inefficient.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Audric)</author>
		<pubDate>Wed, 28 Jun 2006 14:51:11 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Ok since my physics are non-existent(ball_x adds until it hits the paddle, then it subtracts;ball_y adds until it hits the wall then it subtracts) I declared 10 variables(5 for the five pixel&#39;s x values and 5 for the y&#39;s). It would of made sense to make a tail[5][2] but I wasn&#39;t thinking about clean code. Tail1 is always equal to the middle of the ball. If the ball_x is adding, then the next tail&#39;s x value is ball_x - 5.</p><p>I had the idea to make the program &quot;remember&quot; where the ball has been from 5 frames before but I didn&#39;t know how to do it. I&#39;ll look in to elverion&#39;s idea.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (neil dwyer)</author>
		<pubDate>Wed, 28 Jun 2006 20:47:23 +0000</pubDate>
	</item>
</rss>
