lesson 2 - mrahmedcomputing.co.uk · lesson 2 spawning asteroids ... you now need to add a second...

25
1 Bristol Metropolitan Academy – Computer Science and ICT Department 2017 Lesson 2 Spawning Asteroids Open the Construct 2 file that you were working on last lesson. Go to the “Project” menu. Insert the “SpawnPoint” object into the “Main” layer. Click and drag. Same process as background and player ship

Upload: others

Post on 14-Aug-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lesson 2 - mrahmedcomputing.co.uk · Lesson 2 Spawning Asteroids ... You now need to add a second action to this system event. ... Under the ^Behaviours _ option, change the Speed

1

Bristol Metropolitan Academy – Computer Science and ICT Department 2017

Lesson 2

Spawning Asteroids

Open the Construct 2 file that you were working on last lesson.

Go to the “Project” menu. Insert the “SpawnPoint” object into the “Main” layer.

Click and drag. Same process as background and player ship

Page 2: Lesson 2 - mrahmedcomputing.co.uk · Lesson 2 Spawning Asteroids ... You now need to add a second action to this system event. ... Under the ^Behaviours _ option, change the Speed

2

Bristol Metropolitan Academy – Computer Science and ICT Department 2017

Once you insert the “SpawnPoint” object; it should look like this.

Resize the “SpawnPoint” object and then insert 7 more. Then position them around the layout

(outside the black area). Your layout should look like the one below.

Page 3: Lesson 2 - mrahmedcomputing.co.uk · Lesson 2 Spawning Asteroids ... You now need to add a second action to this system event. ... Under the ^Behaviours _ option, change the Speed

3

Bristol Metropolitan Academy – Computer Science and ICT Department 2017

Now insert the “AsteroidLarge” object from the Projects menu.

The Asteroid should be outside the layout.

Page 4: Lesson 2 - mrahmedcomputing.co.uk · Lesson 2 Spawning Asteroids ... You now need to add a second action to this system event. ... Under the ^Behaviours _ option, change the Speed

4

Bristol Metropolitan Academy – Computer Science and ICT Department 2017

Navigate to the events sheet. Select “Add Event”. Select “System”, then select “Next”.

Page 5: Lesson 2 - mrahmedcomputing.co.uk · Lesson 2 Spawning Asteroids ... You now need to add a second action to this system event. ... Under the ^Behaviours _ option, change the Speed

5

Bristol Metropolitan Academy – Computer Science and ICT Department 2017

Select “Pick random instance”. Then select “Next”.

You will then need to select the “SpawnPoint” object by clicking on the <click to choose> option.

Page 6: Lesson 2 - mrahmedcomputing.co.uk · Lesson 2 Spawning Asteroids ... You now need to add a second action to this system event. ... Under the ^Behaviours _ option, change the Speed

6

Bristol Metropolitan Academy – Computer Science and ICT Department 2017

Select the “SpawnPoint” object. Then click on “Done”.

Page 7: Lesson 2 - mrahmedcomputing.co.uk · Lesson 2 Spawning Asteroids ... You now need to add a second action to this system event. ... Under the ^Behaviours _ option, change the Speed

7

Bristol Metropolitan Academy – Computer Science and ICT Department 2017

A System Event that selects a random spawn point, should now be created in you events sheet.

“Right Click” on the event that you created (event 5) and “Add another condition”.

Page 8: Lesson 2 - mrahmedcomputing.co.uk · Lesson 2 Spawning Asteroids ... You now need to add a second action to this system event. ... Under the ^Behaviours _ option, change the Speed

8

Bristol Metropolitan Academy – Computer Science and ICT Department 2017

Select “System”, then select “Next”.

Page 9: Lesson 2 - mrahmedcomputing.co.uk · Lesson 2 Spawning Asteroids ... You now need to add a second action to this system event. ... Under the ^Behaviours _ option, change the Speed

9

Bristol Metropolitan Academy – Computer Science and ICT Department 2017

Select “Every X seconds”. Then select “Next”.

In this window. Type in:

random(5)

This sets a random number between 1 and 5.

Page 10: Lesson 2 - mrahmedcomputing.co.uk · Lesson 2 Spawning Asteroids ... You now need to add a second action to this system event. ... Under the ^Behaviours _ option, change the Speed

10

Bristol Metropolitan Academy – Computer Science and ICT Department 2017

You should now have a system event with 2 conditions. The system should select a random

“SpawnPoint” every few seconds now.

Now you need to add actions for these events. Select “Add action”. Then Select “SpawnPoint” and

Next.

Page 11: Lesson 2 - mrahmedcomputing.co.uk · Lesson 2 Spawning Asteroids ... You now need to add a second action to this system event. ... Under the ^Behaviours _ option, change the Speed

11

Bristol Metropolitan Academy – Computer Science and ICT Department 2017

Select “Spawn another object”. Then select “Next”.

Select the “AsteroidLarge” object by clicking on the <click to choose> option.

Page 12: Lesson 2 - mrahmedcomputing.co.uk · Lesson 2 Spawning Asteroids ... You now need to add a second action to this system event. ... Under the ^Behaviours _ option, change the Speed

12

Bristol Metropolitan Academy – Computer Science and ICT Department 2017

Once you have chosen the “AsteroidLarge” object; set it so that is spawns on Layer “1”. Click Done.

Note: Layer was set to “1” because that is the number assigned to the

“Main” Layer.

Page 13: Lesson 2 - mrahmedcomputing.co.uk · Lesson 2 Spawning Asteroids ... You now need to add a second action to this system event. ... Under the ^Behaviours _ option, change the Speed

13

Bristol Metropolitan Academy – Computer Science and ICT Department 2017

You now need to add a second action to this system event. Select “Add action”. Then select

“AsteroidLarge” and “Next”.

Page 14: Lesson 2 - mrahmedcomputing.co.uk · Lesson 2 Spawning Asteroids ... You now need to add a second action to this system event. ... Under the ^Behaviours _ option, change the Speed

14

Bristol Metropolitan Academy – Computer Science and ICT Department 2017

Select “Set angle towards position”. Then select “Next”.

Type in the following into the X option:

PlayerShip.X

Type in the following into the Y option:

PlayerShip.Y

Then click on “Done”.

Page 15: Lesson 2 - mrahmedcomputing.co.uk · Lesson 2 Spawning Asteroids ... You now need to add a second action to this system event. ... Under the ^Behaviours _ option, change the Speed

15

Bristol Metropolitan Academy – Computer Science and ICT Department 2017

Your system event should look like this.

Press “F5” to test and run your program.

Page 16: Lesson 2 - mrahmedcomputing.co.uk · Lesson 2 Spawning Asteroids ... You now need to add a second action to this system event. ... Under the ^Behaviours _ option, change the Speed

16

Bristol Metropolitan Academy – Computer Science and ICT Department 2017

You should notice that the asteroids are moving too fast and do not bounce off of each other. To fix

this, first select the asteroid which is off the main layout.

When the asteroid is selected, the “Properties” menu for the object will be available on the left

hand side of the screen. Under the “Behaviours” option, change the Speed to “50” and change

Bounce to “Yes”.

Press “F5” to test the game.

Page 17: Lesson 2 - mrahmedcomputing.co.uk · Lesson 2 Spawning Asteroids ... You now need to add a second action to this system event. ... Under the ^Behaviours _ option, change the Speed

17

Bristol Metropolitan Academy – Computer Science and ICT Department 2017

Asteroid Collisions

Navigate to the events sheet. Select “Add event”. The select “AsteroidLarge” and “Next”.

Page 18: Lesson 2 - mrahmedcomputing.co.uk · Lesson 2 Spawning Asteroids ... You now need to add a second action to this system event. ... Under the ^Behaviours _ option, change the Speed

18

Bristol Metropolitan Academy – Computer Science and ICT Department 2017

Select “On collision with another object”. Then select “Next”.

Select the “PlayerShip” object by clicking on the <click to choose> option.

Page 19: Lesson 2 - mrahmedcomputing.co.uk · Lesson 2 Spawning Asteroids ... You now need to add a second action to this system event. ... Under the ^Behaviours _ option, change the Speed

19

Bristol Metropolitan Academy – Computer Science and ICT Department 2017

Once you have chosen the “PlayerShip” object, click “Done”.

An event should then be created (Asteroid collision with Player Ship).

Page 20: Lesson 2 - mrahmedcomputing.co.uk · Lesson 2 Spawning Asteroids ... You now need to add a second action to this system event. ... Under the ^Behaviours _ option, change the Speed

20

Bristol Metropolitan Academy – Computer Science and ICT Department 2017

On this event, select “Add action”. Then select “PlayerShip” and “Next”.

Select “Destroy”. Then “Done”.

Page 21: Lesson 2 - mrahmedcomputing.co.uk · Lesson 2 Spawning Asteroids ... You now need to add a second action to this system event. ... Under the ^Behaviours _ option, change the Speed

21

Bristol Metropolitan Academy – Computer Science and ICT Department 2017

When the Player Ship collides with the Asteroid, the Player Ship with be destroyed.

If you press “F5” to test it, you will notice that the Player Ship does not appear again unless you

close the game and start again.

To make the Player Ship respawn again. Select “Add action” on the collision event (event 6). Then

select “System” and “Next”.

Page 22: Lesson 2 - mrahmedcomputing.co.uk · Lesson 2 Spawning Asteroids ... You now need to add a second action to this system event. ... Under the ^Behaviours _ option, change the Speed

22

Bristol Metropolitan Academy – Computer Science and ICT Department 2017

Select “Wait”. Then “Next”.

Set the Seconds to “2”. Then click on “Done”.

Page 23: Lesson 2 - mrahmedcomputing.co.uk · Lesson 2 Spawning Asteroids ... You now need to add a second action to this system event. ... Under the ^Behaviours _ option, change the Speed

23

Bristol Metropolitan Academy – Computer Science and ICT Department 2017

Again, on the collision event, select “Add action”. Select “System”. Then select “Done”.

Select “Create object”.

Page 24: Lesson 2 - mrahmedcomputing.co.uk · Lesson 2 Spawning Asteroids ... You now need to add a second action to this system event. ... Under the ^Behaviours _ option, change the Speed

24

Bristol Metropolitan Academy – Computer Science and ICT Department 2017

Select the “PlayerShip” object by clicking on the <click to choose> option.

Page 25: Lesson 2 - mrahmedcomputing.co.uk · Lesson 2 Spawning Asteroids ... You now need to add a second action to this system event. ... Under the ^Behaviours _ option, change the Speed

25

Bristol Metropolitan Academy – Computer Science and ICT Department 2017

Once you have chosen the “PlayerShip” object, set the layer to “1” and set X to “320” and Y to “240”

(X and Y coordinates for the centre of the layout). Click Done.