Time for action — creating the tiles

When we create the set of tiles, we want to place them inside a grid of three lines with five tiles in each. For this, we will create a new method:

  1. Add the method CreateTitles to the game class.
    Method CreateTiles:Int()
    
  2. To reset the tile count, which is needed to determine a new level, we set the variable TileCount to 0.
    TileCount = 0
    
  3. Now create two FOR loops, one for the y position factor from 1 to 3 and one for the x position factor from one to five.
    For Local y:Int = 1 To 3
    For Local x:Int = 1 To 5
    
  4. Create a local object through CreateImage. The position will be calculated as one-sixth of the canvas width times the x factor, and 80 times the y factor, plus 100. This will place the tiles equally over the top part of the screen.
    Local tile:ftObject = eng.CreateImage(atlas,96,0,32,32,cw/6*x,80*y+100)
    
  5. Now, set the radius of the object to 16 pixels and its scale to factor 2.0.
    tile.SetRadius(16)
    tile.SetScale(2.0)
    
  6. Assign it to the game layer.
    tile.SetLayer(layerGame)
    
  7. For collision detection, set its collision group to grpTile and that it will collide with the ball.
    tile.SetColGroup(grpTile)
    tile.SetColWith(grpBall, True)
    
  8. Now, raise the tile count by one.
    tileCount += 1
    
  9. Close both FOR loops and the method itself.
    Next
    Next
    Return 0
    End
    

What just happened?

To automatically create a new set of tiles, we have created a new method. It will be called later on, at the start of a new game, and also when all tiles are destroyed and the game proceeds to a new level.

The main actor—creating the ball

Our main actor, the one we will have control of, is the ball. It won't be controlled by a paddle but by using the device's accelerometer feature. This means that, when you tilt the device in a particular direction, the ball rolls in that direction.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.144.6