Project 5
Last updated
Was this helpful?
Last updated
Was this helpful?
For project 5, you will be integrating scenes into your previous project. We'll use a Finite State Machine to model the logic to manage changing scenes.
For our final project, we'll have 2 different Finite State Machines, since we had already implemented a FSM to control our character's animation. So, the diagram below shows that there are nested FSM's in our project. The FSM's are independent, each relies on it's own state variable to keep track of the current state. We need to provide code to implement the conceptual model captured in each FSM's structure.
In the example project, I have used object literal syntax to specify properties for 2 button objects. This provides a nice way to organize, access, and modify data associated with a single object.
Here is code to define 2 object literals, and example code to show how to use these objects in custom functions.
Inside mouseClicked( ), we call functions that we've designed to take a button object as input parameter. Within the custom functions: drawButton, restartClicked, and checkClicked, the button's properties are accessed using dot notation. For both button objects, we've defined the same properties, we can easily add additional buttons to the project using the same format.
To restart the animation within Scene2, we've created a button: animationButton that is drawn inside the draw function if the currentState is Scene2. When the mouse is clicked, then animationButton checks to see if the mouse is within it's borders, if so, then it executes a function, initializeScene2( )
that resets all of the animation control variables back to their initial state, including changing the Animation state variable: WaveState back to it's initial value: "UP", count is reset to 0, angle is reset to it's initial value.
You will follow the instructions for creating scenes in the Khan academy tutorials for: SceneManagement.
Example projects: SceneManagement with Character Animation:
Simple SceneManagement: