Filters

Other

D

Your name is required for this document. It is only stored on this local computer and no where else. Please enter your name below:

Lesson 7Shark Bait

Knox badge
Lesson 7Shark Bait
  • How to use communication between objects (sprites) in Scratch
  • How to use logic in Scratch
  • I will be able to make a game in Scratch using a series of instructions

In this lesson we are going to build upon what we did in lesson 4 and add in a shark. This will make the game more of a challenge. If you have finished lesson 4, you can open that to give you a head start. You can find lesson 4 here.

Finished product

You can see a preview of the finished game below:

Setup the diver, treasure and stage

  1. Delete the cat sprite
  2. Add a diver sprite
  3. Add a shark sprite
  4. Set the backdrop to an underwater backdrop
  5. Create two variables, one called lives and one called points

Resize your sprites

Resize your sprites

Resize both the shark and the diver to about 50% to make sure that it's not too big and not too small.

Setting up the diver

Once again, the diver is going to follow the mouse. Add the following blocks to the diver make the diver follow the mouse:

Resize your sprites

Set up the shark

The shark's purpose is to catch the diver. In your shark sprite, add the following blocks:

Shark code
Pay close attention to the fact that the diver moves three steps whereas the shark only moves two. This means that the diver can escape the shark and will make it possible for the player to win. The shark will also stop moving when the point variable is 10 or more.
Try out what you have just created.

Lives

The diver will need lives and when they reach 0 the player loses.

To do this, add the following blocks to your diver, remembering to use the variable called lives:

Lives code

The go to x: 138 y: 104 block is very important since it moves the diver away from the shark when they are touching it and prevents the shark removing all lives in one go.

The broadcast bite and wait part is also very important to ensure that the diver also tells the shark to move away when he is bitten. This broadcast feature is a really useful part of Scratch that allows sprites (also known as objects in computer programming) to communicate.

Shark code

On the shark there needs to be some code that lets the player know they have been bitten by the shark. Add the code blocks on the right to the shark to make a bite sound when the shark touches the diver and to move the shark when he bites the diver:

Shark code
Try out what you have just created.

Adding stars

Much like in lesson 5, we are going to add stars. The code blocks for our starts will be the same as in that lesson but with an extra bit added that makes the blocks go up to the top:

Stars code 1
Stars code 2

Adding a win condition to the diver

Now we need to allow our diver to win by getting 10 points. To do this, add this sequence of blocks to your diver sprite:

Win code

Adding a loss condition to the diver

Now we need to make it possible for our player to lose. To do this, add the following sequence to your diver:

Lose code
Try out what you have just created.

Duplicate the stars

Duplicate your stars so you have multiple stars in the game, say 5 of them.

  • Add in a rare item that the player can collect that would give them a live back
  • Advanced: Create an item that would allow the player to move faster (you will need a variable that stores the number of steps the player is to move)
S1 Scratch Lessons
S1 Scratch Extension Tasks
S1 Scratch Assessment
Assessment
Provide Feedback

What did you think of this lesson?

!
-- DragonDocs version 0.9 --

20.08.2017

Started on DragonDocs
Created a YASS/PHP and HTML-based system for saving and retrieving data

21.08.2017
Added CSS styles to page
Added JavaScript code to the page

02.02.2018
Added the multipage option (used in my dissertation)
Added the XMLHttpRequest-based multipage requests

08.02.2018
Added the Accessibility features
Filters added

10.02.2018
Purple filter added

17.03.2018
Added the Note class
Added the Did You Know class

-- DragonDocs version 1.0 (Yosemite) --

02.10.2019
First trial of DragonDocs in teaching

04.10.2019
Added the Task, Starter, Review your learning sections

07.10.2019
Added the feedback feature
Added the Dark Mode toggle

19.09.2020
Performance gains through the removal of unnecessary code
Added the Learning Intentions and Success Criteria features
Added the school badge

31.09.2021
Changed the headings (h2) to be more consistent with my website
Added sections to the pages - sections must be preceded by a h2
Added the "I have read this section" buttons
Changed the main heading zone to gradient text like my website
Added the table of contents feature

02.02.2022
Added the Print feature
Updated the footer to feature a new gradient
Added the Test It! class
Added the green flag
Automated the table of contents using JavaScript

06.02.2022
Added the 'includes' feature to the document, allowing inclusion of other files easily
Removed the requirement that the IP address must be one of the schools I have taught at, opening these documents to the public

02.03.2022
Once a section has been read or completed, the user can now hide that section

10.10.2022
Added the Extension task class
Changed the scrollbar on Windows to match that of macOS

-- DragonDocs version 2.0 (Kilimanjaro) --

07.08.2023
Added the Save button and the ability to save 'results' or answers to a Word document

12.01.2024
Added the large numbers class
Removed the background of the page navigation

-- DragonDocs version 2.1 (Aurora) --

08.02.2024
Added the active class to active links in the bottom section

09.02.2024
Added the image upload feature

10.02.2024
Added a fix that prevents the upload of non-image files into an image upload
Added pasting images to the upload feature

11.02.2024
Added the ability to view the changelog from a document
Improved the feedback system by recording the DragonDocs User ID and the Document ID data
The feedback from DragonDocs can be accessed much easier

12.02.2024
Added the new step_by_step_mode feature, allowing sections to be viewed individually
Added the ability to lock and unlock DragonDocs

22.02.2024
Added new checkboxes to each list item in a .task or .step
Added functionality to said checkboxes to add a strikeout to steps completed

23.02.2024
Added the new 'step' class
Steps are now auto incremented in CSS so the name displays the step number
Activities are now also auto incremented to display the activity number

25.02.2024
Added the 'matcher' feature to DragonDocs
Fixed an issue in which a closed section would retain it's original height within the document navigation
Added starters and the lesson review to the navigation on the side
The learning intentions and success criteria in teaching documents have now been redesigned to match my slides design

26.02.2024
All buttons are now on the right hand side
The accessibility button now has WAI under it

-- DragonDocs version 2.2 (Serengeti) --

26.02.2024
Code has been rewritten from the ground up to be object-oriented, making additional features easier to add

28.08.2024
Changed the look of grouped multiple choice buttons

06.03.2024
Added the new dragondocs_name feature and the requires_name property which allows names to be prepended to saved documents

09.03.2024
Added code so when the user types in their name and hits the enter key it will save that data and close the modal window
Added the new DragonShow and DragonDocs Link - a connection between both services that allows the presenter to communicate with users of DragonDocs from a DragonShow
Added the new timer option which is sent from DragonShows

04.04.2024
The matcher feature is no longer embed from jamiebalfour.scot but actually a feature of DragonDocs
Made DragonDocs 100% object-oriented, meaning much better management and better performance

05.04.2024
Made subtle changes to the interface to tidy it up a bit

06.04.2024
The multiple choice questions are now also part of the object oriented interface

09.04.2024
As requested, h3 elements are now included in the 'floating navigation'
The active navigation element now becomes bold and the left border has been retired

Time left

: