You are previewing GameMaker Game Programming with GML.
O'Reilly logo
GameMaker Game Programming with GML

Book Description

Learn GameMaker Language programming concepts and script integration with GameMaker Studio through hands-on, playable examples

In Detail

GameMaker: Studio is a popular game engine used to publish games to a variety of platforms. Although GameMaker: Studio's drag-and-drop functionality makes creating games simple and fast, utilizing scripts can really help organize and speed up GameMaker's workflow exponentially.

This hands-on guide will help you build a strong foundation in programming in GameMaker Language by taking you through several example games. Knowledge gained by the end of the book can be applied so you can build your own line of exciting games.

What You Will Learn

  • Create script resources as well as custom scripts for events
  • Learn how to import, compress, and play sound effects and background music
  • Build particle effect systems to give games a little extra flare
  • Track and display user interface elements such as health and scoring
  • Program and interact with simple yet challenging artificial intelligence
  • Read player input from a variety of sources
  • Utilize alarms to create a clean series of events
  • Establish a finite state machine to track a character's current state
  • Complete easy and fun games from start to finish
  • Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

    Table of Contents

    1. GameMaker Game Programming with GML
      1. Table of Contents
      2. GameMaker Game Programming with GML
      3. Credits
      4. About the Author
      5. About the Reviewers
      6. www.PacktPub.com
        1. Support files, eBooks, discount offers and more
          1. Why Subscribe?
          2. Free Access for Packt account holders
      7. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Conventions
        5. Reader feedback
        6. Customer support
          1. Downloading the example code
          2. Downloading the color images of this book
          3. Errata
          4. Piracy
          5. Questions
      8. 1. Getting Started – An Introduction to GML
        1. Creating GML scripts
          1. Creating GML scripts within an event
          2. Creating scripts as resources
          3. Scripting a room's creation code
        2. Understanding parts of GML scripts
          1. Programs
            1. snake_case
          2. Variables
            1. Variable prefixes
            2. Variable scope
              1. Built-in variables
              2. Creating custom constants
          3. Functions and accessing script resources
            1. Arguments
          4. Expressions
            1. Expression symbols
          5. Conditional statements
            1. If, else, and switch
            2. repeat, while, do, and for
            3. break, continue, and return
          6. Arrays
            1. Two-dimensional arrays
          7. Commenting
          8. Errors
        3. Pushing your buttons
          1. Creating the project
          2. Gathering resources
            1. Sprites – spr_button
            2. Objects – obj_button
            3. Room – rm_main
          3. The events of obj_button
            1. The Create event
            2. The Left Button event
            3. The Left Pressed event
            4. The Mouse Enter event
            5. The Mouse Leave event
            6. The Global left release event
          4. The Draw GUI event
            1. Scripts – scr_create_button
            2. scr_random_position
          5. Creating buttons using scripts
            1. Scripting room creation code
            2. Creating scr_random_position
          6. Exporting and importing the button
        4. Summary
      9. 2. Random Organization – Creating a Puzzle Game
        1. Understanding sprite variables and functions
          1. Positioning and origin
            1. Layering with depth
          2. Rotating
          3. Scaling
          4. Working with frames and color
        2. Setting up the puzzle game
          1. Sprites – spr_grid
            1. spr_pieces
            2. Objects – obj_grid_manager
            3. obj_grid_block and obj_puzzle_piece
            4. Room – rm_gameplay
            5. Scripts
        3. Aligning the pieces of the puzzle game to a grid
          1. The Create event of obj_grid_manager
          2. scr_create_in_grid
        4. Understanding and utilizing randomization
          1. Random functions
          2. Randomizing the board
        5. Checking pieces
          1. scr_get_puzzle_piece
          2. scr_check_adjacent
          3. scr_check_board
        6. Running it all together
        7. Summary
      10. 3. So How Do I Play? – Adding Player Interaction
        1. Designing player interaction
          1. Reading input with the mouse
          2. Understanding mouse variables and functions
            1. Working with touch devices
        2. Creating resources to integrate mouse input into the puzzle game
          1. Adding new events to obj_grid_manager
            1. The Create event
          2. Updating spr_grid and obj_grid_block
            1. Adding new frames to spr_grid
            2. Implementing the Mouse events for obj_grid_block
            3. Entering the grid with the mouse
            4. Pressing the left mouse button
            5. Releasing the left mouse button globally
            6. The Mouse Leave event
          3. Swapping pieces
          4. obj_puzzle_piece
            1. scr_swap_pieces
          5. Updating scr_check_board
        3. Updating organization with scr_reorganize_board
        4. Integrating keyboard input
          1. Introducing keyboard functions, variables, and events
          2. Integrating the Keyboard event updates
            1. Utilizing the press <any key> event
            2. Implementing the release <any key> event
        5. Summary
      11. 4. Juicy Feedback – Aural and Visual Effects
        1. Introducing alarms
          1. Arming the puzzle game's alarms
          2. Setting up the first alarm
          3. Are pieces shifting?
            1. Applying is_shifting_pieces
          4. Determining where pieces should move
            1. Setting the Alarm 0 event of obj_puzzle_piece
            2. Making pieces fall with Alarm 1 in obj_puzzle_piece
          5. Setting the alarms
            1. Updating scr_swap_pieces
            2. Updating scr_check_board
            3. Updating scr_reorganize_board
        2. Hiding the pin drop – adding audio
        3. Creating sound resources
          1. Gathering audio resources
          2. Introducing audio functions
          3. Playing puzzling sounds
            1. Swapping sounds in scr_swap_pieces
            2. Playing the pop sound in scr_reorganize_board
            3. Fading in the music with obj_grid_manager
        4. Visualizing effects with particles
          1. Managing a particle system
          2. Emitting particles
            1. Shaping and distributing within emitters
          3. Creating different particle types
            1. Shaping particle types
          4. Particle-specific functions
        5. Integrating particles
          1. obj_particle_manager
            1. The Create event
            2. The Destroy event
            3. Placing obj_particle_manager
          2. Creating bursts within scr_reorganize_board
        6. Summary
      12. 5. Solving the Puzzle – Finishing Touches to the Puzzle Game
        1. Drawing and graphical user interface
          1. Understanding draw functions
            1. Drawing rectangles
            2. Setting color and alpha
          2. Drawing circles and ellipses
            1. Setting a circle's precision
          3. Drawing points, lines, and arrows
            1. Drawing text
            2. Setting font and text alignment
          4. Drawing sprites
            1. Tiling sprites
          5. Establishing the drawing order
        2. Gathering resources for creating the main menu
          1. Creating obj_main_menu
          2. Building a new room – rm_main_menu
          3. Creating fonts – fnt_title and fnt_main
            1. Creating the fonts
        3. Scripting obj_main_menu
          1. The Create event
            1. Utilizing div and mod
          2. Drawing the menu
          3. The Global Left Button event
          4. The press <any key> event
          5. The Global Left Release event
          6. The release <any key> event
            1. event_perform
          7. scr_on_menu_button_pressed
        4. Changing obj_grid_manager
        5. Integrating score and time
          1. Scoring and combos
          2. The Create event of obj_grid_manager
          3. Earning points in scr_reorganize_board
          4. Drawing UI in obj_grid_manager
          5. Timing and game over
          6. Adding new variables to the Create event of obj_grid_manager
          7. Using Alarm 1 and Alarm 2 in obj_grid_manager
            1. Alarm 1
            2. Alarm 2
          8. Drawing the timer
        6. Summary
      13. 6. Finite State Machines – Starting the 2D Platformer
        1. Introducing finite state machines
        2. Gathering resources for the platformer
          1. Establishing Lil' Vlad's sprites
            1. The standing sprite – spr_vlad_idle
            2. The walking sprite – spr_vlad_walk
            3. The jumping sprite – spr_vlad_jump
          2. Jumping with sound – snd_jump
          3. Creating a new object resource – obj_vlad
            1. Utilizing the User defined events
          4. Placing Vlad in a room – rm_level1
        3. Defining Vlad's state constants
        4. Starting Vlad's events and scripts – walking
          1. The Create event
          2. The Step event
          3. Standing still – the User Defined 0 event
          4. Walk this way – the User Defined 1 event
          5. Adding new variables for jumping
          6. Using up to jump – the Step event update
          7. Falling state – the User Defined 2 event
          8. Looping the jump – the Animation End event
        5. Summary
      14. 7. It's in the Name – Platforms and Collisions
        1. Collision – a crash course
          1. Creating masks for collision
          2. Working with placement and movement functions
            1. Testing placement
            2. Movement functions
        2. Gathering resources to build platforms
          1. Sprites – spr_basic_platform and spr_solid_platform
          2. Objects – obj_basic_platform and obj_solid_platform
            1. Solidifying objects
        3. Populating the room
        4. Working with Collision events
          1. Updating the Create event of obj_vlad
          2. The Collision events of obj_vlad
          3. Creating the script resource scr_test_collision
          4. Updating the Step event
        5. Moving platforms with paths
          1. Creating path resources
          2. Utilizing the path_start function
          3. Gathering resources for the path creation
          4. The spr_moving_platform sprite
          5. obj_moving_platform
          6. pth_horizontal and pth_vertical_ellipse
        6. Integrating the moving platforms
          1. Creating instances of obj_moving_platform
          2. Interacting with obj_moving_platform
            1. Creating a new variable – current_platform
            2. Updating to the User Defined 2 event
            3. scr_test_collision and current_platform
            4. Using the Step End event
          3. Drawing a path
        7. Preventing Vlad from leaving
          1. Defining global.room_left and global.room_right
          2. Updating the End Step event
        8. Knowing the design ahead of time (when possible)
        9. Summary
      15. 8. Setting the Stage – Views, Backgrounds, and Tiles
        1. Expanding the room – views
          1. Setting the view
        2. Adjusting view parameters
        3. Preparing the game for obj_camera
          1. The Create event
          2. The End Step event
          3. Adding the camera with Creation Code
        4. Setting the environment – backgrounds
          1. Introducing background variables
          2. Creating background resources
          3. Preparing the game for background resources
            1. Building an atmosphere with bg_main
          4. Utilizing the background
          5. Setting a background index with bg_index
          6. Scripting scr_inverse_lerp
            1. Moving the background in the End Step event of obj_camera
        5. Introducing tiles
          1. Creating tiles
          2. Building resources for tiles
            1. Tiling with bg_tiles_main
          3. Applying tiles
          4. Utilizing tile_add and other tile functions
          5. Placing tiles with scripts – scr_define_tiles
          6. Using scr_define_tiles
          7. Drawing tiles in obj_moving_platform
        6. Summary
      16. 9. Breaking Vlad – Pickups, Hazards, and Enemies
        1. Tracking health with Draw and Draw GUI
          1. Displaying UI with the Draw and Draw GUI events
            1. Creating a new font – fnt_score_text
            2. Setting up the Draw GUI event
            3. Displaying health with the Draw event
            4. Updating the Create event
            5. Arming the Alarm 0 event in obj_vlad
        2. Working with pickups
          1. Gathering resources to create pickups
            1. Initializing sprite resources for pickups
            2. Pickup object resources
            3. Script resource – scr_collect_pickup
            4. Colliding with obj_vlad
        3. Dying from hazards
          1. Establishing a death state
            1. Setting up two new events – User Defined 3 and Alarm 1
          2. Gathering resources for hazards
            1. Creating the sprite and object resources
            2. Scripting scr_damage_vlad
          3. Falling off the screen into the abyss
        4. Fighting the player with enemies
          1. Enemy 1 – mutant garlic
            1. Gathering resources for garlic
            2. Sprite resource – spr_enemy_garlic
            3. Object resource – obj_enemy_garlic
            4. Scripting the Create event of obj_enemy_garlic
            5. Making garlic move with the Step event
            6. Reacting upon collision with scr_collide_enemy
            7. Colliding with the player – the Collision event of obj_vlad
          2. Enemy 2 – the flying book
            1. Gathering resources to create the flying book
            2. The sprite resource – spr_enemy_book
            3. The object resource – obj_enemy_book
            4. Initializing the Create event of obj_enemy_book
            5. Anthropomorphizing the book in the Step event
        5. Summary
      17. 10. GOAL – Timelines and Feedback Review
        1. GOAL!
          1. Gathering resources for creating the goal
            1. Sprite resource – spr_goal_door
            2. Object resource – obj_goal_door
        2. Introducing timelines
          1. Using timelines
        3. Gathering resources for integrating the timeline
          1. Font resource – fnt_large_text
          2. Creating and updating events for obj_goal_door
            1. Using the Animation End event
            2. Drawing congratulatory text with the Draw GUI event
          3. Deactivating objects with scr_deactive_instances and the Draw event
            1. Freezing instances with scr_deactivate_instances
            2. Drawing deactivated instances
        4. Creating and applying the timeline
          1. Step 0
          2. Step 15
          3. Step 90
          4. Applying tm_finish_level
        5. Reviewing polish, feedback, and juiciness
          1. Gathering resources to play sounds
          2. Playing music with scr_play_music
          3. Reviewing the obj_particle_manager object
          4. Giving feedback with pickups
        6. Providing feedback when Vlad is damaged
        7. Extending the enemy death sequence
          1. Updating scr_collide_enemy and Step events for enemies
          2. Creating tm_enemy_death
            1. Step 0
            2. Step 5
            3. Step 25
            4. Step 30
        8. Summary
        9. In closing...
      18. Index