Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Monkey Game Development: Beginner's Guide
Monkey Game Development: Beginner's Guide

Monkey Game Development: Beginner's Guide: Create monetized 2d games deployable to almost any platform with this book and ebook.

eBook
$28.99 $32.99
Paperback
$54.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with Print?

Product feature icon Instant access to your digital copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Redeem a companion digital copy on all Print orders
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Table of content icon View table of contents Preview book icon Preview Book

Monkey Game Development: Beginner's Guide

Chapter 2. Getting to Know your Monkey—a Trip to the Zoo

Phew, there was a lot of dry and general information in the first chapter! As I told you, you could have skipped the chapter if you already knew about all that it covered. Anyway, it is time now to become a little bit more practical, and so we should get down to business.

Assuming that you already have Monkey installed on your machine, we will work together through some Monkey game development basics. We won't go through every Monkey command as it is shipped with good documentation. There is no need to repeat everything again, here. Anyway, I am right behind you!

So, in this chapter, we will learn the following:

  • How to load a script

  • About projects and how we can create one

  • The basic structure of a simple game

  • How to draw circles and rectangles

  • How to read keyboard input

  • How to print messages to the browser window

  • How to export your game to HTML5 and run it inside a browser

Quite some stuff, isn't it? Hopefully the page limit for this chapter...

Call the Monk and start praying—the Monkey IDE


We are just kidding here; there are no religious activities planned in this chapter. Even though sometimes you will find yourself praying that a new piece of code you have created works like it should.

Ok, if you haven't installed Monkey already, then it is time to do that now. We have covered this part in Chapter 1, Monkey — Huh?, already.

Why learn about Monk?

Monk is the code editor/IDE that ships with Monkey. It is the first place that you will fire up when you start using Monkey. So, it is important to know your first main tool, if you want to develop games with Monkey.

Starting up Monk

It's time now to start Monk. You will do this by double-clicking on the Monk.app icon on OSX or start Monk.exe in Windows.

Monk's user interface

Monk's user interface is divided into three sections:

  • The toolbar

  • The code editor area

  • The info box

The toolbar

All functions of Monk can be called through keyboard shortcuts and through the main menu. Some functions are...

Time for action — opening a sample script


Opening an existing script can be done through several methods. One is through the toolbar. Follow the given steps:

  1. 1. Click on the Open icon in the toolbar:

    Next, you will see a file dialog where you can select a .Monkey file to be opened.

  2. 2. Navigate, within the dialog, into the bananas folder of Monkey's main directory.

    There, you have subfolders from some authors of sample scripts.

  3. 3. Head to the mak folder, and from within that, to the firepaint folder. Inside, you will find the firepaint.Monkey file.

  4. 4. Select it and click on the Open button in the File dialog. Voila! Monk just opened the selected script:

  5. 5. Of course, there are other ways to open a script. For example, you can double-click on a filename inside the Nav tree view.

What just happened?

You have opened your first Monkey script. Good job! Please note how the GUI has changed. In the top of Monk, you see the file path of your currently visible script. Also, for each script you open or...

Where is my navi?


Games are not usually coded with just 10-20 lines. We talk here about at least a few hundred lines of code. And to help you navigate through your code more easily, Monk supports the Code tab in the info box on the right. To practice navigation in a script file a little, here is the next task.

Time for action — navigating to the Main() function


Every Monkey game needs a Main() function. To find it, select the Code tab in the info box. There you find two parent nodes. Try to find Main() in one of them. Found it? Good. Click on it. You will see that the code area changed and the cursor jumped to the top line of the definition of the Main() function:

What just happened?

Navigating through a script is very easy. Search for the item you want to jump to inside the Code tab of the info box and click on it. The content of the code tab always reflects the changes inside the code area!

Save... save... save!


One of the first and most important rules of software development is save your code, save it a lot. Remember this and live by it. There is nothing worse than a hard drive failure or a power outage after an hour of coding.

Time for action — saving a script


To save a script, here are some things you have to do:

  1. 1. Open an empty script by pressing Ctrl + N in Windows or cmd + N on OSX. Monkey will open a fresh and empty code area for you.

  2. 2. Next, type anything inside it, just anything.

  3. 3. Now, save your script. For this, you should use your mouse and the menu. Click on File | Save as. A dialog opens where you can set the filename and location to save your script to.

  4. 4. Do this and click on Save.

What just happened?

You have saved your first script. Most likely, it isn't even close to a run-worthy script, but you have learned how to save your creation. Did you notice how the caption of the tab for the code area changed? And also the title bar of Monk's window? They now reflect the name you gave your script when you saved it.

Projects—bringing in some organization


When you look at the Nav tab of the info box, it's nice that you can browse through the folders of Monkey and open scripts from there. Good news is near; you can do this with your own code too. That is why Monk supports projects. They become new entries under the initial tree view inside the Nav tab.

Time for action — creating a project


Let's assume that we want to turn the FirePaint example into a project. For this, you have to create a new project first. Follow the ensuing steps:

  1. 1. Click on File | Project Manager, in the menu. A new dialog will open.

  2. 2. There, you will first see the Monkey project. To create a new one, click on Add Project.

  3. 3. In the following dialog, you need to give your project a name. For now, My firepaint project should be fine. Also select the folder where the previous sample script was loaded from. After you do this, the top of the dialog should look a little like this:

    The bottom of the dialog with fields including sub-version controls is not functional and is probably a relic from Monk's origins of being the BlitzMAX IDE.

  4. 4. Now, click on OK to create your project.

What just happened?

In the first dialog, there is now a new line with the project title. If you select this line, you could either change the properties of your project or remove it completely. You...

The Monkey programming language


To create games with Monkey, you should know a little bit about its programming language and its features. We won't cover the whole manual here, but will go through some of the most important parts of it. But first, you should write your first script. Without any practice, you say? Right, just like that!

Time for action — Monkey's Hello World


Here is a version of the famous Hello World script, done in Monkey. You have to start somewhere. You will learn what the starting point of every Monkey app looks like, the Main() function, and how to print some text to the browser. Ok, let's go!

  1. 1. Start with a single line comment that describes the app.

    'Monkeys Hello World
    
  2. 2. Next is the function header for the Main() function, the piece of code that will be called at the start of the app. Every function starts with the keyword Function, then its name, followed by opening and closing parentheses.

    Function Main()
    
  3. 3. Now, it's time to print the famous text Hello World. For this, Monkey provides the Print command. And don't forget to indent the code through the menu or just by pressing the Tab key once.

    Print ("Hello World")
    
  4. 4. Every function needs to be closed. In Monkey, we do this with the End command.

    End
    
  5. 5. Now, save your script. The name and folder are not important.

  6. 6. Build and run the script by...

Running your first script in a browser


To start this script, press Ctrl + R for Windows or cmd + R for OSX, to build and run the script. For this, select HTML5 as the target platform. You should see something similar to the following screenshot:

Cool, isn't it? And you did this all yourself.

Our first little game... PONGO


It's time that you develop your first little game. A small game, but a game for sure. Do you remember a game called PONG? If not, here again is a Wikipedia link that describes PONG: http://en.wikipedia.org/wiki/Pong.

Your game PONGO will be a single-player game. The opponent will be controlled by the computer. As it is pretty brainless, it will actually have two paddles to work with. Unfair, but who said life is fair?

The paddle for the player will be controlled by pressing the up and down keys on the keyboard. The goal of the game is to reach 10 points. You get a point once the opponent is not able to play the ball back.

So what features does the game have?

  • You need to read the keyboard to control the paddle

  • You need to draw a circle for the ball

  • You need to draw rectangles for the paddles

  • You need to check if the ball collides with the paddles and react to it

  • You need to print some messages on the screen to inform the player about the state of the game

Time for action — the basic structure of your game


We will now build the basic structure for every game. Follow the given steps:

  1. 1. Your first command in Pongo, and in every game, should be the Strict command, so that Monkey will keep us on track regarding giving identifiers the right type.

    Strict
    
  2. 2. Next should be some comments that describe the script somehow.

    #rem
    Script: Pongo.Monkey
    Description: Sample script from chapter #2 of the book "Monkey Game Development Beginners guide" by PacktPub
    Author: Michael Hartlef
    #end
    
  3. 3. Because we want to use the Monkey built-in framework mojo, we have to import it.

    Import mojo
    
  4. 4. Now, we need to create the pongo class that extends from mojo's app class. We will include empty OnCreate, OnUpdate, and OnRender methods that we will fill later on.

    Class pongo Extends App
    Method OnCreate:Int()
    SetUpdateRate(60)
    Return True
    End
    Method OnUpdate:Int()
    Return True
    End
    Method OnRender:Int()
    Return True
    End
    End
    Function Main:Int()
    New pongo
    Return True
    End
    
  5. 5. The...

Pongo's data structure


Each game needs to store data. We have talked about variables and stuff like that. For this, we will include some field variables in our pongo class:

Time for action — adding some data fields


  1. 1. One of the elements of Pongo is the paddle, so we need to add fields to store its X and Y position at the beginning of the class definition. To add data fields we need to extend the pongo class.

    Class pongo Extends App
    Field pX:Float = 630.0 'X pos on the right side of the canvas
    Field pY:Float = 240.0 'Y pos in the middle of the canvas
    
  2. 2. Next will be the data fields for the ball. X/Y position and its X/Y speed.

    Field pX:Float = 240.0 'Y pos in the middle of the canvas
    Field bX:Float = 320.0 'X pos of the ball in the middle of canvas
    Field bY:Float = 240.0 'Y pos in the middle of the canvas
    Field bdX:Float = 3.5 'X speed of the ball
    Field bdY:Float = 1.5 'Y speed of the ball
    
  3. 3. For both enemy paddles, we need to add their data fields for the X/Y positions and the Y speed. We will use 1-dimension arrays for this.

    Field bdY_Float = 1.5 'Y speed of the ball
    Field eX:Float[] = [5.0, 55.0] 'X pos of both paddles
    Field eY:Float[] = [240.0, 240.0] 'Y...

Time for action — rendering the game field


Which elements will be rendered in the game?

  • The player paddle

  • Enemy paddle #1

  • Enemy paddle #2

  • The ball

  • A wall at the top

  • A wall at the bottom

  • A middle line

The last three elements can be grouped together as a background. So let us do just that:

  1. 1. Now, insert the drawing routines for the background graphics. Between the OnUpdate method and the OnRender method, create a new method called DrawPlayField.

    Method OnUpdate:Int()
    Return True
    End
    Method DrawPlayField:Int()
    'Draw the top wall with a rectangle
    DrawRect(0,0,640,5)
    'Botton wall
    DrawRect(0,475,640,5)
    'Middle line, 13 pieces, each 10 pixel long
    For Local i:= 5 To 465 Step 20
    DrawRect(318,i,4,10)
    Next
    Return True
    End
    Method OnRender:Int()
    
  2. 2. We need to modify the OnRender method now, so that the new DrawPlayField method can be called.

    Method OnRender:Int()
    Cls 'Clear the canvas each frame
    DrawPlayField() 'this call draws the background
    Return True
    End
    
  3. 3. Like before, save your script and test it...

Time for action — drawing the ball and the paddles


The next thing we want to draw is the ball and the paddles. Follow the ensuing steps:

  1. 1. For this, we will add a single DrawCircle command and some DrawRect commands to the OnRender method.

    Method OnRender:Int()
    Cls 'Clear the canvas each frame
    DrawPlayField() 'Draw the play field
    DrawRect(pX, pY-30, 5, 60) 'Draw the player paddle
    DrawRect(eX[0], eY[0]-30, 5, 60) 'Draw the enemy paddle #1
    DrawRect(eX[1], eY[1]-30, 5, 60) 'Draw the enemy paddle #2
    DrawCircle(bX, bY, 5) 'Draw the ball with a radius of 5
    Return True
    
  2. 2. Better "save" than sorry. So, you should save this script under a name of your choice and test it again.

  3. 3. For the rest of the process, you can use the pre-built script Pongo_04.Monkey. Does your game look like this now?

  • Visually, we are 99 percent done. What's missing is the printing of the game score and a message about the game state. We will get to this soon.

The next thing we will add is the movement of the paddles and...

Time for action — player paddle movement


First, we will create a new method called ControlPlayer.

  1. 1. This method will check for keyboard input and move the player paddle according to it. Add this method to the pongo class.

    Method ControlPlayer:Int()
    
  2. 2. When the player presses the up key, we are moving the player paddle by 5 pixels, upwards.

    If KeyDown(KEY_UP) Then 'check if UP key is pressed
    pY -= 5.0 'subtract 5 pixel from Y position
    

    As the paddle should stop at the top, we check if its Y position is less than 25 pixels away (paddle height is equal to 50 pixel) and set its Y position back to 25 pixels.

    If pY < 25.0 Then pY = 25.0 'Check against top wall
    Endif:Now we check if the DOWN key is pressed and move the paddle accordingly. Again, we check if it reaches the bottom wall.
    If KeyDown(KEY_DOWN) Then 'Check if DOWN key is pressed
    pY += 5.0 'Add 5 pixels to Y position
    If pY > 455.0 Then pY = 455.0 'Check against bottom wall
    Endif
    
  3. 3. Now, close the method.

    Return True
    End
    
  4. 4. To actually...

Time for action — moving the enemy paddles


Computer-controlled movements, or the so-called Artificial Intelligence (AI) , are sometimes very hard to create. But for a start, we will keep it very simple. And simple will be the key here. Our computer-controlled movement will look like this. One paddle will move with a speed of 10 pixels up and down, the other with a speed of 5 pixels in the opposite direction.

  1. 1. For this, you need to create a new method, called ControlEnemies.

    Method ControlEnemies:Int()
    
  2. 2. Next, we update the paddles' Y positions. As we have two paddles to control, we will use a FOR loop for this, so we don't have to repeat the code. Remember that arrays in Monkey are zero-based.

    For Local ep:Int = 0 to 1
    eY[ep] += edY[ep] 'Update the paddles Y position
    
  3. 3. Next, we will check if a paddle reaches the top wall.

    If eY[ep] < 25.0 Then 'Check if paddles reaches top wall
    eY[ep] = 25.0
    edY[ep] *= -1 'Revers its Y speed
    Endif
    
  4. 4. Now, we will check if a paddle reaches the bottom...

Time for action — moving the ball


Moving the ball is as simple as moving the paddles, as you will see.

  1. 1. For updating the ball's position, you need to create a new method called UpdateBall. At first, we will update the ball's X and Y position:

    Method UpdateBall:Int()
    bX += bdX 'Add the X speed of the ball to its X position
    bY += bdY 'Add the Y speed of the ball to its Y position
    

    We could end here, but then the ball would not bounce of the walls and would just disappear in nowhere land.

  2. 2. Add a check if the ball hits the top wall and reacts to it.

    If bY < 10.0 then
    bY = 10.0 'Set the Y position back to 10.0
    bdY *= -1 'Inverse the balls Y speed
    Endif
    
  3. 3. Next, check if the ball hits the bottom wall and, again, reacts to it.

    If bY > 470.0 then
    bY = 470.0 'Set the Y position back to 470.0
    bdY *= -1 'Inverse the balls Y speed
    Endif
    
  4. 4. Now, check against the left wall. If it hits it, add a point to the player's points.

    If bX < 5.0 then
    bX = 5.0 'Set the X position back to 5.0
    bdX *= ...

Time for action — controlling the ball with the player's paddle


It's nice to see the ball bounce off the walls, but in a game of Pongo, you need to be able to control the ball with your paddle. So we will implement this now. Follow the given steps:

  1. 1. Let's start with the player paddle. We need a new method that checks the collision of the ball with the player's paddle. Create a new method called CheckPaddleCollP. Please note the return type is Boolean.

    Method CheckPaddleCollP:Bool()
    
  2. 2. Next, we want to check if the ball is close to the paddle regarding its X position.

    If bX > 625.0 Then
    
  3. 3. The next check will be if the ball's Y position is between minus 25 pixels and plus 25 pixels from the paddel's Y position. If yes, then return True from this method.

    If ((bY >= pY-25.0) and (bY <= pY+25.0)) Then
    Return True
    Endif
    
  4. 4. Now, close off the first If check, return False, because the ball didn't hit the paddle, and then close the method.

    Endif
    Return False
    End
    
  5. 5. Ok, now we need to call...

Time for action — letting the enemy paddles fight back


It isn't fair that only the player can push the ball back. The enemy needs this ability too. For sure, you can imagine it already; we will build a method first that will check and report back a collision of the ball with the enemy paddles:

  1. 1. Create a new method with the name CheckPaddleCollE, but this time with the return type of an integer.

    Method CheckPaddleCollE:Int()
    
  2. 2. Again, we first want to check if the ball is close to the paddles. As there are two of them, we will do this inside a FOR loop and set the index for the paddle arrays.

    For Local ep:Int = 0 To 1
    If (bX > (eX[ep]-5)) And (bX < (eX[ep]+5)) Then
    
  3. 3. Next, we check again if the ball's Y position is within +25/-25 pixels of the paddle's Y position. If it is, then return the index of the paddle.

    If ((bY >= eY[ep]-25.0) And (bY <= eY[ep]+25.0)) Then
    Return ep
    Endif
    
  4. 4. Now, close off the first If check and the FOR loop. Then, return -1, so we can see that no paddle...

Time for action — acting on the different game modes


The last thing to add is the need to act to the game modes. We have three modes:

  • 0=Start of game

  • 1=Gameplay

  • 2=GameOver

We want to direct and inform the player about what mode the game is in and how they can start it. Then if the victory conditions are achieved, we want to give a visual response.

  1. 1. The first mode is bound to a new method that we will create now. Create a new method called StartGame.

    Method StartGame:Int()
    
  2. 2. We want to print a message only once; that is why we need the field modeMessage. If it is 0, then we can print this message. If we don't use such an approach, the message will be printed every time we call this method.

    If modeMEssage = 0 Then
    
  3. 3. Now set messageMode to 1 and print a message:

    modeMessage = 1
    Print ("Press P to start the game")
    Endif
    
  4. 4. In this method, we will also check if the P key was hit and set messageMode and gameMode accordingly.

    If KeyHit(KEY_P) Then
    modeMessage = 0
    gameMode = 1 'mode = Game playing...

Exporting your game as an HTML5 website


Everytime you let your code run by pressing Ctrl + R on Windows or cmd + R on OSX, you have built all the files that are needed to run your code from a web server. In the folder of your project, Monkey has created a build folder. Inside this folder, you will find an HTML5 folder with all translated HTML5 and JavaScript files and a data folder containing your resources.

If you want to run your game from a web space, all you need to do is copy and transfer all the content of the HTML5 folder to your web space. The web address for your game could look like this: http://www.yourdomain.com/MonkeyGame.html.

Remember that to play HTML5 games on your browser, you need one that supports HTML5!

One more thing... comment your code!


Well, we are not at a presentation show of the next big thing from a fruity computer company, but this is very important! As you might have noticed already, we have commented the code in Pongo a lot. Some will say that you only need to add comments to your code when you show it to other people. Other people say that it will also help you to understand your own code, later on.

Imagine finishing a piece of code, and then after several months, having to look at it again and make important changes or fix a nasty bug. Without comments, it could become very difficult to do, even for yourself on your own code. A well-commented source code is much easier to understand.

And remember the two different methods to comment code in Monkey:

  • Single-line comments, such as:

    'This is a single line comment
    
  • And multi-line comments, such as:

    #rem
    This is
    a multi line
    comment!
    #end
    

So, make it a habit to comment your code. One day you will thank yourself for it!

Summary


We covered quite a few Monkey basics here and also programmed our first little game, Pongo. So what did we learn about exactly in this chapter?

  • We opened Monk, the code editor, and learned how to create a project. This is something you will use very often, later on.

  • While we created our first script, we learned how to print messages into the browser during the development of our first game, Pongo.

  • We learned how to read input from the keyboard and draw basic shapes, such as circles and rectangles.

  • In Pongo, we created a very simple computer AI and used a simple algorithm to check for collisions.

Now you know quite a few things about Monkey. But do yourself a favour; also study the documentation of Monkey, and study the sample scripts in the bananas folder. They are a fountain of information.

Next stop, next game!

Left arrow icon Right arrow icon

Key benefits

  • Create eight fun 2d games.
  • Understand how to structure your code, your data structures and how to set up the control flow of a modern 2D game
  • Learn how to deploy your games to iOS, Android, XNA (Xbox, Windows Phone 7) and desktop platforms (Windows, OSX)

Description

Monkey is a programming language and toolset that allows its user to develop modern 2D games easily for mobile and other platforms like iOS, Android, HTML5, FLASH, OSX, Windows and XNA. With Monkey you can create best selling games in a matter of weeks, instead of months.Monkey Game Development Beginner's Guide provides easy-to-follow step by step instructions on how to create eight different 2D games and how to deploy them to various platforms and markets. Learning about the structure of Monkey and how everything works together you will quickly create eight classical games and publish them to the modern app markets. Throughout the book you will learn important game development techniques like collision detection, handling player input with mouse, keyboard or touch events and creating challenging computer AI. The author explains how to emit particle effects, play sound and music files, use sprite sheets, load or save high-score tables and handle different device resolutions. Finally you will learn how to monetize your games so you can generate revenue.

Who is this book for?

Do you want to quickly create games deployable to all the major desktop and mobile platforms?, if so look no further. You will learn how to utilize the highly versatile Monkey compiler to create 2d games deployable almost anywhere.

What you will learn

  • Implement collision detection and optimize it for mobile devices
  • Handle game controls via touch, keyboard, mouse and accelerometer input
  • Load and playback sound effects and music
  • Sign your applications and publish them to different markets
  • Use 3rd party modules like the fantomEngine game framework to speed up your game development process
  • Store the data of your different game objects effectively in lists, stacks and classes
  • Structure your monkey script into separate objects and files so your code is better maintainable
  • Save and load application states and load level data from text files
Estimated delivery fee Deliver to United States

Economy delivery 10 - 13 business days

Free $6.95

Premium delivery 6 - 9 business days

$21.95
(Includes tracking information)

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Apr 20, 2012
Length: 402 pages
Edition : 1st
Language : English
ISBN-13 : 9781849692038
Languages :
Concepts :

What do you get with Print?

Product feature icon Instant access to your digital copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Redeem a companion digital copy on all Print orders
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Estimated delivery fee Deliver to United States

Economy delivery 10 - 13 business days

Free $6.95

Premium delivery 6 - 9 business days

$21.95
(Includes tracking information)

Product Details

Publication date : Apr 20, 2012
Length: 402 pages
Edition : 1st
Language : English
ISBN-13 : 9781849692038
Languages :
Concepts :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $80.97 $91.97 $11.00 saved
Corona SDK Mobile Game Development: Beginner's Guide
$54.99
Responsive Web Design with HTML5 and CSS3
$43.99
Monkey Game Development: Beginner's Guide
$54.99
Total $80.97$91.97 $11.00 saved Stars icon

Table of Contents

10 Chapters
Monkey—Huh? Chevron down icon Chevron up icon
Getting to Know your Monkey—a Trip to the Zoo Chevron down icon Chevron up icon
Game #2, Rocket Commander Chevron down icon Chevron up icon
Game #2, Rocket Commander
The game objects
The basic file structure
Time for action — building the basic file structure of the game
Hold that data—RocketCommander's data structure
Time for action — creating the general data structure of the game
Detailing the Update process
Time for action — detailing the Update process
Detailing the Render process
Time for action — detailing the Render event
Enhancing the OnCreate event
Time for action — detailing the OnCreate process
Let's build some cities
Time for action — building some cities
Time for action — changing the gameClasses file
Time for action — spawning some cities in the game
Time for action — rendering the cities
Get the launchers ready!
Time for action — implementing the rocket launchers
Time for action — changing the gameClasses file again
Time for action — creating some launchers in the game
Time for action — updating the launchers
Time for action — modifying the menu update process
Time for action — rendering the launchers
Fire! Blast them to pieces!
Time for action — implementing some rockets
Time for action — modifying the gameClasses file
Time for action — modifying the launcher class
Time for action — updating the rockets
Time for action — rendering the rockets
And it goes BOOM!... Explosions
Time for action — implementing explosions
Time for action — modifying the gameClasses file
Time for action — modifying the rocket class
Time for action — updating the explosions
Time for action — rendering the explosions
Don't fear the enemy—bombs
Time for action — creating the bomb class
Time for action — modifying the gameClasses file
Time for action — updating the bombs
Time for action — rendering the bombs
Time for action — modifying the UpdateGame method
Displaying the game score
Time for action — displaying the game score
Summary
Game #3, CometCrusher Chevron down icon Chevron up icon
Game #3, CometCrusher
Using a game framework—the fantomEngine
Game resources
The game objects
The basic file structure
Time for action — create the main source file and its folders
Open the storage please—the data structure of CometCrusher
Time for action — creating the data structure
First changes to the OnCreate method
Time for action — modifying the OnCreate method
Detailing the Render process
Time for action — detailing the OnRender method
This is a setup—creating the game objects
Time for action — creating some layers
Time for action — implementing some stars
Time for action — setting up the player ship
Time for action — creating a method to load sounds
Time for action — creating some game info text objects
Time for action — adding a title screen
Time for action — setting up the high score list
Time for action — create a comet
Time for action — creating some comets
Time for action — finalizing the OnCreate method
We need help—more methods for the Update process
Time for action — loading a high score list
Time for action — showing the high score list
Time for action — the ActivateShield method
Time for action — determine the time delta
Time for action — updating the info text
Time for action — creating a StartNewGame method
Time for action — spawning some engine particle FX
Time for action — creating some explosions
Time for action — spawning some shots
Time for action — saving the high score list
Finalizing the OnUpdate method
Time for action — finalizing the OnUpdate method
Bring in the action—shaping the engine class
Time for action — detailing the collision detection
Time for action — detailing the OnObjectTimer method
Time for action — detailing the OnObjectUpdate method
Time for action — detailing the OnLayerUpdate method
One last thing—creating a FLASH game
Summary
Game #4, Chain Reaction Chevron down icon Chevron up icon
Game #4, Chain Reaction
Modifying the HTML5 canvas size
Time for action — modifying canvas size
Some development basics
Game resources
Game objects
The basic app structure
Time for action — creating the main source file and its folders
The data storage
Time for action — creating the data structure
First changes to the OnCreate event
Time for action — first changes to the OnCreate method
Detailing the OnRender event
Time for action — detailing the OnRender method
Setting up the game objects
Time for action — loading the game sound effects
Time for action — creating layers for the game
Game screen
Time for action — creating buttons
Time for action — creating info text objects
Time for action — composing the game screen
Time for action — creating the title screen
Finalizing the OnCreate event
Time for action — finalizing the OnCreate method
Helper functions for the update process
Time for action — creating collision circles
Time for action — creating the atom elements
Time for action — creating a StartNewGame method
Time for action — implementing the GetDeltaTime method
Time for action — creating a method to update the text information
Detailing the OnUpdate event
Time for action — finalizing the OnUpdate method
Introducing the OnSuspend event
Time for action — modifying the OnSuspend event
Introducing the OnResume event
Time for action — updating the OnResume method
The heart of the game - the engine class
Time for action — enhancing the OnObjectTouch method
Time for action — detailing the OnObjectTransition method
Time for action — acting on timer events
Time for action — detailing the collision detection
Creating an Android app
Summary
Game #5, Balls Out! Chevron down icon Chevron up icon
Game #5, Balls Out!
Which frameworks and modules are used?
Game resources
Our lovely game objects
The basic app structure
Time for action — creating the basic file structure
Modifying the HTML5 canvas size for testing
Time for action — modifying the HTML5 output
The data storage
Time for action — creating the data structure
First changes to the OnCreate event
Time for action — first changes to the OnCreate method
Detailing the OnRender event
Time for action — detailing the OnRender method
Setting up the game objects
Time for action — loading the game sound effects
Time for action — creating layers for the game
Time for action — creating text buttons
Time for action — composing the game screen
Time for action — creating the title screen
Finalizing the OnCreate event
Time for action — finalizing the OnCreate method
Helper methods for the update process
Time for action — creating the tiles
Time for action — creating the ball
The bad guys—our beloved enemies
Time for action — creating the enemy class
More helper functions
Time for action — spawning an enemy
Time for action — creating a StartNewGame method
Bring me up-to-date—detailing the OnUpdate event
Time for action — detailing the OnUpdate method
Eye candy—particle effects
Time for action — creating the particle emitter class
Time for action — spawning a particle emitter
The heart of the game—the engine class
Time for action — enhancing the OnObjectTouch method
Time for action — acting on object update events
Time for action — acting on layer update events
Time for action — detailing the OnObjectTransition method
Time for action — detailing the collision detection
Creating an iOS app
Summary
Game #6, At The Docks Chevron down icon Chevron up icon
Game #7, Air Dogs 1942 Chevron down icon Chevron up icon
Game #7, Air Dogs 1942
Frameworks and modules used
No silver, no gold, but… our game resources!
The game objects
The basic app structure
Time for action — setting up the basic file structure
Storing data
Time for action — creating the data structure
First changes to the OnCreate event
Time for action — first changes to the OnCreate method
Setting up the game objects
Time for action — loading the game sound effects
Time for action — creating layers for the game
Time for action — composing the background screen
Time for action — creating the clouds
Time for action — creating info text objects
Time for action — creating the title screen
Finalizing the OnCreate event
Time for action — finalizing the OnCreate method
Methods for the update process
Time for action — spawning the player plane
Time for action — spawning an enemy plane
Time for action — creating a StartNewGame method
Detailing the OnUpdate event
Time for action — detailing the OnUpdate method
Making it look nicer—some particle effects
Time for action — emitting the smoke
Time for action — creating the explosion
Time for action — spawning a shot
The brain—Computer AI (Artificial Intelligence)
Time for action — following the player
The heart of the game—the engine class
Time for action — enhancing the OnObjectTimer method
Time for action — detailing the OnObjectTransition method
Time for action — acting on object update events
Time for action — detailing the collision response
Time for action — acting of layer update events
Creating a GLFW app
Summary
Game #8, Treasure Chest Chevron down icon Chevron up icon
Game #8, Treasure Chest
Frameworks and modules used
Reusing code
The parts of the game... resources
And here they are… the game objects!
Preparation… the basic app and project structure
Time for action — creating the basic file structure
Creating 2D arrays
Time for action — creating 2D arrays
Storing information… the data storage
Time for action — creating the data structure
First changes to the OnCreate event
Time for action — first changes to the OnCreate method
About the OnRender event
Setting up the game objects
Time for action — loading the game sound effects
Time for action — creating layers for the game
Time for action — composing the background screen
Time for action — creating the title screen
Time for action — creating the "game over" screen
The menu please… creating the menu screen
Time for action — creating text buttons
Time for action — creating the menu screen
Time for action — creating the score screen
Time for action — creating the activate layer method
Finalizing the OnCreate event
Time for action — finalizing the OnCreate method
Dealing with the high-score list
Time for action — loading and saving the high-score list
Time for action — showing the high-score list
Managing the tile map
Time for action — getting tile slot IDs
Time for action — setting a tile slot ID
Check/mark the neighboring tiles
Time for action — checking neighboring horizontal tiles
Time for action — check neighboring vertical tiles
Time for action — clearing the tile map
Time for action — counting matching tiles
Time for action — creating a gem
Time for action — refilling the tile map
Methods for the update process
Time for action — creating a StartNewGame method
Time for action — updating the text info
Time for action — showing the "game over" screen
Time for action — showing the menu
Bring me up-to-date—detailing the OnUpdate event
Time for action — detailing the OnUpdate method
Vroom… vroom—the engine class
Eye candy—particle effects
Time for action — spawning an explosion
Time for action — acting on object timer events
Time for action — enhancing the OnObjectTouch method
Time for action — detailing the OnObjectTransition method
Time for action — acting on layer update events
Summary
Make Some Money for Bananas Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.5
(8 Ratings)
5 star 50%
4 star 50%
3 star 0%
2 star 0%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by




Doug warner Aug 08, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This is actually a very well written book. I found it very useful. this also seem to be the only book I could find on monkey coding, so it also got that going for it.
Amazon Verified review Amazon
TheGreatestAdventurer Sep 25, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Great book for beginner programmers. Concentrates on programming simple games so that the student can see their work. Includes step-by-step programming for 8 games. Chapter 10 discusses how to monetize your games. Over all a great book for would be game and app programmers. Monkey X also has a friendly online community. www.monkey-x.com
Amazon Verified review Amazon
P. Robson Mar 30, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This is a really good book - it is well written, the examples are well thought out, there aren't many errors and most of them are minor. The author has a clue how to program properly (an awful lot of people who write these sorts of books don't) ; it encourages good practice - comments, meaningful names, classes, encapsulation and so on pretty much from the start. Very early on for example it emphasises the importance of putting a proper header on your code files.What it isn't is a beginners guide. It's a beginners guide to Monkey, yes, but if you can't program you will struggle very fast. The introduction is very gentle, shows very basic Hello World examples. The first application (Pong) is followable, just if you aren't a coder. It does use classes and so on but they aren't really intrinsic to the application.The second example, Rocket Commander, explodes in complexity. You create three files with an application class subclassed from an App parent. There's a finite state machine. Things are divided into objects, methods and so on. The explanations of these things are quite good but necessarily brief, otherwise the book would be ten times as long. If you know what these things are, or have some idea, you'll be fine but a beginner to programming would be thrown at this point. What is a class ? What is a finite state machine ? How does this all work ?This isn't a criticism of the book per se - as a way of learning how to code in Monkey it seems, so far, to be really good. It's a worthwhile read for those who can already program in Monkey as well, I think, there seems to be lots of good ideas there. But don't buy it if you don't have some idea how to program, know a little bit about objects and classes and so on.So with that caveat, the book is strongly recommended. As is Monkey :)
Amazon Verified review Amazon
Snader May 09, 2012
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Although I'm am not a beginner at programming for Monkey ([...]), I wanted a book to see some complete programs (simple games) or examples of how these are made from the beginning. This book is great for me. The spare time that I have went mostly in exploring the monkeycoder forums, looking for answers. Now I can easily read this book from beginning to end and I can make everything I want.The author of the book is very active on the monkeycoder forums. So, If you have a question, or something has changed in the newest Monkey versions, he is always willing to help! Great stuff!
Amazon Verified review Amazon
Julio cesar Jun 11, 2012
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
If you want to start as a game developer and get your game in every mobile/not mobile platform with a little effort, this is your book.Here you can get great examples and it's very easy to learn, the language is something like basic, so it's not that hard to code.I don't give it 5 stars because this book teaches you how to use an engine and I would prefer to learn how to make my own, but if this book's objective is to learn make games, then it's achieved.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is the digital copy I get with my Print order? Chevron down icon Chevron up icon

When you buy any Print edition of our Books, you can redeem (for free) the eBook edition of the Print Book you’ve purchased. This gives you instant access to your book when you make an order via PDF, EPUB or our online Reader experience.

What is the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact customercare@packt.com with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at customercare@packt.com using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on customercare@packt.com with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on customercare@packt.com within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on customercare@packt.com who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on customercare@packt.com within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela