Today we will be adding some loot into our game. Loot usually refers to all the tools, weapons, potions, keys, and powerups you might pick up in an RPG after defeating enemies. In this session we will be getting enemies to drop a new weapon we can use.
If you want to download a copy of today's code, you can. Alternatively, if MakeCode is NOT working, there is a Scratch project that is similar, but you will have to work out how to do certain things yourself.
Start by adding a new Variable into on start. This variable will store what weapon you're currently holding.
2. Now create a new Asset for a new type of weapon. The one I have created is called Sceptre.
We're going to modify our on destroyed sprite of kind enemy event so that when the Enemy is destroyed, there is a 1 in 3 chance of creating a new weapon sprite at the location of the enemy that was destroyed.
Here the kind has been set to food just because it was spare.
3. We'll need to be able to pick up our new weapon. To do this we're going to bring in an on sprite of kind player overlaps otherSprite of kind food event. Inside this event we will check whether the user is pressing 'B' and is so, change the currentWeapon (the variable we made in part 1).
4. Now we're going to create a new Asset of the player using the new weapon. This means we can see what weapon we currently have.
We're going to update our on 'A' button pressed now so that depending on what weapon we are holding, we'll do a different attack (and player attack image). We're making a Magic Sceptre that fires out magic projectiles, so we'll need to make a new Magic Projectile asset.
5. Finally we can have our Enemy react properly to the projectiles. For this we'll need an on sprite of kind projectile overlaps otherSprite of kind enemy.
In this event we'll have to both destroy the projectile (so it doesn't carry on attacking forever), and damage the enemy.
At the moment, our attacks only work in one direction. To fix this we'll have to keep track of the last direction our player travelled in. We can do this by creating a new variable to store the direction in on start and updating that variable using lots of on __ button pressed events. Then, using an if statement to check which direction has been set, we can fire in different directions.