A Simple Game! – Part 5

In this lesson, we create a variable called score and update it when a collision occurs. The code occurs in our “Play game” broadcast while moving the ship.

We add the following code:

So that the code becomes:

We add a variable called Still playing to keep track of our current game state:

And the score is only reset during initialization when “StillPlaying” is false.

In the case that the ship is missed after movement was completed,, we simply set “StillPlaying” to false and our score is reset during initialization:

That’s it for our main logic!

Here’s the full code for the spaceship:

Here’s the code for the planet:

A full implementation with all the bells and whistles can be found here:

Planet Destroyer

© 2019  Vedesh Kungebeharry. All rights reserved.  

One thought on “A Simple Game! – Part 5

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s