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

Grid


The first thing we're going to do is to display a grid of tiles that will be our playground. Just to start with, we'll display the back of the tiles.

Tilemaps

A commonly used technique in game development is the implementation of tilesets.

The idea is to create one image that includes more than one asset in it.

We're going to create a tileset called tiles.png. It consists of 12 tiles, 11 different colors (the gray one for the back of the tiles), and the "empty tile" (white). It looks somewhat like the following:

You should be aware that what we're going to do is to create a tiled image that will be indexed as follows:

This is the result of subdividing the actual image in two rows and six columns. We'll end up having twelve 62 x 62 tiles.

The implementation

Let's start with the implementation:

  1. We need to create a file called game.lua that will hold all of the code for our gameplay.

  2. Open it and let's begin coding.

    module("Game", package.seeall)
    GRID_COLS = 5
    GRID_ROWS = 4
    GRID_TILE_WIDTH = 62
    GRID_TILE_HEIGHT...