<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Pong problems</title>
		<link>http://www.allegro.cc/forums/view/587603</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Mon, 18 Sep 2006 07:07:59 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hi all, i am new to allegro, just started around 3 or 4 days ago, i went through tutorials that i could find and learned sum stuff and looked at their code for pong and other games and decided to try and make my own pong clone useing what i had learned, so i set about it and got so far as to make 2 paddles and a ball. Both paddles move fine but i cannot figure out how to make them reflect the ball. i also cannot figure out how to stop the paddles from going off the map or make the ball reflect off the top and bottom walls, can anyone tell me how to set up boundaries for the walls and the paddle to reflect the ball?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Danex!)</author>
		<pubDate>Mon, 18 Sep 2006 00:40:19 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Well, you have 2 problems: making the paddles stay on screen, and making the ball bounce.</p><p>First, the paddles are on the screen if their Y value is 0 or greater, right? The paddle starts at Y, and goes down to Y + height. So, make sure that both paddles always have a Y greater than or equal to 0. Also, if the bottom of the paddle, Y + height, every goes off the bottom of the screen, SCREEN_H, then you need to stop it. That means that, if you detect that Y + height of either paddle is greater than SCREEN_H, you should set that paddle&#39;s Y value to SCREEN_H - height (it&#39;s an equation: Y + height = SCREEN_H, solve for Y).</p><p>The ball should bounce off the top and bottom of the screen if its Y - radius goes under 0 (the top of the screen), or if its Y + radius goes greater than the SCREEN_H (the bottom of the screen). When you detect that that has happened, you should switch the directrion of the ball to moving the opposite direction up or down.</p><p>You can tell if the ball is hitting a paddle because the X value is equal to the paddles X value, and the ball&#39;s Y is both larger than the paddle&#39;s Y value (the ball is lower than the top of the paddle), and less than the paddle&#39;s Y value + height (the ball is higher than the bottom of the paddle). When this happens, just switch the direction that the ball is going, left or right.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (CGamesPlay)</author>
		<pubDate>Mon, 18 Sep 2006 00:58:09 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>cool thx i will try that and post back results<br />Danex!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Danex!)</author>
		<pubDate>Mon, 18 Sep 2006 02:57:43 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>If that&#39;s the case then you shouldn&#39;t respond to this post until after you have the results, because you can&#39;t post twice in a row <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (CGamesPlay)</author>
		<pubDate>Mon, 18 Sep 2006 02:58:45 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>1)<br />ok, i get that part about the paddle logic, i set the paddles to not go below 0 or above 480 with  <br />    if (paddle_1_y &lt; 0){<br />        paddle_1_y = 0;}<br />    if (paddle_2_y &lt; 0){<br />        paddle_2_y = 0;}<br />    if (paddle_1_y &gt; 480){<br />        paddle_1_y = 480;}<br />    if (paddle_2_y &gt; 480){<br />        paddle_2_y = 480;}<br />part of it works becuase the paddle will not go below 0, but the paddle goes alittle below my screen where i can see part but part is off the screen, i think it may be a problem with my screen becuase the paddle diffinently stops and won&#39;t move any more<br />2) i cannot get the ball to move right???, thats my move ball function below, it also has my logic for bounceing the ball off the paddle</p><p>void move_ball(){ </p><p>if (ball_x == 630) {<br />           if (ball_y &gt; paddle_2_y, paddle_2_y + 79 &gt; ball_y)<br />           { ball_x--; } <br />           else if(ball_x==635) {          <br />    ball_x--;<br />    textout_ex( buffer, font, &quot;Player 1 Wins!&quot;, 320, 240, makecol( 255, 0, 0), makecol( 0, 0, 0));      } <br />}<br />    <br />if (ball_x == 5){<br />           if (ball_y &gt; paddle_2_y, paddle_2_y + 79 &gt; ball_y)<br />           { ball_x--; } <br />else if (ball_x==0){<br />ball_x++;<br />    textout_ex( buffer, font, &quot;Player 2 Wins!&quot;, 320, 240, makecol( 255, 0, 0), makecol( 0, 0, 0));<br />    }   } <br />     circlefill( buffer, ball_x, ball_y , 5, makecol( 0,255, 0)); <br />     }
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Danex!)</author>
		<pubDate>Mon, 18 Sep 2006 03:50:05 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>If the paddle&#39;s Y value can become 480, that means that thetop of the paddle will be the very bottom row on the screen, with the rest of the paddle off of the screen. You need to make sure that the paddle&#39;s Y value never goes below the screen height - the paddle height.</p><p><img class="math" src="http://www.allegro.cc/images/tex/2/3/23848766d8dfaad4b7cdb4abf8a2a824-96.png" alt="&lt;math&gt;y_{paddle} + h_{paddle} = h_{screen}&lt;/math&gt;" /></p><p>The move_ball function will need to be written again. In order to properly handle this, you need to have 4 variables. x, y, x_speed, and y_speed. Every time the function is called, add x_speed to x and y_speed to y. To make the ball move up, set y_speed to a negative number. To make the ball move down, set y_speed to a positive number. Same applies to x_speed and moving left/right.</p><p>After you have that working properly, when the ball&#39;s y is less than 0, set y_speed = -y_speed, and when the ball&#39;s y is greater than the screen height, sey y_speed = -y_speed;
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (CGamesPlay)</author>
		<pubDate>Mon, 18 Sep 2006 04:01:24 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>ok so first off i need to change ---&gt;<br />if (paddle_1_y &lt; 0){<br />paddle_1_y = 0;}<br />if (paddle_2_y &lt; 0){<br />paddle_2_y = 0;}<br />if (paddle_1_y &gt; 480){<br />paddle_1_y = 480;}<br />if (paddle_2_y &gt; 480){<br />paddle_2_y = 480;}<br /> to something like ---&gt;<br />if (paddle_1_y + paddle_1_hight &gt; 480){<br />paddle_1_y = 480;}</p><p>and second i need to scrap the whole move ball function and restart with 4 variables of x,y,x_speed,y_speed<br />in the second part i do not understand why that makes the ball move, am i supposed to update x_speed to update x?<br />Danex!<br />P.S. thx for all ur help and understanding that i am ignorant of allegro logic
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Danex!)</author>
		<pubDate>Mon, 18 Sep 2006 04:16:28 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="source-code snippet"><div class="inner"><pre><span class="k1">if</span> <span class="k2">(</span>paddle_1_y <span class="k3">&lt;</span> <span class="n">0</span><span class="k2">)</span>
<span class="k2">{</span>
    paddle_1_y <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span>
<span class="k2">}</span>
<span class="k1">if</span> <span class="k2">(</span>paddle_1_y <span class="k3">+</span> paddle_1_height <span class="k3">&gt;</span> <span class="n">480</span><span class="k2">)</span>
<span class="k2">{</span>
    paddle_1_y <span class="k3">=</span> <span class="n">480</span> <span class="k3">-</span> paddle_1_height<span class="k2">;</span>
<span class="k2">}</span>
</pre></div></div><p>That is how it should look for 1 paddle <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /></p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
i need to scrap the whole move ball function and restart with 4 variables of x,y,x_speed,y_speed<br />in the second part i do not understand why that makes the ball move, am i supposed to update x_speed to update x?
</p></div></div><p>Well, if you have x_speed = 1; and every move_ball you set x = x + x_speed; then the ball will move to the right 1 pixel every time move_ball is called. If x_speed is -1, then the ball will move left 1 pixel every time move_ball is called. You can make it move faster, too. x_speed = 1 means it moves 2 pixels right each call, etc. All of this also applies to the y_speed.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
P.S. thx for all ur help and understanding that i am ignorant of allegro logic
</p></div></div><p>Well, to be technical, this is just math <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (CGamesPlay)</author>
		<pubDate>Mon, 18 Sep 2006 04:37:27 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>mk i set up the boundaries for the paddle like you said and if worked perfectly<br /><img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" /> thanks alot, can you give kudos or karma or something on this forum?<br />also is it a good idea to mix primitives like<br />&quot;circlefill( buffer, ball_x, ball_y , 5, makecol( 0,255, 0));&quot;<br />with bitmaps, or should i just make another bitmap of a ball?<br />P.S. working on the moving ball and i am currently using a primative for the ball and don&#39;t want that to mess my program
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Danex!)</author>
		<pubDate>Mon, 18 Sep 2006 05:04:11 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
thanks alot, can you give kudos or karma or something on this forum?
</p></div></div><p>If there isn&#39;t a check box that says &quot;this question has been answered to my satisfaction&quot;, then no, there isn&#39;t. You have to specify the kind of thread as one &quot;with a specific answer&quot; when you make the thread.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
also is it a good idea to mix primitives like<br />&quot;circlefill( buffer, ball_x, ball_y , 5, makecol( 0,255, 0));&quot;<br />with bitmaps, or should i just make another bitmap of a ball?
</p></div></div><p>Use whatever is easiest, because both are fine.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (CGamesPlay)</author>
		<pubDate>Mon, 18 Sep 2006 05:26:02 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>OK made a new move_ball()<br />void move_ball(){ <br />int x_speed=1;<br />int y_speed=1;<br />ball_x +=  x_speed;<br />ball_y +=  y_speed; </p><p>if (ball_y &lt; 0){<br />ball_y = 0;}<br />if (ball_y  &gt; 475){<br />ball_y = 475;}<br />if (ball_x == 5 &amp;&amp; ball_y &gt;= paddle_1_y  &amp;&amp; ball_y &lt;= paddle_1_y){<br />    x_speed = -1;<br />    y_speed = -1; }<br />if (ball_x == 635 &amp;&amp; ball_y &gt;= paddle_2_y  &amp;&amp; ball_y &lt;= paddle_2_y){<br />    x_speed = -1;<br />    y_speed = -1; }<br />i am gettin somewhere at least cause the ball moves down and to the right<br />and i tried the greator than or equal to math but i am gettin no reflection<br />On, the plus side i applied the same logic used in the paddles to make the ball not able to leave the map<br />However, the ball merely sticks to the bottom and straight lines to the end<br />i believe this is due to me not makeing the ball bounce with this ---&gt;<br />if (ball_y &lt; 0){<br />ball_y = 0;}<br />if (ball_y  &gt; 475){<br />ball_y = 475;}</p><p>what should i add so that</p><p>if (ball_y &lt; 0){<br />ball_y = 0;<br />----&gt;switch direction of incoming ball(bounce)}<br />if (ball_y  &gt; 475){<br />ball_y = 475;<br />----&gt;switch direction of incoming ball(bounce)}
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Danex!)</author>
		<pubDate>Mon, 18 Sep 2006 05:38:39 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p><a href="http://www.allegro.cc/mockup.html">Please read this</a></p><p>Your speed variables are local vairables. Even if you set them to -1, the will get set to 1 when you call the function again. Make them globals <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (CGamesPlay)</author>
		<pubDate>Mon, 18 Sep 2006 05:45:25 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Your speed variables are local vairables. Even if you set them to -1, the will get set to 1 when you call the function again. <b>Make them globals</b> <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div></div><p>

OMFG!!!!111</p><p>Stop the madness!!  CGames is telling a newb to use globals!!!  He&#39;s out of control, someone stop him!!!!</p><p>Danex!, when you use global variables, it makes kittens cry.  <img src="http://www.allegro.cc/forums/smileys/cry.gif" alt=":&#39;(" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (nonnus29)</author>
		<pubDate>Mon, 18 Sep 2006 06:06:35 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>[in scary robot voice] &quot;Use global variables or I make <i>you</i> cry!&quot; [/in scary robot voice]
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kikaru)</author>
		<pubDate>Mon, 18 Sep 2006 06:14:15 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>In Soviet Russia, global variables use <i>you</i>!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (CGamesPlay)</author>
		<pubDate>Mon, 18 Sep 2006 06:18:17 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Whats wrong with globals? half my coding is globals ha ha, well not half but alot<br />Danex!<br />also l o l makes I&#39;m Dumb!...thats pretty funny<br />anyway i made them globals but the ball still doesn&#39;t bounce <img src="http://www.allegro.cc/forums/smileys/sad.gif" alt=":(" /><br />the following is my entire program as u can see lots of globals</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="p">#include &lt;allegro.h&gt;</span></td></tr><tr><td class="number">2</td><td><span class="p">#include &lt;cstdlib&gt;</span></td></tr><tr><td class="number">3</td><td><span class="p">#include &lt;time.h&gt;</span></td></tr><tr><td class="number">4</td><td><a href="http://www.allegro.cc/manual/BITMAP" target="_blank"><span class="a">BITMAP</span></a> <span class="k3">*</span>buffer<span class="k2">;</span></td></tr><tr><td class="number">5</td><td><span class="k1">void</span> move_ball<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span> </td></tr><tr><td class="number">6</td><td><span class="k1">volatile</span> <span class="k1">long</span> speed_counter<span class="k2">;</span> </td></tr><tr><td class="number">7</td><td><span class="k1">void</span> increment_speed_counter<span class="k2">(</span><span class="k2">)</span> <span class="k2">{</span></td></tr><tr><td class="number">8</td><td>speed_counter <span class="k3">+</span><span class="k3">+</span><span class="k2">;</span> <span class="k2">}</span></td></tr><tr><td class="number">9</td><td><a href="http://www.allegro.cc/manual/END_OF_FUNCTION" target="_blank"><span class="a">END_OF_FUNCTION</span></a><span class="k2">(</span>increment_speed_counter<span class="k2">)</span></td></tr><tr><td class="number">10</td><td><span class="k1">int</span> ball_x <span class="k3">=</span> <span class="n">320</span><span class="k2">;</span></td></tr><tr><td class="number">11</td><td><span class="k1">int</span> ball_y <span class="k3">=</span> <span class="n">240</span><span class="k2">;</span></td></tr><tr><td class="number">12</td><td><span class="k1">int</span> <a href="http://www.delorie.com/djgpp/doc/libc/libc_639.html" target="_blank">random</a><span class="k2">;</span></td></tr><tr><td class="number">13</td><td><span class="k1">int</span> paddle_1_y <span class="k3">=</span> <span class="n">240</span><span class="k2">;</span></td></tr><tr><td class="number">14</td><td><span class="k1">int</span> paddle_1_height <span class="k3">=</span> <span class="n">79</span><span class="k2">;</span></td></tr><tr><td class="number">15</td><td><span class="k1">int</span> paddle_2_height <span class="k3">=</span> <span class="n">79</span><span class="k2">;</span></td></tr><tr><td class="number">16</td><td><span class="k1">int</span> paddle_2_y <span class="k3">=</span> <span class="n">240</span><span class="k2">;</span></td></tr><tr><td class="number">17</td><td><span class="k1">int</span> paddle_1_x <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span></td></tr><tr><td class="number">18</td><td><span class="k1">int</span> paddle_2_x <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span></td></tr><tr><td class="number">19</td><td><span class="k1">int</span> x_speed<span class="k3">=</span><span class="n">2</span><span class="k2">;</span></td></tr><tr><td class="number">20</td><td><span class="k1">int</span> y_speed<span class="k3">=</span><span class="n">1</span><span class="k2">;</span></td></tr><tr><td class="number">21</td><td><span class="k1">int</span> main<span class="k2">(</span><span class="k1">int</span> argc, <span class="k1">char</span> argv <span class="k2">[</span><span class="k2">]</span><span class="k2">)</span> <span class="k2">{</span></td></tr><tr><td class="number">22</td><td>    <a href="http://www.allegro.cc/manual/allegro_init" target="_blank"><span class="a">allegro_init</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">23</td><td>    <a href="http://www.allegro.cc/manual/install_timer" target="_blank"><span class="a">install_timer</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">24</td><td>    <a href="http://www.allegro.cc/manual/LOCK_VARIABLE" target="_blank"><span class="a">LOCK_VARIABLE</span></a><span class="k2">(</span>speed_counter<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">25</td><td>    <a href="http://www.allegro.cc/manual/LOCK_FUNCTION" target="_blank"><span class="a">LOCK_FUNCTION</span></a><span class="k2">(</span>increment_speed_counter<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">26</td><td>    <a href="http://www.allegro.cc/manual/install_int_ex" target="_blank"><span class="a">install_int_ex</span></a><span class="k2">(</span>increment_speed_counter,BPS_TO_TIMER<span class="k2">(</span><span class="n">60</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">27</td><td>    <a href="http://www.allegro.cc/manual/install_keyboard" target="_blank"><span class="a">install_keyboard</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">28</td><td>    <a href="http://www.allegro.cc/manual/set_color_depth" target="_blank"><span class="a">set_color_depth</span></a><span class="k2">(</span><span class="n">16</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">29</td><td>    <a href="http://www.allegro.cc/manual/set_gfx_mode" target="_blank"><span class="a">set_gfx_mode</span></a><span class="k2">(</span>GFX_AUTODETECT,<span class="n">640</span>,<span class="n">480</span>,<span class="n">0</span>,<span class="n">0</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">30</td><td>    </td></tr><tr><td class="number">31</td><td>    <a href="http://www.allegro.cc/manual/BITMAP" target="_blank"><span class="a">BITMAP</span></a> <span class="k3">*</span>paddle_1<span class="k2">;</span></td></tr><tr><td class="number">32</td><td>    <a href="http://www.allegro.cc/manual/BITMAP" target="_blank"><span class="a">BITMAP</span></a> <span class="k3">*</span>paddle_2<span class="k2">;</span></td></tr><tr><td class="number">33</td><td>    paddle_1 <span class="k3">=</span> <a href="http://www.allegro.cc/manual/load_bitmap" target="_blank"><span class="a">load_bitmap</span></a><span class="k2">(</span><span class="s">"paddle1.bmp"</span>,NULL<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">34</td><td>    paddle_2 <span class="k3">=</span> <a href="http://www.allegro.cc/manual/load_bitmap" target="_blank"><span class="a">load_bitmap</span></a><span class="k2">(</span><span class="s">"paddle2.bmp"</span>,NULL<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">35</td><td>    buffer <span class="k3">=</span> <a href="http://www.allegro.cc/manual/create_bitmap" target="_blank"><span class="a">create_bitmap</span></a><span class="k2">(</span><span class="n">640</span>,<span class="n">480</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">36</td><td>    <span class="k1">void</span> setup<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">37</td><td>    <span class="k1">while</span> <span class="k2">(</span><span class="k3">!</span><a href="http://www.allegro.cc/manual/key" target="_blank"><span class="a">key</span></a><span class="k2">[</span>KEY_ESC<span class="k2">]</span><span class="k2">)</span></td></tr><tr><td class="number">38</td><td>    <span class="k2">{</span> </td></tr><tr><td class="number">39</td><td>          </td></tr><tr><td class="number">40</td><td>    <span class="k1">while</span> <span class="k2">(</span>speed_counter <span class="k3">&gt;</span><span class="n">0</span><span class="k2">)</span> </td></tr><tr><td class="number">41</td><td>          <span class="k2">{</span></td></tr><tr><td class="number">42</td><td>                         </td></tr><tr><td class="number">43</td><td>                         </td></tr><tr><td class="number">44</td><td>    <span class="k1">if</span> <span class="k2">(</span><a href="http://www.allegro.cc/manual/key" target="_blank"><span class="a">key</span></a><span class="k2">[</span>KEY_LEFT<span class="k2">]</span><span class="k2">)</span><span class="k2">{</span></td></tr><tr><td class="number">45</td><td>    paddle_1_y <span class="k3">+</span><span class="k3">+</span><span class="k2">;</span></td></tr><tr><td class="number">46</td><td>    paddle_1_y <span class="k3">+</span><span class="k3">+</span><span class="k2">;</span> <span class="k2">}</span></td></tr><tr><td class="number">47</td><td>      <span class="k1">else</span> <span class="k1">if</span> <span class="k2">(</span><a href="http://www.allegro.cc/manual/key" target="_blank"><span class="a">key</span></a><span class="k2">[</span>KEY_RIGHT<span class="k2">]</span><span class="k2">)</span><span class="k2">{</span></td></tr><tr><td class="number">48</td><td>    paddle_1_y <span class="k3">-</span><span class="k3">-</span><span class="k2">;</span></td></tr><tr><td class="number">49</td><td>    paddle_1_y <span class="k3">-</span><span class="k3">-</span><span class="k2">;</span> <span class="k2">}</span></td></tr><tr><td class="number">50</td><td>    <span class="k1">if</span> <span class="k2">(</span><a href="http://www.allegro.cc/manual/key" target="_blank"><span class="a">key</span></a><span class="k2">[</span>KEY_A<span class="k2">]</span><span class="k2">)</span> <span class="k2">{</span></td></tr><tr><td class="number">51</td><td>    paddle_2_y <span class="k3">+</span><span class="k3">+</span><span class="k2">;</span></td></tr><tr><td class="number">52</td><td>    paddle_2_y <span class="k3">+</span><span class="k3">+</span><span class="k2">;</span> <span class="k2">}</span>                </td></tr><tr><td class="number">53</td><td>    <span class="k1">else</span> <span class="k1">if</span> <span class="k2">(</span><a href="http://www.allegro.cc/manual/key" target="_blank"><span class="a">key</span></a><span class="k2">[</span>KEY_D<span class="k2">]</span><span class="k2">)</span><span class="k2">{</span></td></tr><tr><td class="number">54</td><td>    paddle_2_y <span class="k3">-</span><span class="k3">-</span><span class="k2">;</span></td></tr><tr><td class="number">55</td><td>    paddle_2_y <span class="k3">-</span><span class="k3">-</span><span class="k2">;</span> <span class="k2">}</span> </td></tr><tr><td class="number">56</td><td>    speed_counter <span class="k3">-</span><span class="k3">-</span><span class="k2">;</span> </td></tr><tr><td class="number">57</td><td>    <span class="k1">if</span> <span class="k2">(</span>paddle_1_y <span class="k3">&lt;</span> <span class="n">0</span><span class="k2">)</span><span class="k2">{</span></td></tr><tr><td class="number">58</td><td>    paddle_1_y <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span><span class="k2">}</span></td></tr><tr><td class="number">59</td><td>    <span class="k1">if</span> <span class="k2">(</span>paddle_2_y <span class="k3">&lt;</span> <span class="n">0</span><span class="k2">)</span><span class="k2">{</span></td></tr><tr><td class="number">60</td><td>    paddle_2_y <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span><span class="k2">}</span></td></tr><tr><td class="number">61</td><td>    <span class="k1">if</span> <span class="k2">(</span>paddle_1_y <span class="k3">+</span> paddle_1_height <span class="k3">&gt;</span> <span class="n">480</span><span class="k2">)</span><span class="k2">{</span></td></tr><tr><td class="number">62</td><td>    paddle_1_y <span class="k3">=</span> <span class="n">480</span> <span class="k3">-</span> paddle_1_height<span class="k2">;</span><span class="k2">}</span></td></tr><tr><td class="number">63</td><td>    <span class="k1">if</span> <span class="k2">(</span>paddle_2_y <span class="k3">+</span> paddle_2_height <span class="k3">&gt;</span> <span class="n">480</span><span class="k2">)</span><span class="k2">{</span></td></tr><tr><td class="number">64</td><td>    paddle_2_y <span class="k3">=</span> <span class="n">480</span> <span class="k3">-</span> paddle_2_height<span class="k2">;</span><span class="k2">}</span></td></tr><tr><td class="number">65</td><td>    </td></tr><tr><td class="number">66</td><td>    <span class="k2">}</span></td></tr><tr><td class="number">67</td><td>    </td></tr><tr><td class="number">68</td><td>    move_ball<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">69</td><td>    <a href="http://www.allegro.cc/manual/draw_sprite" target="_blank"><span class="a">draw_sprite</span></a><span class="k2">(</span>buffer, paddle_1, <span class="n">0</span>, paddle_1_y<span class="k2">)</span><span class="k2">;</span>                                                  </td></tr><tr><td class="number">70</td><td>    <a href="http://www.allegro.cc/manual/draw_sprite" target="_blank"><span class="a">draw_sprite</span></a><span class="k2">(</span>buffer, paddle_2, <span class="n">620</span>, paddle_2_y<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">71</td><td>    <a href="http://www.allegro.cc/manual/blit" target="_blank"><span class="a">blit</span></a><span class="k2">(</span>buffer,<a href="http://www.allegro.cc/manual/screen" target="_blank"><span class="a">screen</span></a>,<span class="n">0</span>,<span class="n">0</span>,<span class="n">0</span>,<span class="n">0</span>,<span class="n">640</span>,<span class="n">480</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">72</td><td>    <a href="http://www.allegro.cc/manual/clear_bitmap" target="_blank"><span class="a">clear_bitmap</span></a><span class="k2">(</span>buffer<span class="k2">)</span><span class="k2">;</span> <span class="k2">}</span></td></tr><tr><td class="number">73</td><td><a href="http://www.allegro.cc/manual/destroy_bitmap" target="_blank"><span class="a">destroy_bitmap</span></a><span class="k2">(</span>paddle_1<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">74</td><td><a href="http://www.allegro.cc/manual/destroy_bitmap" target="_blank"><span class="a">destroy_bitmap</span></a><span class="k2">(</span>paddle_2<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">75</td><td><a href="http://www.allegro.cc/manual/destroy_bitmap" target="_blank"><span class="a">destroy_bitmap</span></a><span class="k2">(</span>buffer<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">76</td><td><span class="k1">return</span> <span class="n">0</span><span class="k2">;</span><span class="k2">}</span></td></tr><tr><td class="number">77</td><td><a href="http://www.allegro.cc/manual/END_OF_MAIN" target="_blank"><span class="a">END_OF_MAIN</span></a><span class="k2">(</span><span class="k2">)</span> </td></tr><tr><td class="number">78</td><td>&#160;</td></tr><tr><td class="number">79</td><td>&#160;</td></tr><tr><td class="number">80</td><td>     </td></tr><tr><td class="number">81</td><td><span class="k1">void</span> move_ball<span class="k2">(</span><span class="k2">)</span><span class="k2">{</span> </td></tr><tr><td class="number">82</td><td>ball_x <span class="k3">=</span> ball_x <span class="k3">+</span> x_speed<span class="k2">;</span></td></tr><tr><td class="number">83</td><td>ball_y <span class="k3">=</span> ball_y <span class="k3">+</span> y_speed<span class="k2">;</span> </td></tr><tr><td class="number">84</td><td>&#160;</td></tr><tr><td class="number">85</td><td><span class="k1">if</span> <span class="k2">(</span>ball_y <span class="k3">&lt;</span> <span class="n">0</span><span class="k2">)</span><span class="k2">{</span></td></tr><tr><td class="number">86</td><td>ball_y <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span><span class="k2">}</span></td></tr><tr><td class="number">87</td><td><span class="k1">if</span> <span class="k2">(</span>ball_y  <span class="k3">&gt;</span> <span class="n">475</span><span class="k2">)</span><span class="k2">{</span></td></tr><tr><td class="number">88</td><td>ball_y <span class="k3">=</span> <span class="n">475</span><span class="k2">;</span><span class="k2">}</span></td></tr><tr><td class="number">89</td><td><span class="k1">if</span> <span class="k2">(</span>ball_x <span class="k3">=</span><span class="k3">=</span> <span class="n">5</span> <span class="k3">&amp;</span><span class="k3">&amp;</span> ball_y <span class="k3">&gt;</span><span class="k3">=</span> paddle_1_y  <span class="k3">&amp;</span><span class="k3">&amp;</span> ball_y <span class="k3">&lt;</span><span class="k3">=</span> paddle_1_y<span class="k2">)</span><span class="k2">{</span></td></tr><tr><td class="number">90</td><td>    x_speed <span class="k3">=</span> <span class="n">1</span><span class="k2">;</span></td></tr><tr><td class="number">91</td><td>    y_speed <span class="k3">=</span> <span class="n">1</span><span class="k2">;</span> <span class="k2">}</span></td></tr><tr><td class="number">92</td><td><span class="k1">if</span> <span class="k2">(</span>ball_x <span class="k3">=</span><span class="k3">=</span> <span class="n">635</span> <span class="k3">&amp;</span><span class="k3">&amp;</span> ball_y <span class="k3">&gt;</span><span class="k3">=</span> paddle_2_y  <span class="k3">&amp;</span><span class="k3">&amp;</span> ball_y <span class="k3">&lt;</span><span class="k3">=</span> paddle_2_y<span class="k2">)</span><span class="k2">{</span></td></tr><tr><td class="number">93</td><td>    x_speed <span class="k3">=</span> <span class="k3">-</span><span class="n">1</span><span class="k2">;</span></td></tr><tr><td class="number">94</td><td>    y_speed <span class="k3">=</span> <span class="k3">-</span><span class="n">1</span><span class="k2">;</span> <span class="k2">}</span>                 </td></tr><tr><td class="number">95</td><td><span class="k1">if</span> <span class="k2">(</span>ball_x <span class="k3">=</span><span class="k3">=</span> <span class="n">640</span><span class="k2">)</span> <span class="k2">{</span></td></tr><tr><td class="number">96</td><td>ball_x <span class="k3">=</span><span class="n">0</span><span class="k2">;</span></td></tr><tr><td class="number">97</td><td><a href="http://www.allegro.cc/manual/textout_ex" target="_blank"><span class="a">textout_ex</span></a><span class="k2">(</span> <a href="http://www.allegro.cc/manual/screen" target="_blank"><span class="a">screen</span></a>, <a href="http://www.allegro.cc/manual/font" target="_blank"><span class="a">font</span></a>, <span class="s">"Player 1 Wins!"</span>, <span class="n">320</span>, <span class="n">240</span>, <a href="http://www.allegro.cc/manual/makecol" target="_blank"><span class="a">makecol</span></a><span class="k2">(</span> <span class="n">255</span>, <span class="n">0</span>, <span class="n">0</span><span class="k2">)</span>, <a href="http://www.allegro.cc/manual/makecol" target="_blank"><span class="a">makecol</span></a><span class="k2">(</span> <span class="n">0</span>, <span class="n">0</span>, <span class="n">0</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>      </td></tr><tr><td class="number">98</td><td><a href="http://www.allegro.cc/manual/rest" target="_blank"><span class="a">rest</span></a><span class="k2">(</span><span class="n">5000</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">99</td><td><a href="http://www.delorie.com/djgpp/doc/libc/libc_298.html" target="_blank">exit</a><span class="k2">(</span>EXIT_FAILURE<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">100</td><td><span class="k2">}</span>    </td></tr><tr><td class="number">101</td><td><span class="k1">if</span> <span class="k2">(</span>ball_x <span class="k3">=</span><span class="k3">=</span> <span class="n">0</span><span class="k2">)</span><span class="k2">{</span></td></tr><tr><td class="number">102</td><td>ball_x <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span></td></tr><tr><td class="number">103</td><td><a href="http://www.allegro.cc/manual/textout_ex" target="_blank"><span class="a">textout_ex</span></a><span class="k2">(</span> <a href="http://www.allegro.cc/manual/screen" target="_blank"><span class="a">screen</span></a>, <a href="http://www.allegro.cc/manual/font" target="_blank"><span class="a">font</span></a>, <span class="s">"Player 2 Wins!"</span>, <span class="n">320</span>, <span class="n">240</span>, <a href="http://www.allegro.cc/manual/makecol" target="_blank"><span class="a">makecol</span></a><span class="k2">(</span> <span class="n">255</span>, <span class="n">0</span>, <span class="n">0</span><span class="k2">)</span>, <a href="http://www.allegro.cc/manual/makecol" target="_blank"><span class="a">makecol</span></a><span class="k2">(</span> <span class="n">0</span>, <span class="n">0</span>, <span class="n">0</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">104</td><td><a href="http://www.allegro.cc/manual/rest" target="_blank"><span class="a">rest</span></a><span class="k2">(</span><span class="n">5000</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">105</td><td><a href="http://www.delorie.com/djgpp/doc/libc/libc_298.html" target="_blank">exit</a><span class="k2">(</span>EXIT_FAILURE<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">106</td><td><span class="k2">}</span></td></tr><tr><td class="number">107</td><td><a href="http://www.allegro.cc/manual/circlefill" target="_blank"><span class="a">circlefill</span></a><span class="k2">(</span> buffer, ball_x, ball_y , <span class="n">5</span>, <a href="http://www.allegro.cc/manual/makecol" target="_blank"><span class="a">makecol</span></a><span class="k2">(</span> <span class="n">0</span>,<span class="n">255</span>, <span class="n">0</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span> <span class="k2">}</span></td></tr></tbody></table></div></div><p>

basically when i run it the ball move down and right then hits the wall i set up prints &quot;Player 1 Wins!&quot; then exits<br />that means i have the exit running right but even if u place the paddle in the way of the ball it doesn&#39;t do anything, and if the ball touches the way it goes on a straight path from the wall to the end<br />so i need something to cause the ball to change directions when it touches a wall or a paddle<br />Danex!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Danex!)</author>
		<pubDate>Mon, 18 Sep 2006 06:18:36 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>In order for the ball to bounce off the top of the screen, you need to see when the ball&#39;s y is less than 0<br /><span class="source-code"><span class="k1">if</span><span class="k2">(</span>ball_y <span class="k3">&lt;</span> <span class="n">0</span><span class="k2">)</span></span><br />And if it is, then make it move down instead.<br /><span class="source-code">    y_speed <span class="k3">=</span> <span class="n">1</span><span class="k2">;</span></span></p><p>Do the opposite for downward movement.</p><p>[edit]<br />Fixed.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (CGamesPlay)</author>
		<pubDate>Mon, 18 Sep 2006 06:24:22 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>sweet it works, and you can reflect the ball and all but now it randomly just changes direction in mid screen, whats goin on there?<br />Danex!<br />[edit]<br />i was wrong it does not bounce off the paddle, it just randomly changed directions right before paddle so now i have dirctions errors and no bounce paddle
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Danex!)</author>
		<pubDate>Mon, 18 Sep 2006 06:43:57 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>It shouldn&#39;t randomly bounce mid-screen if your code is what you have up there in addition to what I said.</p><p>About the ball going through paddles: you compare that the ball&#39;s y is &gt;= the paddle&#39;s y, and that the ball&#39;s y is &lt;= the paddle&#39;s y. This means you have to hit the very top of the paddle in order to bounce.</p><p>You should be checking that the ball&#39;s y is &gt;= the paddle&#39;s y, and the ball&#39;s y is &lt;= the paddle&#39;s y + height. That is, the ball needs to be in between the top of the paddle and the bottom of it.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (CGamesPlay)</author>
		<pubDate>Mon, 18 Sep 2006 06:55:20 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>cool that works now the paddles bounce and all and i found the problem which was the ball is not bounceing randomly, sum how paddle 2 affects the ball as far as 3/4 of the map away from itself, (its like their is a virtual paddle at mid screen that does the same thing as paddle 2) i am goin thru my code to see how this is happening, also now i have the problem of the ball always moveing in the same direction when it hits a paddle or a wall so i need to add a angle of attack sum how, any ideas or suggestions?<br />Danex!<br />[edit]<br />fixed the problem with the extened reach of paddle, i had a &#39;&gt;&#39; sign backwards ha ha::)
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Danex!)</author>
		<pubDate>Mon, 18 Sep 2006 07:07:59 +0000</pubDate>
	</item>
</rss>
