In today's session we're going to be adding Quests!
Quests are tasks or activities set by Non-Player-Characters (NPCs). When the player completes the quest they could be rewarded with Loot or Experience Points.
To take a sneak peak at the new code you can download the final version of Lost in Wale using the link below:
First, we'll need to create an NPC we can talk to. To do this, head to thew Assets tab and create a new Image. This image will be the appearance of our NPC.
With our NPC drawn, we can now create a sprite for them in on start. Use set mySprite to sprite of kind Player to do this.
Make sure however to set the correct image, make a new variable instead of using mySprite, and...
Create a new kind. On the set ____ to kind Player, we can click the drop down to change Player out for something else.
We're going to create a new kind called NPC.
Finally we need to set the position of our NPC. This can be done with set mySprite position to x 0 y 0. This goes in on start underneath the last block we placed.
5. Next we'll add a new on sprite of kind player overlaps otherSprite of kind Player event.
Here it's important to check that the last Player kind is changed to NPC.
6. In this event we need to check if the player is pressing the 'B' button. For that we need an if statement from the Logic panel.
7. In the diamond part of the if we need to add is B button pressed. This is found in the Controller panel.
8. Now we need to perform an extra check to see if the NPC we are next to is the right NPC. This is essential if we have multiple NPCs because otherwise all NPCs would say the same thing.
9. Add this time, an if - else statement, and put it inside if is B button pressed.
10. In the diamond part of this if we will need an Equals Comparrison block. This looks like < 0 = 0 >.
11. We need to check if the sprite we are overlapping currently is the same one that we created in on start.
For this we can grab otherSprite from the top of the event and put it in the left-hand side of the < 0 = 0 >.
The right-hand side should be filled with the variable that represents the NPC we want to talk to (as named in step 2).
12. Finally, in the first part of this if we can get the NPC to speak. This is best done witht the show long text " " bottom. block found in the Game panel.
13. Now we're going to add a new NPC. So again, head to the Assets tab and create a new image for this NPC.
14. This new NPC is different. They're going to unlock a door for the Player. So, whilst we're in the Assets tab, modify your Tilemap to include a door (and maybe a room).
15. Put your mouse over the door. In the bottom left of the editor you should see some numbers separated by a comma. Write these down! We'll need them later.
16. Make sure you add Walls to the room and door to make them solid.
17. Add your new NPCin on start as a sprite using set mySprite to sprite [ ] of kind NPC and set mySprite position to x 0 y 0 exactly as we did in steps 2 and 4.
18. Returning to on sprite of kind Player overlaps otherSprite of kind NPC we can add new logic for what happens with the new NPC. To do this, click the (+) on the inner if (the one that compares otherSprite = myNPC).
19. Do this until we have exactly an else if and an else.
20. Here we can put a new < 0 = 0 > block in the diamond and add otherSprite to the left and the variable for our new NPC on the right.
21. Inside this else if we can add a new if - else that checks to see what level the player is at. This is done with a < 0 < 0 > block and the Level varaible.
22. If the player is below the required level we can show long text to say something about that.
23. However, if the player is above the required level we can show long text again. We can also unlock the door by set [ ] at tilemap col 0 row 0.
This is found in the Scene panel and we should set it to be those numbers we remember when we were drawing the door in step 15.
24. Finally, we also need to disable the solid wall at the same location. This is done with set wall off at tilemap col 0 row 0 from the Scene panel. Again you'll need to put those same numbers in.