Colliding with the Snake
70. When the monkey collides with the Snake we will set up something more interesting to happen rather than just have the monkey disappear. Add the following to Event Sheet 1:
71. Add Event > Body > On collision with another object > Snake > Done
72. Add Action > Body > Destroy
73. Add Action > LeftArm > Destroy
74. Add Action > RightArm > Destroy
75. Add Action > LeftLeg > Destroy
76. Add Action > RightLeg > Destroy
77. Add Action > Head > Apply impulse towards position > Impulse: 20 > X: 20 > Y: 20 > Image point: 0 > Done
78. Add Action > Tail Apply impulse towards position > Impulse: 20 > X: 40 > Y: 40 > Image point: 0 > Done
79. Save the game and run the layout. Watch what happens when the monkey collides with the snake!!
80. Close the browser and return to Event Sheet 1.
Testing if the Monkey has collected all the Bananas
81. Once the monkey has collected all the bananas, we want to stop the game and display an appropriate message on the screen. To do this, we initially need to create the Text sprites on Layout 1, but on a new Layer which we will call HUD.
82. Switch to the Layers tab on the Projects/Layers/Objects panel.
83. Lock the Main layer and add a new layer. Rename this layer to HUD. Keep this layer selected.
84. Switch to the Layout 1 window and do the following:
85. Double click on the Layout 1 window (towards the end of the layout) > double click Text > click once on the Layout 1 window.
86. Make the following changes to the Properties panel (on the left):
87. Switch to Event Sheet 1 and add the following Events/Actions:
88. Add Event > System > Compare variable > Variable: Bananas > Less or equal > Value:0 > Done
89. Add Action > FinishText > Set Visible > Visiblity: Visible > Done
90. Add Action > FinishText > Set position to another object > Head > Image point: 0 > Done
91. Add Action > Body > Apply impulse towards position > Impulse:20 > X:mouse.x > Y:mouse.y > Image point:0 > Done
92. Add Action > Body > Set immovable > Setting: immovable > Done
93. To make the game easy to have another go (when the Snake destroys the monkey), we will set up the right mouse button to restart the layout. To do this do the following:
94. Add Event > Double click Mouse > On click > Mouse button: Right > Clicked > Done
95. Add Action > System > Restart Layout.
96. Add Action > System > Reset global variables (this is so the Bananas variable will default back to its original value when you restart the game).
97. Save and run your game. The Congratulations text should appear when all the Bananas have been collected. The monkey should also become immovable as soon as the Bananas are collected.