Inside the OnObjectCollision
method, we will remove tiles, and the ball, and will spawn some particle effects:
obj2
is equal to grpEnemy
. That means the ball collided with the enemy:Method OnObjectCollision:Int(obj1:ftObject, obj2:ftObject) If obj2.GetColGroup() = g.grpEnemy Then
obj1
, the ball:obj1.Remove()
300
milliseconds and a kind
flag of 1:
g.SpawnEmitter(obj1.GetPosX(), obj1.GetPosY(), 300,1)
g.sndExplo.Play()
lifes
variable of the game
class:g.lifes -= 1
g.CreateBall() Endif
This was the check against enemy collisions. Now, we handle the tile set.
obj2
is equal to grpTile:
If obj2.GetColGroup() = g.grpTile Then
We will do a very simple collision resolution. This means we will determine the angle from the ball to the tile and then calculate a new angle by adding 180 degrees to it.
ca:
Local ca:Float = obj.GetSpeedAngle() + obj.GetTargetAngle(obj2) + 180.0
obj.SetSpeedAngle(ca)
g.score += (10 * g.levelNum)
obj2.Remove()
200
milliseconds:g.SpawnEmitter(obj2.GetPosX(), obj2.GetPosY(), 200)
obj.AddSpeed(5)
g.tileCount -= 1
IF
check:g.sndHit.Play() Endif Return 0 End
By adding the handling of the collision events, we have finished the game in this chapter. When the ball hits the enemy, it will be destroyed and the lives left will be reduced. If the ball hits a tile, the tile will be destroyed and the game score will be rise. And both events, particle emitters will be spawned and a explosion sound will be played.
Now that you have done your homework, it is time to become a hero. There is still a lot that you can do to make the game more exciting:
You see, there is so much to add. Go ahead and become a hero!