<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Enslave the Mouse</title>
		<link>http://www.allegro.cc/forums/view/590654</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Fri, 23 Mar 2007 01:26:33 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Is there any good way to keep the mouse within a set area? I&#39;m trying to make a little shooting game in which there is a limited range. However, using set_position causes the game to slow down drastically. What other method is there?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SkaxCo)</author>
		<pubDate>Thu, 22 Mar 2007 05:58:39 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p><span class="source-code"><a href="http://www.allegro.cc/manual/set_mouse_range" target="_blank"><span class="a">set_mouse_range</span></a><span class="k2">(</span><span class="k2">)</span></span><br />Do you mean that?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Dalrymple)</author>
		<pubDate>Thu, 22 Mar 2007 06:00:38 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Is there a way to keep it inside a curved area?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SkaxCo)</author>
		<pubDate>Thu, 22 Mar 2007 06:02:40 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Check if it&#39;s outside your arbitrary bounds, and if it is, move it back with <span class="source-code"><a href="http://www.allegro.cc/manual/position_mouse" target="_blank"><span class="a">position_mouse</span></a><span class="k2">(</span><span class="k2">)</span></span>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (gnolam)</author>
		<pubDate>Thu, 22 Mar 2007 06:04:47 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I already said, that makes it lag like crazy if its on the very edges of the screen. I would upload a demo, but I don&#39;t know how.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SkaxCo)</author>
		<pubDate>Thu, 22 Mar 2007 06:06:47 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>He said position_mouse() and I quote
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
causes the game to slow down drastically
</p></div></div><p>
But I&#39;m guessing he&#39;s calling it a little bit too much.</p><p>[edit]
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
I would upload a demo, but I don&#39;t know how.
</p></div></div><p>
Click attachments when you write a post...<br />Or copy and paste your code inside some </p><pre>&lt;code&gt;tags&lt;/code&gt;</pre><p>
[/edit]
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Dalrymple)</author>
		<pubDate>Thu, 22 Mar 2007 06:07:14 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>If you can tell me how to upload a demo you could see it slow...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SkaxCo)</author>
		<pubDate>Thu, 22 Mar 2007 06:08:52 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Maybe <span class="source-code"><a href="http://www.allegro.cc/manual/get_mouse_mickeys" target="_blank"><span class="a">get_mouse_mickeys</span></a></span> is going to be best for your situation... I&#39;ll wait for you to post your code first though.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Dalrymple)</author>
		<pubDate>Thu, 22 Mar 2007 06:11:14 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You will need to store the mouse x and y coords by and use get_mouse_mickeys as suggested.  This way you have total control over where the mouse is.  You will have to draw the cursor yourself though.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Steve Terry)</author>
		<pubDate>Thu, 22 Mar 2007 06:12:27 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hmm... to check if the mouse is inside your circle you should use... the equation of a cirlce! (otherwise known as pythagoras&lt;- did i spell that right?)</p><p>X^2 + Y^2 = r^2</p><p>where x and y are the mouse&#39;s co-ords, and r is the radius of your circle, if they are greater than the result is greater than r^2, then the mouse is outside of your circle.</p><p>And each loop through your logic, if the mouse is inside the circle, store its co-ords in some int&#39;s, when its outside the circle, set the mouse position to the last know co-ords of the mouse.</p><p>That should be one quick way of keeping your mouse in a circle <img src="http://www.allegro.cc/forums/smileys/undecided.gif" alt=":-/" /></p><p>Now, you&#39;ll also need to offset the x and y co-ords of the mouse when you check them, since the origin of the circle would be the top left of the screen. </p><p>As for a curved area, make a bigger circle, and adjust the offsets. If you have no idea what i&#39;ve been rambling on about, say so.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (The Unknown)</author>
		<pubDate>Thu, 22 Mar 2007 06:23:53 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yeah, I&#39;m good at math and geometry and stuff. So i can adjust the range each time the mouse moves...thanks, I&#39;ll see if it works.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
You will need to store the mouse x and y coords by and use get_mouse_mickeys as suggested. This way you have total control over where the mouse is. You will have to draw the cursor yourself though.
</p></div></div><p>
...what? By manually draw, do you mean have no real cursor and manually draw the sprite?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SkaxCo)</author>
		<pubDate>Thu, 22 Mar 2007 06:51:38 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yes manually draw the sprite.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Steve Terry)</author>
		<pubDate>Thu, 22 Mar 2007 06:57:05 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>This is...sort of the code; I&#39;ll comment to make it easier to understand.<br />Note: buffy is my buffer. This also draws a line to the point at the mouse and uses trigonometry. PlayerX is the location of the player, the Y always equals 480.
</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> aiming<span class="k2">(</span><span class="k1">int</span> mousex, <span class="k1">int</span> mousey, <span class="k1">int</span> playerx, <span class="k1">int</span> weprange<span class="k2">)</span><span class="k2">{</span></td></tr><tr><td class="number">2</td><td>  <span class="k1">double</span> dx, dy, dr, angle<span class="k2">;</span></td></tr><tr><td class="number">3</td><td>  <span class="k1">int</span> lr, pointx, pointy<span class="k2">;</span></td></tr><tr><td class="number">4</td><td>  dx <span class="k3">=</span> mousex <span class="k3">-</span> playerx<span class="k2">;</span></td></tr><tr><td class="number">5</td><td>  <span class="k1">if</span><span class="k2">(</span>dx <span class="k3">&lt;</span> <span class="n">0</span><span class="k2">)</span><span class="k2">{</span></td></tr><tr><td class="number">6</td><td>    lr <span class="k3">=</span> <span class="k3">-</span><span class="n">1</span><span class="k2">;</span></td></tr><tr><td class="number">7</td><td>    dx <span class="k3">*</span><span class="k3">=</span> <span class="k3">-</span><span class="n">1</span><span class="k2">;</span></td></tr><tr><td class="number">8</td><td>  <span class="k2">}</span></td></tr><tr><td class="number">9</td><td>  <span class="k1">else</span></td></tr><tr><td class="number">10</td><td>    lr <span class="k3">=</span> <span class="n">1</span><span class="k2">;</span></td></tr><tr><td class="number">11</td><td>  dy <span class="k3">=</span> FIELD_H <span class="k3">-</span> mousey<span class="k2">;</span></td></tr><tr><td class="number">12</td><td>  <span class="k2">(</span>dy <span class="k3">&lt;</span>       <span class="n">0</span><span class="k2">)</span>?<span class="k2">(</span>dy <span class="k3">=</span>   <span class="n">1</span><span class="k2">)</span><span class="k2">:</span><span class="k2">(</span>dy <span class="k3">=</span> dy<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">13</td><td>  <span class="k2">(</span>dy <span class="k3">&gt;</span> FIELD_H<span class="k2">)</span>?<span class="k2">(</span>dy <span class="k3">=</span> <span class="n">480</span><span class="k2">)</span><span class="k2">:</span><span class="k2">(</span>dy <span class="k3">=</span> dy<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">14</td><td>  dr <span class="k3">=</span> <a href="http://www.delorie.com/djgpp/doc/libc/libc_738.html" target="_blank">sqrt</a><span class="k2">(</span><span class="k2">(</span>dx<span class="k3">*</span>dx<span class="k2">)</span><span class="k3">+</span><span class="k2">(</span>dy<span class="k3">*</span>dy<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">15</td><td>  angle <span class="k3">=</span> <a href="http://www.delorie.com/djgpp/doc/libc/libc_49.html" target="_blank">atan</a><span class="k2">(</span>dy<span class="k3">/</span>dx<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">16</td><td>  <span class="k1">if</span><span class="k2">(</span>dr <span class="k3">&gt;</span> weprange<span class="k2">)</span><span class="k2">{</span></td></tr><tr><td class="number">17</td><td>    dr <span class="k3">=</span> weprange<span class="k2">;</span></td></tr><tr><td class="number">18</td><td>    dx <span class="k3">=</span> dr <span class="k3">*</span> <a href="http://www.delorie.com/djgpp/doc/libc/libc_113.html" target="_blank">cos</a><span class="k2">(</span>angle<span class="c">/**PI/180*/</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">19</td><td>    dy <span class="k3">=</span> dr <span class="k3">*</span> <a href="http://www.delorie.com/djgpp/doc/libc/libc_728.html" target="_blank">sin</a><span class="k2">(</span>angle<span class="c">/**PI/180*/</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">20</td><td>    pointy <span class="k3">=</span> <span class="k2">(</span><span class="k1">int</span><span class="k2">)</span><span class="k2">(</span>FIELD_H <span class="k3">-</span> dy<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">21</td><td>    pointx <span class="k3">=</span> <span class="k2">(</span><span class="k1">int</span><span class="k2">)</span><span class="k2">(</span>playerx <span class="k3">+</span> <span class="k2">(</span>dx<span class="k3">*</span>lr<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/set_mouse_range" target="_blank"><span class="a">set_mouse_range</span></a><span class="k2">(</span>playerx, <span class="n">480</span>, pointx, pointy<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">23</td><td>    <span class="c">//position_mouse(pointx, pointy); THIS cAUSES LAG</span></td></tr><tr><td class="number">24</td><td>  <span class="k2">}</span></td></tr><tr><td class="number">25</td><td>  pointy <span class="k3">=</span> <span class="k2">(</span><span class="k1">int</span><span class="k2">)</span><span class="k2">(</span>FIELD_H <span class="k3">-</span> dy<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">26</td><td>  pointx <span class="k3">=</span> <span class="k2">(</span><span class="k1">int</span><span class="k2">)</span><span class="k2">(</span>playerx <span class="k3">+</span> <span class="k2">(</span>dx<span class="k3">*</span>lr<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/line" target="_blank"><span class="a">line</span></a><span class="k2">(</span>buffy, playerx, <span class="n">480</span>, pointx, pointy, AIMING<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">28</td><td><span class="k2">}</span></td></tr></tbody></table></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SkaxCo)</author>
		<pubDate>Thu, 22 Mar 2007 07:00:08 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>This might be a bad way, but it could work...</p><p>Before the game begins, make a 2d integer array. Set its width and height to the maximum distance you want the mouse to be able to travel.</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">int</span> max_distance <span class="k3">=</span> <span class="n">200</span><span class="k2">;</span>    <span class="c">// Radius of the circle</span>
<span class="k1">int</span> mouse_box<span class="k2">[</span><span class="n">400</span><span class="k2">]</span><span class="k2">[</span><span class="n">400</span><span class="k2">]</span><span class="k2">;</span>
<span class="k1">int</span> xd<span class="k2">;</span>
<span class="k1">int</span> yd<span class="k2">;</span>

<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> <span class="n">400</span><span class="k2">;</span> <span class="k3">+</span><span class="k3">+</span>i<span class="k2">)</span> <span class="k2">{</span>
        <span class="k1">for</span> <span class="k2">(</span><span class="k1">int</span> j <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span> j <span class="k3">&lt;</span> <span class="n">400</span><span class="k2">;</span> <span class="k3">+</span><span class="k3">+</span>j<span class="k2">)</span> <span class="k2">{</span>

                xd <span class="k3">=</span> i <span class="k3">-</span> max_distance<span class="k2">;</span>
                yd <span class="k3">=</span> j <span class="k3">-</span> max_distance<span class="k2">;</span>
                <span class="c">// Check Distance</span>
                mouse_box<span class="k3">&lt;</span>i&gt;<span class="k2">[</span>j<span class="k2">]</span> <span class="k3">=</span> <span class="k2">(</span><a href="http://www.delorie.com/djgpp/doc/libc/libc_738.html" target="_blank">sqrt</a><span class="k2">(</span>xd <span class="k3">*</span> xd <span class="k3">+</span> yd <span class="k3">*</span> yd<span class="k2">)</span> <span class="k3">&lt;</span> max_distance<span class="k2">)</span><span class="k2">;</span>
        <span class="k2">}</span>
<span class="k2">}</span>
</pre></div></div><p>

I didn&#39;t test it, but that should create an array with the shape of a circle in &quot;1&#39;s&quot; and outside the circle in &quot;0&#39;s&quot;</p><p>Now all you have to do is record where the mouse was in the previous game cycle, and check its current position against the array.</p><div class="source-code"><div class="toolbar"></div><div class="inner"><table width="100%"><tbody><tr><td class="number">1</td><td>&#160;</td></tr><tr><td class="number">2</td><td><span class="c">// These 2 variables should be declared at the beginning of the program</span></td></tr><tr><td class="number">3</td><td><span class="k1">int</span> previous_mouse_x<span class="k2">;</span></td></tr><tr><td class="number">4</td><td><span class="k1">int</span> previous_mouse_y<span class="k2">;</span></td></tr><tr><td class="number">5</td><td>&#160;</td></tr><tr><td class="number">6</td><td><span class="c">// Put this at the bottom of your game cycle:</span></td></tr><tr><td class="number">7</td><td>&#160;</td></tr><tr><td class="number">8</td><td><span class="c">// If the mouse is not in the circle</span></td></tr><tr><td class="number">9</td><td><span class="k1">if</span> <span class="k2">(</span>mouse_box<span class="k2">[</span><a href="http://www.allegro.cc/manual/mouse_x" target="_blank"><span class="a">mouse_x</span></a><span class="k2">]</span><span class="k2">[</span><a href="http://www.allegro.cc/manual/mouse_y" target="_blank"><span class="a">mouse_y</span></a><span class="k2">]</span> <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">10</td><td>&#160;</td></tr><tr><td class="number">11</td><td>    <span class="c">// Put it back to wherever it was before</span></td></tr><tr><td class="number">12</td><td>    <a href="http://www.allegro.cc/manual/position_mouse" target="_blank"><span class="a">position_mouse</span></a><span class="k2">(</span>previous_mouse_x, previous_mouse_y<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">13</td><td>&#160;</td></tr><tr><td class="number">14</td><td><span class="k2">}</span> <span class="k1">else</span> <span class="k2">{</span></td></tr><tr><td class="number">15</td><td>        previous_mouse_x <span class="k3">=</span> <a href="http://www.allegro.cc/manual/mouse_x" target="_blank"><span class="a">mouse_x</span></a><span class="k2">;</span></td></tr><tr><td class="number">16</td><td>        previous_mouse_y <span class="k3">=</span> <a href="http://www.allegro.cc/manual/mouse_y" target="_blank"><span class="a">mouse_y</span></a><span class="k2">;</span></td></tr><tr><td class="number">17</td><td><span class="k2">}</span></td></tr></tbody></table></div></div><p>

If it works, it should work fast.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (peelemachine)</author>
		<pubDate>Thu, 22 Mar 2007 09:49:46 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>peelemachine: Wow, overengineering.<br />The slow down is in the position_mouse function, not in the checking function. Distance check will be similarly effective.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Billybob)</author>
		<pubDate>Thu, 22 Mar 2007 10:07:40 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yeah you could do a distance check every time but that would be slow, hence my happy binary circle. I didn&#39;t know position_mouse() was so slow. That&#39;s stupid. Allegro&#39;s stupid. Life sucks.</p><p>EDIT:<br />To the OP:<br />What if you made the cursor disappear? Then you could just not draw it, and not process any clicks or movement. I don&#39;t know what kind of game you&#39;re making though.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (peelemachine)</author>
		<pubDate>Thu, 22 Mar 2007 10:15:43 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>position_mouse() shouldn&#39;t slow anything down.</p><p>I&#39;m suspecting something else is the real culprit, like poor timing (rest()?), acquire/release pairs, mixed logic and drawing, etc.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (gnolam)</author>
		<pubDate>Thu, 22 Mar 2007 17:15:31 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thats pretty clever peelemachine, like what i said, but you only need to do the math once.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (The Unknown)</author>
		<pubDate>Fri, 23 Mar 2007 00:08:40 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Enslave the Mouse
</p></div></div><p>

<span class="remote-thumbnail"><span class="json">{"name":"390901~Two-Mice-Behind-Bars-Posters.jpg","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/f\/2\/f2cacff827d0c2d79f1503d6f3c4baea.jpg","w":337,"h":450,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/f\/2\/f2cacff827d0c2d79f1503d6f3c4baea"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/f/2/f2cacff827d0c2d79f1503d6f3c4baea-240.jpg" alt="390901~Two-Mice-Behind-Bars-Posters.jpg" width="240" height="320" /></span></p><p>Easy. They don&#39;t fight back.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Leniuch)</author>
		<pubDate>Fri, 23 Mar 2007 01:26:33 +0000</pubDate>
	</item>
</rss>
