[4.5.9] Extended Maze Game Tutorial - Golf Swing

CluckFox

Active member
In collaboration with other NESMakers on Discord, I have developed a simple golf swing input mechanic that uses the Background HUD. It is based on the Beginner Maze Game tutorial and expands upon it by adding the following:
  • Golf Club Selection and Swing Power Meter HUD Elements
  • Input Scripts to manipulate Club Selection and Swing Power Meter
  • A custom doHandleGameTimer.asm script to pseudo-animate the Swing Power Meter
  • User Constants to configure various aspects of these scripts
No modification of any NESMaker game engine files is required. However this only covers creating a golf-swing input system. It is up to each individual developer to make use of the input system's variables to accomplish game-specific things.

Usage​

Follow the Maze Game Tutorial - Beginner video to create a new NESMaker project. It takes about 30 minutes and serves as the foundation for all the following instructions. You will not need the attached scripts until the final step.

Step 1 - Create User Variables​

Navigate to Project Settings > User Variables

Create the following four new variables:
  1. golfClub represents a golf club selection, which a later physics computation could use as input.
  2. golfPower represents the force of a golf swing from the player starting and stopping the back-and forth motion of the swing meter.
  3. swingTrigger used by the new input and timer scripts to actuate the back-and-forth swing meter
  4. gameTimer same as above

Your User Variables dialog should look like the following picture.

User Variables dialog with golfClub, golfPower, swingTrigger, gameTimer

Step 2 - Set Up HUD Elements​

Navigate to Project Hierarchy > HUD & Boxes > HUD Elements

Pick two unused HUD elements and set them to 2: Text in the Type: drop-down. Set the String on one to CLUB: and position it above the LIVES: element. Set the String on the other to POWER: and position it on top of the SCORE: element. The HUD preview should look like the following picture.
HUD with SCORE and POWER labels

Pick one more unused HUD element and set its Type: to 3: Number. Set the Element Var to golfClub and the Max Value to 1. Position it above the number next to LIVES:.

Pick the final unused HUD element and set its Type: to 0: Var Tiles. Set its Element Var to golfPower and the Max Value to 8.

Before the final element will show up, click the button next to Full Tile and pick the solid white square from the selection dialog. Click the button next to Empty Tile and pick the solid tile to the left of the white one.

Position the final HUD element over the number next to SCORE:. The HUD preview should look like the following picture.
HUD with SCORE and POWER variables

Step 3 - Create User Constants​

Navigate to Project Settings > User Constants

Add the following four new constants:
  1. GOLF_POWER_HUD with the index of the HUD element that represents golfPower
  2. GOLF_CLUB_HUD with the index of the HUD element that represents golfClub
  3. GOLF_CLUB_MIN with a value between 0-9 as the minimum value allowed for golfClub
  4. GOLF_CLUB_MAX with a value between 0-9 as the maximum value allowed for golfClub
For example, to let the player cycle between three clubs marked 4, 5, and 6 set GOLF_CLUB_MIN to 4 and GOLF_CLUB_MAX to 6.

Your User Constants dialog should look like the following picture.
User Constants with GOLF_POWER_HUD, GOLF_CLUB_HUD, GOLF_CLUB_MIN, GOLF_CLUB_MAX

Step 4 - Add Scripts​

Download and unarchive the attached ZIP file. It contains a directory called GOLF_DEMO. Copy the entire directory to NESMaker_4_5_9\NESMaker_4_5\GameEngineData\Routines. The GOLF_DEMO directory should be at the same level as BASE_4_5.

Navigate to Project Hierarchy > Scripts > Input Scripts to verify the GOLF_DEMO directory is visible to NESMaker. Your screen should look like the following picture.
Input Scripts showing GOLF_DEMO directory

Double-click the GOLF_DEMO directory, and double-click the following four files to add them to your project:

  1. startSwing.asm
  2. keepSwinging.asm
  3. endSwing.asm
  4. cycleClubAngle.asm
Navigate to Project Hierarchy > Input Editor and bind the new scripts to the A and B buttons.

Select Player for Target and Main Game for Game State. Bind the following actions to the new scripts:

  • PRESS B - cycleClubAngle.asm
  • PRESS A - startSwing.asm
  • HOLD A - keepSwinging.asm
  • RELEASE A - endSwing.asm
Your Inputs Editor screen should look like the following picture.
Input editor showing bindings for A and B buttons

Last, include the new Handle Game Timer script to the game.

Navigate to Project Settings > Script Settings

Locate Handle Game Timer in the Game folder, just a few items before the Tiles folder (see image for reference). Select it, then in the Visible .asm files list double click on GOLF_DEMO and then double click doHandleGolfGameTimer.asm.

Your screen should look like the following once the script is set.
step4_script2.png

Try It Out​


Export and Test your game. You should see the new HUD elements. Change the club selection by tapping the B button. Hold and release the A button a few times to get the swing of the swing meter.

Credits​


Big thanks to @PewkoGames for testing my WIP code in their WIP games. It's been a pleasure serving the General! ;)

More thanks to @alextheawesome_101 and @9Panzer for reviewing/editing this tutorial.
 

Attachments

  • GOLF_DEMO_rev1.zip
    1.9 KB · Views: 4

PasseGaming

Active member
Absolutely awesome! We need more of our more talented coding members to make this sort of stuff to help out those that need it. Thank you so much!
 

CluckFox

Active member
Absolutely awesome! We need more of our more talented coding members to make this sort of stuff to help out those that need it. Thank you so much!
Thank you for your kind words. I like writing and I really like the games NESMakers are making. I want to help minimize the role coding plays in your creative expressions.
 

Jonny

Well-known member
I'd been thinking about something like this for a casting spells at differenct intensities. So, button can be held longer to do more damage at the expense of time and the monster getting closer. Done many times before I expect but I can't think of an example atm. This tutorial will make it possible. Thanks.
 
Top Bottom