Pickups are game objects like collectibles that the rules of your game might require your player to collect to finish a level.
We are basically going to add a new sprite object, have it destroyed when PlayerBox collides with it (go "through" it) and add score to a global variable we will want to display on screen at all time.
First, let's add a new sprite object, and import the PNG\Items\yellowJewel.png file from the Abstract Platformer pack.
You can now close the Animation Editor.
In the Properties tab, rename this new object to Pickup.
Add the Sine behavior to it.
The Sine behavior can adjust an object's properties (like its position, size or angle) back and forth according to an oscillating sine wave.
In our game, we add it to the Pickup object, in order to have the pickup "float" above ground in a vertical movement over several pixels.
In the properties of the behavior, change its Movement property from Horizontal to Vertical in order for us to have the jewel going up and down as if it was floating above ground.
Modify the Magnitude property to 8. This means the movement will happen over 8 pixels to the top and 8 pixels to the bottom, a total of 16 pixels.
Modify the Period property to 1. This means the movement will happen over 1 second of time (instead of the original 4), making it far quicker.
You can modify those values according to your liking and specificities of your game.
You can now create instances (hold down the ctrl of your keyboard and drag drop an instance to create a copy of it) of the Pickup object and place them over platforms in your level.
Now we will want to display a score and raise this score each time the PlayerBox object collides with a Pickup.
To do so, and in the limits of the free edition, we are going to reuse the PlayerLayer layer and modify it to display some text object.
We will want to move the various objects which are on this layer to the Platforms layer.
In the Project bar, select EdgeMarker. This selects all the instances of the object at once. In the Properties bar, modify the value of the property Layer from PlayerLayer to Platforms.
Do the same for the objects PlayerBox, PlayerAnim, Enemy and Pickup.
Now your layer PlayerLayer has no objects on it.
Make sure to select it and rename it to HUD. (This is short for Heads-Up Display.)
When it is selected, insert an object on it.
Select the Text object an position it in the dashed area that represents our viewport.
Rename the Text object to txtScore.
Select the HUD layer and check its properties in the Properties bar.
Set the property Parallax to 0,0.
This makes the layer HUD "fixed", and in addition with the Scroll To behavior that is on the PlayerBox object, will make it so that the txtScore object is always visible on screen.
Now we want to display some score in that text object. Go into the Event Sheet view.
Right-click in the space around the events and select Add Global Variable.
This creates a new global variable for use to use. Name the variable Score.
Once done, in the first event in the event sheet, the one with the condition Every Tick, add a new action.
Select the txtScore object and select the Set text action.
In the field Text, type : "Score : " & score
This is an example that allows you to display some regular text ("Score :") and display the content of a variable as well (here our score variable).
& is there to combine the written text (everything in between quotes " ") and other values, in this case our variable score.
This process is called concatenation.
Now let's add an event to destroy Pickup and add some points to our score.
Add a new event, PlayerBox -> On collision with another object - Pickup.
Add an action Pickup -> Destroy (category Misc.)
Add an action System -> Add to (category Global & local variable)
Select the variable Score from the dropdown list if it is not already selected. Set the Value text field to 10.
The resulting event should look something like :
Preview the game.
Pickup now disappear when your character walks on them, and the Score is displayed in the top left corner, modified each time you walk through a Pickup.
We're finished with our small game for now.