The example code stacks and files below include code techniques, comments, and questions that may assist with the creation of your project. You are encouraged to explore, modify, and adapt the code for your own use.
The Scratch Stage
The Scratch stage is 480 pixels wide and 360 pixels tall. The centre of the stages has a position location we refer to as (0, 0). This means X = 0, Y = 0.
Here are a couple of other position examples:
If a sprite is on the left edge of the screen but centred vertically, the position would be referred to as (-240, 0). This means X = -180, Y = 0.
If a sprite is on the top edge of the screen but centred horizontally, the position would be referred to as (0, 180). This means X = -180, Y = 0.
If a sprite is almost on the right of the screen and about three quarters toward the top (as in the third image), it could be located at (200,100). This means X = -180, Y = 0.
A simple (but 'chunky') way to allow sprites to be moved left and right (in the 'X direction') when keys are pressed. These IF blocks have two conditions that (in this case):
Prevent the sprite moving right if the X position if the sprite is not less than ( < symbol) 195 pixels.
Prevent the sprite moving left if the X position if the sprite is not greater than ( > symbol) -188 pixels.
The sprite will move 10 pixels in either direction when a key press is detected, however it will move in 'chunks' not completely smoothly.
Try it!
This is a better and smoother way of coding movement that is more efficient (gets the coding task done more quickly and smoothly).
This approach using IF blocks within a forever LOOP allows sprites to move more cleanly than using 'event triggers' with key-presses. This is the preferred way of coding movement in our games. This codes player sprite movement in the X-direction (left/right). You can adapt it to move a character in the Y-direction using the up/down arrow keys.
This is because the code is always checking for a key press. You need to be careful, however, as too many forever LOOPs can cause slowdown in your programs.
Your teacher will help you develop techniques to create efficient code by demonstrating and sharing various tips and tricks for coding in Scratch.
Falling objects move in the 'negative Y direction'. This example creates a clone of the ball sprite every two seconds.
You will need to delete clones, otherwise your Scratch projects will eventually slow down due to Scratch having to draw too many sprites to the screen.
Project link: https://scratch.mit.edu/projects/858615690/
Project link: https://scratch.mit.edu/projects/416124749/
Project link: https://scratch.mit.edu/projects/510014334/
Description
This project shows how sprites can act as buttons that navigate to different backgrounds using events.
Hiding and showing of these buttons (and other sprites) is necessary when the appropriate navigation occurs.
Most of these sprites usually have a number of event blocks with a simple show or hide block.
In addition to the button examples, this project shows how clones can be used decoratively.
Questions to consider
There is one green flag code block on the background. What is its purpose?
How and why do the various button sprites appear and disappear?
Keywords
Buttons, Menu, Navigation, Title Screen, Instructions, Credits, Background Change, Music
Project link
Description
A math quiz that uses variables to generate questions and store answers.
IF statements determine if the answer is correct, and if the score increases.
A LOOP reduces the amount of code needed to create the game.
An IF statement determines the condition of whether the player passes or fails.
Questions to consider
How is the correct answer calculated?
How is the correct answer compared with the user answer?
Keywords
Variables, Random Numbers, User Input, IF / ELSE, Greater Than, Is Equal To
Project link
Description
Questions to consider
Keywords
Variables, Random Numbers, Variables as Sprites, Check IF correct answer
Project link
Project link: https://scratch.mit.edu/projects/479398829/
Project link: https://scratch.mit.edu/projects/322204637/
Project link: https://scratch.mit.edu/projects/381161039/
Description
Questions to consider
Keywords
Variables, Random Numbers, User Input, IF / ELSE, Greater Than, Is Equal To, Sprites, Drawing
Project link
Description
This project shows two methods of jumping.
The first is simple jumping using the space bar to trigger two glide blocks. This allows for simple dodging games to be created, but separate event blocks would need to be created to allow for collisions, scoring, losing lives/health etc. This is due to glide blocks 'taking control' of the code in any given event (until the gliding is completed).
The second is a more complex approach, which allows for left/right movement, and jumping across platforms.
Questions to consider
Describe the purpose of each of the variables used in the dinosaur sprite.
Explain the two scenarios where colours are used for detecting collisions.
Explain how levels are incorporated into this 'game'.
Keywords
Jumping, Gravity, Sprites, Movement, Platform, Levels Using Costumes
Project link
Description
Questions to consider
Keywords
Jumping, Gravity, Sprites, Movement, Platform
Project link:
Description
Questions to consider
Keywords
Variables, Shooting, Collisions, X/Y, Point to Mouse
Project link
Description
Questions to consider
Keywords
Clones, Sprites, Movement
Project link
Description and Questions
This project incorporates a number of techniques and approaches to coding in Scratch. These include:
Five variables: CarScore, CarLives, CarPosition, EnemyPosition, EnemySpeed
My Blocks
Win and lose scenarios using IF blocks
Randomisation
Questions to Consider
Describe the purpose of each of the five variables.
Explain how the enemy's position is randomised and speed increased.
Explain how the winning and losing scenarios are coded.
Outline two problems with this game and how you could fix them using code.
Keywords
Sprites, Variables, Collisions, Game, Win/Lose, My Blocks, Difficulty
Project link: