The OnObjectCollision
method has two parameters. The first object is the one that actually checks against a collision with the second object. To identify an object, we will compare against its collision group field, collGroup
.
i
to the OnObjectCollision
method.Method OnObjectCollision:Int(obj:ftObject, obj2:ftObject) Local i:Int
collGroup
field of the second object is g.grpComet
. As this is a constant from the game
class, we need to add the prefix g
. which stores it.If obj2.collGroup = g.grpComet Then
tag
field with the constant comet size g.cmLarge
.If obj2.tag = g.cmLarge Then
15
particles via g.SpawnExplosion
at the position of the first object.g.SpawnExplosion(15,obj.xPos, obj.yPos)
g.cmMiddle
.For i = 1 To 2 g.CreateComet(g.cmMiddle,obj2.xPos, obj2.yPos, Rnd(1,4)/2,Rnd(0,359)) Next
100
points to the game score. Then close the IF check.g.score = g.score + 100 Endif
tag
is equal to g.cmMiddle
. This time create only 10
particles, three small comets, and add 250
points to the game score.If obj2.tag = g.cmMiddle Then g.SpawnExplosion(10,obj.xPos, obj.yPos) For i = 1 To 3 g.CreateComet(g.cmSmall,obj2.xPos, obj2.yPos, Rnd(1,4)/2,Rnd(0,359)) Next g.score = g.score + 250 Endif
tag
field of the second object equals g.cmSmall
. Create only 5
particles and add 500
points to the score. Don't create any new comets.If obj2.tag = g.cmSmall Then g.SpawnExplosion(5,obj.xPos, obj.yPos) g.score = g.score + 500 Endif
1
from g.cometCount
and remove the second object.g.cometCount -= 1 obj2.Remove() Endif
That's all for collision checks against comets. The next stop will be the player shots. Why? Because when they hit a comet they need to be removed too.
collGroup
field of the first object equals g.grpShot
. If yes, then remove it.If obj.collGroup = g.grpShot Then obj.Remove() Endif
Check if the collGroup
field of the first object equals g.grpPlayer
. If yes, subtract 1 from g.lifes.
If obj.collGroup = g.grpPlayer Then g.lifes -= 1 Endif Return 0 End
During a collision, a lot of things happen. Depending on which objects have collided with each other, you have removed them and updated the game score. If a large or medium-sized comet was destroyed, you have also created a set of smaller comets. This gives the illusion that the former comet was blasted into smaller pieces.