Project 5
Last updated
Last updated
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.
You will follow the instructions for creating scenes in the Khan academy tutorials for: SceneManagement. https://www.khanacademy.org/computing/computer-programming/programming-games-visualizations#programming-scenes
Example projects: SceneManagement with Character Animation: https://www.khanacademy.org/computer-programming/project-5-example-v2/5126765991624704
Simple SceneManagement: https://www.khanacademy.org/computer-programming/project-5-example/4912927631409152
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.