<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Mouse Over IsometricTiles</title>
		<link>http://www.allegro.cc/forums/view/617294</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Thu, 01 Mar 2018 11:42:14 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;m trying to think of a way of determining whether the mouse is currently over an isometric tile without selecting the adjacent tiles. With Allegro 4 I could create a color mask in a sub bitmap and use get_pixel to find where the mouse was. Is there a way to do this with Allegro 5?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (dakatt)</author>
		<pubDate>Tue, 27 Feb 2018 10:46:55 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I have exactly what you need.  I too used to use the colour map idea until I found this little gem, and it&#39;s easier than you may think.
</p><div class="source-code snippet"><div class="inner"><pre>tile_mx <span class="k3">=</span> <span class="k2">(</span><span class="k1">int</span><span class="k2">)</span><span class="k2">(</span><span class="k2">(</span><span class="k2">(</span><span class="k2">(</span><span class="k1">float</span><span class="k2">)</span><a href="http://www.allegro.cc/manual/mouse_y"><span class="a">mouse_y</span></a> <span class="k3">+</span> <span class="k2">(</span><span class="k1">float</span><span class="k2">)</span>scroll_y<span class="k2">)</span> <span class="k3">/</span> <span class="k2">(</span><span class="k1">float</span><span class="k2">)</span>TILE_Y<span class="k2">)</span> <span class="k3">+</span> <span class="k2">(</span><span class="k2">(</span><span class="k2">(</span><span class="k1">float</span><span class="k2">)</span><a href="http://www.allegro.cc/manual/mouse_x"><span class="a">mouse_x</span></a> <span class="k3">+</span> <span class="k2">(</span><span class="k1">float</span><span class="k2">)</span>scroll_x<span class="k2">)</span> <span class="k3">-</span> <span class="k2">(</span><span class="k2">(</span><span class="k1">float</span><span class="k2">)</span>MAPSIZE <span class="k3">*</span> <span class="k2">(</span><span class="k1">float</span><span class="k2">)</span>TILE_X<span class="k3">/</span><span class="n">2</span><span class="k2">)</span><span class="k2">)</span> <span class="k3">/</span> <span class="k2">(</span><span class="k1">float</span><span class="k2">)</span>TILE_X<span class="k2">)</span><span class="k2">;</span>
tile_my <span class="k3">=</span> <span class="k2">(</span><span class="k1">int</span><span class="k2">)</span><span class="k2">(</span><span class="k2">(</span><span class="k2">(</span><span class="k2">(</span><span class="k1">float</span><span class="k2">)</span><a href="http://www.allegro.cc/manual/mouse_y"><span class="a">mouse_y</span></a> <span class="k3">+</span> <span class="k2">(</span><span class="k1">float</span><span class="k2">)</span>scroll_y<span class="k2">)</span> <span class="k3">/</span> <span class="k2">(</span><span class="k1">float</span><span class="k2">)</span>TILE_Y<span class="k2">)</span> <span class="k3">-</span> <span class="k2">(</span><span class="k2">(</span><span class="k2">(</span><span class="k1">float</span><span class="k2">)</span><a href="http://www.allegro.cc/manual/mouse_x"><span class="a">mouse_x</span></a> <span class="k3">+</span> <span class="k2">(</span><span class="k1">float</span><span class="k2">)</span>scroll_x<span class="k2">)</span> <span class="k3">-</span> <span class="k2">(</span><span class="k2">(</span><span class="k1">float</span><span class="k2">)</span>MAPSIZE <span class="k3">*</span> <span class="k2">(</span><span class="k1">float</span><span class="k2">)</span>TILE_X<span class="k3">/</span><span class="n">2</span><span class="k2">)</span><span class="k2">)</span> <span class="k3">/</span> <span class="k2">(</span><span class="k1">float</span><span class="k2">)</span>TILE_X<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

The variables are pretty self explanatory.  TILE_X, TILE_Y for tile sizes, MAPSIZE for the size of the map, there is the mouse location in mouse_x and mouse_y.  There is scroll_x and scroll_y which is the upper left corner of the visible map.  I use this in an isometric map editor I programmed with a large scrolling map.</p><p>Note: This is for a large flat isometric map.  If you have layers with things like hills, it gets more complex to detect which tile you are on.  There are many ideas on how to do this, but not many people seem to want to share them. <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Neil Roy)</author>
		<pubDate>Tue, 27 Feb 2018 11:40:54 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Allegro 4/5/DirectX/et al doesn&#39;t really change how you do it.</p><p><a href="https://stackoverflow.com/questions/6915555/how-to-transform-mouse-location-in-isometric-tiling-map">https://stackoverflow.com/questions/6915555/how-to-transform-mouse-location-in-isometric-tiling-map</a></p><p><a href="https://gamedev.stackexchange.com/questions/38320/is-it-possible-to-map-mouse-coordinates-to-isometric-tiles-with-this-coordinate">https://gamedev.stackexchange.com/questions/38320/is-it-possible-to-map-mouse-coordinates-to-isometric-tiles-with-this-coordinate</a></p><p><a href="http://archive.gamedev.net/archive/reference/programming/features/mm4ihm/index.html">http://archive.gamedev.net/archive/reference/programming/features/mm4ihm/index.html</a>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Chris Katko)</author>
		<pubDate>Tue, 27 Feb 2018 13:14:09 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thank you Neil, I did try using your code but I couldn&#39;t get it to work.</p><p>The last link you gave Chris is what I&#39;m looking for but I don&#39;t know the Allegro 5 (or can remember the Allegro 4) code to implement it. I just remember the concept of creating a mouse mask with different colors, blitting it to a buffer/bitmap which wasn&#39;t seen and then using the get_pixel method to find out whether the current tile should be modified. Thanks again guys
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (dakatt)</author>
		<pubDate>Tue, 27 Feb 2018 14:14:13 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p><span class="source-code"> <a href="http://www.allegro.cc/manual/al_get_pixel"><span class="a">al_get_pixel</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a> <span class="k3">*</span>bitmap, <span class="k1">int</span> x, <span class="k1">int</span> y<span class="k2">)</span></span> ?? <img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Dizzy Egg)</author>
		<pubDate>Tue, 27 Feb 2018 16:08:55 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I think what you&#39;re talking about is a pix map or a picking buffer
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Tue, 27 Feb 2018 21:55:18 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yes, possibly :/ Can Allegro 5 do something like this?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (dakatt)</author>
		<pubDate>Tue, 27 Feb 2018 22:23:45 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Well, the code works, I use it in my Isometric editor. I pulled that straight out of it in fact.</p><p>I have some notes on this, let me pull them up and maybe they will help.  It&#39;s been a while since I looked at them.  </p><p>-------<br />isoX = map X coordinates<br />isoY = map Y coordinates<br />isoMapMaxY = How big is the map in Y direction<br />tileWidth = what is the width of the isometric map tile<br />tileHeight = what is the height of the isometric map tile</p><p>Lets assume that the whole map fits the screen for now.</p><p>screenX = screen x coordinate<br />screenY = screen y coordinate</p><p>Now, lets look at the code now with all this extra info.</p><p>From isometric coordinates to screen coordinates:<br />screenX = (isoX - isoY + isoMapMaxY) * (tileWidth / 2);<br />screenY = (isoX + isoY) * (tileHeight / 2);</p><p>From screen coordinates to isometric coordinates:<br />isoX = ( ((screenY + scrollY) / tileHeight) + ((screenX + scrollX) - (isoMapMaxY * tileWidth/2)) / tileWidth )<br />isoY = ( ((screenY + scrollY) / tileHeight) - ((screenX + scrollX) - (isoMapMaxY * tileWidth/2)) / tileWidth )</p><p>isoX = (screenY / 32) + (screenX - 320) / 64<br />isoY = (screenY / 32) - (screenX - 320) / 64<br />-------
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Neil Roy)</author>
		<pubDate>Wed, 28 Feb 2018 00:09:29 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I always wanted to make an isometric game, problem is I could not draw a sprite if my life depended on it <img src="http://www.allegro.cc/forums/smileys/rolleyes.gif" alt="::)" />. and you never find enough graphics for an isometric game.<br />Top down graphics are much easier to get.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Ariesnl)</author>
		<pubDate>Wed, 28 Feb 2018 13:42:05 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/617294/1035575#target">Ariesnl</a> said:</div><div class="quote"><p>
I always wanted to make an isometric game, problem is I could not draw a sprite if my life depended on it <img src="http://www.allegro.cc/forums/smileys/rolleyes.gif" alt="::)" />. and you never find enough graphics for an isometric game.<br />Top down graphics are much easier to get.
</p></div></div><p>
 - Use placeholder graphics</p><p> - Learn to make isometric graphics even if you suck at it.</p><p> - Pay someone for ready-made licensed art (and optionally modify the art for your game using the art pack as a template for art-style)</p><p> - Pay someone to made new art. (If your game is worth playing, it&#39;s worth blowing a few hundred bucks or more on some artist to make it visually appealing.)
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Chris Katko)</author>
		<pubDate>Wed, 28 Feb 2018 13:51:00 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Here&#39;s some tiles I made myself, you&#39;re welcome to use them if you wish, at least to get you started.  The roads are in the same style as SimCity2000, but they&#39;re not copied from that game, I made them myself from scratch (no copyright issues).</p><p>There&#39;s tutorials online, I suggest looking up tutorials on making tiles with Blender.  I am not much of an artist either, but creating 3D renders is easier and perfect for isometric tiles.  Another good program that helps create them easier is Inkscape, there are tutorials for it as well.</p><p><span class="remote-thumbnail"><span class="json">{"name":"611311","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/3\/a\/3a6c816125706c8159fd3cb7fcbb72df.png","w":640,"h":256,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/3\/a\/3a6c816125706c8159fd3cb7fcbb72df"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/3/a/3a6c816125706c8159fd3cb7fcbb72df-240.jpg" alt="611311" width="240" height="96" /></span></p><p>I organized these tiles in a binary fashion.  So the north corner is 1, the east corner is 2, the south corner is 4 and the west corner is 8.  To get the tile number you want, just figure out which corners you wish to be raised, so if you want the north and east corner, that&#39;s tile #3 (1 + 2).  The roads are organized in a similar fashion. I done it this way so that in my Isomed editor you can just draw the roads and tiles and it will use binary logic to select and combine tiles (I done something like this in my Deluxe Pacman 2 editor to draw as well).</p><p>This is an example of how these look.  Believe it or not, I created these tiles just with Microsoft&#39;s Paint, that&#39;s it.</p><p><span class="remote-thumbnail"><span class="json">{"name":"611312","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/3\/0\/30d213ee3764963ecda394a09d720c36.jpg","w":495,"h":269,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/3\/0\/30d213ee3764963ecda394a09d720c36"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/3/0/30d213ee3764963ecda394a09d720c36-240.jpg" alt="611312" width="240" height="130" /></span>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Neil Roy)</author>
		<pubDate>Wed, 28 Feb 2018 14:26:04 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>OK, I&#39;ll try and explain more clearly. I want to take what&#39;s on display (ie the buffer in allegro 4), draw a bitmap of the mouse mask over the top of (the copy of) the display and then use the mouse coordinates to check which color the mouse cursor is currently over. All of this should be invisible to the user. Here is my current code for this function :</p><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number">  1</span><span class="k1">void</span> CLayer::CheckMouse<span class="k2">(</span><span class="k1">int</span> tile_xpos,<span class="k1">int</span> tile_ypos,<span class="k1">int</span> xt,<span class="k1">int</span> yt<span class="k2">)</span><span class="k2">{</span>
<span class="number">  2</span><span class="k1">if</span><span class="k2">(</span>mouse_x&gt;<span class="k3">=</span>tile_xpos <span class="k3">&amp;</span><span class="k3">&amp;</span> <a href="http://www.allegro.cc/manual/mouse_x"><span class="a">mouse_x</span></a><span class="k3">&lt;</span><span class="k3">=</span>tile_xpos<span class="k3">+</span>TILE_W <span class="k3">&amp;</span><span class="k3">&amp;</span> mouse_y&gt;tile_ypos <span class="k3">&amp;</span><span class="k3">&amp;</span> <a href="http://www.allegro.cc/manual/mouse_y"><span class="a">mouse_y</span></a><span class="k3">&lt;</span>tile_ypos<span class="k3">+</span>TILE_H<span class="k2">)</span><span class="k2">{</span>
<span class="number">  3</span>    current_mx <span class="k3">=</span> tile_xpos<span class="k2">;</span> 
<span class="number">  4</span>    current_my <span class="k3">=</span> tile_ypos<span class="k2">;</span>
<span class="number">  5</span>
<span class="number">  6</span>    current_xtile<span class="k3">=</span>xt<span class="k2">;</span>
<span class="number">  7</span>    current_ytile<span class="k3">=</span>yt<span class="k2">;</span>
<span class="number">  8</span>
<span class="number">  9</span>                <span class="c">//create image/copy of screen and overlay mouse mask</span>
<span class="number"> 10</span>                <span class="c">//use get_pixel() to find current color of mouse x/y</span>
<span class="number"> 11</span>
<span class="number"> 12</span>                <span class="c">//finally increase/decrease the current_xtile/current_ytile depending</span>
<span class="number"> 13</span>                <span class="c">//on the color</span>
<span class="number"> 14</span>
<span class="number"> 15</span>    over_tile<span class="k3">=</span><span class="k1">true</span><span class="k2">;</span>
<span class="number"> 16</span>    
<span class="number"> 17</span>  <span class="k2">}</span>
<span class="number"> 18</span><span class="k2">}</span>
</div></div><p>

At present it takes the coords of the current tile, checks to see if the cursor is within its border and if it is assigns the current tiles array position to the current_ variables. Does anybody know how to go about this? thanks
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (dakatt)</author>
		<pubDate>Thu, 01 Mar 2018 04:23:33 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You&#39;re talking about a mousemap (search online for that term).</p><p>I used to use one with my program, this one to be exact (with the tiles I posted above if you want it)...</p><p><span class="remote-thumbnail"><span class="json">{"name":"611314","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/a\/3\/a3043314ff5c121b96d07e5ad63cae05.png","w":640,"h":128,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/a\/3\/a3043314ff5c121b96d07e5ad63cae05"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/a/3/a3043314ff5c121b96d07e5ad63cae05-240.jpg" alt="611314" width="240" height="48" /></span></p><p>It&#39;s a fairly simple technique, just figure out which tile you are clicking on, which tile number is at that location, then check the identical mousemap.  You just check the colour at the location your mouse clicked on and go from there.  If the colour is red, you clicked on a tile north of the position your mouse is on (actually, north-west, depending on how you draw them).  If you clicked on cyan, you go one tile south, blue is north-west etc.</p><p>I have not bothered to try coding this with Allegro 5, though it should be simple.  I used Allegro 4 for my Isometric project (it&#39;s an older one).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Neil Roy)</author>
		<pubDate>Thu, 01 Mar 2018 05:28:14 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thanks again Neil. A mouse map is what I&#39;m talking about, I&#39;ve done it before with Allegro4 I just don&#39;t know what specific lib functions I used. Had I access to my old Isometric project I could probably take a stab at it since most variables and function names just seem to have the al_ prefix. Problem is I don&#39;t have the old code so I can&#39;t  do that. </p><p>The concept is simple - make a bitmap (subbitmap? Idk), add to it a mouse map (again no clue on how to merge bitmaps), get colour from said bitmap. Maybe this allegro doesn&#39;t have the same functionality as the previous version although this stuff seems like it should be standard.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (dakatt)</author>
		<pubDate>Thu, 01 Mar 2018 10:02:08 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The way I did it was I loaded two totally separate bitmaps, the main graphics and the mousemap (I provided some above).  Once you know what tile you are in (just a general idea, the square area, not the isometric one), you then check which tile type if there then check the equivalent mousmap tile for the colour.</p><p>You just need an Allegro function where you can check the colour of a pixel on a bitmap.  In this case, I have a 32bit PNG file for the mousemap.  </p><p>I have not done this for Allegro 5 yet, but I would think you need to lock the bitmap for reading only, then call a function to read a pixel and check the colour.  Should be pretty straight forward to be honest.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Neil Roy)</author>
		<pubDate>Thu, 01 Mar 2018 11:42:14 +0000</pubDate>
	</item>
</rss>
