Contents
Introduction
Flash and Game Development
Who Is This Book For?
What Do You Need To Use This Book?
Prerequisite Knowledge
Software Applications
Source Files
Using the Example Games in Your Projects
What You’ll Find in This Book
The FlashGameU.com Website
1. Using Flash and ActionScript 3.0
What Is ActionScript 3.0?
Creating a Simple ActionScript Program
A Simple Use of trace
Creating Screen Output
Our First ActionScript 3.0 Class
Working with Flash CS5
Display Objects and Display Lists
The Stage
The Library
The Timeline
Writing and Editing ActionScript
ActionScript Game Programming Strategies
Single Class Method
Smallest-Step Approach
Good Programming Practices
Basic ActionScript Concepts
Creating and Using Variables
Condition Statements
Loops
Functions
Testing and Debugging
Types of Bugs
Methods of Testing
Using the Debugger
Publishing Your Game
Formats
Flash
HTML
ActionScript Game Programming Checklist
Publishing and Document Settings
Class, Function, and Variable Names
Runtime Issues
Testing Issues
2. ActionScript Game Elements
Creating Visual Objects
Using Movie Clips
Making Buttons
Drawing Shapes
Drawing Text
Creating Linked Text
Creating Sprite Groups
Setting Sprite Depth
Accepting Player Input
Mouse Input
Keyboard Input
Text Input
Creating Animation
Using Timers
Time-Based Animation
Physics-Based Animation
Programming User Interaction
Moving Sprites
Dragging Sprites
Collision Detection
Accessing External Data
External Variables
Loading Data
Saving Local Data
Miscellaneous Game Elements
Custom Cursors
Playing Sounds
Loading Screen
Random Numbers
Shuffling an Array
Displaying a Clock
System Data
Game Theft and Security
3. Basic Game Framework: A Matching Game
Placing Interactive Elements
Methods for Creating Game Pieces
Setting Up the Flash Movie
Creating the Basic ActionScript Class
Using Constants for Better Coding
Shuffling and Assigning Cards
Game Play
Adding Mouse Listeners
Setting Up Game Logic
Checking for Game Over
Encapsulating the Game
Creating the Game Movie Clip
Adding an Introduction Screen
Adding a Play Again Button
Adding Scoring and a Clock
Adding Scoring
Adding a Clock
Displaying Time
Displaying Score and Time After the Game Is Over
Adding Game Effects
Animated Card Flips
Limited Card-Viewing Time
Sound Effects
Modifying the Game
4. Brain Games: Memory and Deduction
Arrays and Data Objects
Arrays
Data Objects
Arrays of Data Objects
Memory Game
Preparing the Movie
Programming Strategy
Class Definition
Setting the Text, Lights, and Sounds
Playing the Sequence
Switching Lights On and Off
Accepting and Checking Player Input
Modifying the Game
Deduction Game
Setting Up the Movie
Defining the Class
Starting a New Game
Checking Player Guesses
Evaluating Player Moves
Ending the Game
Clearing Game Elements
Modifying the Game
5. Game Animation: Shooting and Bouncing Games
Game Animation
Time-Based Animation
Coding Time-Based Animation
Air Raid
Movie Setup and Approach
Flying Airplanes
Moving Gun
Skyward Bullets
The Game Class
Modifying the Game
Paddle Ball
Setting Up the Movie
Class Definition
Starting the Game
Starting a New Ball
Game Animation and Collision Detection
Game Over
Modifying the Game
6. Picture Puzzles: Sliding and Jigsaw
Manipulating Bitmap Images
Loading a Bitmap
Breaking a Bitmap into Pieces
Sliding Puzzle Game
Setting Up the Movie
Setting Up the Class
Loading the Image
Cutting the Bitmap into Pieces
Shuffling the Pieces
Reacting to Player Clicks
Animating the Slide
Game Over and Cleanup
Modifying the Game
Jigsaw Puzzle Game
Setting Up the Class
Loading and Cutting the Image
Dragging Puzzle Pieces
Game Over
Modifying the Game
7. Direction and Movement: Air Raid II, Space Rocks, and Balloon Pop
Using Math to Rotate and Move Objects
The Sin and Cos Functions
Using Cos and Sin to Drive a Car
Calculating an Angle from a Location
Air Raid II
Altering the Gun
Changing the Bullets
Changes to AirRaid2.as
Space Rocks
Game Elements and Design
Setting Up the Graphics
Setting Up the Class
Starting the Game
Score and Status Display Objects
Ship Movement and Player Input
Shields Up!
Rocks
Missiles
Game Control
Modifying the Game
Balloon Pop
Game Elements and Design
Setting Up the Graphics
Setting Up the Class
Starting the Game
Preparing a Game Level
Main Game Events
Player Controls
Popping Balloons
Ending Levels and the Game
Timeline Scripts
Modifying the Game
8. Casual Games: Match Three and Collapsing Blocks
Reusable Class: Point Bursts
Developing the Point Burst Class
Using Point Bursts in a Movie
Match Three
Playing Match Three
Game Functionality Overview
The Movie and MatchThree Class
Setting Up the Grid
Player Interaction
Animating Piece Movement
Finding Matches
Finding Possible Moves
Score Keeping and Game Over
Modifying the Game
Collapsing Blocks
Setting Up the Graphics
Setting Up the Class
Starting the Game
Recursion
Recursive Block Removal
Falling Blocks
Checking for Empty Columns
Game Over
Modifying the Game
9. Word Games: Hangman and Word Search
Strings and Text Fields
ActionScript 3.0 String Handling
Applying Text Formatting to Text Fields
Hangman
Setting Up the Hangman
The Hangman Class
Word Search
Development Strategy
Defining the Class
Creating the Word Search Grid
User Interaction
Dealing with Found Words
Modifying the Game
10. Questions and Answers: Trivia and Quiz Games
Storing and Retrieving Game Data
Understanding XML Data
Importing External XML Files
Trapping Load Errors
Trivia Quiz
Designing a Simple Quiz Game
Setting Up the Movie
Setting Up the Class
Loading the Quiz Data
Message Text and Game Button
Moving the Game Forward
Displaying the Questions and Answers
Judging the Answers
Ending the Game
Deluxe Trivia Quiz
Adding a Time Limit
Adding Hints
Adding a Factoid
Adding Complex Scoring
Randomizing the Questions
Picture Quiz
Better Answer Arrangement
Recognizing Two Types of Answers
Creating Loader Objects
Determining the Right Answer
Expanding the Click Area
Images for Questions
Modifying the Game
11. Action Games: Platform Games
Designing the Game
Level Design
Designing the Class
Planning Which Functions Are Needed
Building the Class
Class Definition
Starting the Game and Level
Keyboard Input
The Main Game Loop
Character Movement
Scrolling the Game Level
Checking for Collisions
Enemy and Player Death
Collecting Points and Objects
Showing Player Status
Ending the Levels and the Game
The Game Dialog Box
Modifying the Game
12. Game Worlds: Driving and Racing Games
Creating a Top-Down Driving Game
Creating a Top-Down World
Game Design
The Class Definition
The Constructor Function
Finding the Blocks
Placing the Trash
Keyboard Input
The Game Loop
Moving the Car
Checking for Trash and Trashcan Collisions
The Clock
The Score Indicators
Game End
Modifying the Game
Building a Flash Racing Game
Racing Game Elements
Making the Track
Sound Effects
Constants and Variables
Starting the Game
The Main Game Loop
Car Movement
Checking Progress
The Countdown and the Clock
Game Over
Modifying the Game
13. Card Games: Higher or Lower, Video Poker, and Blackjack
Higher or Lower
Creating the Deck
Setting Up the Class
Starting the Game
Responding to Player Moves
Cleaning Up
Modifying the Game
Video Poker
Shuffle Up and Deal
Timed Events
Making the Deck
Game Elements
Setting Up the Class
Shuffling the Cards
Timed Events
Here’s the Deal
Drawing Cards
Finishing a Hand
Calculating Poker Winnings
Modifying the Game
Blackjack
Game Elements
Setting Up the Class
Starting the Game
Timed Events
Dealing Cards
Hit or Stay
The Dealer’s Moves
Calculating Blackjack Hands
Other Game Functions
Modifying the Game
14. 3D Games: Target Practice, Racing Game, and Dungeon Adventure
Flash 3D Basics
Setting 3D Positions
Rotating Objects
Target Practice
Game Elements
Setting Up the Class
Starting the Game
Drawing the Cannon and Target
Moving the Cannon
Firing the Cannonball
Modifying the Game
3D Racing Game
Game Elements
Setting Up the Movie
User Control
Player Movement
Z-Index Sorting
Modifying the Game
3D Dungeon Adventure
Game Elements
Setting Up the Game
Constructing the Dungeon
Main Game Function
Player Movement
Collecting Coins
Game Limitations
Extending the Game
15. Building Games for the iPhone
Getting Started with iOS Development
What You Need
Publishing for iOS
The iOS Game-Building Process
Design and Programming Considerations
Screen Size
No Web Page
Touch
Processor Speed
Accelerometers
Sliding Puzzle Adaptation
Adjusting the Screen Size
Changing Publishing Settings
Including the Image
Publishing
Marble Maze Game
Setting Up the Class
Starting the Game
Game Play
Collision Detection
Game Over
Modifying the Game
Optimizing for iOS Devices
Use the GPU and Bitmap Caching
Object Pooling
Simplifying Events
Minimizing Screen Redrawing
More Optimization Techniques
Beyond the iPhone
Index