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 4Treasure Hunt Game

Knox badge
Lesson 4Treasure Hunt Game
  • What coordinates are and how they relate to a sprite
  • How to make a sprite move using user input from the mouse
  • I will be able to make a sprite follow the mouse
  • I will be able to make a simple game where the player collects treasure
  • I will be able to add a time limit to my game
1

Match all of the words to their definitions on the right!

Keyword
Event
Variable
Condition
Loop
Definition
Can be either true or false
Repeats something multiple times
Has a name and stores a value.
Something that happens in a program

In this lesson you are going to build a Scratch game. In this game the diver collects treasure to gain points.

Finished product

You can see a preview of the finished game below:

Setup the diver, treasure and stage

Follow these steps to get started with your game:

  1. Open Scratch on your computer
  2. Name your Scratch project as: Diving Game
  3. Delete your Cat sprite from the game
  4. Add the Diver1 sprite to your game
  5. Add the Star sprite to your game
  6. Change your backdrop to the Underwater 1 backdrop
  7. Create a variable called points for all sprites
  8. Create a variable called time for all sprites
  9. Save your project

Add mouse controls to your character

In the previous lesson we looked at how to make our cat sprite move using the keyboard. For our diver to move, we need to add some blocks to make the diver follow the mouse.

Try out what you have just created.

What happens to the diver when he gets to the mouse?

To fix the issue where the diver starts to flash backwards and forwards, change your code to:

Without this code, the driver would constantly flash backwards and forwards when the mouse cursor goes over it.

Collecting stars

Select your Star and add the following blocks:

Make the points variable increase by 1 and put it inside the if block. Remember to set the points to 0 at the start as shown below:

Points
Try out what you have just created.

Moving the star

Each time the player gets a star we want the star to appear in another location on the scene.

To do this, we are going to make the star go to a random position on the scene. Find the following three blocks and then add them after the hide block.

Your blocks should now look like the blocks following.

Try out what you have just created.

Duplicate our stars

Let's make more than one star to collect. To copy all the code we have put in and keep it exactly the same, we need to duplicate the star:

Do this 4 times to get to a total of 5 stars.

Position our sprites

Now that you have created your stars, position them similar to below by clicking on them in the stage and dragging them to where they are to go.

Try out what you have just created.

Adding a time limit

Go back to the diver sprite.

Follow these steps to create a timer in your game:

  1. Go back to the diver sprite.
  2. Create a variable to store time.
  3. Add the following blocks to your diver:
    Adding time
  4. A timer is something that repeats over and over for a certain amount of time. This means we can use a loop in Scratch to make a timer.

    To do this, add the following blocks below what you just added:

    Updating the time

    This code is make a timer that ticks every one second removing 1 from the time variable.

  5. Now we need to make the game stop when the timer runs out. Change your code so that it looks like:

    Updating the time

    What this does is checks if the player has not got 10 points and then tells them they have run out of time.

Winning the game

To win the game, we should have something similar to the previous game. By including a forever around our points check, we can constantly be checking to see how many points the player has and stop the game when they get a certain number. Add the following blocks to our diver:

Updating the time
Try out what you have just created.
  • Add an item that if picked up takes away a point.
  • Try to animate your stars when they are collected. You could use the following blocks instead of just using the hide block:
    Animating the stars
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

: