Thank you for visiting Blazing Games

Making A chemical mixing machine

The chemical mixing machine, the locks on the door, and picking up the strips are all part of the same MovieClip and the same class. You could rightly argue that this is bad coding as you are combining multiple different functioning elements into a single class. A better way of coding this would be to have the mixing machine and locks in their own class and have those classes be part of the SecretLab class. The funny thing about deadlines, even self-imposed ones, is that when you are nearing the end of one you don't properly think through things in your rush to get things finished. I suppose the "I can clean this up later" excuse is to blame but later rarely comes.

The SecretLab class is the controlling class for the room. As you have seen in earlier chapters, adventure games often have each room in an adventure have its own script for handling what can happen in that room. There is only one room in this adventure so the SecretLab class is both the main game code and the room script. It, of course, holds the chemical mixing machine. This machine consists of a grid of buttons for entering chemicals, some control buttons for clearing and mixing chemicals, a chemical mix display, and a slot for inserting strips. The buttons on the grid all call the same handler which simply determines which chemical is supposed to be added and adds it to the display.

private function chemHandler(event:Event):void
{
var chemTarget:int = 0;

for (var cntr:int = 0; cntr < _chemButtonList.length; ++cntr)
if (event.target == _chemButtonList[cntr])
chemTarget = cntr + 1;
if (chemTarget > 0)
_mix_movie.addChemical(chemTarget);
}

Before you can write a chemical on a strip, that strip needs to be inserted into the machine. This is done using the inventory system covered in a previous chapter so the code for dealing with it will not be covered here but feel free to look at the source file for the handleInsert function. Putting the chemical onto a chemical strip is simply the process of making sure a strip is inserted into the machine and cloning the machine’s mix onto the strip.

private function handleMix(event:Event)
{
var chemStrip:ChemicalStrip;

_strip_movie.cloneMix(_mix_movie);
if (_stripInserted > 0) {
chemStrip = ChemicalStrip(_chemStrips[_stripInserted-1].getIcon());
chemStrip.cloneMix(_mix_movie);
}
_mix_movie.clearMix();
}

With that, we have a machine for creating chemical strips used to open a door to a dimensional portal that will lead the player to an alternate dimension's version of Earth.

Previous page
Chapter 44 Page 5

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