<?xml version="1.0" encoding="ISO-8859-1"?>
<rdf:RDF
	xmlns="http://purl.org/rss/1.0/"
	xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
	xmlns:dc="http://purl.org/dc/elements/1.1/">
	<channel rdf:about="http://feeds.garagegames.com/rss/blogs/developer/25175/">
		<title>Blog for Tom Cassiotis at GarageGames.com</title>
		<description>Blog feeds for Gamers and Developers in the GarageGames community.</description>
		<link>http://www.garagegames.com/</link>
		<image rdf:resource="http://www.garagegames.com/images/GarageGames_logo_small_w.gif" />
		<dc:date>2008-11-22T08:10:06+00:00</dc:date>
		<items>
			<rdf:Seq>
				<rdf:li rdf:resource="http://www.garagegames.com/blogs/25175/13707"/>
				<rdf:li rdf:resource="http://www.garagegames.com/blogs/25175/13698"/>
			</rdf:Seq>
		</items>
	</channel>
	<item rdf:about="http://www.garagegames.com/blogs/25175/13707">
		<dc:format>text/html</dc:format>
		<dc:date>2007-10-12T20:56:45+00:00</dc:date>
		<dc:creator>Tom Cassiotis</dc:creator>
		<title>TGB Learning Project (Continued)</title>
		<link>http://www.garagegames.com/blogs/25175/13707</link>
		<description>Following up from my previous &lt;a href='http://www.garagegames.com/index.php?sec=mg&amp;amp;mod=resource&amp;amp;page=view&amp;amp;qid=13698'&gt;.plan&lt;/a&gt; here some documentation on the development approach that i took.&lt;br&gt;&lt;br&gt;&lt;a href='http://www.youtube.com/watch?v=YjkuJmKfTHc' target=_blank&gt;Connect3 Video&lt;/a&gt;&lt;br&gt;&lt;br&gt;Send me a message at tom at game2 dot com and I will send you a link to the game source.&lt;br&gt;&lt;br&gt;&lt;b&gt;Organization:&lt;/b&gt;&lt;br&gt;The game logic almost exclusively resides in the class GameGrid (&lt;b&gt;gameGrid.cs&lt;/b&gt;).  It is instantiated by a empty tileset named GameTileLayer.&lt;br&gt;&lt;br&gt;&lt;i&gt;Game Pieces&lt;/i&gt; are the only other 'objects' and they have a minor set of code in the form of a behaviour in order to be able to quickly determine if they are moving.&lt;br&gt;&lt;br&gt;The game is set to different states and the game state is checked on a timer currently set to fire every 150ms. Doing the same code on update seems uneccessary (I think that fires every 16ms) and causes some stuttering.&lt;br&gt;&lt;br&gt;User action is handled by onMouseDown/Up at the sceneWindow2D level (game.cs) and pushed to GameGrid to be handled.  The mouse down event sets the game piece to be moved (GameGrid::swapAchor) and on the mouse up if the anchor game piece and the game piece that is under the mouse are adjacent then it begins the swap and sets the game state to $waitingOnMockSwap.  When the game pieces stop moving the result of the swap is considered.&lt;br&gt;&lt;br&gt;&lt;b&gt;Game States:&lt;/b&gt;&lt;br&gt;&lt;img src='http://www.game2.com/Spew/connect3_states.png'  alt=&quot;&quot;&gt;&lt;br&gt;&lt;br&gt;&lt;i&gt;$waitingOnUser&lt;/i&gt; - The game is done all its work and is waiting for the user to make their next move.  Mouse handling routines are only considered in this state (so you don't move Game Pieces while a previous move is still being resolved).&lt;br&gt;&lt;br&gt;&lt;i&gt;$waitingOnMockSwap&lt;/i&gt; - A swap of Game Pieces happens even if it does not result in any matches.  In this game state, we will wait until all Game Pieces have stopped moving and then consider if that swap causes a match, if it does we switch to $waitingOnSwap game state otherwise we reverse the swap and set the game state to $waitingOnSwapReverse.&lt;br&gt;&lt;br&gt;&lt;i&gt;$waitingOnSwap&lt;/i&gt; - Once the Game Pieces stop moving, we remove the matched pieces and (GameGrid::clearMatchedPieces) and execute 'gravity' which makes any Game Pieces that are 'floating' to fall down.  We now set the game state to $waitingOnGravity.&lt;br&gt;&lt;br&gt;&lt;i&gt;$waitingOnSwapReverse&lt;/i&gt; - The user swap did not resolve in a match and so in this game state we wait for the Game Pieces to get back to their original position and once they do we switch the game state to $waitingOnUser.&lt;br&gt;&lt;br&gt;&lt;i&gt;$waitingOnGravity&lt;/i&gt; - Gravity has been executed and we are just waiting for the pieces to come to their destination.  As soon as they stop moving we start the creation of new Game Pieces one Game Piece per row at a time (so that the falling pieces are spaced).  If there are still empty spots in the grid we switch states to If there are more pieces and switch to $waitingOnFillSpotsCont otherwise it changes to $waitingOnFillSpots.&lt;br&gt;&lt;br&gt;&lt;i&gt;$waitingOnFillSpotsCont&lt;/i&gt; - We ended up in this state if there are still empty spots in the grid.  We create another Game Pieces for each column that is missing a spot and if by this act we have filled the grid then we switch the game state to $waitingOnFillSpots otherwise we stay in $waitingOnFillSpotsCont state so that we can create more Game Pieces.&lt;br&gt;&lt;br&gt;&lt;i&gt;$waitingOnFillSpots&lt;/i&gt; - The grid now has all its spots filled but the Game Pieces may still be falling into place.  As soon as the Game Pieces stop moving we switch to $waitingOnSwap so we can evaluate if the new Game Pieces have also caused a match to happen.&lt;br&gt;&lt;br&gt;&lt;b&gt;Memory Representation and Game Pieces:&lt;/b&gt;&lt;br&gt;&lt;br&gt;There are two 2-dimensional arrays that represent the board.  The first array stores the Game Piece type for each spot in the grid with zero implying an empty position and the second array holding that actual Game Piece (t2dStaticSprite).&lt;br&gt;&lt;br&gt;To create the Game Pieces dynamically I used the approach that the Checkers example introduced, namely having one named object per Game Piece type added in TGB Builder and then using 'cloneWithBehaviors' to make copies.&lt;br&gt;&lt;br&gt;&lt;b&gt;Knowing when the Game Pieces have stopped moving:&lt;/b&gt;&lt;br&gt;&lt;br&gt;I needed to be able to wait until the Game Pieces have finished their movement before I could continue and was having quite a bit of head scratching before I figured out a clean way of doing this.&lt;br&gt;&lt;br&gt;All movement is done through 'moveTo' which has a callback 'onPositionTarget' when the object has reached it's destination. I was then able to keep track which Game Pieces were moving or stationary by, assigning a 'isMoving' variable to true when 'moveTo' was executed and then set it back to false when 'onPositionTarget' was called.  In the onTimer, we can then iterate through all Game Pieces and see if any of them are moving (GameGrid::anyPiecesMoving).  My first attempt was to use a Class but due to a a bug with cloneWithBehaviors I had to use a Behaviour to do this (~/game/behaviors/GamePiece.cs).&lt;br&gt;&lt;br&gt;&lt;b&gt;Determining a match:&lt;/b&gt;&lt;br&gt;&lt;br&gt;GameGrid::evaluateBoard does this by iterating through the memory representation of the grid checking for each grid position if there is a horizontal match, followed by a search for any vertical matches. Along the way, matched GamePieces are added to a list so that they can be destroyed all at once.&lt;br&gt;&lt;br&gt;&lt;b&gt;Determining if any moves are left:&lt;/b&gt;&lt;br&gt;&lt;br&gt;GameGrid::isBoardComplete iterates through all pieces on the board and swaps (just the memory representation) the Game Piece with the right and checks for a horizontal and vertical match for both the current spot and the spot to the right.  It then swaps the Game Piece with the piece below it and does the same horizontal/vertical check on those to spots. &lt;br&gt;&lt;br&gt;The function does not evaluate the whole game grid for each swap, just the two spots that were swap which makes it pretty efficient.  The memory representation is reset back after each evaluation.&lt;br&gt;&lt;br&gt;This function is pretty heavy regardless but luckily it iis only called when the player completes a successful swap and so does not pose a performance issue.</description>
	</item>
	<item rdf:about="http://www.garagegames.com/blogs/25175/13698">
		<dc:format>text/html</dc:format>
		<dc:date>2007-10-10T20:15:17+00:00</dc:date>
		<dc:creator>Tom Cassiotis</dc:creator>
		<title>TGB Learning Project</title>
		<link>http://www.garagegames.com/blogs/25175/13698</link>
		<description>I decided to put some time in learning TGB by doing a simple small game that fit well in the type of game TGB is meant/designed to do well out of the box.  (I'm working with 1.5)&lt;br&gt;&lt;br&gt;I chose to do a completely basic match-3 game concentrating on game functionality and not worrying about the quality of the graphics or fun factor or selling (strictly to understand the tools and the language).&lt;br&gt;&lt;br&gt;&lt;b&gt;What I have:&lt;/b&gt;&lt;br&gt;- Basic start screen&lt;br&gt;- Game Logic&lt;br&gt;- Basic Sounds&lt;br&gt;- Basic Effect&lt;br&gt;- Basic game piece movement&lt;br&gt;- User Interaction&lt;br&gt;- Basic Scoring&lt;br&gt;- 'Wild' game piece (matches any other game piece)&lt;br&gt;&lt;br&gt;&lt;b&gt;Left to do:&lt;/b&gt;&lt;br&gt;1) Screen to tell you you do not have matches (I currently know when there are no moves left but I do not inform the player (i have a breakpoint for myself :) )&lt;br&gt;2) Text Effect for long matches (4+ game piece matches) and string of matches&lt;br&gt;3) Better scoring.  I have seen this in other games and it would be neat to code up; A point multiplier that starts at 1x but as you get big matches it increases in short amounts of times, while pauses decays the bonus.&lt;br&gt;&lt;br&gt;&lt;img src='http://www.game2.com/Spew/Connect3_1.png'  alt=&quot;&quot;&gt;&lt;br&gt;&lt;br&gt;I am looking for some guidance.  I would like to have someone take a look at the code and let me know if they would approach this differently.  I am a software developer for a very long time but I have not had the chance on doing game programming and things that may be obvious to some may not be to me.&lt;br&gt;&lt;br&gt;I'm hoping to incorporate any suggestions and making this available for others to learn from (for free of course).&lt;br&gt;&lt;br&gt;UPDATE: &lt;a href='http://www.youtube.com/watch?v=YjkuJmKfTHc' target=_blank&gt;www.youtube.com/watch?v=YjkuJmKfTHc&lt;/a&gt;</description>
	</item>
</rdf:RDF>
