Close
Close full mode
logoMakeCode AP CSP

Tutorials on Randomness

Random Sprite Location

Go to Activity: Random Sprite Location.

Complete student tasks 1-3.

Tasks

Tasks 1

  • Adjust the code to pick a random number from 1 to 100.
  • Add a new variable anotherRandom to pick a random number from 20 to 30.
  • Add splash screen for anotherRandom variable to display the result.

Shared project:

Task 1 Challenges

  • Use blocks to generate a random number that can result in both negative and positive values.

Shared project:

Task 2

  • Add an on A button pressed block.
  • Make the event code for the A button move a sprite to a new random position.
  • Add another sprite and make it move with the B button.

Shared project:

Task 2 Challenge

  • Make both sprites change position with the A button and make the B button give one of the sprites a random velocity.

Shared project:

Tasks 3

  • Add at least 2 more sprites with random or fixed position.
  • Add an on overlap event result in a new behavior that uses pick random.9

Shared project:

Task 3 Challenge

  • Make multiple sprites randomly change position with the A button and both of the sprites a random velocity.

Shared project:

Questions

Describe how the ability to generate a random value can make a game more interesting and/or challenging.

Reflection/Homework

Make a hypothesis of a good use of pick random that you would like to design into a future game - especially something we don’t know how to do yet. Be descriptive of the game and how a random value would be needed.

πŸ“˜ Unit 3 - AAP Part 1 β€” Previous
How Computers Generate Random Numbers
Next β€” πŸ“˜ Unit 3 - AAP Part 1
Day 14