*Note: Graphics in the Rocks Rock game that are not in the source code are not part of the open source license.  Please insert your own graphics, sound, etc. into the existing framework.

1. Game Flow

The game begins with the initialization of variables in a blank frame before the menu.  This ensures that the variables get initialized the first time through the game.  The game then stops at the main menu/title screen.  Upon pressing start, the game then goes to the secondary menu (Intro frame).  If the Credits button is pressed, the game then goes straight to the Credits frame.  At the intro frame, the user is then given the option to enter his or her name.  There are two buttons on the screen leading to either start the game (Level1Intro) or review the rocks (Igneous).

If the rock review is chosen, the user is guided through three information pages about the different rocks (Igneous, Sedimentary, Metamorphic frames).

When the next button on the Metamorphic frame, or the Start Game button on the Intro frame is pressed, the game goes to the Level1Rocks frame.  This frame contains the rocks that will be displayed on level 1 and the actions contained on this frame set up some of the parameters to be used in level 1.  Upon clicking next, level 1 begins.  If the maximum score is reached for level 1, the game then flows to the Level1Congrats frame.  This frame congratulates the user, displays his or her score, and does some of the take-down for the level.  There are two buttons for the user to click.  Upon clicking next, the game flows to Level2Rocks and the cycle is continued and upon clicking menu, the flow returns to the main menu frame.

If either the end of the game is reached (Level3Congrats frame) or the maximum number of drops is reached without reaching the maximum score on a level, the game flows to the GameOver frame.  This frame displays the user’s score and has three options:  Return to main menu, return to last level, and Credits.  These buttons do as their text indicates and returns the user to the Menu frame, the last level that they attempted to conquer, or to the Credits frame.  However, since some of the setup for the levels is done in the frame prior to the level, the flow goes back to the intro frame before the level (Level1Rocks, Level2Rocks, etc.)

2. Variables

2.1.   itemCount: Counts the number of the item created in each level by the attachMovie function.

2.2.   maxItemNum: Maximum number of items to be created in the level.

2.3.   speed: Speed of the objects that will appear on the conveyor belt on that particular level.

2.4.   Level: Current level variable.

2.5.   maxScore: Variable used to determine the maximum score needed to continue to the next level.  As soon as score is equal to or greater than maxScore, the game will continue to the congratulations frame for that level.

2.6.   done: Used to determine if the level has been completed either by reaching the maximum score or maximum number of drops.

2.7.   done2: Used to determine if level 3 has been completed by reaching the maximum number of objects hitting the trash.

2.8.   timeDelay: delay between objects appearing on the conveyor belt on that particular level(in milliseconds).

2.9.   invisible: Sets objects’(rocks, elements, etc.) visibility to false.  The variable is set on the main timeline and checked upon entering each frame in the object’s code.

2.10.  item:Array(): Holds the objects to be randomly displayed on each level.  It is necessary to statically declare the length of the array whenever setting up the array for each level.  This is so that upon returning to the level, objects added to the array in later levels are not used in a lower level.

2.11. n: Counter used to attach a numeric value to the end of each instance name created by the attachMovie function.  This assures that no instance names will have the same name.

2.12. maxDrops: The maximum number of drops to be allowed on each specific level.

2.13.  RockGet: Boolean variable used to determine if rocks need to be produced on the level.

2.14.  played: Boolean variable used to determine if the level has previously been played.

2.15. Level1Score: Holds the score at the end of Level 1 to be transferred to Level 2.

2.16.  Level2Score: Holds the score at the end of Level 2 to be transferred to Level 3.

2.17.  score: Holds the score of the user to be displayed to the screen.

2.18. drops: Counts the number of drops of the objects onto either one of the categories or dropping of the conveyor belt into the trash.

2.19. sendToTrash: Used to control objects remaining on the screen whenever the level is completed either by the maximum score or maximum number of drops being reached.  When sendToTrash is equal to true, the object will become invisible and be located behind the trash can without taking away from the user’s score.

2.20.correctSound: Sound variable that holds a random sound to be played whenever an object is dropped onto the correct correctSpot instance.

2.21.  wrongSound: Sound variable that holds a random sound to be played whenever an object is dropped onto the wrong correctSpot instance.

2.22.correctSounds: Array that holds a number of sounds that will be played at random when an object is dropped onto the correct correctSpot instance.

2.23.wrongSounds: Array that holds a number of sounds that will be played at random when an object is dropped onto the wrong correctSpot instance.

2.24. initialMove: This Boolean variable is used to make sure that the object moves down the c_belt whenever it is first created.

2.25.  trashRocks: This variable keeps track of how many rocks have hit the trash object on level 3.

2.26. maxTrashRocks: Holds the maximum number of rocks to hit the trash object on level 3 before the game ends.

3. Frame Labels

3.1.   Menu: First frame of the game containing the main menu options.

3.2.   Intro: Secondary menu with options to enter the user’s name, go straight to the game, or review information on the objects.

3.3.   Igneous: Information about the igneous rock classification to help with identifying igneous rocks.

3.4.   Sedimentary: Information about the sedimentary rock classification to help with identifying sedimentary rocks.

3.5.   Metamorphic: Information about the metamorphic rock classification to help with identifying metamorphic rocks.

3.6.   Level1rocks: Lists the rocks that will be used in level 1.  This frame is used as a set-up for level 1.

3.7.   Level1: Level 1 of the game.

3.8.   Level1Congrats: Congratulates the user if maximum score for level 1 is reached.  Used as a take-down for level 1.

3.9.   Level2Rocks: Lists the rocks that will be used in level 2.  This frame is used as a set-up for level 2.

3.10. Level2: Level 2 of the game.

3.11. Level2Congrats: Congratulates the user if maximum score for level 2 is reached.  Used as a take-down for level 2.

3.12.  GameOver: Frame to signal the end of the game for the user.  Reached whenever the end of the game (level 2 passed) is reached or when the maximum number of drops on a level is reached without reaching the maximum score.

3.13. Credits: Frame that lists contributors to the game.  Reached either from the Menu or GameOver frames.

4. Level Flow

On each level there are symbols that are accessed in the object code to maintain the correct flow of the game.  There are four main aspects: the objects, the conveyor belt, the trash, and the correct spots.  When the object appears on the conveyor belt (referred to as c_belt), it moves across the belt until it is picked up using the mouse.  When it is dropped onto one of the correct spots, it either increases the score by 100 or decreases by 50 depending on if the correct spot has been chosen.  Also, when dropped on one of these spots, the object’s visibility will be set to false and the drops counts will be incremented.  If the object is dropped anywhere else on the screen, the object currently returns to the center of the belt.  When left on the belt, it will continue moving until it hits the trash can (referred to as trash), at which point it will subtract 50 points from the score and its visibility will be turned to false.

When either the maximum score of maximum number of drops is reached, the level will end and flow to either the congrats frame or the game over frame.

The flow for level 3 is a bit different in that it does not have a static ending point and does not use the getRock function to create its objects.  Instead, it uses the getRock2 function which functions in basically the same way, but speeds up the production of objects on every fifth object.  Also, rather than creating objects until the maximum score or maximum number of drops is reached, the level continues until the maximum number of trash rocks, stored in maxTrashRocks, is reached.  In this way, the level is never ending and provides an incentive to improve at the game and obtain the maximum score.

5. Main Timeline Functions

5.1.   getRock() this function is used to create the objects that will appear on the conveyor belt.  It begins by storing a random integer between 0 and the length of the item array that will be used to randomly generate an object.  The function then checks if the maximum number of items for the level has been generated or if the level has ended.  If either of these conditions occurs, it will not generate a new object.  If neither of these conditions occurs, the function uses the attachMovie function to create a new instance of the symbol stored in item[x].  The instance is called item[x]n where n is the integer stored in the counter variable n.  This naming scheme is accomplished by placing the item[x] + n parameter in the attachMovie function and is done to ensure that no two instances have the same name.  The object is placed on the next highest depth level using the built in functionality of Flash, and created in a place that will be at the beginning of the c_belt.  After creating the object, the n and itemCount counters are incremented.  The second aspect of the getRock() function is the setInterval function.  It essentially calls the getRock function every specified amount of time.  In our case, we declare the time in the itemDelay variable.

5.2.   getRock2() this function is used to create the objects that will appear on the conveyor belt in the third, never-ending level of Rocks Rock.  It begins by storing a random integer between 0 and the length of the item array that will be used to randomly generate an object.  The function then checks if the level has ended before creating the objects. If either of these conditions occurs, it will not generate a new object.  If neither of these conditions occurs, the function uses the attachMovie function to create a new instance of the symbol stored in item[x].  The instance is called item[x]n where n is the integer stored in the counter variable n.  This naming scheme is accomplished by placing the item[x] + n parameter in the attachMovie function and is done to ensure that no two instances have the same name.  The object is placed on the next highest depth level using the built in functionality of Flash, and created in a place that will be at the beginning of the c_belt.  After creating the object, the n and itemCount counters are incremented.  Using the modulo functionality, the function then increases the speed of the objects and decreases the time between the creation of the objects on each fifth object.  The second aspect of the getRock2() function is the setInterval function.  It essentially calls the getRock function every specified amount of time.  In our case, we declare the time in the itemDelay variable.

5.3.   onEnterFrame controls the flow of each level.  It checks upon entering each frame to see if the maximum score has been reached or if the maximum number of drops has been reached and sends the game to the corresponding frame.

6. Sound Functions

6.1.   playWrongSound plays a random wrong sound when an object is dropped onto the wrong correctSpot instance.  First it stores a random integer between 0 and the length of the wrongSounds array into variable randWrong.  It then attaches the sound found in wrongSounds[randWrong] to the sound variable wrongSound and starts the sound.

6.2.   playCorrectSound plays a random correct sound when an object is dropped onto the correct correctSpot instance.  First it stores a random integer between 0 and the length of the correctSounds array into variable randCorr.  It then attaches the sound found in correctSounds[randCorr] to the sound variable correctSound and starts the sound.

7. Object Code

7.1.   this.moving controls the objects while they are moving along the c_belt.  It is called using the onEnterFrame functionality to constantly check the status of the object.  It first checks to see if the object is on the c_belt, and if it is, moves it along the c_belt at the speed specified on the main timeline.  It then checks to see if the object has hit the trash.  If it has and the level is not yet done, it increments the drop counter and subtracts 50 from the score.  This is done only once because the trashCount counter is incremented when it hits the trash, and the drop counter and score are only affected when trashCount equals one.  Whether the level is done or not, when the object hits the trash, its visible parameter is set to false.  The function then checks to see if the invisible parameter on the main timeline is set to false, and if it is, it sets the object’s visible parameter to false.  Finally, it checks to see if the sendToTrash parameter on the main timeline is set to false, and if it is, sends the object to the trash and sets the trashCount to 2 so that it will be turned invisible but will not increment the drops counter or decrease the score.

7.2.   onEnterFrame The reason for this function is to ensure that the object moves when it is first created.  When the initialMove variable equals true, it calls the this.moving function.  Also, if the invisible parameter on the main timeline is set to true then the object’s visible parameter is set to false.

7.3.   onPress When the mouse is pressed on the object, the startDrag function is called on the object.  Also, upon clicking on the object the first time, it stops the onEnterFrame function.

7.4.   onRelease This function is called every time an object is released.  The first thing is does is to stop the drag function.  Next, there are a series of checks to see where you have released the object.  For the purposes of documentation, we will refer to the correct spot to drop the object as correctSpot1 and the wrong spots to drop the object as correctSpot2 and correctSpot3.  When the object is dropped onto correctSpot1, the playCorrectSound function on the main timeline is called to play a random correct sound.  It then snaps the object to the location of correctSpot1, increases the score by 100, and increases the drop counter by 1.  The object’s visible parameter is then turned to false.  When the object is dropped onto correctSpot2 or correctSpot3, the playWrongSound function on the main timeline is called to play a random wrong sound.  It then snaps the object to the location of correctSpot2 or correctSpot3, decreases the score by 50, and increases the drop counter by 1.  The object’s visible parameter is then turned to false.  If the object is released in a spot other than on one correctSpot instances, the object is returned to the middle of the c_belt and the this.moving function is called.

8. Linkage

In order to reference objects in the source code (sound objects, movie clips, etc.), you must link them to the Actionscript using the Linkage option in the library.  Some of the code used in the source code refers to objects that are not in the library.  You can insert your own objects into the library and link them using the same names or change the names in the code to match your object names.