I would like to create a game where you have three lives. And after the third life, you die and the game restarts. But I did not find any kind of instruction to this topic and I am not even sure if this is possible to do in cospaces. So, if you are able to do this can somebody please help me. Also, I am a beginner, so if possible I need a detailed and “easy” instruction how to code.
To keep track of lives you use a variable value that decreases when a condition is met. Below is step-by-step guide, but feel free to check out the CoBlocks Basic Tutorial, too
In this space we want our character to lose a live when colliding against a cactus
First, we create the cactus - items and add them to CoBlocks. Then we open the Code Editor and select CoBlocks
Let’s create a variable called
myLives. We set its value to
Now we need to create an event handler that does something whenever the cactus collides with the camera (make sure to add the camera to CoBlocks, too!). In this case we change (or subtract)
-1 from our
Finally, we add an
if-statement to check when the
myLives variable reached
0. If it does, we switch to another scene called “Restart”. In that “Restart” - scene, you can place a single block to move back to the starting scene.
Now we can test our code! Press Play and open the CoBlocks debugger to see your code in action!
That’s it! I added a remixable space below, if you want to check out how to continue from here
Thank you very much. I hope this will help me.
How to make the lives go down and at the same time restart the scene
You can check out this tutorial or use the “Parkour game template” when creating a new CoSpace as a base for your game.
I hope that helps!
That video really needs renaming, @Simon - I would never have guessed it contained a tutorial from the name and thumbnail; in fact I’ve never watched any of those videos, purely for that reason - they look like a marketing videos.
I suggest “Make a Game in CoSpaces Edu” or similar.
Geoff @ TechLeap
Thank you for your feedback, @techleapnz!
I will bring this up to the team.