thunderpoy.blogg.se

How to create your own game on scratch
How to create your own game on scratch




how to create your own game on scratch
  1. How to create your own game on scratch code#
  2. How to create your own game on scratch series#

Make sure you drag any blocks beneath these back to the original script. ask Should the cat meow or scream when it's nipped by the crab? and wait.The blocks you need to move are the following: Now drag the blocks that run that routine to the 'hat' for your custom block. I'm going to call it: 'User defines cat sound'. Click the Make a Block button, and name your first block. Make sure you've got the cat selected, and go to the More Blocks section. Let's create two custom blocks: one for the routine that asks the user to define what the cat will say, and one for the routine that makes the cat react to being caught by the crab. Here's what the cat scripts look like now: The cat sprite currently has quite a lot of blocks in its main script, so let's apply this principle to that. Creating a Custom Block to Shorten a ScriptĪnother way you can use custom blocks is to replace large routines in your scripts, making your scripts shorter and easier to manage. If you want to make a custom block apply to all of your sprites, create it in the Stage.

How to create your own game on scratch code#

This has only reduced the code by three lines in that script, but you can see how if you were using larger routines or repeating them more often, for different sprites perhaps, it would make things more efficient. The script will now have 11 blocks of code instead of 14: Once you've done that, edit the script with those two repeating blocks in it so that the two blocks are replaced by your custom block each time. These will be the wait 1 secs and change Timer by -1 blocks. To define this block, you need to add the blocks it will replace beneath that 'hat'. You'll now see a new script 'hat' called define Count down every second (or whatever you've called it): You'll be presented with the New Block dialog box: Select the Stage and click on More Blocks. This isn't a lot of repeating code, so in a real project you might choose to leave it as is, but for the purpose of this tutorial let's replace it with a custom block. In this project the main script for the Stage includes some repetition of two lines: Rename it and you're good to go! Creating a Custom Block to Avoid Repetitionįirst you need to identify where a custom block would make your scripts more efficient. Scratch will save a duplicate of my project as a new project in your account. Log in to Scratch and go to the page for my project on animations.Ĭlick the See Inside button to view the project: In the toolbar, click File > Save as a copy: Make sure you've clicked the See Inside button so you can see the workings of the project.

how to create your own game on scratch

Open Scratch and go to the project you want to duplicate. Here's how you do each of these (you'll only need to do one).

  • Remix the project I created to support the last tutorial.Īlternatively you can just carry on working in the same project you already created.
  • Open the project you created for the last tutorial and make a duplicate of that.
  • We're going to be working with the project created in the last part of this series, on animations. We'll use the assets and scripts we've created so far and add more.ĭepending on whether you worked along with that tutorial, there are two ways to get started for this tutorial:
  • a web browser with access to Scratch (I recommend using a modern browser like Chrome, Firefox, Safari or Opera for the best experience).
  • In this tutorial we'll be using the first three approaches.
  • Creating routines in which values or strings can be altered each time you add the routine to a script.
  • Creating recursive routines in which the routine is run again if a condition is or is not met.
  • If your scripts are getting large and unwieldy, use them to tidy things up and store long routines elsewhere.
  • This way you can define a routine once and then use it whenever you need to by inserting your custom block into your project.
  • Use them to apply the DRY (Don't Repeat Yourself) principle to your projects, replacing blocks which you use more than once with a custom block.
  • We'll use a custom block to make our code tidier and easier to work with. In this part we'll continue working on that project. The game has some animations and keeps score, which it displays at the end. You've created a game in which the user chases a cat with a crab, the cat says 'Ouch!' when the crab nips it, and a score is kept.

    How to create your own game on scratch series#

    You're now most of the way through this beginner's series on Scratch.






    How to create your own game on scratch