In this method, we will check whether certain keys are hit on the keyboard. This is to turn the plane or change its speed. Also, we make sure that the player can shoot bullets himself and spawn some smoke if the planes are hit. And finally, we make the enemy plane follow the player.
OnObjectUpdate
method, check whether the object is equal to g.player
.Method OnObjectUpdate:Int(obj:ftObject) If obj = g.player Then
8.0
.obj.SetSpeed(8.0)
If KeyDown(KEY_LEFT) Then obj.SetAngle(-g.eng.GetDeltaTime()/16.0,True)
If KeyDown(KEY_RIGHT) Then obj.SetAngle(g.eng.GetDeltaTime()/16.0,True)
10
.If KeyDown(KEY_UP) Then obj.SetSpeed(10.0)
6.0
.If KeyDown(KEY_DOWN) Then obj.SetSpeed(6.0)
If KeyHit(KEY_S) Then g.SpawnShot(obj)
If g.hits > 0 Then g.SpawnSmoke(obj, g.hits) Endif
g.enemy
.If obj = g.enemy Then
FollowPlayer(obj)
If g.hitsC > 0 Then g.SpawnSmoke(obj, g.hitsC) Endif Return 0 End
Yes, we can finally control the player plane and the enemy plane will now follow the player plane and try to shoot at it. Build and run the game, and see for yourself.