Essentials_Scratch_v1.pdf

(9844 KB) Pobierz
ESSENTIALS
LEARN TO
CODE
ON
YOUR
Written by
SCRATCH
MAKE SIMPLE GAMES AND APPLICATIONS
WITH
Raspberry Pi
The MagPi Team
THE OFFICIAL
RASPBERRY PI
MAGAZINE
25
%
SAV
UP T E
O
2
FREE
PI ZERO!
Subscribe in print for six or 12 months to receive this stunning free gift
Subscribe today & receive:
A free Pi Zero v1.3 (the latest model)
A free Camera Module connector
A free USB & HDMI cable bundle
Delivered with your first issue!
Pricing
Get six issues:
£30
(UK)
£45
(EU)
$69
(USA)
£50
(Rest of World)
Subscribe for a year:
£55
(UK)
£80
(EU)
$129
(USA)
£90
(Rest of World)
Direct Debit: £12.99
(UK)
(quarterly)
Other benefits:
Save up to 25% on the price
Free delivery to your door
Exclusive Pi offers & discounts
Get every issue first (before stores)
How to subscribe:
magpi.cc/Subs1
(UK / ROW)
Call +44(0)1202 586848 (UK/ROW)
imsnews.com/magpi
(USA)
Call 800 428 3003 (USA)
Search ‘The MagPi’
on your app store:
3
WELCOME TO
LEARN TO CODE
WITH SCRATCH
C
oding doesn’t just have to be about typing
in line after line of gobbledygook. Created
by the boffins at MIT, Scratch enables
anyone – children and adults alike – to start
programming within minutes, without any prior
knowledge. You simply drag and drop various code
blocks and link them together like jigsaw pieces
to form logical scripts, unobstructed by confusing
jargon and tricky syntax. Even better, Scratch is
included as standard in the Raspbian operating
system for the tiny Raspberry Pi computer. It can
even be used with the Pi’s GPIO pins to interact
with electronic components and sensors.
In this book, we’ll help you start coding with
Scratch, guiding you step by step through the
process of creating all sorts of projects: games,
animations, quizzes, electronics circuits, and more.
It’ll be educational and also a lot of fun.
Phil King
Contributing Editor, The MagPi magazine
FIND US ONLINE
raspberrypi.org/magpi
EDITORIAL
GET IN TOUCH
magpi@raspberrypi.org
DESIGN
Managing Editor:
Russell Barnes
russell@raspberrypi.org
Contributing Editor:
Phil King
Sub Editors:
Lorna Lynch and Laura Clay
Contributors:
Sean McManus, William Bell & Code Club
Critical Media:
criticalmedia.co.uk
Head of Design:
Dougal Matthews
Designers:
Lee Allen, Mike Kay
DISTRIBUTION
THE MAGPI SUBSCRIPTIONS
Select Publisher Services Ltd
PO Box 6337, Bournemouth
BH1 9EH |
+44 (0)1202 586 848
magpi.cc/Subs1
Seymour Distribution Ltd
2 East Poultry Ave, London
EC1A 9PT |
+44 (0)207 429 4000
In print, this product is made using paper
sourced from sustainable forests and
the printer operates an environmental
[
management system which has been
Chapter One
]
assessed as conforming to ISO 14001.
4
This book is published by Raspberry Pi (Trading) Ltd., Mount Pleasant House, Cambridge, CB3
0RN. The publisher, editor and contributors accept no responsibility in respect of any omissions
or errors relating to goods, products or services referred to or advertised in this product. Except
where otherwise noted, content in this magazine is licensed under a Creative Commons Attribution-
NonCommercial-ShareAlike 3.0 Unported (CC BY-NC-SA 3.0).
[ LEARN TO CODE WITH SCRATCH ]
ESSENTIALS
CONTENTS
06
[
CHAPTER ONE
]
GET STARTED
WITH SCRATCH
Find your way around
30
[
CHAPTER SIX
]
ADA POETRY GENERATOR
Use lists to write random poems
11
[
CHAPTER TWO
]
BOUNCY HEDGEHOG
Make your first game
35
[
CHAPTER SEVEN
]
LIGHT AN LED
Connect an LED to the GPIO pins
16
[
CHAPTER THREE
]
LOST IN SPACE
Create an animation
40
[
CHAPTER EIGHT
]
LED TRAFFIC LIGHTS
Build a pedestrian crossing
21
[
CHAPTER FOUR
]
CHATBOT
An interactive character
45
[
CHAPTER NINE
]
MULTIPLE-CHOICE QUIZ
Create a fun quiz game
25
[
CHAPTER FIVE
]
BOAT RACE
Code an arcade game
49
[
CHAPTER TEN
]
ADD A TITLE SCREEN
Make professional-looking games
54
[
CHAPTER ELEVEN
]
ADD A HIGH SCORE TABLE
Keep players coming back
59
[
CHAPTER TWELVE
]
BUILD A SPACE SHOOTER
Create an impressive 3D game
70
[
CHAPTER THIRTEEN
]
QUICK REFERENCE
A handy guide to blocks and more
[
Don’t Panic
]
[
Contents
5
Zgłoś jeśli naruszono regulamin