How To Put Game Over After Losing Lives In Scratch

Jun 11, 2012  Adding a timer and game over function to a game in Scratch - Duration: 7:39. Innova8IT 19,781 views. Scratch 2.0 Make a game over screen - Duration: 10:00. Travis Codes 48,983 views.

This is the 5th step out of 10 of the Gamedev Canvas tutorial. You can find the source code as it should look after completing this lesson at Gamedev-Canvas-workshop/lesson5.html.

It's fun to watch the ball bouncing off the walls and be able to move the paddle around, but other than that the game does nothing and doesn't have any progression or end goal. It would be good from the gameplay point of view to be able to lose. The logic behind losing in breakout is simple. If you miss the ball with the paddle and let it reach the bottom edge of the screen, then it's game over.

Aug 28, 2011 using the scratch program, how to you change the background to a game over screen once your game lives are a 0? Im at the end of my game and i want to know how to make the background change once my lives are at 0. I know how to change the background and i know it has to be a if statement but what do i put in the if part!!! Mar 29, 2019 To start over after losing a job, reflect on your goals and whether this might be a good time to change direction. Then, ask around for leads and dedicate time to look for work. To learn how to start over after the death of a loved one, keep reading. Jan 22, 2016  Vincent Quarles builds on a previously written tutorial by adding a pause, a main menu, and a game over screen to his Dodger game clone in Unity. Monday's basketball: No. 22 Wisconsin scratches out win over Illinois. Badgers get the job done with leading scorer Ethan Happ sitting on the bench down the stretch of a 64-58 victory.

Implementing game over

Let's try to implement game over in our game. Here's the piece of code from the third lesson where we made the ball bounce off the walls:

Instead of allowing the ball to bounce off all four walls, let's only allow three now — left, top and right. Hitting the bottom wall will end the game. We'll edit the second if block so it's an if else block that will trigger our 'game over' state upon the ball colliding with the bottom edge of the canvas. For now we'll keep it simple, showing an alert message and restarting the game by reloading the page.

First, replace where you initially called setInterval()

with:

/virtual-dj-karaoke-download.html. Then replace the second if statement with the following:

Letting the paddle hit the ball

The last thing to do in this lesson is to create some kind of collision detection between the ball and the paddle, so it can bounce off it and get back into the play area. The easiest thing to do is to check whether the center of the ball is between the left and right edges of the paddle. Update the last bit of code you modified again, to the following:

If the ball hits the bottom edge of the Canvas we need to check whether it hits the paddle . if yes, then it bounces off just like you'd expect; if not then the game is over as before.

How To Put Game Over After Losing Lives In Scratch Lyrics

Compare your code

Here's the working code for you to compare yours against:

Exercise: make the ball move faster when it hits the paddle.

How To Put Game Over After Losing Lives In Scratch Youtube

Next steps

We're doing quite well so far and our game is starting to feel a lot more worth playing now you can lose! But it is still missing something. Let's move on to the sixth chapter — Build the brick field — and create some bricks for the ball to destroy.

How To Put Game Over After Losing Lives In Scratch Song

This maze game has been adapted for school use from a lecture written by Carl Gustafsson.

Scoring

Each time the player picks up a diamond we will add 5 points to the score. We will give them 50 points for reaching the target.

Add the 'Set the Score' action (from the score tab) to both the diamond and the target object in the collision event with the person.

For the diamond object, in the properties make the new score 5, but make sure that you tick relative

Relative means that 5 will be added to the existing score. If you don't tick relative, then the total score would be set to 5.

For the target object collision with person event, you will need to add in 'Set the score relative to 50' immediately after Play sound

Why Can't I See the Score?

The score is normally automatically displayed in the title bar at the top of the screen. You can set whether or not it is displayed in action settings.

Choose any object that appears at the start of the game. Add a creation event for it. In the actions, choose the Score tab and Set the Window Caption info.

Ending the Game more Gracefully: Showing a High Score Table

We need to now look at what happens if the player is in the last room. As it is at the moment, if the next room doesn't exist, the game will just end.

How To Put Game Over After Losing Lives In Scratch Free

It would be better if we could show a high score table before ending the game. Luckily Game Maker has a built in high score table we can use.

After playing the sound and setting the score, the game should pause for a second before moving to the next room. This is just to give the player time to hear the sound and work out what is happening, so we will add in a Sleep action.
Add in block markers for the else section. This means that all actions in the block will be done if the next room doesn't exist. In other words, it is the end of the game.

In the 'Else' block, firstly display a message saying something like 'Game Over' or Congratulations!'

The 'Show the highscore table' action will automatically show a table. You can adjust settings for how it looks.

How many milliseconds would it need to sleep if I wanted to pause the game for 2 secs?

Displaying the Score more Attractively

You can display the scored more attractively by creating your own score object.

You will need to import a font to use for drawing the score. Right click on Fonts, or choose the 'Add a Font' icon Choose a suitable font.

Create a new object called objControllerMain

The controller object does not need a sprite, as you do not see it. It is used to manage the score in the game.

Add the draw event to the new object.
The draw event is triggered every step of the game when the instance of the object is about to be drawn on the screen. If the draw event isn't there, Game Maker will automatically draw the sprite that is assigned to the object.

As soon as anything is assigned to the draw event, the normal drawing of the sprite is skipped. Instead the actions of the draw event are carried out.

Add 'Set a font for drawing text' action

After the font is set, you can now draw the score using the 'Draw the score' action

Leave the x and y coordinates at 0, and tick relative. This means that the score will be drawn in the same place as the objControllerMain

Now place the objControllerMain in the room where you want the score to appear.

It will appear as a blue ball with a question mark. When the game runs, you will see the score.

Now you have your own score object, you will want to remove the score from the window caption.

You may want to enlarge your room height by 32 pixels and put your score object in the new strip at the bottom of the play area.

Setting Lives

The number of lives the player has left is saved in the lives variable. You can set the number of lives when you load your first room. Choose the creation event for an object in your room. On the score tab, set lives to the number of lives you want.

The player's score and number of remaining lives will appear in the title bar when you play the game.

Decreasing the number of lives

During the game, events will occur (such as collisions) that will mean the player should lose a life. You add this in the actions for the event that has caused the player to lose a life. When all lives are lost, you will want the game to end.

To your collision event (or whatever event will cause a loss of life), add a 'Set the number of lives' action (from the score tab)

Set the lives to be -1 and Relative.

-1 relative causes -1 to be added to the existing lives, giving the effect of subtracting a life.

How To Put Game Over After Losing Lives In Scratch Lyrics

Instead of ending the game immediately, you may wish to show the highscore table)

Create a simple game where you have 6 bouncing bombs in a box and a plane that the player controls with the cursor keys.

Give the player 3 lives to start with.

Whenever a bomb collides with the plane the player should lose a life until the game ends when all lives are gone.

Save it as lives

Using a Health Bar

A health bar is created in the Draw event for an object. You can create a controller object with no sprite that does this. When you draw the health bar, you need to give the coordinates for the top left corner of it (x1,y1) and the coordinates for the bottom right corner of it (X2,y2)

In the create event for an object, you will need to set the initial health to the value you want. (between 1 and 100)

Then in the event that causes you to lose health, take off health by setting its value to -10 (or whatever value you want) relative.

Click here for an example you can download that shows you how a healthbar works.