As it can be destroyed by the enemy, we will wrap up its creation inside its own method. That makes this process reusable.
CreateBall
into our game
class.Method CreateBall:Int ()
CreateImage
method. It will be placed in the lower center of the canvas:ball = eng.CreateImage(atlas,64,0,32,32,cw/2,ch-50)
ball.SetRadius(16) ball.SetScale(1.5)
ball.SetFriction(0.8)
ball.SetLayer(layerGame)
grpBall
, so that it can collide with the enemies and the tiles:ball.SetColGroup(grpBall) ball.SetColWith(grpEnemy, True) ball.SetColWith(grpTile, True)
20
, and close the method off:ball.SetMaxSpeed(20) Return 0 End
We have created a reusable method to create a ball whenever we need one. Fancy several player balls? Not at the moment, but it could be an enhancement that you could add on your own.
You know what would be cool? Having the player control several balls at the same time. You could do this in different ways, either by modifying the preceding method to create several balls at different positions, or make this method flexible regarding its position and once you call it, give the position with the call.