CreatePlayer
to the game class.Method CreatePlayer:Int()
CreateImage
with our texture atlas. The positioning doesn't matter because we will do this later on.player = eng.CreateImage(atlas,0,0,32,32, 0,0)
player.SetFriction(0.2) player.SetMaxSpeed(20.0)
True
via SetWrapScreen
.player.SetWrapScreen(True)
layerGame
.player.SetLayer(layerGame)
grpPlayer
) so that it can actually collide with comets set grpComets
. The radius of the circle collision detection will be set to 12
pixels.player.SetColGroup(grpPlayer) player.SetColWith(grpComet, True) player.SetRadius(12)
player.SetActive(False)
We now need to create the shield that protects the ship. The process of creation is similar to that of the player ship.
shield = eng.CreateImage(atlas,32,96,32,32,0,0)
shield.SetScale(2.0) shield.SetSpin(15) shield.SetLayer(layerGame)
shield.SetParent(player)
13
pixels.shield.SetColGroup(grpShield) shield.SetColWith(grpComet, True) shield.SetRadius(13)
shield.SetActive(False) Return 0 End
With the method CreatePlayer
, you set up your ship in one go. It is always good to separate code in methods or functions, as it makes the code more readable.
Our little game will feature two sound effects. One for a shot and one for an explosion. The nice thing is that you can create the code for loading the sounds to be format independent. fantomEngine will automatically choose the correct format depending on the platform. For HTML5, the best format so far is OGG, and for a FLASH game, it is MP3. To load the sounds, we will create a new method called LoadSounds
.