O'Reilly logo

Monkey Game Development by Michael Hartlef

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action — getting tile slot IDs

To get tile slot IDs we will create the GetSlotX And GetSlotY methods, as follows:

  1. First add the method GetSlotX into the game class with a parameter of the type ftObject.
    Method GetSlotX:Int(obj:ftObject)
    
  2. Store the x position of the object. It is divided by its width and stored in the local variable xp with the type INT.
    Local xp:Int = obj.GetPosX()/obj.GetWidth()
    
  3. Return xp and close the method.
    Return xp
    End
    
  4. Next, add the method GetSlotY to the game class.
    Method GetSlotY:Int(obj:ftObject)
    
  5. Store the y position of the object. It is divided by its width and stored in the local variable yp with the type INT.
    Local yp:Int = obj.GetPosY()/obj.GetHeight()
    
  6. Return yp and close this method.
    Return yp
    End
    

What just happened? ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required