1st Edition

Learn to Code with Games

By John M. Quick Copyright 2016
    312 Pages 68 B/W Illustrations
    by A K Peters/CRC Press

    306 Pages
    by A K Peters/CRC Press

    A novel approach for the classroom or self-study, Learn to Code with Games makes coding accessible to a broad audience. Structured as a series of challenges that help you learn to code by creating a video game, each chapter expands and builds your knowledge while providing guidelines and hints to solving each challenge.

    The book employs a unique problem-solving approach to teach you the technical foundations of coding, including data types, variables, functions, and arrays. You will also use techniques such as pseudocode and process mapping to formulate solutions without needing to type anything into a computer, and then convert the solutions into executable code.

    Avoiding jargon as much as possible, Learn to Code with Games shows you how to see coding as a way of thinking and problem solving rather than a domain of obscure languages and syntaxes. Its practical hands-on approach through the context of game development enables you to easily grasp basic programming concepts.

    Our Hero Is Stuck!
    Required Files
    Unity Game Engine
    Challenge: Make Luna Move
    Hint: Visualizing the Game World
    Hint: Visualization and Code
    Hint: Position
    Problem-Solving Techniques
    A Note about Example Solutions
    Example Solution: Make Luna Move
    Bonus Challenge: Make Luna Move Faster (or Slower)
    Bonus Hint: User Input in Unity

    Characters and Characteristics
    Required Files
    Challenge: Data Types
    Hint: Data Type Descriptions
    Hint: How Computers Think
    Challenge Extension: Data Types
    Example Solution: Data Types
    Challenge: Defining Variables
    Hint: Access Levels
    Hint: Naming Variables
    Hint: Declaring Variables
    Challenge Extension: Defining Variables
    Example Solution: Defining Variables
    Challenge: Initializing Variables
    Hint: Initialization
    Hint: Unity’s Start ( ) Function
    Hint: Comments
    Example Solution: Initializing Variables

    The Bounds of the World
    Required Files
    Challenge: Detecting Boundary Collisions
    Hint: 2D Collisions
    Hint: Operators
    Hint: Expressions
    Hint: Screen Size in Unity
    Example Solution: Boundary Collisions
    Challenge: Accounting for the Character
    Hint: Origin Point
    Hint: Game Components in Unity
    Example Solution: Accounting for the Character

    Sprinting and Sneaking
    Required Files
    Challenge: Making Luna Sprint
    Hint: Function Calls
    Hint: The Unity Update ( ) Function
    Hint: Conditional Statements
    Hint: Increment and Decrement Operators
    Hint: Getters and Setters
    Hint: Unity’s GetComponent Command and Dot Notation
    Example Solution: Making Luna Sprint
    Challenge: Making Luna Invisible
    Hint: Boolean Flags
    Hint: Boolean Operators
    Hint: Unity’s Time.time Command
    Hint: Local Variables
    Example Solution: Making Luna Invisible

    Required Files
    Challenge: Collecting Objects
    Hint: Primitive and Composite Data Types
    Hint: Unity Tags
    Hint: Axis-Aligned Bounding Box Collisions
    Hint: Unity Destroy ( ) Function
    Example Solution: Collecting Objects

    Spawning Objects
    Required Files
    Challenge: Spawning Collectables
    Hint: Unity Prefabs
    Hint: Unity Prefab Instantiation
    Hint: Random Number Generation
    Hint: Parent Objects in Unity
    Hint: for and while Loops
    Example Solution: Spawning Collectables

    Taking Inventory
    Required Files
    Challenge: Keeping Track of Collectables in an Inventory
    Hint: The using Directive
    Hint: The C# List
    Hint: Add and Remove Functions
    Hint: Access by Index
    Hint: The Count Property
    Hint: Function Argument Usage
    Example Solution: Keeping Track of Collectables in an Inventory

    A Party of Heroes
    Required Files
    Challenge: Managing a Group of Heroes
    Hint: Unidimensional Arrays
    Hint: Unity Tags for Multiple Objects
    Hint: foreach Loops
    Example Solution: Managing a Group of Heroes

    Generating a Tile Map
    Required Files
    Challenge: Generating a Tile Map
    Hint: Tile Maps in Games
    Hint: Multidimensional Arrays
    Hint: Nested Loops
    Hint: Nested Loops with Multidimensional Arrays
    Example Solution: Generating a Tile Map

    Spawning Objects on a Tile Map
    Required Files
    Challenge: Spawning Objects on a Tile Map
    Hint: Functions
    Hint: Functions with Return Values
    Hint: Functions with Arguments
    Example Solution: Spawning Objects on a Tile Map

    Level Generation
    Required Files
    Challenge: Generating the Map Scene
    Hint: Coupling and Cohesion
    Hint: Refactoring for Better Management
    Example Solution: Generating the Map Scene

    Game State Management
    Required Files
    Challenge: Managing the Game State
    Hint: Singleton Design Pattern
    Hint: The Unity Awake ( ) and DontDestroyOnLoad ( ) Functions
    Hint: The Unity Application.LoadLevel ( ) Function
    Hint: Unity Physics 2D Collisions
    Example Solution: Managing the Game State

    Required Files
    Challenge: Bringing the Gameplay Together
    Hint: Obstacles and Artificial Intelligence
    Hint: Game State and Score
    Hint: More Collisions
    Hint: More Spawns
    Hint: Reset the Game
    Example Solution: Bringing the Gameplay Together

    Appendix A: Pseudocode Reference

    Appendix B: Process Mapping Reference


    John M. Quick is an expert in the strategic enhancement of motivation, learning, and performance. He collaborates with industry and university clients to strategically solve the greatest challenges in motivation, learning, and performance. John earned a PhD in Educational Technology at Arizona State University, where he researched enjoyment and individual differences in games. He created the Gameplay Enjoyment Model (GEM) and Gaming Goal Orientations (GGO) model to guide the design of effective game-based solutions. John has released more than 15 digital games. His games focus on innovative topics, such as learner engagement, employee performance improvement, and cutting-edge interfaces. John has over 5 years of classroom experience at the higher education level. He has instructed courses on computer literacy, game design, and programming at Michigan State University (East Lansing), Arizona State University (Tempe), and DigiPen Institute of Technology Singapore.

    "Now is definitely the time for a book like this. In the realms of web design and game design, knowledge of coding is essential, even for non-programmers on the team."
    —Carrie Heeter, Michigan State University, East Lansing, USA