Book Image

Monkey Game Development: Beginner's Guide

By : Michael Hartlef
Book Image

Monkey Game Development: Beginner's Guide

By: Michael Hartlef

Overview of this book

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.
Table of Contents (16 chapters)
Monkey Game Development
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
3
Game #2, Rocket Commander
4
Game #3, CometCrusher
5
Game #4, Chain Reaction
6
Game #5, Balls Out!
8
Game #7, Air Dogs 1942
9
Game #8, Treasure Chest

Time for action — spawning the player plane


We need a method that will make the player plane appear. The plane should appear on the left side of the screen, facing upwards. Like the clouds, the plane will wrap around the screen once it moves over the screen edges.

  1. 1. Add a new method called SpawnPlayer to the class game.

    Method SpawnPlayer:Int ()
    
  2. 2. Store the reference to the player plane object inside its corresponding field.

    player = eng.CreateImage(atlas,0,0,64,64,cw/4,ch/2)
    
  3. 3. Scale it down to a factor of 0.7 and set the speed of the plane to 8.

    player.SetScale(0.7)
    player.SetSpeed(8)
    
  4. 4. The player should wrap around the screen.

    player.SetWrapScreen(True)
    
  5. 5. For collision detection, set the collision group to grpPlayer and the radius to 24 pixels. As the plane is already scaled down, the actual radius will be stored as 24 times 0.7.

    player.SetColGroup(grpPlayer)
    player.SetRadius(24)
    
  6. 6. Reset the hit points to 0. Then, close the method.

    hits=0
    Return 0
    End
    

What just happened?

Using the SpawnPlayer...