Scratch Game
Expert
45 mins
Teacher/Student led
+120 XP
What you need:
Chromebook/Laptop/PC or iPad/Tablet

Sea Battle - Part 2

In this project we make a game where you captain a ship and battle against submarines and planes! This is part two of this project.

Teacher Notes

Live Class Feed

This is a live feed of the latest activity by your students on this lesson. It will update in real-time as they work on the lesson.
Load previous activity

    1 - Complete part 1 of this project

    In a separate lesson you should have completed part 1 of this project. Open your project in Scratch and continue to the next step in this lesson.

    Or if you wish you can use this starter project that has part 1 completed.

     https://scratch.mit.edu/projects/293643968/editor/

    2 - Add 'score' and 'lives' variables

    We need to create 2 more variables to store our score and lives. Create the following variables:

    • 'score' will store our score
    • 'lives' will store how many lives we have left

    Once you've created these new variables we can set their values for the start of the game. Add in the two new blocks under the when I receive [start] block in the battleship sprite:

    whenIreceivestart add them under heresetlivesto3start off with 3 livessetscoreto0set score to 0 at the startgotox0y46

    3 - Score a point

    Now let's add 1 to your score each time you hit a submarine.

    In the submarine sprite, find the 'if touching my torpedo' code block and add the change [score] by 1  block into it.

    iftouchingmy torpedothenchangescoreby1 add this new blockwait.2secondsdeletethisclone find this block

    Once you've added this block in, test that it works by playing the game. Each time you hit a submarine your score should go up by 1.

    4 - Lose a life

    Next add some code so you lose a life each time you get hit by an enemy torpedo.

    Add the following new 'if then' group of blocks inside the forever block in the battleship sprite.

    whenIreceivestartgotox0y46pointindirection90switchcostumetobattleshipshowforeverifkeyright arrowpressed?thenchangexby5ifkeyleft arrowpressed?thenchangexby-5iftouchingenemy torpedo?thenchangelivesby-1lose a life add in these new blocks

    Test that this works before moving onto the next step.

    5 - Game over

    Finally add the following code finish the game when you've no lives left.

    Again add the following new 'if then' group of blocks inside the forever block in the battleship sprite.

    whenIreceivestartgotox0y46pointindirection90switchcostumetobattleshipshowforeverifkeyright arrowpressed?thenchangexby5ifkeyleft arrowpressed?thenchangexby-5iftouchingenemy torpedo?thenchangelivesby-1iflives<1thenhideswitchbackdroptogame overbroadcastgameover add in these new blocks

    Unlock the Full Learning Experience

    Get ready to embark on an incredible learning journey! Get access to this lesson and hundreds more in our Digital Skills Curriculum.

    Copyright Notice
    This lesson is copyright of Coding Ireland. Unauthorised use, copying or distribution is not allowed.

    Scratch is developed by the Lifelong Kindergarten Group at the MIT Media Lab. It is available for free at https://scratch.mit.edu
    🍪 Our website uses cookies to make your browsing experience better. By using our website you agree to our use of cookies. Learn more