On the last card you saw the collectable I created. It’s a star that just adds one point when you grab it. That’s pretty boring.
On this card, you’re going to create a new collectable, but you’re going to do it in a way that makes adding more collectables easy, so you can invent your own powers and bonuses and really make the game your own!
Add a new costume to the “Collectable” sprite for your new power-up. I like the lightning bolt, but pick whatever you like.
Notice that I’ve already included some pieces to make this easier for you with the
collectable-type
variable and thepick costume
more block. You’re going to need to improve on them though.collectable-type
is passed topick-costume
when it’s called, where it becomestype
and can be used inside the more block
First, you need to set the collectable type. It’s just a number, used to tell the program what costume, rules etc. to use for the collectable. You’re going to want to pick it at random, to keep things interesting. This example gives a 1/50 chance:
Pro Tip!
There can be a different value set as the
collectable-type
for each clone. Think of it like creating a new copy of the variable on the main “collectable” sprite with the value that was incollectable-type
the instant that clone was created. One of the things that makes clones special is that they cannot change the values of any variables they start with. They are effectively constant values.Great! Now you’re setting a different value for the collectable type, but none of the code knows what to do with it yet!
First, just teach the
pick-costume
more block to set the new costume when it gets the new type, like this (using whatever costume you picked):Now you need to decide what the powerup will do. We’ll start with something simple: giving the player a new life. On the next card, you’ll make it do something cooler.
To create the powerup code, go into more blocks and Make a Block. Expand the Options section and add a number input. Name the block
react-to-player
and the number inputtype
. Make thereact-to-player
block either give the same points prize that the star is already giving, or increase the player’s lives, depending on thetype
of powerup.Update the
when I start as a clone
code to replace the points increase with a call toreact-to-player
, passingcollectable-type
. Stars still boost points but the new powerup adds lives.