top of page
Search

Questing

  • seanmcgarry65
  • Mar 17, 2023
  • 5 min read

This week, I finished implementing the leveling system and added the game's first quest.


First, the leveling system levels the player up based on how much experience they've earned. Each enemy in the game is worth a different amount of experience. Once the player levels up, their maximum HP increases, as well as the damage they can do with their sword.


This is an image of the level up effect that is used when the player gains a level. In the game, it is animated as a little triangle that shoots up from the player and explodes into the words 'Level up!'.


There is now text in the UI that shows what level the player is at and how much experience they have. These increase dynamically as the player earns experience and levels.


Every tick, the game adjusts the content of the UI texts to be up to date.


Every time the player levels up, the game adds 1 to their level, 10 to their maximum health, 10 to their -current- health (so that if they're at full health they can see right away that their health has increased) and 10 to their sword's damage. It also spawns the level up effect and pins it to the player.


(Fun fact: No enemy currently in the game has more than 25 health, so after leveling up twice the player will kill each enemy in one hit)


When the level up effect finishes its animation, it is destroyed.


The quest is called by a function. When it is, the game plays a sound and the event trigger sets an instance variable saying that the quest has been accepted.


Once it has been, the game then checks that against a global variable saying the same thing, and sets -that- variable to true. This is done so that the status of the quest can be tracked as the player moves across layouts. On the same step, the game also sets the stage of the quest to the first stage.


The function is called when the player is overlapping an event trigger and swings their sword.


(The code above is slightly out of date; the game no longer checks that quest Pest Control hasn't been accepted, and while the player still activates this event by pressing Z, the game is specifically checking to see if they're attacking or not. This was changed due to a bug where the game would cycle through text too fast for the player to even see it)


When these conditions are met, the game calls a mapped function based on the quest name variable in the event trigger. These functions are mapped at the start of the game.


It took a lot of experimenting to get this code to work as desired.


When the function is called, it sets an instance variable on the player saying that they are now interacting with something, and makes a text box and its contents visible in the middle of the screen. It then sets the time scale to zero so that the game is paused while the player is reading.


When the player presses Z, the text box and its contents are made invisible again, and the event trigger starts a short timer (1/4 of a second) to reset the interacting variable, before the game sets the time scale back to 1, unpausing the game.


If the player is set to be interacting with something, then when the timer to reset that variable finishes, the interaction variable is set to false again.


Like the previous snippets, it took quite some time to get these segments of code working as desired.


While the quest is set to stage one, the game starts counting how many Octoroks that the player has killed. On each Octorok being destroyed, the game adds 1 to the variable keeping track of how many have been killed. Once five Octoroks have been defeated, the game sets the Pest Control quest stage to 'Stage 1 Complete'.


When the quest is set to Stage 2, the game starts keeping track of how many quest items (in this case, herbs) have been collected.


When the player collides with a quest item that is playing the herb animation while in Stage 2 of the quest, the game plays a sound, destroys the quest item, and adds 1 to the variable counting how many herbs have been collected.


Once three herbs have been collected, the game sets the relevant global variable to say that Stage 2 of the quest is complete.


This is what the quest item object looks like when set to the 'herb' animation.


During the quest, the player will have to interact with a second NPC. This NPC recycles some earlier code to make the text boxes appear. After that, they have a simple branching dialogue tree based on what variables are currently true or false. If the player hasn't yet obtained food for them, they say 'I'm famished...'. If the player has done that, they then check to see if the food has been delivered yet. If it hasn't, they say 'Oh! My food! Thank you!', and the game sets the variable that checks if the food is delivered to true. If the player -has- delivered the food to them, they say 'I'm stuffed...'.


That NPC only becomes relevant once the Pest Control quest progresses to Stage 3.


When the quest is set to stage 3, then when the player collides with a quest item playing the 'food' animation, the game plays a sound, destroys the quest item, and sets the variable determining whether the player has collected the food to true.


Once the player is overlapping an event trigger which has the variable determining that 'food' is a required quest item AND the player has obtained the food AND that the food has been delivered, the game marks Stage 3 as complete.


This is what the quest item looks like when it is set to the 'food' animation.


These are screenshots of a sprite used in the UI code below at different points in its animation. The first image is a scroll that is rolled up, and the second image is the same scroll once it has been unfurled.


Once the quest is marked as complete, it calls the ShowQuestCompleteUI function.


When this function is called, the system waits 1 second, then sets the UI scroll to visible, and sets the animation for the scroll to 'Open'.


When the scroll finishes the open animation, the game sets the text inside the scroll saying the quest is complete to be visible. The game then waits three seconds, sets both the scroll and the text to invisible, and sets the animation of the scroll back to 'closed'.


If you would like to play the game in its current state, you can do so by following the link below:



 
 
 

Recent Posts

See All

Comments


bottom of page