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

Gameplay


Now let's take a look at what we need in order to implement the gameplay. First of all, we need to create all of the structures (and initialize them) for the game state. We'll be using another grid, this time to store a randomized distribution of numbers.

Initialization

  1. Add a call at the bottom of the Game:initialize () method to an auxiliary function.

      self:restartGamePlay ()
  2. Add the auxiliary function as well.

    function Game:restartGamePlay ()
      self.distributionGrid = MOAIGrid.new ()
      self.distributionGrid:setSize (GRID_COLS, GRID_ROWS)
    1. First, we create a grid that will hold the distribution of our colors. This grid also has a dimension of 5 x 4. Note that we don't need to set the tile size now as this grid won't be rendered.

        local tiles = {
          2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 
          7, 7, 8, 8, 9, 9, 10, 10, 11, 11
        }
    2. This table is just a temporary array of tiles; as you see, we start from 2 (1 is the back tile, remember?) and repeat each number twice. These numbers represent the color...