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

Sea Battle - Part 1

In this project we make a game where you captain a ship and battle against submarines! This is part one of two parts 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 - Create a new Scratch project

    We've created a starter project that has some custom backdrops and sprites already setup. Open this starter project by clicking on the following link:

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

    2 - Program the backdrops

    There are 3 backdrops included with this project, a 'title' backdrop to appear at the start of the game, a 'sea' backdrop to appear while you play the game and a 'game over' backdrop to appear when the game is finished.

    Add the following code to the backdrop:

    whenclickedswitchbackdroptotitlewhenIreceivestartswitchbackdroptoseawhenIreceivegameoverswitchbackdroptogame over


    3 - Program the Start button

    When the instructions screen is showing, we also want to display a Start button that will start the game when the user clicks on it.

    Add the following code to the 'Button2' sprite:

    whenclickedshowwhenthisspriteclickedbroadcaststarthidewhenIreceivegameovershow


    4 - Move your battleship

    Now we will setup the 'battleship' sprite for the start of the game and code it to move when you press the left and right arrows. Add the following code to the 'battleship' sprite:

    whenclickedsetsizeto50%hidewhenIreceivestartgotox0y46pointindirection90switchcostumetobattleshipshowforeverifkeyright arrowpressed?thenchangexby5ifkeyleft arrowpressed?thenchangexby-5



    5 - Fire your torpedo

    We're going to program the 'x' key to fire our torpedo when it is pressed. When fired, the torpedo will continually move down until it touches a submarine or the edge of the screen.

    Add the following code to the 'my torpedo' sprite:

    whenxkeypressedcreatecloneofmyselfwhenIstartasacloneswitchcostumetonormalgotobattleship the torpedo needs to start at the same current location of your battleshipshowrepeatuntiltouchingedgeiftouchingsubmarinethenswitchcostumetohit this is the explosion costume of the torpedowait0.2secsdeletethisclonechangeyby-4 move it downdeletethisclone



    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