Dragon Encounter: Altera FPGA Game

 Vincent Gatto and Mike Paige made a working social ineraction game wherein the player tries to survive an encounter with a dragon by convincing the dragon to leave.  The dialog with the dragon takes the form of multiple  choice re sponses that the player  can choose from.  The player will attempt to choose the response he or she thinks will most likely convince the dragon to leave in peace instead of eating the player.  Depending on the player's choices throughout the conversation, the dragon will develop an opinion of the player.  If the player successfully gains the favor of the dragon, he will leave and the player will win.

The game runs off a single Altera DE2 FPGA.  The conversations are Markovian in nature; sequential, but the exact queries and possible responses will vary depending on the dragon's immediate disposition toward the player or the player's immediate response.  The dragon's disposition takes the form of a number stored in a data array (a register), with one extreme being favored and the other being hated.  The conversation and optional responses are sent via VGA to an external monitor.  The player inputs their choices directly on the DE2 board itself, each response in the conversation corresponding to a switch numbered 1 through 3.



 The main engine behind our project was largely implemented using adapted versions of John Loomis’ VGA adapter and text rendering modules.  The base files can be found here; we modified them to fit the needs of the project.  After some initial analysis, we found that the program worked by dividing the screen into rectangular sections 8 pixels wide and 16 pixels tall.  In addition, to keep the image on the screen stable, the program’s VGA sync module refreshed the screen one pixel at a time.  Thus, in order to produce the text necessary to realize our design, we developed a relatively simple algorithm that would change the specified character to be displayed whenever the “active pixel” reached the top-left corner of one of the rectangular sections.  The character itself was specified by assigning an 8-bit hex value to the register “qchr”.  For example:


case (px / 4’d8) // dividing the total pixels by 8 makes it easy to specify the desired “column”

1: qchr <= 8’h48; // H

2: qchr <= 8’h65; // e

3: qchr <= 8’h6c; // l

4: qchr <= 8’h6c; // l

5: qchr <= 8’h6f; // o

6: qchr <= 8’h21; // !

default: qchr <= 8’h00; // display a space everywhere else


The above code would output the word “Hello!” starting at the left edge of the screen (column 1) and a blank space everywhere else.  This basic algorithm was repeated on a significantly larger scale for all of the conversations that would take place in the game.  All of these case structures were then compiled into one larger “master” case structure, which would call up the desired batch of text based on the current state of the game’s controlling state machine.

The game’s controlling state machine, meanwhile, was a fairly simple affair.  The current game state would simply wait for user input through one of four switches and then change states depending on the input that was received.  The text displayed onscreen was determined solely by state and state alone, meaning our machine adhered closely to Moore’s state machine design. (More on that topic can be found here.)

The sentences were generated using a parser written in Java that would take in a typed sentence and spit out Verilog code that would be recognised by our driver.  The graphics of the woman and the dragon are renderred the same say as the sentences.  Each 8 by 16 pixel block of the picture is a character stored with the rest of the characters in the text library.  The image was first drawn by hand in a graphics program, then set with an overlay where each pixel was represented by the appropriate ascii that the character library would recognize.  That text was ported into a Java parser (similar to the sentence parser) that would spit out code that could be easily inserted into the character library.



The primay goal and major challenge of the project was to understand and implement a monitor controller.  The controller needed to be able to write the alphabet and certain punctuation to the screen and update it as necessary.

The second challenge was to program a convincing dragon into the game; we predicted this task to be not as challenging as the monitor controller.

The final task was to incorporate player input, which was the easiest task of all and was given the lowest priority.

If there was time to spare, the game had plans to be polished in a number of ways including graphics and sound.


Concluding Remarks

Some design files are available under the documents page.  Included are an older version of the state diagram, the Java sentence parser, the state driver and the text writer (not the driver).


The Game





This type of game is strongly remeniscent of dating sims.

The game is suitable in content for most audiences.

  Bug! State transition will sometimes exhibit irregular behavior, placing the player at the wrong part in the conversation