From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Example Code

Dr Mario

Code and Documents

Attachment

Summary:

This submission is a recreation of one of my all time favorite games on the NES - Dr. Mario.  I have recreated all the functionality and graphics for the 1-player mode, including the cute virus dancing animations.

The goal of the game is to eliminate viruses by stacking coloured pills overtop of them.  Mario will continually drop pills of random colours - you must move these around and stack them appropriately.  Align 4 of the same colour in a row, either vertically or horizontally, and those pieces disappear.  If you can eliminate all of the viruses on the board, you win!

Function:

  1. To have fun playing a classic game
  2. Demonstrates accurate timing using resetable timed loops
  3. Demonstrates good use of picture rings

Steps to execute code:

Front Panel.jpg

  1. Unzip the file
  2. Open the project
  3. Open the Main VI.vi and run it.
  4. Select keys to use during play.  Simply replace the letter or symbol for each key as required.  You can also use the arrow keys (which are enabled for directional movement by default)
  5. Select difficulty setting.  The higher the difficulty, the more viruses are intially present.
  6. Select the pill drop speed.
  7. Press Start!
  8. Move the pills around and stack them overtop of pesky viruses to eliminate them!

Screenshots:

Main VI:  The architecture of the main VI is an event-driven  queued state machine that interacts with the user's button presses and  mouse clicks.  In addition to these elements, (5) other manager VI's run  in parallel, each having their own independant architecture based  around timed loops. some of which are stopped and restarted often in response to game status.

Main Loop.jpg

Auto Drop Manager:  A simple resetable timed loop.  Once initiated, this timed loop adds a  state to the main queue to drop the active piece one step.  If the user  presses the down button at any time, or the game detects that the piece  cannot be dropped any further, this timed loop is stopped remotely from  the Main VI.  It is restarted again after the piece has moved down, or when a new piece is made available.

Auto Drop Manager.jpg

Virus Flip Manager:  This manager uses a timed loop to add states to a queued state machine to toggle the image of the viruses on the board on the front panel.  The manager is able to adjust the value of the main board because the refnum of the board is saved to a global variable and used here.  This manager is one of a few that write to the main board in the main VI, so a semaphore is used everywhere the board is written to, to ensure that race conditions do not occur.

Virus Flip Manager.jpg

Dancing Virus Manager:  This manager handles the movement (rotation) and state selections of the large dancing viruses in the bottom lefthand corner of the main VI screen using a timed loop to add states to a queued state machine.  Similar to the board, refnums of these picture rings are save to global variables, and properties and values of these are adjusted here.

Dancing Virus Manager.jpg

Hold Down Key / Hold Left Right Key Managers: These managers are very similar.  They have (2) nested Timed Loops that are initially dormant.  When the user presses down a key, the outer loop wakes up and starts timing how long the key is held down for.  If it is held down past a threshold time, the inner loop wakes up, and moves the active pill at a fast, predefined rate.  If the user releases the key, or the game detects that the piece  cannot be dropped any further, the main loop stops both of these loops.

Hold Down Key Manager.jpg

VI Snippet:

Each square in the board is a typedef picture ring as shown below.  The code simply adjusts the state of each square in response to game mechanics.

Main Screen Pic Ring.jpg

To maintain a consistent look, typedef picture rings were used for all numbers.

Block Numbers.jpg

VI attached below (LabVIEW 2010)

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
mike_nrao
Member
Member
on

Not executable. 'Which Button Was Pressed.vi" is missing.  This was one of my favorite games of all time!  You have some slick tricks for recreating the look.

wirebirdlabs
Member
Member
on

I'm bummed about the missing VI. But when I saw how easy it would be to fix, I went ahead and tried playing the game. For the fix, just remove the missing VI, wire the Scan Code into the Case Structure, and use these values (I chose the 'z' and 'x' key for Rotate CCW and Rotate CW respectively):

DrMarioFix.png

But then when I ran it, I got this error:

DrMarioError.png

So I clicked the "whatever, who cares, I wanna play Mario!" button (Disguised as "continue"), and got this error:

DrMarioError2.png

So then I had to press the "Screw You Too! Mario, NOW!" button. But then, this error:

DrMarioError3.png

And that happened with all 8 Timed Loops, but finally... Mario! If you're interested in watching me make a minute-and-forty-seconds worth of bad decisions (well beyond my Ballmer Peak) before killing my first virus, check it out here on Screencast.

(OK, Screencast is down right now, I'll post the link later! That's what... the eleventh bummer tonight? )

Contributors