Thank you for visiting Blazing Games

Making Chemicals strip

As the main puzzle that this game revolves around is based on the creation of chemical strips, these are an important part of the game. When you think about it, a lot of the functionality of the image strip is also needed by the machine used to create the image strips so breaking the strip into sharable components was an important consideration in the design of this episode’s code. Three classes make up the chemical strip. These are the Chemical Color, the Chemical Mix and the actual Chemical Strip.

The ChemicalColor holds the color to display when representing the chemical as a color. As this is the visual clue for helping the player know what is on the strip, it is tied to a MovieClip object within the frames of the movie being the different colors that represent the chemical colors. The actual colors used have no importance with the exception of the violet color as that is the professor’s favorite color. The other colors used for mixing are based on a letter and a number so could be anything but happen to be red and blue. The code to implement this is exceedingly simple as it only has to go to the frame that is tied to the color that is being selected.

ChemicalMix obviously is a group of chemicals. It is a visual representation of the mix so it is contained in a MovieClip and holds a set of ChemicalColor movieClips. The chemical colors are stored in an array with an index used to determine which color is the next to be set. The important part of this class is the ability to count the number of an indicated color on the strip. This is used by the core game in order to determine if the strip has the right portion of a needed chemical.

public function getChemicalParts(chemical:int):int
{
var chemCount:int = 0;
for (var cntr:int = 0; cntr < NUM_CHEMS_ON_STRIP; ++cntr)
if (_chemStack[cntr].getChemical() == chemical)
++chemCount;

return chemCount;
}

Finally we have the ChemicalStrip class. As with all the other classes, it is tied to a MovieClip. The movie clip has a Chemical Mix on it. The actual validation of the strip is done here. As I was in a rush while writing this, The validation is passed as an array with the array made up of pairs. The even elements (0,2,...) is the chemical number while the odd elements contain the count of that chemical.

public function validateMix(pattern:Array):Boolean
{
var isValid = true;
for (var cntr:int = 0; cntr < pattern.length; cntr += 2) {
if (_mix_movie.getChemicalParts(pattern[cntr]) != pattern[cntr+1])
isValid = false;
}
return isValid;
}

With the strip out of the way, the core of the game can now be created. This is the chemical mixing machine which is part of the secret lab class that we will be covering next section.


Previous page
Chapter 44 Page 4

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