Wednesday, August 1, 2007

Making One of those Weeks episode 15, part 4

Within the initialization of the game, we have to set up the different “constants” that are used to reflect the states of the rock and walnut. We are using ActionScript 2 still, so constants are not true constants but are simply variables who's value never is changed once set.

// Rock states
O15ROCK_NUT = 2;
// walnut states
O15NUT_NONE = 0;
O15NUT_HUSK = 1;
O15NUT_ROCK = 2;
O15NUT_NUT = 3;

The rock may appear to be a complex beast, at least if you quickly look at the large chunk of code below used to control it, but really is quite simple once you think about what the four possible states of the rock are and what happens in each of those states.

function rockAction()
invState = inv_movie.getInventoryMode();

if (invState == O15INV_STATENORMAL) {
if (ootw15_rockState == O15ROCK_NUT) {
ootw15_rockState = O15ROCK_SHELL;
ootw15_walnutState = O15NUT_NUT;
showMessage("I got the nuts, and I'm not even playing poker!");
} else
showMessage("It is a very big rock. Too big for me to pick up.");
} else if (invState == O15INV_STATESTICK)
showMessage("Hitting the rock with a stick isn't going to help!");
else if (invState == O15INV_STATEROCK) {
if (ootw15_rockState == O15ROCK_HUSK) {
ootw15_rockState = O15ROCK_NUT;
ootw15_walnutState = O15NUT_ROCK;
showMessage("That worked, but now the walnut has to be cured by leaving them in a cool dry area for a few weeks. Thankfully this one is meant as a gift so I won’t have to do that.");
} else if (ootw15_rockState == O15ROCK_NUT) {
showMessage("The walnut has to be cured before it should be opened. Besides, it is suppose to be a gift.");
} else
showMessage("Wow. Banging two rocks together makes a sound!");
} else if (invState == O15INV_STATEHUSK) {
// the only time there is a husk in inventory is before this point
// so we don't really need to do any checks on rock state.
ootw15_rockState = O15ROCK_HUSK;
ootw15_walnutState = O15NUT_ROCK;
} else


No comments: