ebook img

Coding Games in Python PDF

226 Pages·2018·29.56 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Coding Games in Python

codin G ames G PY THON R IN US_001_half_title.indd 1 23/02/18 6:38 pm codin G ames G PY THON R IN US_002-003_Title.indd 2 23/02/18 6:38 pm US_002-003_Title.indd 3 23/02/18 6:38 pm codin G ames G PY THON R IN US_002-003_Title.indd 3 23/02/18 6:38 pm CAROL VORDERMAN MBE is one of Britain’s best-loved TV presenters and is renowned for her mathematical skills. She has hosted numerous TV shows on science and technology, from Tomorrow’s World to How 2, and was co-host of Channel 4’s Countdown for 26 years. A Cambridge University engineering DK UK graduate, she has a passion for communicating science and technology and Project editor Ben Ffrancon Davies Senior art editor Sunita Gahir is particularly interested in coding. Consultant editor Craig Steele Jacket design development manager Sophia MTT Jacket editor Claire Gell Producer, pre-production Gillian Reid Senior Producer Alex Bell US editors Jill Hamilton, Kayla Dugger Managing editor Lisa Gillespie CRAIG STEELE is a specialist in computing science education who helps people Managing art editor Owen Peyton Jones develop digital skills in a fun and creative environment. He is a founder of Publisher Andrew Macintyre CoderDojo in Scotland, which runs free coding clubs for young people. Craig Associate publishing director Liz Wheeler has run digital workshops with the Raspberry Pi Foundation, Glasgow Science Art director Karen Self Centre, Glasgow School of Art, BAFTA, and the BBC micro:bit project. Craig’s first Design director Phil Ormerod Publishing director Jonathan Metcalf computer was a ZX Spectrum. DK INDIA Senior editor Bharti Bedi Project art editor Sanjay Chauhan Editor Tina Jindal Assistant art editors Rabia Ahmad, Simar Dhamija, Sonakshi Singh DR. CLAIRE QUIGLEY studied computing science at Glasgow University, Jacket designer Juhi Sheth where she obtained BSc and PhD degrees. She has worked in the Computer Jackets editorial coordinator Priyanka Sharma Laboratory at Cambridge University and Glasgow Science Centre, and is Managing jackets editor Saloni Singh currently working on a project to develop a music and technology resource DTP designer Sachin Gupta for primary schools in Edinburgh. She is a mentor at CoderDojo Scotland. Senior DTP designer Harish Aggarwal Senior managing editor Rohan Sinha Managing art editor Sudakshina Basu Pre-production manager Balwant Singh First American Edition, 2018 Published in the United States by DK Publishing 345 Hudson Street, New York, New York 10014 Copyright © 2018 Dorling Kindersley Limited DANIEL McCAFFERTY holds a degree in computer science from the University DK, a Division of Penguin Random House LLC of Strathclyde. He has worked as a software engineer for companies big and 18 19 20 21 22 10 9 8 7 6 5 4 3 2 1 small in industries from banking to broadcasting. Daniel lives in Glasgow with 001–309872–July/2018 his wife and two children, and when not teaching young people to code, he All rights reserved. enjoys bicycling and spending time with his family. Without limiting the rights under the copyright reserved above, no part of this publication may be reproduced, stored in or introduced into a retrieval system, or transmitted, in any form, or by any means (electronic, mechanical, photocopying, recording, or otherwise), without the prior written permission of the copyright owner. Published in Great Britain by Dorling Kindersley Limited A catalog record for this book is available from the Library of Congress. DR. MARTIN GOODFELLOW is a teaching associate in the Computer and ISBN: 978-1-4654-7361-5 Information Sciences department at the University of Strathclyde. He has Printed in China also developed educational computer science content and workshops for A WORLD OF IDEAS: other organizations in the UK and China, including CoderDojo Scotland, SEE ALL THERE IS TO KNOW Glasgow Life, Codemao, and the BBC. He is currently the Scottish www.dk.com Ambassador for National Coding Week. US_004-005_imprint.indd 4 22/02/18 1:40 pm US_004-005_imprint.indd 5 22/02/18 1:40 pm CAROL VORDERMAN MBE is one of Britain’s best-loved TV presenters and is renowned for her mathematical skills. She has hosted numerous TV shows on science and technology, from Tomorrow’s World to How 2, and was co-host of Channel 4’s Countdown for 26 years. A Cambridge University engineering graduate, she has a passion for communicating science and technology and is particularly interested in coding. CRAIG STEELE is a specialist in computing science education who helps people develop digital skills in a fun and creative environment. He is a founder of CoderDojo in Scotland, which runs free coding clubs for young people. Craig has run digital workshops with the Raspberry Pi Foundation, Glasgow Science Centre, Glasgow School of Art, BAFTA, and the BBC micro:bit project. Craig’s first computer was a ZX Spectrum. DR. CLAIRE QUIGLEY studied computing science at Glasgow University, where she obtained BSc and PhD degrees. She has worked in the Computer Laboratory at Cambridge University and Glasgow Science Centre, and is currently working on a project to develop a music and technology resource for primary schools in Edinburgh. She is a mentor at CoderDojo Scotland. DANIEL McCAFFERTY holds a degree in computer science from the University of Strathclyde. He has worked as a software engineer for companies big and small in industries from banking to broadcasting. Daniel lives in Glasgow with his wife and two children, and when not teaching young people to code, he enjoys bicycling and spending time with his family. DR. MARTIN GOODFELLOW is a teaching associate in the Computer and Information Sciences department at the University of Strathclyde. He has also developed educational computer science content and workshops for other organizations in the UK and China, including CoderDojo Scotland, Glasgow Life, Codemao, and the BBC. He is currently the Scottish Ambassador for National Coding Week. US_004-005_imprint.indd 5 22/02/18 1:40 pm Contents 8 FOREWORD COIN COLLECTOR BIG QUIZ HAPPY GARDEN GETTING STARTED 60 How to build Coin Collector 100 How to build Big Quiz 156 How to build Happy Garden Score: 0 Garden happy for: 16 seconds 12 What is Python? What is the 7 14 Gaming in Python capital of France? 16 Installing Python London Paris 18 Installing Pygame Zero 20 Using IDLE Berlin Tokyo 22 Your first program FOLLOW THE NUMBERS BALLOON FLIGHT SLEEPING DRAGONS LEARNING THE BASICS 70 How to build Follow the Numbers 118 How to build Balloon Flight 178 How to build Sleeping Dragons Score: 0 28 Creating variables 32 Making decisions 36 Playing with loops 40 Functions 44 Fixing bugs 6 2 SHOOT THE FRUIT RED ALERT DANCE CHALLENGE REFERENCE 50 How to build Shoot the Fruit 82 How to build Red Alert 138 How to build Dance Challenge 198 Project reference 220 Glossary Score: 0 222 Index 224 Acknowledgments US_006-007_Contents.indd 6 22/02/18 12:23 pm US_006-007_Contents.indd 7 22/02/18 12:23 pm BIG QUIZ HAPPY GARDEN 100 How to build Big Quiz 156 How to build Happy Garden Garden happy for: 16 seconds What is the 7 capital of France? London Paris Berlin Tokyo BALLOON FLIGHT SLEEPING DRAGONS 118 How to build Balloon Flight 178 How to build Sleeping Dragons Score: 0 6 2 DANCE CHALLENGE REFERENCE 138 How to build Dance Challenge 198 Project reference 220 Glossary Score: 0 222 Index 224 Acknowledgments US_006-007_Contents.indd 7 22/02/18 12:23 pm Foreword Computer programmers are the unsung heroes of the modern world. From smartphones beginning of this book before moving on to the more complex games as the book to laptops, traffic systems to bank cards, their hard work touches almost every aspect progresses. By following the step-by-step guides, you’ll find out how professional of our lives. Behind each technological advance is a team of creative coders. coders think when they’re building a computer game. Follow those steps carefully and you’ll have your own games up and running in no time. Then, if you really want to push Over the past 30 years, computer games have become one of the most exciting and yourself, you can try tweaking the code to make your games unique. popular areas of the entertainment industry to work in. Becoming a game programmer takes creative flair to help create the story, graphics, music, and characters you need Everybody, whether a beginner or a pro, makes mistakes. Nothing frustrates a coder for your games, and the technical know-how to bring them to life. Who knows? This more than the bugs that manage to creep into their programs. If something goes book may be the very first step on your journey from gamer to game maker. wrong in one of your games, go back over your code and check it all carefully. There are hints and tips throughout the book that will help you do this. Most importantly, Learning to code isn’t just for people who want to be professional programmers, don’t get disheartened—finding and fixing errors in your code is all part of being a though. Coding skills are useful in lots of different jobs that may seem to have nothing programmer. The more practice you get, the fewer bugs your code will contain, and to do with computers at first. Programming expertise is essential to subject areas as the quicker you’ll catch the little ones that still appear. diverse as science, business, art, and music. Most importantly, have fun! Once you’ve completed the games, you can show them off This book uses a programming language called Python®, a fairly simple text-based to your friends and family—they’ll be amazed by what you’ve managed to make. This language, and is perfect for beginners, or as a step up from Scratch™. However, book is packed with games to suit every audience, and we hope you enjoy building and unlike Scratch, it was not created especially to teach coding. Python is as popular with playing them as much as we enjoyed creating them for you. budding coders as it is with professionals, and is one of the most widely used professional programming languages in the world. It pops up in banking, medicine, animation, and even space exploration. Have fun coding! The best way to learn any new language is to get immersed in it, and programming languages are no different. Building your own computer games is a fun way to combine theory and practice. If you’re a brand-new coder, start off with the basics at the US_008-009_Foreword.indd 8 22/02/18 12:23 pm US_008-009_Foreword.indd 9 23/02/18 2:31 pm

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.