beginners-step-by-step-coding-course-learn-computer-programming-the-easy-way

Page 36

Output using movement Scratch is an ideal language for programming simple games and applications that move images around the screen. It has a set of blue Motion blocks that can be used to control a sprite’s movement. Coordinates

180

x axis 0

240

(x=180, y=120) y axis

In Scratch, any position on the Stage can be pinpointed using the x and y coordinates. The x axis runs from -240 on the left to 240 on the right, and the y axis runs from -180 at the bottom to 180 at the top. When writing a program, coordinates can be used to place a sprite in a particular position.

–240

0

(x=–120, y=60)

(x=–180, y=60) –180

x and y grid The Stage here has been marked with grid lines every 60 steps. Try these positions in the Motion blocks (below) for moving a sprite using coordinates.

(x=60 y=-120)

Moving sprites using coordinates These Motion blocks can be used to move a sprite to a particular position on the Stage using coordinates. The go to x: y: block and set x to and set y to blocks are often used to set a sprite’s starting position.

go to x: 0 y: 0 Set sprite position Makes a sprite jump to a particular point on the Stage. The numbers in the block can be edited to choose different coordinates.

glide 1 secs to x: 0 y: 0 Move sprite in given time This block smoothly moves the sprite to a particular point. The time taken for this journey can be specified in the input area for seconds.

change x by 10 Alter x position Changes the x position by the number in the block, without changing the y position. It is used to move a sprite sideways.

set x to 0 Change x position Moves the sprite to a particular x position, without changing its y position. The sprite will jump straight there.

change y by 10 Alter y position Changes the y position by the specified number, without changing the x position.

set y to 0 Change y position Moves the sprite to a particular y position, without changing its x position. As with the similar x block, the sprite jumps straight there.

x position Show x position This block does not move a sprite, but shows the sprite’s x position when clicked. Drop it into other blocks to use this coordinate in a script.

y position Show y position Does not move a sprite, but shows its y position. It can also be used with other blocks. For example, a sprite can be made to say its y position (see p.38).


Turn static files into dynamic content formats.

Create a flipbook

Articles inside

Other programming languages

5min
pages 344-347

PROJECT: Responsive website

52min
pages 304-343

ACKNOWLEDGMENTS

1min
page 360

INDEX

26min
pages 352-359

GLOSSARY

16min
pages 348-351

Graphic user interfaces

2min
pages 286-287

Libraries and frameworks

2min
pages 284-285

Object-oriented JavaScript

2min
pages 282-283

JavaScript debugging

3min
pages 280-281

Functions in JavaScript

2min
pages 278-279

Input and output

3min
pages 272-273

Loops in JavaScript

5min
pages 274-277

Logic and branching

2min
pages 270-271

Variables and data types

6min
pages 266-269

PROJECT: Styling the web

29min
pages 242-263

Code editors

4min
pages 208-209

Build a better website

4min
pages 214-215

Responsive layouts

2min
pages 240-241

HTML forms and hyperlinks

3min
pages 212-213

How the Web works

3min
pages 206-207

Exploring basic HTML

4min
pages 210-211

Pygame Zero

2min
pages 176-177

PROJECT: Budget manager

20min
pages 158-175

Logic operators and branching

3min
pages 104-105

Objects and classes

2min
pages 156-157

PROJECT: Team allocator

14min
pages 118-129

Libraries

3min
pages 116-117

What is Python?

3min
pages 94-95

Loops in Python

5min
pages 108-111

Installing Python

3min
pages 96-97

Using functions

3min
pages 50-51

Sending messages

3min
pages 48-49

Input

3min
pages 46-47

Logic and decisions

3min
pages 44-45

Managing program flow

4min
pages 40-41

Manipulating data

3min
pages 42-43

Output using movement

4min
pages 36-37

Output using looks and sounds

4min
pages 38-39

Coloured blocks and scripts

3min
pages 34-35

FOREWORD

2min
pages 10-11

What is programming?

3min
pages 16-17

Programming languages

6min
pages 22-27

What is Scratch?

2min
pages 28-29

About this book

3min
pages 12-15

Working as a software developer

2min
pages 20-21

Coding in the real world

1min
pages 18-19
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.