<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Tetris Clone Algorithim</title>
		<link>http://www.allegro.cc/forums/view/589304</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Sat, 30 Dec 2006 00:59:55 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hi all,<br />I&#39;m out to make a tetris clone and need some thoughts on the rotating of the blocks as they fall down the playing area. I would like the keys to work like this: KEY_DOWN would accelerate the rate of fall, KEY_RIGHT would move the block right, KEY_LEFT would move the block left, and KEY_UP would rotate the block clockwise in 90 degree increments. Nothing fancy.</p><p>I&#39;m not familiar with the function rotate_sprite(bmp, spr, x, y, itofix(64)).<br />If I use the rotate_function above it will rotate the sprite 90 degrees to the right?</p><p>In the game the user needs to have the ability to rotate the sprites as many times as they want before it reaches the bottom. What is a good method of doing this?</p><p> switch(state){<br />   <br />   state 1: rotate_sprite(bmp, spr, x, y, itofix(64));<br />   break;<br />   <br />   state 2: rotate_sprite(bmp, spr, x, y, itofix(128));<br />   break;</p><p>   state 3: rotate_sprite(bmp, spr, x, y, itofix(270));<br />   break;<br />   <br />   state 4: rotate_sprite(bmp, spr, x, y, itofix(0));<br />   default:break;<br />}</p><p>Any ideas or suggestion are greatly appreciated
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (shangshu)</author>
		<pubDate>Thu, 28 Dec 2006 13:59:12 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Seems good to me, for the displaying part. (type &#39;case 1&#39;, not &#39;state 1&#39; of course)<br />It can be shortened to one line, but it would be less readble IMHO.</p><p>Hovever, you&#39;ll need something else to detect collisions:<br />- test if the piece can go left or right, before allowing the move<br />- test if the piece can go down<br />- test if rotation is possible without overlapping the playfield edges or the old pieces.</p><p>For collision testing, you can use for example an array of 4x4 booleans.<br />And the playfield would also have an array of booleans.</p><p>edit: I don&#39;t know if that was the question, but pressing left or right would set<br /><span class="source-code">state <span class="k3">=</span> <span class="k2">(</span>state % <span class="n">4</span><span class="k2">)</span> <span class="k3">+</span> <span class="n">1</span><span class="k2">;</span> <span class="c">// increment</span></span><br />and<br /><span class="source-code">state <span class="k3">=</span> <span class="k2">(</span><span class="k2">(</span>state <span class="k3">+</span> <span class="n">3</span><span class="k2">)</span> % <span class="n">4</span><span class="k2">)</span> <span class="k3">+</span> <span class="n">1</span><span class="k2">;</span> <span class="c">// decrement</span></span>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Audric)</author>
		<pubDate>Thu, 28 Dec 2006 15:09:36 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>well, if you keep everything in an array, I think it would be useful not to draw the tetrominoes as sprites, but just draw the blocks as represented in the array
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (raccoon)</author>
		<pubDate>Thu, 28 Dec 2006 15:20:34 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yeah, make a 4x4 block array and rotate it by swapping columns with rows (first column is first row of the &quot;transformed&quot; matrix). If you do that upside-down you rotate clockwise.<br />Then just draw the array to the screen.</p><div class="source-code snippet"><div class="inner"><pre><span class="k3">-</span><span class="k3">-</span><span class="k3">-</span><span class="k3">-</span> <span class="k3">-</span><span class="k3">-</span><span class="k3">-</span><span class="k3">-</span> <span class="k3">-</span>XX- <span class="k3">-</span><span class="k3">-</span><span class="k3">-</span><span class="k3">-</span> 
<span class="k3">-</span>X-- XXX- <span class="k3">-</span><span class="k3">-</span>X- <span class="k3">-</span><span class="k3">-</span><span class="k3">-</span>X
<span class="k3">-</span>X-- X--- <span class="k3">-</span><span class="k3">-</span>X- <span class="k3">-</span>XXX
<span class="k3">-</span>XX- <span class="k3">-</span><span class="k3">-</span><span class="k3">-</span><span class="k3">-</span> <span class="k3">-</span><span class="k3">-</span><span class="k3">-</span><span class="k3">-</span> <span class="k3">-</span><span class="k3">-</span><span class="k3">-</span><span class="k3">-</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Simon Parzer)</author>
		<pubDate>Thu, 28 Dec 2006 16:50:29 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;m also on a tetris clone and used Simon&#39;s approach but using 0 and 1 as it&#39;s easier to deal with. <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" /></p><p>You must think in blocks not in complete tetris pieces. Good luck!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Ricardo Santos)</author>
		<pubDate>Fri, 29 Dec 2006 10:15:26 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I think Simon meant to use an array of integers as well. His ASCII drawing is just a visualization of how it will look when you draw the array to the screen. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (kentl)</author>
		<pubDate>Fri, 29 Dec 2006 22:35:28 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">shangshu said:</div><div class="quote"><p>
rotate_sprite(bmp, spr, x, y, itofix(270));
</p></div></div><p>
<b>cough</b><br /><span class="source-code"><a href="http://www.allegro.cc/manual/rotate_sprite" target="_blank"><span class="a">rotate_sprite</span></a><span class="k2">(</span>bmp, spr, x, y, <a href="http://www.allegro.cc/manual/itofix" target="_blank"><span class="a">itofix</span></a><span class="k2">(</span><span class="n">192</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span></span>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Harte)</author>
		<pubDate>Sat, 30 Dec 2006 00:59:55 +0000</pubDate>
	</item>
</rss>
