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 — spawning some shots

  1. As always, create a new method. This time it is called SpawnPlayerShot.
    Method SpawnPlayerShot:Int()
    
  2. We need to get the position that is 20 pixels in front of the ship. For this, we can use the GetVector method. It needs the distances and the angle from it, which will be the same as the ship's angle.
    Local ds:Float[] = player.GetVector(20, player.angle)
    
  3. Create a local shot image from the sprite atlas.
    Local sht:ftObject = eng.CreateImage(atlas, 0,96,16,16, ds[0],ds[1])
    
  4. Set the angle of the shot to the same as the ship.
    sht.SetAngle(player.angle)
    
  5. Set the maximum speed to 25 and the actual speed to the player speed + 10.
    sht.SetMaxSpeed(25.0)
    sht.SetSpeed(player.speed+10.0)
    
  6. Scale the object down to a half and let ...

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