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 an enemy plane

Besides using a different image, which is placed and rotated differently, spawning the enemy plane works in a similar way to spawning the player plane.

  1. Add a new method called SpawnEnemy to the game class.
    Method SpawnEnemy:Int ()
    
  2. Assign the image of the plane to the corresponding enemy field.
    enemy = eng.CreateImage(atlas,64,0,64,64,cw/4*3,ch/2)
    
  3. Scale it down to a factor of 0.7.
    enemy.SetScale(0.7)
    
  4. Set its angle to 180 degrees and give it a speed of 8.
    enemy.SetAngle(180)
    enemy.SetSpeed(8)
    
  5. Let the enemy plane wrap around the screen edges.
    enemy.SetWrapScreen(True)
    
  6. For collision detection, set the collision group to grpEnemy and give it a radius of 24.
    enemy.SetColGroup(grpEnemy)
    enemy.SetRadius(24)
    
  7. Reset its ...

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