Docsity

python pygame, Notas de estudo de Engenharia Elétrica

Toggle sidebar
bg1
books for professionals by professionals®
www.apress.com
SOURCE CODE ONLINE
program
arcade Games
With Python and Pygame
—
Fourth Edition
—
Dr. Paul Vincent Craven
This fun and handy book by Dr. Paul Vincent Craven shows you how to learn and use Python
and PyGame to design and build cool arcade games. In Program Arcade Games: With Python
and PyGame, Second Edition, learn how to create fun and simple quiz games; integrate and
start using graphics; animate graphics; integrate and use game controllers; add sound and bit-
mapped graphics; and build grid-based games.
After reading and using this book, you’ll be able to program and build simple arcade game
applications using one of today’s most popular programming languages, Python. You can even
deploy onto Steam and other Linux-based game systems as well as Android, one of today’s
most popular mobile and tablet platforms.
• How to create quiz games
• How to integrate and start using graphics
• How to animate graphics
• How to integrate and use game controllers
• How to add sound and bit-mapped graphics
• How to build grid-based games
Program Arcade Games: With Python and PyGame
Craven Program Arcade Games
9781484 217894
54499
ISBN 978-1-4842-1789-4
$ 44.99
Shelve in:
Graphics/Game Programming
User level:
Beginning–Advanced
related Titles
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Pré-visualização parcial do texto

Baixe python pygame e outras Notas de estudo em PDF para Engenharia Elétrica, somente na Docsity!

program

arcade Games

With Python and Pygame

Fourth Edition

Dr. Paul Vincent Craven

Program Arcade

Games

With Python and Pygame

Fourth Edition

Paul Vincent Craven

This book is dedicated to everyone who loves to learn.

v

Contents at a Glance

About the Author ����������������������������������������������������������������������������������������������������xix

vii

Contents

About the Author ����������������������������������������������������������������������������������������������������xix

viii

x

xi

xiii

xiv

xvi

xvii

  • ■Chapter 1: Before Getting Started… ���������������������������������������������������������������������� Introduction ������������������������������������������������������������������������������������������������������������xxi
  • ■Chapter 2: Create a Custom Calculator ���������������������������������������������������������������
  • ■Chapter 3: What Is a Computer Language? ���������������������������������������������������������
  • ■Chapter 4: Quiz Games and If Statements �����������������������������������������������������������
  • ■Chapter 5: Guessing Games with Random Numbers and Loops ��������������������������
  • ■Chapter 6: Introduction to Graphics ��������������������������������������������������������������������
  • ■Chapter 7: Back to Looping �������������������������������������������������������������������������������
  • ■Chapter 8: Introduction to Lists �������������������������������������������������������������������������
  • ■Chapter 9: Introduction to Animation ����������������������������������������������������������������
  • ■Chapter 10: Functions ���������������������������������������������������������������������������������������
  • ■Chapter 11: Controllers and Graphics ���������������������������������������������������������������
  • ■Chapter 12: Bitmapped Graphics and Sound �����������������������������������������������������
  • ■Chapter 13: Introduction to Classes ������������������������������������������������������������������
  • ■Chapter 14: Introduction to Sprites �������������������������������������������������������������������
  • ■Chapter 15: Libraries and Modules �������������������������������������������������������������������
  • ■Chapter 16: Searching ���������������������������������������������������������������������������������������
  • ■Chapter 17: Array-Backed Grids ������������������������������������������������������������������������
  • ■Chapter 1: Before Getting Started… ���������������������������������������������������������������������� Introduction ������������������������������������������������������������������������������������������������������������xxi
  • Installing and Starting Python ������������������������������������������������������������������������������������������
  • Windows Installation ������������������������������������������������������������������������������������������������������������������������������
  • Mac Installation ��������������������������������������������������������������������������������������������������������������������������������������
  • Unix Installation ��������������������������������������������������������������������������������������������������������������������������������������
  • Optional Wing IDE �����������������������������������������������������������������������������������������������������������������������������������
  • Viewing File Extensions����������������������������������������������������������������������������������������������������
  • Learn to Make Games and Get Paid ���������������������������������������������������������������������������������
  • Get the Most from This Book ����������������������������������������������������������������������������������������������������������������
  • Send Feedback �������������������������������������������������������������������������������������������������������������������������������������
  • ■Chapter 2: Create a Custom Calculator ���������������������������������������������������������������
  • Printing ���������������������������������������������������������������������������������������������������������������������������
  • Printing Text ������������������������������������������������������������������������������������������������������������������������������������������
  • Printing Results of Expressions ������������������������������������������������������������������������������������������������������������
  • Printing Multiple Items �������������������������������������������������������������������������������������������������������������������������
  • Escape Codes �����������������������������������������������������������������������������������������������������������������
  • Comments ����������������������������������������������������������������������������������������������������������������������
  • Assignment Operators ����������������������������������������������������������������������������������������������������
  • Variables�������������������������������������������������������������������������������������������������������������������������
  • Operators������������������������������������������������������������������������������������������������������������������������
  • Operator Spacing ����������������������������������������������������������������������������������������������������������������������������������
  • Order of Operations �������������������������������������������������������������������������������������������������������� ■ Contents
  • Trig Functions �����������������������������������������������������������������������������������������������������������������
  • Custom Equation Calculators �����������������������������������������������������������������������������������������
  • Review����������������������������������������������������������������������������������������������������������������������������
  • Multiple Choice Quiz �����������������������������������������������������������������������������������������������������������������������������
  • Short Answer Worksheet ����������������������������������������������������������������������������������������������������������������������
  • Exercise ������������������������������������������������������������������������������������������������������������������������������������������������
  • ■Chapter 3: What Is a Computer Language? ���������������������������������������������������������
  • Short History of Programming����������������������������������������������������������������������������������������
  • Review����������������������������������������������������������������������������������������������������������������������������
  • Multiple Choice Quiz �����������������������������������������������������������������������������������������������������������������������������
  • Short Answer Worksheet ����������������������������������������������������������������������������������������������������������������������
  • Exercise ������������������������������������������������������������������������������������������������������������������������������������������������
  • ■Chapter 4: Quiz Games and If Statements �����������������������������������������������������������
  • Basic Comparisons ���������������������������������������������������������������������������������������������������������
  • Indentation ���������������������������������������������������������������������������������������������������������������������
  • Using And/Or ������������������������������������������������������������������������������������������������������������������
  • Boolean Variables �����������������������������������������������������������������������������������������������������������
  • Else and Else If ���������������������������������������������������������������������������������������������������������������
  • Text Comparisons �����������������������������������������������������������������������������������������������������������
  • Multiple Text Possibilities ���������������������������������������������������������������������������������������������������������������������
  • Case Insensitive Comparisons ��������������������������������������������������������������������������������������������������������������
  • Example if Statements ���������������������������������������������������������������������������������������������������
  • Review����������������������������������������������������������������������������������������������������������������������������
  • Multiple Choice Quiz �����������������������������������������������������������������������������������������������������������������������������
  • Short Answer Worksheet ����������������������������������������������������������������������������������������������������������������������
  • Exercise ������������������������������������������������������������������������������������������������������������������������������������������������
  • ■Chapter 5: Guessing Games with Random Numbers and Loops �������������������������� ■ Contents
  • for Loops ������������������������������������������������������������������������������������������������������������������������
  • Counting by Numbers Other Than One �������������������������������������������������������������������������������������������������
  • Nesting Loops ���������������������������������������������������������������������������������������������������������������������������������������
  • Keeping a Running Total �����������������������������������������������������������������������������������������������������������������������
  • Example for Loops ����������������������������������������������������������������������������������������������������������
  • while Loops ��������������������������������������������������������������������������������������������������������������������
  • Using Increment Operators �������������������������������������������������������������������������������������������������������������������
  • Looping Until User Wants to Quit ����������������������������������������������������������������������������������������������������������
  • Common Problems with while Loops ���������������������������������������������������������������������������������������������������
  • Example while Loops �����������������������������������������������������������������������������������������������������
  • Random Numbers�����������������������������������������������������������������������������������������������������������
  • The randrange Function �����������������������������������������������������������������������������������������������������������������������
  • The random Function ���������������������������������������������������������������������������������������������������������������������������
  • Review����������������������������������������������������������������������������������������������������������������������������
  • Multiple Choice Quiz �����������������������������������������������������������������������������������������������������������������������������
  • Short Answer Worksheet ����������������������������������������������������������������������������������������������������������������������
  • Exercise ������������������������������������������������������������������������������������������������������������������������������������������������
  • ■Chapter 6: Introduction to Graphics ��������������������������������������������������������������������
  • Computer Coordinate Systems ���������������������������������������������������������������������������������������
  • Pygame Library ��������������������������������������������������������������������������������������������������������������
  • Colors �����������������������������������������������������������������������������������������������������������������������������
  • Open a Window ��������������������������������������������������������������������������������������������������������������
  • Interacting with the User ������������������������������������������������������������������������������������������������
  • The Event Processing Loop�������������������������������������������������������������������������������������������������������������������
  • Processing Each Frame ������������������������������������������������������������������������������������������������������������������������
  • Ending the Program��������������������������������������������������������������������������������������������������������
  • Clearing the Screen ��������������������������������������������������������������������������������������������������������
  • Flipping the Screen �������������������������������������������������������������������������������������������������������� ■ Contents
  • Open a Blank Window ����������������������������������������������������������������������������������������������������
  • Drawing Introduction ������������������������������������������������������������������������������������������������������
  • Drawing Lines ����������������������������������������������������������������������������������������������������������������
  • Drawing Lines with Loops and Offsets ���������������������������������������������������������������������������
  • Drawing a Rectangle ������������������������������������������������������������������������������������������������������
  • Drawing an Ellipse ���������������������������������������������������������������������������������������������������������
  • Drawing an Arc ���������������������������������������������������������������������������������������������������������������
  • Drawing a Polygon ���������������������������������������������������������������������������������������������������������
  • Drawing Text�������������������������������������������������������������������������������������������������������������������
  • Full Program Listing �������������������������������������������������������������������������������������������������������
  • Review��������������������������������������������������������������������������������������������������������������������������
  • Multiple Choice Quiz ���������������������������������������������������������������������������������������������������������������������������
  • Short Answer Worksheet ��������������������������������������������������������������������������������������������������������������������
  • Exercise ����������������������������������������������������������������������������������������������������������������������������������������������
  • ■Chapter 7: Back to Looping �������������������������������������������������������������������������������
  • Print Statement End Characters �����������������������������������������������������������������������������������
  • Advanced Looping Problems ����������������������������������������������������������������������������������������
  • Review��������������������������������������������������������������������������������������������������������������������������
  • Multiple Choice Quiz ���������������������������������������������������������������������������������������������������������������������������
  • Short Answer Worksheet ��������������������������������������������������������������������������������������������������������������������
  • Exercise ����������������������������������������������������������������������������������������������������������������������������������������������
  • ■Chapter 8: Introduction to Lists �������������������������������������������������������������������������
  • Working with Lists ��������������������������������������������������������������������������������������������������������
  • Iterating through a List �������������������������������������������������������������������������������������������������
  • Adding to a List ������������������������������������������������������������������������������������������������������������
  • Summing or Modifying a List ���������������������������������������������������������������������������������������
  • Slicing Strings ��������������������������������������������������������������������������������������������������������������
  • Secret Codes ���������������������������������������������������������������������������������������������������������������� ■ Contents
  • Associative Arrays ��������������������������������������������������������������������������������������������������������
  • Review��������������������������������������������������������������������������������������������������������������������������
  • Multiple Choice Quiz ���������������������������������������������������������������������������������������������������������������������������
  • Short Answer Worksheet ��������������������������������������������������������������������������������������������������������������������
  • Exercise ����������������������������������������������������������������������������������������������������������������������������������������������
  • ■Chapter 9: Introduction to Animation ����������������������������������������������������������������
  • Animating Snow �����������������������������������������������������������������������������������������������������������
  • Code Explanation ��������������������������������������������������������������������������������������������������������������������������������
  • Full Program Listing ���������������������������������������������������������������������������������������������������������������������������
  • 3D Animation ����������������������������������������������������������������������������������������������������������������
  • Review��������������������������������������������������������������������������������������������������������������������������
  • Multiple Choice Quiz ���������������������������������������������������������������������������������������������������������������������������
  • Short Answer Worksheet ��������������������������������������������������������������������������������������������������������������������
  • Exercise ����������������������������������������������������������������������������������������������������������������������������������������������
  • ■Chapter 10: Functions ���������������������������������������������������������������������������������������
  • Function Parameters ����������������������������������������������������������������������������������������������������
  • Returning and Capturing Values �����������������������������������������������������������������������������������
  • Returning Values���������������������������������������������������������������������������������������������������������������������������������
  • Capturing Returned Values �����������������������������������������������������������������������������������������������������������������
  • Improving the volume_cylinder Example �������������������������������������������������������������������������������������������
  • Documenting Functions �����������������������������������������������������������������������������������������������
  • Variable Scope �������������������������������������������������������������������������������������������������������������
  • Pass-by-copy ���������������������������������������������������������������������������������������������������������������
  • Functions Calling Functions �����������������������������������������������������������������������������������������
  • Main Functions and Globals �����������������������������������������������������������������������������������������
  • Short Examples ������������������������������������������������������������������������������������������������������������
  • Mudball Game Example������������������������������������������������������������������������������������������������
  • Review�������������������������������������������������������������������������������������������������������������������������� ■ Contents
  • Multiple Choice Quiz ���������������������������������������������������������������������������������������������������������������������������
  • Short Answer Worksheet ��������������������������������������������������������������������������������������������������������������������
  • Correcting Code ����������������������������������������������������������������������������������������������������������������������������������
  • Exercise ����������������������������������������������������������������������������������������������������������������������������������������������
  • ■Chapter 11: Controllers and Graphics ���������������������������������������������������������������
  • Mouse���������������������������������������������������������������������������������������������������������������������������
  • Keyboard ����������������������������������������������������������������������������������������������������������������������
  • Game Controller �����������������������������������������������������������������������������������������������������������
  • Review��������������������������������������������������������������������������������������������������������������������������
  • Multiple Choice Quiz ���������������������������������������������������������������������������������������������������������������������������
  • Short Answer Worksheet ��������������������������������������������������������������������������������������������������������������������
  • Exercise ����������������������������������������������������������������������������������������������������������������������������������������������
  • ■Chapter 12: Bitmapped Graphics and Sound �����������������������������������������������������
  • Storing the Program in a Folder �����������������������������������������������������������������������������������
  • Setting a Background Image ����������������������������������������������������������������������������������������
  • Moving an Image ����������������������������������������������������������������������������������������������������������
  • Sounds �������������������������������������������������������������������������������������������������������������������������
  • Full Listing ��������������������������������������������������������������������������������������������������������������������
  • Review��������������������������������������������������������������������������������������������������������������������������
  • Multiple Choice Quiz ���������������������������������������������������������������������������������������������������������������������������
  • Short Answer Worksheet ��������������������������������������������������������������������������������������������������������������������
  • Exercise ����������������������������������������������������������������������������������������������������������������������������������������������
  • ■Chapter 13: Introduction to Classes ������������������������������������������������������������������
  • Why Learn About Classes? �������������������������������������������������������������������������������������������
  • Defining and Creating Simple Classes �������������������������������������������������������������������������
  • Adding Methods to Classes ������������������������������������������������������������������������������������������
  • Example: Ball Class ����������������������������������������������������������������������������������������������������������������������������
  • References ������������������������������������������������������������������������������������������������������������������� ■ Contents
  • Functions and References ������������������������������������������������������������������������������������������������������������������
  • Review Questions �������������������������������������������������������������������������������������������������������������������������������
  • Constructors �����������������������������������������������������������������������������������������������������������������
  • Avoid This Mistake ������������������������������������������������������������������������������������������������������������������������������
  • Review Questions �������������������������������������������������������������������������������������������������������������������������������
  • Inheritance �������������������������������������������������������������������������������������������������������������������
  • Is-A and Has-A Relationships �������������������������������������������������������������������������������������������������������������
  • Static Variables vs� Instance Variables �������������������������������������������������������������������������
  • Instance Variables Hiding Static Variables������������������������������������������������������������������������������������������
  • Review��������������������������������������������������������������������������������������������������������������������������
  • Multiple Choice Quiz ���������������������������������������������������������������������������������������������������������������������������
  • Short Answer Worksheet ��������������������������������������������������������������������������������������������������������������������
  • Exercise ����������������������������������������������������������������������������������������������������������������������������������������������
  • ■Chapter 14: Introduction to Sprites �������������������������������������������������������������������
  • Basic Sprites and Collisions �����������������������������������������������������������������������������������������
  • Moving Sprites �������������������������������������������������������������������������������������������������������������
  • The Game Class������������������������������������������������������������������������������������������������������������
  • Other Examples ������������������������������������������������������������������������������������������������������������
  • Shooting things�����������������������������������������������������������������������������������������������������������������������������������
  • Walls ���������������������������������������������������������������������������������������������������������������������������������������������������
  • Platforms ��������������������������������������������������������������������������������������������������������������������������������������������
  • Snake/Centipede ��������������������������������������������������������������������������������������������������������������������������������
  • Using Sprite Sheets ����������������������������������������������������������������������������������������������������������������������������
  • Review��������������������������������������������������������������������������������������������������������������������������
  • Multiple Choice Quiz ���������������������������������������������������������������������������������������������������������������������������
  • Exercise ����������������������������������������������������������������������������������������������������������������������������������������������
  • ■Chapter 15: Libraries and Modules ������������������������������������������������������������������� ■ Contents
  • Why Create a Library? ��������������������������������������������������������������������������������������������������
  • Creating Your Own Module/Library File: �����������������������������������������������������������������������
  • Namespace ������������������������������������������������������������������������������������������������������������������
  • Third Party Libraries �����������������������������������������������������������������������������������������������������
  • Review��������������������������������������������������������������������������������������������������������������������������
  • Multiple Choice Quiz ���������������������������������������������������������������������������������������������������������������������������
  • Short Answer Worksheet ��������������������������������������������������������������������������������������������������������������������
  • Exercise ����������������������������������������������������������������������������������������������������������������������������������������������
  • ■Chapter 16: Searching ���������������������������������������������������������������������������������������
  • Reading from a File ������������������������������������������������������������������������������������������������������
  • Reading into an Array ���������������������������������������������������������������������������������������������������
  • Linear Search ���������������������������������������������������������������������������������������������������������������
  • Linear Search Algorithm ���������������������������������������������������������������������������������������������������������������������
  • Variations on the Linear Search �����������������������������������������������������������������������������������
  • Does at Least One Item Have a Property? ������������������������������������������������������������������������������������������
  • Do All Items Have a Property? ������������������������������������������������������������������������������������������������������������
  • Create a List with All Items Matching a Property��������������������������������������������������������������������������������
  • Binary Search ���������������������������������������������������������������������������������������������������������������
  • Review��������������������������������������������������������������������������������������������������������������������������
  • Multiple Choice Quiz ���������������������������������������������������������������������������������������������������������������������������
  • Short Answer Worksheet Linear Search Review���������������������������������������������������������������������������������
  • Binary Search Review ������������������������������������������������������������������������������������������������������������������������
  • Challenge Question �����������������������������������������������������������������������������������������������������������������������������
  • Exercise ����������������������������������������������������������������������������������������������������������������������������������������������
  • ■Chapter 17: Array-Backed Grids ������������������������������������������������������������������������
  • Application �������������������������������������������������������������������������������������������������������������������
  • Drawing the Grid���������������������������������������������������������������������������������������������������������������������������������
  • Populating the Grid �����������������������������������������������������������������������������������������������������������������������������
  • Final Program �������������������������������������������������������������������������������������������������������������������������������������
  • Review�������������������������������������������������������������������������������������������������������������������������� ■ Contents
  • Multiple Choice Quiz ���������������������������������������������������������������������������������������������������������������������������
  • Short Answer Worksheet ��������������������������������������������������������������������������������������������������������������������
  • ■Chapter 18: Sorting �������������������������������������������������������������������������������������������
  • Swapping Values ����������������������������������������������������������������������������������������������������������
  • Selection Sort ���������������������������������������������������������������������������������������������������������������
  • Insertion Sort ����������������������������������������������������������������������������������������������������������������
  • Review��������������������������������������������������������������������������������������������������������������������������
  • Multiple Choice Quiz ���������������������������������������������������������������������������������������������������������������������������
  • Short Answer Worksheet ��������������������������������������������������������������������������������������������������������������������
  • ■Chapter 19: Exceptions��������������������������������������������������������������������������������������
  • Vocabulary��������������������������������������������������������������������������������������������������������������������
  • Exception Handling�������������������������������������������������������������������������������������������������������
  • Example: Saving High Score�����������������������������������������������������������������������������������������
  • Exception Objects ���������������������������������������������������������������������������������������������������������
  • Exception Generating ���������������������������������������������������������������������������������������������������
  • Proper Exception Use ���������������������������������������������������������������������������������������������������
  • Review��������������������������������������������������������������������������������������������������������������������������
  • Multiple Choice Quiz ���������������������������������������������������������������������������������������������������������������������������
  • Short Answer Worksheet ��������������������������������������������������������������������������������������������������������������������
  • ■Chapter 20: Recursion ���������������������������������������������������������������������������������������
  • Where Is Recursion Used? �������������������������������������������������������������������������������������������
  • How Is Recursion Coded?���������������������������������������������������������������������������������������������
  • Controlling Recursion Depth�����������������������������������������������������������������������������������������
  • Recursion Factorial Calculation������������������������������������������������������������������������������������
  • Recursive Rectangles ���������������������������������������������������������������������������������������������������
  • Fractals ������������������������������������������������������������������������������������������������������������������������
  • Recursive Binary Search ���������������������������������������������������������������������������������������������� ■ Contents
  • Review��������������������������������������������������������������������������������������������������������������������������
  • Short Answer Worksheet ��������������������������������������������������������������������������������������������������������������������
  • ■Chapter 21: Formatting �������������������������������������������������������������������������������������
  • Decimal Numbers ���������������������������������������������������������������������������������������������������������
  • Strings ��������������������������������������������������������������������������������������������������������������������������
  • Leading Zeros ���������������������������������������������������������������������������������������������������������������
  • Floating-Point Numbers �����������������������������������������������������������������������������������������������
  • Printing Dollars and Cents ��������������������������������������������������������������������������������������������
  • Use in Pygame��������������������������������������������������������������������������������������������������������������
  • Review��������������������������������������������������������������������������������������������������������������������������
  • Short Answer Worksheet ��������������������������������������������������������������������������������������������������������������������
  • ■Chapter 22: Exercises ����������������������������������������������������������������������������������������
  • Exercise 1: Custom Calculators ������������������������������������������������������������������������������������
  • Program A �������������������������������������������������������������������������������������������������������������������������������������������
  • Program B�������������������������������������������������������������������������������������������������������������������������������������������
  • Program C �������������������������������������������������������������������������������������������������������������������������������������������
  • Exercise 2: Create-a-Quiz ���������������������������������������������������������������������������������������������
  • Description �����������������������������������������������������������������������������������������������������������������������������������������
  • Example Run���������������������������������������������������������������������������������������������������������������������������������������
  • Exercise 3: Camel ���������������������������������������������������������������������������������������������������������
  • Description of the Camel Game ����������������������������������������������������������������������������������������������������������
  • Sample Run of Camel �������������������������������������������������������������������������������������������������������������������������
  • Programming Guide ����������������������������������������������������������������������������������������������������������������������������
  • Hints ���������������������������������������������������������������������������������������������������������������������������������������������������
  • Exercise 4: Create-a-Picture ����������������������������������������������������������������������������������������
  • Description �����������������������������������������������������������������������������������������������������������������������������������������
  • Exercise 5: Loopy Lab ��������������������������������������������������������������������������������������������������� ■ Contents
  • Part 1 ��������������������������������������������������������������������������������������������������������������������������������������������������
  • Part 2 ��������������������������������������������������������������������������������������������������������������������������������������������������
  • Part 3 ��������������������������������������������������������������������������������������������������������������������������������������������������
  • Part 4 ��������������������������������������������������������������������������������������������������������������������������������������������������
  • Exercise 6: Adventure!��������������������������������������������������������������������������������������������������
  • Description of the Adventure Game ����������������������������������������������������������������������������������������������������
  • Sample Run ����������������������������������������������������������������������������������������������������������������������������������������
  • Creating Your Dungeon �����������������������������������������������������������������������������������������������������������������������
  • Step-by-step Instructions �������������������������������������������������������������������������������������������������������������������
  • Exercise 7: Animation ���������������������������������������������������������������������������������������������������
  • Requirements �������������������������������������������������������������������������������������������������������������������������������������
  • Exercise 8: Functions ���������������������������������������������������������������������������������������������������
  • Exercise 9: User Control �����������������������������������������������������������������������������������������������
  • Exercise 10: Bitmapped Graphics and User Control �����������������������������������������������������
  • Exercise 11: Classes and Graphics �������������������������������������������������������������������������������
  • Instructions �����������������������������������������������������������������������������������������������������������������������������������������
  • Exercise 12: Sprite Collecting���������������������������������������������������������������������������������������
  • Exercise 13: Sprite Moving �������������������������������������������������������������������������������������������
  • Exercise 14: Spell Check ����������������������������������������������������������������������������������������������
  • Requirements �������������������������������������������������������������������������������������������������������������������������������������
  • Steps to Complete: �����������������������������������������������������������������������������������������������������������������������������
  • Example Run���������������������������������������������������������������������������������������������������������������������������������������
  • Exercise 15: Final Exercise �������������������������������������������������������������������������������������������
  • Video Game Option �����������������������������������������������������������������������������������������������������������������������������
  • Text Adventure Option�������������������������������������������������������������������������������������������������������������������������
  • Index ���������������������������������������������������������������������������������������������������������������������

xxi

Introduction

It all started in 1983 when my dad, who was also a teacher, bought an Apple //e computer for our use at home. Since it was to be “dad’s computer” for educational purposes only, my brother and I were not allowed to purchase any games. So, at the local library I found two programming books by David H. Ahl: BASIC Computer Games and More BASIC Computer Games. These books had code I could use to type in and run my own games. This was the beginning of my creative outlet with computers. As a computer science professor, I have found getting other people to program their own games as a great way to foster interest in computer science. Unfortunately, back when I started teaching students this way, the type of book I started with in the 1980s did not seem to be available any longer. I wanted to help others learn to program the same way I started. To provide a textbook for my students, I began to write my own programming book. I started the website ProgramArcadeGames.com in 2009. The book you have in your hand morphed from the materials on that website and from student input from my beginning computer programming classes. I would like to acknowledge and thank everyone who took time to give feedback, no matter how large or small. This book is the product of hundreds of students I have worked with personally, and the feedback of hundreds of people on-line. I continue to develop the website and use this book to share my love of programming with others.

1

Chapter 1

Before Getting Started…

This introductory chapter has two parts:

  • Getting your computer set up to write games.
  • Job and career prospects in technology.

Installing and Starting Python To get started, two programs need to be installed: Python and Pygame. Python is the computer language we will program in, and Pygame is a library of commands that will help make writing games easier.

Windows Installation

If you are working with a computer that already has Python and Pygame set up on it, you can skip this step. But if you want to set up Python and Pygame on your own Windows computer, don’t worry. It is very easy.

  1. Run the Python installer downloaded from http://ProgramArcadeGames.com/python-3.4.3.msi
  2. Run the Pygame installer downloaded from http://ProgramArcadeGames.com/pygame-1.9.2a0.win32-py3.4.msi