Thursday, August 25, 2011

DDTe3 Hour 9 Twist puzzle

While it has been a while since the last post in this series due to a family tragedy, I am now back to posting weekly and am continuing my series of articles on the creation of Dozen Days of Tiles episode 3. This is a game in a day challenge in which instead of developing a game in under 24 hours (development time) I am instead seeing how many games can be created in 24 hours of development time. Today the creation of the twist puzzle is covered.
 
The twist puzzle takes a 2x2 block of tiles and rotates them counter-clockwise. The only new game mechanic revolves around the rotation of tiles, which can be handled using existing BasePuzzleModel classes. There are no changes needed to the view class making this is a very quick project. 

The game mechanic that needs to be implemented is a performTwist method. This could be done using three swaps as outlined in the following pseudo-code:
    swap x,y with x+1,y
    swap x+1,y with x+1,y+1
    swap x+1,y+1 with x,y+1

However this results in six tile moves. Because I already knew which game I was going to develop right after this one was finished, I decided to use a more efficient four-way swap as the next game in the series would be better able to utilize this code. Having long-term plans is always nice, even if they don't come to fruition they are giving you a path to follow.

PuzzleGallery.TwistPuzzleGame.prototype.performTwist = function(p)
{
   var temp = this.puzzle.getPuzzlePiece(p.x, p.y);
   this.puzzle.setPuzzlePiece(p.x, p.y, this.puzzle.getPuzzlePiece(p.x+1, p.y));
   this.puzzle.setPuzzlePiece(p.x+1, p.y, this.puzzle.getPuzzlePiece(p.x+1, p.y+1));
   this.puzzle.setPuzzlePiece(p.x+1, p.y+1, this.puzzle.getPuzzlePiece(p.x, p.y+1));
   this.puzzle.setPuzzlePiece(p.x, p.y+1, temp);
   this.view.update();   
}

This still leaves the problem that tiles along the right and bottom edges are not valid to click on so the onTileClick callback method has to be slightly changed.

PuzzleGallery.TwistPuzzleGame.prototype.onTileClick = function(p)
{
   if (( p.x < (this.puzzle.puzzleWidth-1)) && (p.y < (this.puzzle.puzzleHeight-1)))
       this.performTwist(p);
}

The game scrambling likewise needs to be changed. As with the sliding puzzle game, a scramble method that randomly selects a valid tile and performs a twist on that tile is all that was needed.

PuzzleGallery.TwistPuzzleGame.prototype.scramble = function()
{
   var p = new BGLayers.Point();
   var w = this.puzzle.puzzleWidth;
   var h = this.puzzle.puzzleHeight;
   var n = w * h * 10;
  
   for (var cntr = 0; cntr < n; ++cntr) {
       p.x = Math.floor(Math.random() * (w-1));
       p.y = Math.floor(Math.random() * (h-1));
       this.performTwist(p);
   }
}

While I try to focus on writing about the theory behind the code and try only to show the relevant bits of code, almost all the code that I wrote is in this article. Still, finishing a game in well under an hour (though I am still counting the time as an hour to simplify my time-keeping) is great.

Thursday, August 18, 2011

Adjusting Blazing Games Plans

Sorry for the long delay between posts. I will continue my series on the creation of Dozen Days of Tiles episode 3 next week as this week I am going to discuss the changes I am making to Blazing Games. With the added responsibilities that have come after my mother's death, I have been forced to rethink my plans for Blazing Games. This may be a good thing if I can stick to my new plans, but as I have a habit of falling back to my old way of doing things only time will tell. If you have visited the Blazing Games site, you may already know that I am switching the updating of the site to every other week. Quite frankly, once a month is just not often enough for what I want to do yet weekly is just too frequent. The games and open source releases that will appear on the site will be smaller games for the time being as I am going to start focusing on one large scale game at a time and that large scale game is going to be small enough that I should be able to complete it in a reasonable period of time. To prevent other people from stealing my work, sneak previews of my bigger project will either be older builds of the game or will have large chunks of the content omitted.

Right now Blazing Games is more of a hobby that just happens to earn enough to cover it's costs, unless you count my time in which case the books would be well into the red right now. Now that there are some, albeit a small number, of indies who are making a lot of money and many more who are making a living off of their creations, it is probably time that I focus on turning my hobby into a real business. While I happen to be in a good position at the moment, my mother's bout with cancer has been a brick to the back of the head reminder about how quickly things can change.

My spare-time playing around with the creation of a larger scale game (and my own Fantasy Combat game Engine) has taught me how much different it is developing a large scale game than the simple games I tend to have on my site. This has caused me to rethink my plans for my first larger game and break the development of the larger game down into a number of smaller games that will lead to the final game. As Blazing Games simply does not have enough visitors to justify exclusivity to the larger games, I am going to be experimenting with releasing the game on various game portals as well as experimentation with porting the games to the various phone platforms and their respective stores.

I do plan on continuing my open sourcing of older games from my site, but some of my favourite games will be upgraded and enhanced. Some of the tools I am developing for my larger scale projects will be released as open source as will some of the libraries that I am developing. Full games will probably continue to use the GPL license while libraries will use the far-less restrictive MIT license.

While the site will be updated every other week, this blog will be returning to a weekly release again, if only so I can get caught up with my making of DDT series. While I do hope I can turn Blazing Games into a real company, I know the odds are against me. Still, it is worth a try and right now I have the motivation, it is just a matter of finding enough of that elusive thing called "time".