Every game needs an objective. In our game, the hero needs to the top of the platforms to reach the flashing star.
We don't have a star asset, so I've provided one below:
Right and click this image and save it as “star.png” in the data/object folder.
Create a object section for this star and position it at the top right hand platform:
[StarGraphic] Texture = star.png [StarObject] Graphic = StarGraphic Position = (690, 40, 0)
Add the star to the Scene section's child list so that it is created when the platforms are:
[Scene] ChildList = PlatformObject # MiddlePlatformObject # TopLeftPlatformObject # TopPlatformObject # TopRightPlatformObject # StarObject
Run the game and you will have a star in the top right hand corner:
It will be nice if the star pulses colour and slowly turns. We can use two FXSlot sections for this:
[StarFlashSlotFX] Type = hsv Curve = smoother StartTime = 0 EndTime = 1 StartValue = (0,255,255) EndValue = (255,255,255) [StarRotateSlotFX] Type = rotation Curve = linear StartTime = 0 EndTime = 2 StartValue = 0 EndValue = 359
Now group the two slots under one FX section:
[StarFX] SlotList = StarFlashSlotFX # StarRotateSlotFX KeepInCache = true Loop = true
The FX section will be in charge of ensuring they stay in memory and that they both loop.
Add the FX to the StarObject:
[StarObject] Graphic = StarGraphic Position = (690, 40, 0) FXList = StarFX
Cool. Run that and the star should turn and flash.
The only problem is that the turning pivot for the star is a little off. Fix that on the StarGraphic:
[StarGraphic] Texture = star.png Pivot = center
Run that. And it will turn nicely.
One more tweak: As the sprite is turning, there are some jaggies, smooth them out my applying smoothing to the StarObject:
[StarObject] Graphic = StarGraphic Position = (690, 40, 0) FXList = StarFX Smoothing = true
Run that and you should get:
Great! Next, is to make the hero collide with the star in order to win the game.
The star object will need a static body, with a solid body part:
[StarBody] Dynamic = false PartList = StarBodyPart [StarBodyPart] Type = box Solid = true SelfFlags = star CheckMask = hero
And add the body to the StarObject:
[StarObject] Graphic = StarGraphic Position = (690, 40, 0) FXList = StarFX Smoothing = true Body = StarBody
We've also declared flags to make sure that we only care if the star collides with the hero and nothing else.
We will set that collision up in a moment.