Thank you for visiting Blazing Games

Coding a Rainbow

While there are technically two separate puzzles in the game, both puzzles are dependent on each other so when coding the game, both puzzles where handled together. This slightly complicates things, as there are three possible states for a ball. The Buried state means that the ball has not been dug up yet. The inventory state means that it has been added to inventory. The combo state means that it has been added to the correct slot in the rainbow puzzle. Each ball is assigned a number, and an array holding the current ball state is created. The functions to see if a ball is in a particular state work by simply seeing if the ball's assigned value is set to the indicated state constant.

function restartOotW23()
{
BALLSTATE_BURRIED = 0;
BALLSTATE_INVENTORY = 1;
BALLSTATE_COMBO = 2;
BALL_RED = 1;
BALL_YELLOW = 2;
BALL_GREEN = 3;
BALL_BLUE = 4;
BALL_VIOLET = 5;

// array element 0 is
ballArray = new Array(0, 0,0,0,0,0);
}

function isBallBurried(id)
{
return (ballArray[id] == BALLSTATE_BURRIED);
}
function isBallInInventory(id)
{
return (ballArray[id] == BALLSTATE_INVENTORY);
}
function isBallInSlot(id)
{
return (ballArray[id] == BALLSTATE_COMBO);
}

The screen that contains all the mounds sets the visibility of the mound by checking to see if each ball is buried. As we know where each ball is, the mounds simply call the grabBall function passing the appropriate color id. This changes the state of the ball and gets the mound screen to redraw itself. The bsod mounds simply call the game over animation.

function grabBall(id)
{
ballArray[id] = BALLSTATE_INVENTORY;
gotoAndPlay("mounds");
}

function redMound()
{
grabBall(BALL_RED);
}

function greenMound()
{
grabBall(BALL_GREEN);
}

function blueMound()
{
grabBall(BALL_BLUE);
}

function yellowMound()
{
grabBall(BALL_YELLOW);
}

function violetMound()
{
grabBall(BALL_VIOLET);
}

function bsodMound()
{
gotoAndPlay("bsod");
}

The slot puzzle works by having the slots pass their id to a handleSlot function which then checks the inventory to find out which ball has been selected from the inventory. How the inventory system works has been discussed in previous chapters so all that really needs to be added is that the balls have been assigned state values that correspond to the orb color constants. If the inventory state happens to match the id of the slot that the player clicked on, the balls state is changed to the combo state. If the ball is being placed in the wrong slot then the state is changed back to the buried state. Finally, a win game check is performed by simply counting how many balls are in the combo state.

function handleSlot(id)
{
var invMode = inv_movie.getInventoryMode();
if (invMode == id)
ballArray[id] = BALLSTATE_COMBO;
else
ballArray[invMode] = BALLSTATE_BURRIED;

//check for win
var comboCount = 0;
for (cntr = 1; cntr < 6; ++cntr)
if (ballArray[cntr] == BALLSTATE_COMBO)
++comboCount;
if (comboCount == 5)
gotoAndPlay("win");
else
gotoAndPlay("combo");
}

function handleRedSlot()
{
handleSlot(BALL_RED);
}
function handleGreenSlot()
{
handleSlot(BALL_GREEN);
}
function handleBlueSlot()
{
handleSlot(BALL_BLUE);
}
function handleYellowSlot()
{
handleSlot(BALL_YELLOW);
}
function handleVioletSlot()
{
handleSlot(BALL_VIOLET);
}

Previous page
Chapter 23 Page 5

About - Privacy Policy - Contact - Links - FAQ
Copyright © 2008 Blazing Games Inc. All Rights Reserved