Tag Archives: flash

My third full flash game is finally done! While my last one, Juggle Basher was essentially just a breakout clone, Block Merchant goes beyond the many tetris clones out there. It has different pieces, a new game mechanic of money and a shop which allows you to buy and sell blocks to optimize your set. The programming side of things was definitely a bit harder than the breakout clone, but where I really spent more time was the graphics. I probably put as much time into making the intro screen and the shop screen as into the programming. Fortunately, a fellow konger who goes by zoranac offered to help out with the music. He's been churning out all kinds of music in the Kongregate colabs.

As usual, I've put the game up on Kongregate and set it up to hook into their high scores api so your achievements will get recorded.

I ran into some problems with handling the block sprites. I was basically just using the same built-in .x and .y properties built into flash sprites and adding some number to currentBlock.y in the event loop for gravity, and either adding or subtracting from currentBlock.x when a direction arrow was pressed. The problem with this was that it made collision detection a pain, and it also raised questions like what to do with a block partway between two square locations. In a game like Tetris or Blockout, the squares of the playing pieces have to fit into the squares on the board.

The way I decided to fix it was this-- give the block class getters and setters for x,y coordinates in terms of the grid of the playing area, not in terms of pixels on the screen. I made all animation in discrete 1 square increments and this also made collision detection much easier. Here's the top of my block class:

public class Block extends Sprite {
  static const size:int = Board.gridSize; //size of the board's "squares"
  static var list:Array = []; // for keeping track of all the blocks

  var edge_color:int;
  var inner_color:int;
  var shape:Array;
  var type:String;
  var _gy:int; // the y position in grid squares rather than pixels
  var _gx:int; // the x position in grid squares rather than pixels
  var _gwidth:int;
  var _gheight:int;

And the getters and setters for the grid variables:

function get gy():int {
  return ((this.y-Board.top)/ size);
function set gy(gy:int):void {
  this.y = gy * size + Board.top;
function get gx():int {
  return ((this.x)/ size);
function set gx(gx:int):void {
  this.x = gx * size;

With the convenience of these getters and setters, along with a few others for width and height of pieces in terms of grid squares, it made animation very easy. I didn't need to refer to x,y screen coordinates again in the block class and could just increment or decrement currentBlock.gx or currentBlock.gy by one to move a block one square. Collision detection was similarly simplified. Instead of needing to use hitTestObject() as I did in the other two games I've made, all that was necessary was 2 dimensional array of the playing grid, filled with zeros for empty locations and ones for locations with a block. Then, before moving a piece, I just check to see which grid locations the piece would occupy and not allow the move if they're occupied. For example, If I had a long thin piece occupying squares (5,4), (5,5), (5,6), and (5,7) then all I'd have to do is check (6,4), (6,5), (6,6) and (6,7). If all of them are unoccupied then I can increment currentBlock.gy and move the piece. Moving left, I'd check (4,4), (4,5), (4,6) and (4,7).

In retrospect it seems obvious that a grid representation would be the way to go for a game with pieces and a playing field broken up into discrete squares (or cubes for blockout), but it wasn't the first idea I had.

My second flash game is a breakout clone. It should be very familiar to anyone who ever played Arkanoid, Breakout or other paddle games. It's simple in terms of graphics, but it was much more work for me than the side-shooter I made since I had no stock graphics to work from. The collision detection was also a bit of a headache. Since there are multiple levels and score screens, I tried putting them into different frames instead of keeping everything in a single frame as I had in my first game.

It is a little disappointing to have taken so long to put this online, but life has been busy. My distractions have included moving to Beijing, making a visa run to Mongolia, fending off a beggar who tried to rob me, getting started on my HSK prep classes and a really cool girl I've recently met.

Anyway, the game is up on Kongregate now and if you play it there, it's hooked into their high scores api and your achievements will get recorded.

I've been staying with my friend in Kunming over the past 3 weeks and have really enjoyed the vacation. I was definitely a bit burnt out when I left Taipei. I've lost a bit of motivation as far as my rails project is concerned, largely because it was aimed at people learning Chinese in Taiwan and I'm neither in Taiwan, nor learning Chinese (other than a few character simplifications) at the moment.

I'm not sure what compelled me to do it, but I just started on Kongregate.com's tutorials for making flash games. Ever since Sonia showed me her art work and what she could do with flash a couple of years ago, I've had a bit more interest in the subject. Anyway, Kongregate linked to Adobe's free trial version of CS5 Flash and I downloaded it. It's good for 30 days. Interestingly, it says that Actionscript is an ECMA script. I guess that means some skills I pick up will transfer to Javascript once I get back into the rails project.