C. Program Description for Developers

This Program Description will be broken into 9 parts, each corresponding to a file or function required to run Memory Quest. These include:

Scripts:

  • Memory Quest.m (Executes the main game.)
  • Soundtrack.m (Generates and plays soundtrack on loop.)

Functions:

  • Combat.m (Creates combat screen and play)
  • Choice1.m (Executes the first selected choice.)
  • Choice2a.m (Executes the second selected choice within the first storyline branch.)
  • Choice2b.m (Executes the second selected choice within the second storyline branch.)
  • DrawUX.m (Draws scenes as a set of tiled sprites.)
  • SplashDraw.m (Draws full 960 x 540 pages as a single image.)
  • BossFight.m (Specialized combat designed for the final boss of the game.)

 

MemoryQuest.m

This is the main script that contains most of the game’s story content.

Variable List:

  • PlayerClass:  Global string variable-represents the player’s class, which determines the sprites rendered in combat scenes.
  • Gender: Global variable- represents the players selected gender as a number, either “1” for masculine, or “2” for feminine.
  • PlayerMaxHP: Global variable- represents the player’s maximum HP value as an integer.
  • PlayerHP: Global Variable- represents the player’s current in-game HP value as an integer.
  • PlayerSTR: Global variable- represents the player’s in game strength value for combat as an integer.
  • PlayerSPD: Global variable- represents the player’s in-game speed value for combat as an integer.
  • PlayerEnergy: Global variable- represents the player’s current in-game energy value for combat as an integer.
  • PlayerRG: Global variable- represents the player’s energy value recovery rate as an integer.
  • Gold: Global variable- player reward value, for use as  in-game currency.
  • Name: Global variable- player’s name as a string.
  • pause: Local variable- placeholder variable meant to serve as a way to make the game wait for the player to advance.
  • ClickX: Local Variable- records x-coordinate of last mouse click input. Used to select choices on the figure screen.
  • ClickY: Local Variable- records y-coordinate of last mouse click input. Used to select choices on the figure screen.
  • C1: Local variable- records what the players first choice decision is.
  • C2: Local variable- records what the players second choice decision is.
  • C3: Local variable- records what the players third choice decision is.
  • C4: Local variable- records what the players fourth choice decision is.

The pause variable is used in between all texts and new scenes.

To initiate the main script, the program first loads a landing screen and then a title page utilizing the SplashDraw function.

After the title screen, the first forest scene is drawn using the DrawUX function.

Fprintf commands are used to communicate opening narration.

A prompt is given using the input function for the player to set their name. This is stored as a string.

This is followed by more narration communicated through fprintf.

The DrawUX function is used to display the character selection menu- a series of six sprites.

The player is prompted to choose a character, and clicks a certain area of the character selection. This is recorded as a ClickX and ClickY value. These values are then put into an if-then statement that checks for what range of x and y values the click falls into.

If the ClickY falls into the upper row, the player’s Gender variable is set to 2, or female.

If the ClickY falls into the lower row, the player’s Gender variable is set to 1, or male.

If the ClickX value falls into the left column, the player’s PlayerClass Variable is set to “Axeman”, and their stats (STR,SPD,RG) are set accordingly.

If the ClickX value falls into the center column, the player’s PlayerClass Variable is set to “Hunter”, and their stats (STR,SPD,RG) are set accordingly.

If the ClickX value falls into the rightcolumn, the player’s PlayerClass Variable is set to “Healer”, and their stats (STR,SPD,RG) are set accordingly.

The scene is set back to normal gameplay. Narration continues.

The character is prompted to choose their course of action. DrawUX is used to set up a two-button overlay on the scene. The player must now click on one of the buttons in the figure to decide. This is recorded as a ClickX and ClickY value. These values are then put into an if-then statement that checks for what range of x and y values the click falls into.

If the ClickX value falls into the area of the “1” button, the C1 variable is set to 1.

If the ClickX value falls into the area of the “2” button, the C1 variable is set to 2.

The C1 variable is then put into the “choice1” function.

After the “choice1” function has been executed, the C1 variable is used in an if-then statement to determine the player’s second decision.

If C1 is 1, then the player follows the river story line. The DrawUX function draws the river scene. Within this story line, the player can select either to swim through the river(1), or attempt to find a bridge(2). DrawUX is used to set up a two-button overlay on the scene.

Click values are then put into an if-then statement that checks for what range of x and y values the click falls into.

If the  system records the click as the “1” button, then the C2 variable is set to “1”. 

If the  system records the click as the “2” button, then the C2 variable is set to “2”.

The choice2a(C1) function is then initiated.

If C1 is 2, then the player follows the torch story line. The DrawUX function draws the torch overlaid onto the original scene. Within this story line, the player can select either to leave the torch and follow a deer towards water (1), or attempt to take the torch. (2). DrawUX is used to set up a two-button overlay on the scene.

Click values are then put into an if-then statement that checks for what range of x and y values the click falls into.

If the system records the click as the “1” button, then the C2 variable is set to “1”.

If the system records the click as the “2” button, then the C2 variable is set to “2”.

The choice2b(C1) function is then initiated.

After the second choice has been made, assuming that the game did not end during combat, the DrawUX screen returns to the original forest sprite. The text narrates that the player has escaped the forest.

Narration continues.

DrawUX draws the town setting, as scenes change.

Narration continues.

DrawUX draws a local pub scene.

At a local pub, the player can either continue with dialogue(1), or order a meal for an increased HP stat(2). DrawUX is used to set up a two-button overlay on the scene. The player must now click on one of the buttons in the figure to decide. This is recorded as a ClickX and ClickY value. These values are then put into an if-then statement that checks for what range of x and y values the click falls into.

If the ClickX value falls into the area of the “1” button, the C3 variable is set to 1.

If the ClickX value falls into the area of the “2” button AND the player’s Gold variable value is above or equal to 10, the C3 variable is set to 2.

Otherwise, the C3 variable is set to 1.

C3 is then used to go through an if-the statement that interprets the selection.

If C3 is equal to 2, then the player’s MaxHP variable is set to the original value +10, the player’s Gold variable is set to the original value – 10,  and dialogue leads back into the story. Otherwise, dialogue is given to lead back to the original story.

The story continues, and the player is told that they can either gather supplies at the blacksmith(1) , or the apothecary(2) . DrawUX draws the town setting once again as scenes change.

DrawUX is used to set up a two-button overlay on the scene. The player must now click on one of the buttons in the figure to decide.  This is recorded as a ClickX and ClickY value. These values are then put into an if-then statement that checks for what range of x and y values the click falls into.

If the ClickX value falls into the area of the “1” button the C3 variable is set to 1.

If the ClickX value falls into the area of the “2” button the C3 variable is set to 2.

C4 is then used to go through an if-the statement that interprets the selection.

If C4 is equal to 1 AND the player’s Gold variable value is above or equal to 25, then the player’s STR variable is set to the original value +4, the player’s Gold variable is set to the original value – 15,  and dialogue leads back into the story.

If C4 is equal to 2 AND the player’s Gold variable value is above or equal to 25, then the player’s RG variable is set to the original value +1, the player’s Gold variable is set to the original value – 15,  and dialogue leads back into the story.

Otherwise, dialogue is given to lead back to the original story without any stat changes.

Narration continues. DrawUX changes the setting to the original forest scene.

Narration continues until the boss is reached. DrawUX overlays the boss sprite onto the scene.

Narration given.

BossFight function is initiated.

After the BossFight function is initiated, the program closes and clears all windows, and the game ends.

Combat.m

This explains the combat system.

Variable List:

  • All Global variables listed in MemoryQuest.m
  • EnemClass-Local variable that determines what kind of enemy appears.
  • EnemHP-Local variable that determines how much health the enemy has.
  • EnemEnergy-Amount of energy the enemy currently has in-game.
  • EnemSTR-Local variable determining enemy strength stat as integer.
  • EnemSPD-Local variable determining enemy speed stat as integer.
  • EnemRG-Local variable determining enemy energy recovery stat as integer.
  • EnemMove-Local variable that represents what move the enemy has made.
  • PlayerMove-Local variable that represents what move the player has made.
  • EnemAttackPWR- Sum of energy and strength stat for combatant.
  • PlayerAttackPWR-Sum of energy and strength stat for combatant.

Combat is the same for both Enemy classes 1 (Dragon) and 2 (Monster Knight). The only difference is how narration is given, the scene created by DrawUX, and how the stats are set.

First, an if-then statement is set up, identifying what class of enemy the player is fighting.

Depending on what enemy class is selected, the stats are set as follows.

Enemy class 1:

  • EnemHP=55;
  • EnemEnergy=0;
  • EnemSTR=5;
  • EnemSPD=8;
  • EnemRG=1;

Enemy class 2:

  • EnemHP=55;
  • EnemEnergy=0;
  • EnemSTR=8;
  • EnemSPD=5;
  • EnemRG=1;

All Player stats are set by their global variable values. PlayerHP is set to their MaxHP.

DrawUX function is used to create a screen containing a backdrop, the necessary enemy sprite, the player sprite, and three buttons for Attack, Deflect, and Focus.

Using an input command, the player is prompted to either skip or begin a tutorial.

If the player’s input is “1”,  the the tutorial is skipped, and combat continues.

Otherwise, the tutorial is given as a set of text given in the command window.

Next, a while loop is set up, keeping the following scripts running until either the Player or Enemy HP is less than or equal to 0.

First the enemy move is selected. If the EnemEnergy stat is less than 1, then a random integer between 2 and 3 is generated using the randi() function. Otherwise, a random integer is generate between 1 and 3. This random integer is then set as EnemMove.

Text prompts the player that a new turn has begun.

The player must now click on one of the three buttons in the figure to decide on their move. This is recorded as a ClickX and ClickY value. These values are then put into an if-then statement that checks for what range of x and y values the click falls into.

If the click falls into the “ATK” button area, then the PlayerMove variable is set to “1”. If the PlayerEnergy is less than one however, the system displays that no attack can be made on zero energy, and the turn ends.

If the click falls into the “DEF” button area, then the PlayerMove variable is set to “2”.

If the click falls into the “FCS” button area, then the PlayerMove variable is set to “3”.

Next, fight conditions are established. This is done using an if statement that checks both the Enemy and Player Move variables.

If the Enemy and Player move are both “1”, or attack, the two combatants Energy and Strength stats are added and compared as Enem/PlayerAttackPWR. The higher attack power prevails, and the losing combatant’s HP is set to the original value minus the prevailing opponents attack power. Both combatants new stats are displayed, and the turn ends.

If the Enemy and Player move are both “2”, or deflect, the system displays that both combatants deflect. Both combatants new stats are displayed, and the turn ends.

If the Enemy and Player move are both “3”, or focus, the two combatants Energy stats are set to their original value plus their respective RG values. Both combatants new stats are displayed, and the turn ends.

If the Enemy move is “3” or focus, and the Player move is “1” or attack, then the Enemy’s Energy stat is increased by its RG value, and the Player reduces the Enemy’s HP stat by the calculated PlayerAttackPWR. Vice versa occurs when the Enemy attacks a focusing Player. Both combatants new stats are displayed, and the turn ends.

If the Enemy move is “2” or deflect, and the Player move is “1” or attack, then both combatant’s speed stats are compared. If the Player’s speed stat is greater than the Enemy’s,the Player reduces the Enemy’s HP stat by the calculated PlayerAttackPWR. Otherwise, the system displays that the attack was dodged and the Player’s Energy is set to 0. Vice versa occurs when the Enemy attacks a deflecting Player. Both combatants new stats are displayed, and the turn ends.

If the Enemy move is “2” or deflect, and the Player move is “3” or focus, then the Player’s Energy stat is increased by its RG value. Vice versa occurs when the Enemy focuses as the Player deflects. Both combatants new stats are displayed, and the turn ends.

 

Once either the PlayerHP or EnemyHP is less than or equal to zero, an if-else statement is set up.

If the Player’s HP is less than or equal to zero, the Splash Draw function is used to display a game over screen, and the system closes and clears all windows, then ends the game.

If the Enemy’s HP is less than or equal to zero, the system displays that the Player has won, and rewards are distributed. The Gold variable is increased by 25, Player Strength and Speed stats are increased by 3 and 2.

The combat function then ends, and the system returns to the main script.

Choice1.m

Choice 1 executes the decision made by the player on the first choice.

Variable List:

  • A-Represents C1 in the function parentheses.

The choice made is used for an if-then statement.

If C1 is read as 1, then the DrawUX function is used to draw a river scene, and text is given explaining the situation.

If C1 is read as 2, then the DrawUX function is used to overlay a torch over the scene, and text is given explaining the situation.

Choice2a.m

Choice2a executes the decision made by the player on the first choice after following the “1” pathway.

Choice2b.m

Choice2a executes the decision made by the player on the first choice after following the “1” pathway.

DrawUX.m

DrawUX uses the SimpleGameEngine.m provided to create tiled sprite images using the following variables:

  • All global variables from MemoryQuest.m
  • blank-empty space
  • emptysky -night sky tile
  • moonsky -night sky with moon tile
  • forestGround -grass tile
  • riverGround -river tile
  • townGround -road tile
  • POVGround-grass tile for 1st person
  • POVRiver-river tile for 1st person
  • POVStreet- road tile for 1st person
  • POVTrees-Treeline tile for 1st person
  • POVBar- town pub tile for 1st person
  • BarLow-table tile for 1st person
  • Faxeman= Female Axeman button
  • Maxeman=Male Axeman button
  • Fhunter= Female Hunter button
  • Mhunter=Male Hunter button
  • Fphy= Female Healer button
  • Mphy= Male Healer button
  • Attack= ATK button
  • Deflect=DEF button
  • Focus=FCS button
  • One=”1″ button
  • Two=”2″ button
  • Torch=Torch for overlay
  • OldMan=Barkeep for overlay
  • WaterSnakeTop=Dragon sprite top part
  • WaterSnakeBottom=Dragon sprite bottom part
  • CentaurTop= Knight Monster sprite top part
  • CentaurBottom= Knight Monster sprite bottom part
  • BossTop=Boss sprite top part
  • BossLeft=Boss sprite left part
  • BossBottom=Boss sprite bottom part
  • Situation= tells the program what scene to draw.

The player’s click on the character selection page determines the  value of the “player” variable, setting it to one of the six player sprites on the sheet.

Each DrawUX function is assigned a “Situation” in the function parentheses. This is put into an if then statement, where each situation is then generated as a scene using the drawScene function. The generation is dictated by assigning the vectors rooms_display(first layer) and gameboard_display (second layer) with the variables listed above.

SplashDraw.m

Splash draw acts on the same principles as the DrawUX function, but instead uses the imread(img)function to generate full images, instead of tiled sprites from a sheet.

Variable List:

A=This determines the image shown.

img= Placeholder variable to read out the png in the imread() function.

An if statement is used to identify what image should be shown based on A.

Soundtrack.m

The soundtrack function acts independently of the main script.

First, the clear sound command is given to stop other audio from interfering with the system.

Next, the audioread function is used to read the downloaded m4a files.

These read audio files are loaded as vectors in MATLAB.

A “while true” function is set up to constantly loop a series of five songs played using the playblocking()function.

BossFight.m

The BossFight function acts as a custom combat function, with the only difference being narration, the sprite drawn, enemy stats, and the end conditions.

DrawUX creates a custom combat screen with the boss on overlay.

Stats are set up as such.

  • EnemHP=105;
  • EnemEnergy=2;
  • EnemSTR=9;
  • EnemSPD=9;
  • EnemRG=2;

Combat principles remain the same.

If the Player’s Hp goes to or below 0, the game ends as in regular combat.

If the Boss’ HP reaches 0, then the game reverts to the original forest scene via Draw UX. Narration explains the end of the game, and the SplashDraw function opens the ending page. The function then returns to the main script.