The ships
The ships
Movement
We are now going to make the ships move. Click on the "WarShip01S" object to display its properties in the property explorer, locate and select the "Movements" tab. Choose "Bouncing ball" in the Type property combo box. Our boat will not bounce like a ball, but we are going to use the properties of this movement.
Set the Speed to 18, then click on the "Initial direction" property, and only select the right direction.
Do the same for the other boats. The lower the boat, the faster the speed. The boat facing on the left will have their initial direction set to the left. Don’t hesitate to test the game to see how fast the ships are moving.
Runtime options
The boats are going to be created outside the visible section of the ocean. To increase the speed of your games our software tools have a default behavior of destroying the objects far from the display window area. You have to change the properties to it not to destroy the objects outside of the display window area.
Click on each one of the boats to display its property in the property explorer. Locate and click on the "Runtime Options" tab in the explorer. Now find the property named "Destroy object if too far from frame" and uncheck it. Select "No" in the combo box of the next property ("Inactivate if too far from frame"). Doing this will keep the boats active, even if they are far from the display window.
Creation
Now click on the "Event editor" icon in the toolbar. Enter the following events. Every second, we draw a random number. If the number is greater than 93, we create a boat. We have to put it in the back of the display list, so that it does not appear on the top of the periscope. The next event makes sure the boat is destroyed when it reaches the end of the display (otherwise it would continue exist out of the frame, slowing down the game).
- Every 01"-00
+ Random(100) >= 94
: Create (warship01S) at (-40,121) layer 1
(warship01S) : Bring to back
- (warship01S) leaves the play area on the left or right
(warship01S) : Destroy
We still have three other boats to create using the same technique. Enter the following events to achieve this :
- Every 01"-00
+ Random(100) >= 93
: Create (warship02L) at (-40,121) layer 1
(warship02L) : Bring to back
- (warship02L) leaves the play area on the left or right
(warship02L) : Destroy
- Every 01"-00
+ Random(100) >= 93
: Create (warship03M) at (-40,121) layer 1
(warship03M) : Bring to back
- (warship03M) leaves the play area on the left or right
(warship03M) : Destroy
- Every 01"-00
+ Random(100) >= 93
: Create (submarine05S) at (-40,121) layer 1
(submarine05S) : Bring to back
- (submarine05S) leaves the play area on the left or right
(submarine05S) : Destroy
You can launch the game now. You should see the boats moving to the left or the right in the periscope.
Spread the word!
You can share this document using the following buttons.