Book Image

Developing Mobile Games with Moai SDK

By : Francisco Tufró
Book Image

Developing Mobile Games with Moai SDK

By: Francisco Tufró

Overview of this book

<p>Moai SDK is a fast, minimalist, open-source Lua mobile framework for pro game developers. Moai is built around Lua, a common programming language for games, and offers a single open-source platform for both the front-end elements seen by consumers and the back-end infrastructure.<br /><br />Developing Mobile Games with Moai SDK will guide you through the creation of two game prototypes in a step-by-step way, giving you the basic tools you need in order to create your own games.<br /><br />Developing Mobile Games with Moai SDK introduces the basic concepts behind game development, and takes you through the development of a tile-based memotest, and a platform game prototype as well. You'll end up with a good codebase to start writing your own games.</p> <p>You will learn some tricks that come from real life experience while creating a small framework that will allow you to display images, play sounds, grab input, and so on. You'll also learn how to implement physics using Box2D bindings, and everything in Lua, without having to use any compilations. After doing this, we'll take a look at how to deploy your game to iOS and run it on an iPhone.</p> <p><br />With this book, you should be ready to go and create your own game, release it to the Apple Store, and have enough tools to dig deeper into Moai SDK.</p>
Table of Contents (20 chapters)
Developing Mobile Games with Moai SDK
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
7
Concentration Gameplay
Index

Creating the world


The first step is to create the world that will be in charge of the physics simulation by following the given steps:

  1. Create a file called physics_manager.lua and require it from game.lua.

  2. Now let's build the PhysicsManager module.

    module ( "PhysicsManager", package.seeall )
    function PhysicsManager:initialize ( layer )
    1. The first step is to create the MOAIBox2DWorld object. This will take care of talking to Box2D from Moai SDK.

              self.world = MOAIBox2DWorld.new ()
    2. Then, we need to set up our scale. What we're doing here is saying that one meter on the simulation is equivalent to 38 points in our world coordinates. Since we're using a main character sprite that is 64 points tall, we can say that our character could be about 1.67 meters tall. So, 65 / 1.67 is about 38. That's the calculation needed in order to find that scale.

              self.world:setUnitsToMeters ( 1/38 )

      Tip

      Box2D works better on simulations that contain bodies that go from 0.1 to 10 meters, so take that into...