Sunteți pe pagina 1din 19

Go, Brutus, Go!

Program Guide

Katie Albert, Lauren Pham Autumn 2017


Introduction

This program was written as a prototype for video game publisher MAVCO and designed to be
used on the handheld PROTEUS console. The game allows for single-player use and possesses
both statistic tracking and replay capabilities. Within the program are also options to display the
game instructions and credits.

In “Go, Brutus, Go!” the user’s main objective is to get Brutus Buckeye from one side of the screen
to the other without colliding into any students. At the start of the game, Brutus stands at one end
of the screen, and the students travel across the screen in lines perpendicular to Brutus’ path.
Tapping the screen moves Brutus forward one space, either to a line of traffic or space between
lines. The game ends when a collision occurs or Brutus makes it to the other side. Time is recorded
for the duration of the game, and the high score is the fastest time.

Program Description

The following sections describe the program and its functions in detail. The source code can be
found in Appendix A.

Algorithm/Pseudocode

Include libraries.
Prototype functions.
Main Function
Define variables.
Print title screen (touch to continue).
Print story (touch to continue).
Begin “do…while” loop that keeps program running.
Run start menu function.
Switch-case for user input:
1. Play the game:
a. Show countdown screen.
i. Print “3” for 1 second, “2” for 1 second, and “1” for 1 second.
ii. Run game function.
2. Rules/Instructions:
a. Print rules and instructions to screen.

2
3. Statistics:
a. Print statistics.
4. Credits:
a. Print credits.
End switch case.
Start screen function.
End while loop.
Gameplay Function
Declare variables for positions of Brutus and pedestrians 1, 2, and 3.
Declare variables for x and y position, start time, current time.
Print oval layout to screen.
Print Brutus in original position to screen.
Start timer.
Start while loop:
Print timer to top right of screen.
Print pedestrian to screen.
While position of Brutus does not equal position of pedestrian 1, 2, or 3:
Move position of pedestrian 1 from down the screen.
Move position of pedestrian 2 from down the screen.
Move position of pedestrian 3 from down the screen.
If screen is touched:
Move Brutus forward one space.
Reprint Brutus.
If Brutus position equals pedestrian position:
Print message of loss.
Break while loop.
If Brutus position equals endpoint:
Print message of win.
If current time is less than fastest time:
Store current time as fastest time.
Print message of beating high score.

3
If pedestrian gets to bottom of screen
Reset to top of screen.
Add to pedestrian counter to move across screen.
‘Erase’ pedestrian by writing over in tan color.
Return high score.
Print Oval Function
Declare variables of path 1, 2, 3, 4 locations and path width.
Print Oval layout to screen.
Print Brutus Function
Take in variables of Brutus’s position.
Print Oval layout.
Print Brutus to screen.

Function: int main ( )

Execution of the main program begins by setting the LCD background and font colors and
displaying the title screen. The program then waits for a touch on the screen to display the game
storyline and the player’s objective.

After the user touches the screen again, the “startscreen” function is called and returns the user’s
input choice from the start menu to the variable “status”. A switch-case structure for “status”
determines how the program proceeds, and startscreen is called again outside the switch-case
structure. The switch-case and startscreen call are contained within an indefinite while-loop to
keep the program running until the Proteus is turned off.

Variables

• int high  Variable in which the high score will be returned from the gameplay function
to the main function (initialized at 1000).
• int status  Variable in which the user’s choice from the start menu will be returned from
the startscreen function to the main function.
• int zero  counter to keep program running (initialized at zero).
• float xpos, ypos  Position along x and y-axes of user’s touch on touch screen.

4
Function: float gameplay (float highscore)

When the user selects “Play the game!” from the start menu, a countdown prints to the screen and
the gameplay function is called with the argument “high,” the user’s current high score (which is
initialized at zero at the start of the main function). This function runs the game for the user to play
and returns the user’s current high score as the variable “high” in the main function.

Inside the function is a while-loop that moves each pedestrian down the screen 40 pixels with each
loop and then back up to the top of the screen after they reach the bottom. If pressure is detected
on the screen, the Brutus icon is moved to the right 36 pixels. The while-loop ends when the Brutus
icon collides with a pedestrian graphic or if the Brutus icon reaches the other side of the screen.
The corresponding win or loss message is then displayed, and execution is paused until the screen
is touched. After the user touches the screen, the value of the high score is returned to the main
function, and the main function continues executing.

Variables

• float highscore  Return value for function; User’s lowest time.


• float x_position, y_position  Position along x and y-axes of user’s touch on screen.
• float start1 Stores the time at which the game begins by calling “TimeNow( )” at start of
game.
• float current time  Stores the time duration of that game; Calculated by subtracting
“start1” from “TimeNow( )” function.
• float x  Initialized at 0 and then compared to 0 inside while-loop to keep the pedestrians
moving and clock running; Value becomes 1 when user wins or loses in order to exit while-
loop and end game.
• int brutusx  Position along x-axis of Brutus Buckeye graphic.
• int brutusyin, brutusyout  Position along y-axis of inner and outer circles on Brutus
Buckeye graphic.
• int p1x… p4x  Positions along x-axis of pedestrians on paths 1-4.
• int p1ay… p4ay  Positions along y-axis of the pedestrian on each of the four paths.

Function: void printoval ( )

This function, called at the start of the “printbrutus” function, sets the background color to green
and draws the horizontal pathway to be taken by Brutus as well as the three vertical pedestrian
pathways.

5
Variables

• int path1, path2, path3  Positions along x-axis of pedestrians’ paths.


• int pathwidth  Stores width of pedestrians’ paths in pixels.

Function: void printbrutus (int brutusx, int brutusyin, int brutusyout)

The arguments of the printbrutus function contain the location to which the Brutus Buckeye
graphic is being printed at that point in the execution of the program. This function is called at the
start of the gameplay function with Brutus’ initial x and y-positions as the arguments. Each time
the user taps the screen during the gameplay function, 36 is added to the argument “brutusx,” and
this function is called again to reprint Brutus one space to the right.

Variables

• int brutusx  Position along x-axis of Brutus Buckeye graphic.


• int brutusyin, brutusyout  Position along y-axis of inner & outer circles of Brutus
Buckeye graphic.

Function: int startscreen ( )

This function prints to the screen a start menu with four options: play the game, display statistics,
display rules and instructions, or display credits. The value of the return variable “status” is
determined by the location of the user’s touch on the screen, and this value is returned to another
variable called “status” in the main function. The startscreen function is called in the main function
after the introductory information is displayed and again after each case in the “switch status”
structure.

Variables

• int status  Return value for function; Value is determined by user’s choice from the start
menu (where the user touches the screen on the start menu).
• int xposition, yposition  Coordinates for position of user’s touch on screen.

6
Assumptions

It is assumed that the player knows to only touch the screen once to expect a response. When
touching the screen multiple times in a short amount of time while waiting for the program to load,
it causes the game to load with the touch functions already loaded and Brutus moves without
touching him.

Performance and Limitations

The completed “Go, Brutus, Go!” program allows for gameplay by a single user and successfully
executes based on the user’s performance in the game. Containing the majority of the main
function within an indefinite while-loop gives the game the ability to be replayed. This also
allows the high score to be stored for as long as the Proteus remains on.

Limitations of this version of the program include level of difficulty. The gameplay function was
not written with any variations (i.e. pedestrian speed, number of pedestrians) and can therefore
only support one level of difficulty. Additionally, there is no multiplayer mode or way to store
the name of the top score holder integrated within the program.

Summary & Conclusions

One of the key issues with the original program was the flashing screen. Originally, the entire
screen was getting cleared and the graphics redrawn each time a pedestrian had to be moved down
the screen. To resolve this, the code was rewritten to “erase” the pedestrian graphic by drawing a
circle of the same color of the path over it, and a new pedestrian graphic was drawn farther down.
Because the screen was no longer getting cleared, however, the timer began printing down the
screen instead of in the corner. This issue was eliminated similarly by drawing a green rectangle
in that location before printing the time to the same location in each loop. These adjustments made
the screen much easier to observe during gameplay.

The startscreen function also required debugging because the original program ran the gameplay
function even if the user selected an option other than “Play the game!” from the start menu. This
issue was a result of misplaced relational operators in the “if” statements that made “Play the
game!” the user’s start menu choice regardless of where the user touched the screen. Once these
were adjusted, the start menu functioned as the user would expect.

For future versions of “Go, Brutus, Go!” it is recommended that multiple levels of difficulty be
integrated in the program to enhance the user’s experience. The method of “erasing” instead of
clearing the screen should continue to be utilized in the gameplay function as it will produce
significantly clearer graphics that are much easier to view than a flashing screen.

7
References

[1] Videogame Design – DOCUMENTATION PACKAGE. 2017, December 1.


www.carmen.osu.edu.

8
APPENDIX A
Source Code
//Video Game Design Project
//Lauren Pham and Kathleen Albert
//Harper 10:20

//include libraries
#include <FEHLCD.h>
#include <FEHUtility.h>
#include <LCDColors.h>
using namespace std;

//prototype Brutus print function


void printbrutus(int brutusx, int brutusyin, int brutusyout);

//prototype Oval print function


void printoval();

//prototype game function


float gameplay(float highscore);

//prototype start screen


int startscreen();

int main(void) //start int main


{
//define variables
int status /*status for start screen*/, zero=0 /*while-loop counter*/;
float high=1000 /*high score*/, xpos /*LCD touch position*/, ypos /*LCD touch position*/;

//print title screen


LCD.SetBackgroundColor(GRAY); //set background color
LCD.Clear();
LCD.SetFontColor(SCARLET); //set font color
LCD.WriteRC("Go, Brutus, Go!", 6, 6);
LCD.WriteRC("touch screen to continue", 11, 0);

//while-loop to wait for touch


while (!LCD.Touch(&xpos,&ypos)){
Sleep(25); //sleep to pause before running
} //end while-loop when touched

//print story screen


LCD.Clear(); //clear previous screen
LCD.WriteLine("Brutus needs your help!");
LCD.WriteLine("It's game day and Brutus");

A2
LCD.WriteLine("needs to get across the");
LCD.WriteLine("Oval to give Urban Meyer");
LCD.WriteLine("the game book.");
LCD.WriteLine("Help Brutus get across");
LCD.WriteLine("the Oval as quickly");
LCD.WriteLine("as possible!");
LCD.WriteLine("Touch screen to continue");

//while-loop to wait for touch


while (!LCD.Touch(&xpos,&ypos)){
Sleep(25);
} //end while-loop when touched
while (LCD.Touch(&xpos, &ypos)){
Sleep(1);
} //end while-loop when released

//call start screen function


status=startscreen();

//infinite do while-loop to keep program running


while (zero==0)
{
//switch case
switch (status) {
case (1):
//play the game
//print countdown of 3,2,1
LCD.Clear();
LCD.WriteRC("3", 6, 12);
Sleep(1000);
LCD.Clear();
LCD.WriteRC("2", 6, 12);
Sleep(1000);
LCD.Clear();
LCD.WriteRC("1", 6, 12);
Sleep(1000);

//run game function


high=gameplay(high);

break;

case (2):

A3
//rules and instructions

//print rules and instructions to screen


LCD.Clear();
LCD.WriteLine("To help get Brutus across");
LCD.WriteLine("the Oval, tap the screen");
LCD.WriteLine("to move him forward. ");
LCD.WriteLine("Avoid hitting the");
LCD.WriteLine("pedestrians and be as ");
LCD.WriteLine("quick as possible to");
LCD.WriteLine("get the high score!");
LCD.WriteLine("touch screen to continue");

Sleep(3.0);

//while-loop to wait for touch


while (!LCD.Touch(&xpos,&ypos)){
Sleep(25);
} //end while-loop when touched
while (LCD.Touch(&xpos, &ypos)){
Sleep(1);
} //2end while-loop when released

break;

case (3):
//statistics

//print statistics
LCD.Clear();
LCD.Write("The high score is ");
LCD.Write(high);
LCD.WriteLine(" seconds");
LCD.WriteLine("touch screen to continue");

Sleep(3.0);

//while-loop to wait for touch


while (!LCD.Touch(&xpos,&ypos)){
Sleep(25);
} //end while-loop when touched
while (LCD.Touch(&xpos, &ypos)){
Sleep(1);
} //end while-loop when released

A4
break;

case (4):
//credits

//print credits
LCD.Clear();
LCD.WriteLine("Made by Lauren Pham and");
LCD.WriteLine("Kathleen Albert ");
LCD.WriteLine("in Dec 2017");
LCD.WriteLine("FEH Harper 10:20");
LCD.WriteLine("Video Game Design Project");
LCD.WriteLine("touch screen to continue");

Sleep(3.0);

//while-loop to wait for touch


while (!LCD.Touch(&xpos,&ypos)){
Sleep(25);
} //end while-loop when touched
while (LCD.Touch(&xpos, &ypos)){
Sleep(1);
} //end while-loop when released

break;
}//end switch case
//prompt for start menu input
status=startscreen();
}//end while-loop
}//end int main

//GAME FUNCTION
float gameplay(float highscore)
{
//declare variables for touch position, while-loop, timer
float x_position, y_position, start1, currenttime, x=0;

//declare variables for positions of pedestrians and Brutus


int brutusx=32, brutusyout=119, brutusyin=110;
int p1x=68, p1ay=39;
int p2x=140, p2ay=79;
int p3x=212, p3ay=119;
int p4x=284, p4ay=139;

A5
//record starting time
start1=TimeNow();

//print Oval and Brutus to screen for the first time


printbrutus(brutusx,brutusyout,brutusyin);

//while-loop to keep pedestrians moving and time running


while (x==0){

//print timer
LCD.SetFontColor(DARKGREEN);
LCD.FillRectangle(0,0,50,20);
currenttime=TimeNow()-start1; // calculate current time as difference
LCD.SetFontColor(BLACK); //reset time color to black
LCD.WriteAt(currenttime,0,0); //write current time to screen

//print pedestrians to screen


LCD.SetFontColor(BLACK); //set color to black
LCD.FillCircle(p1x,p1ay,15); //set pedestrian 1a
LCD.FillCircle(p2x,p2ay,15); //set pedestrian 2a
LCD.FillCircle(p3x,p3ay,15); //set pedestrian 3a
LCD.FillCircle(p4x,p4ay,15); //set pedestrian 4a

//if screen is touched


if(LCD.Touch(&x_position, &y_position))
{
//move Brutus over one space
brutusx+=36;

//reprint Brutus to screen


printbrutus(brutusx, brutusyin, brutusyout);

}//end if statement

//if Brutus position equals endpoint


if (brutusx>=319){
//print message of win
LCD.WriteLine("You got Brutus across the Oval! :)");
LCD.WriteLine("");
LCD.Write("Your time: ");
LCD.Write(currenttime);
LCD.WriteLine(" seconds");
LCD.WriteLine("");

A6
//if current time is less than fastest time
if (currenttime<highscore)
{
//store current time as fastest time
highscore=currenttime;
//print message of beating high score
LCD.WriteLine("!You beat the high score!");

LCD.WriteLine("Touch screen to continue");

//while-loop to wait for touch


while (!LCD.Touch(&x_position,&y_position)){
Sleep(25);
} //end while-loop when touched
while (LCD.Touch(&x_position, &y_position)){
Sleep(1);
} //end while-loop when released
}
LCD.WriteLine("Touch screen to continue");

//while-loop to wait for touch


while (!LCD.Touch(&x_position,&y_position)){
Sleep(25);
} //end while-loop when touched
while (LCD.Touch(&x_position, &y_position)){
Sleep(1);
} //end while-loop when released

x=1; //break while-loop


} //end if loop

//losing: if Brutus position equals pedestrian position


if (brutusx==p1x&&(brutusyout==p1ay)) /* if Brutus is on pathway 1*/ {
LCD.WriteLine("You lost! You couldn't get Brutus across the Oval");
x=1; //break while-loop

LCD.WriteLine("Touch screen to continue");

//while-loop to wait for touch


while (!LCD.Touch(&x_position,&y_position)){
Sleep(25);
} //end while-loop when touched
while (LCD.Touch(&x_position, &y_position)){
Sleep(1);

A7
} //end while-loop when released
}

if (brutusx==p2x&&(brutusyout==p2ay)) /* if Brutus is on pathway 2*/ {


LCD.WriteLine("You lost! You couldn't get Brutus across the Oval");
x=1; //break while-loop

LCD.WriteLine("Touch screen to continue");

//while-loop to wait for touch


while (!LCD.Touch(&x_position,&y_position)){
Sleep(25);
} //end while-loop when touched
while (LCD.Touch(&x_position, &y_position)){
Sleep(1);
} //end while-loop when released
}

if (brutusx==p3x&&(brutusyout==p3ay)) /* if Brutus is on pathway 1*/ {


LCD.WriteLine("You lost! You couldn't get Brutus across the Oval");
x=1; //break while-loop

LCD.WriteLine("Touch screen to continue");

//while-loop to wait for touch


while (!LCD.Touch(&x_position,&y_position)){
Sleep(25);
} //end while-loop when touched
while (LCD.Touch(&x_position, &y_position)){
Sleep(1);
} //end while-loop when released
}

if (brutusx==p4x&&(brutusyout==p4ay)) /* if Brutus is on pathway 1*/ {


LCD.WriteLine("You lost! You couldn't get Brutus across the Oval");
x=1; //break while-loop

LCD.WriteLine("Touch screen to continue");

//while-loop to wait for touch


while (!LCD.Touch(&x_position,&y_position)){
Sleep(25);
} //end while-loop when touched
while (LCD.Touch(&x_position,&y_position)){

A8
Sleep(1);
} //end while-loop when touched
}
//'erase' pedestrian
LCD.SetFontColor(TAN); //set color to black
LCD.FillCircle(p1x,p1ay,15); //set pedestrian 1a

LCD.FillCircle(p2x,p2ay,15); //set pedestrian 2a

LCD.FillCircle(p3x,p3ay,15); //set pedestrian 3a

LCD.FillCircle(p4x,p4ay,15); //set pedestrian 4a

//move pedestrian across the screen


p1ay=p1ay+40;
p2ay=p2ay+40;
p3ay=p3ay+40;
p4ay=p4ay+40;

//if pedestrian 1 position gets to bottom of screen


if (p1ay>239){
p1ay=39;}//reset to top of screen

//if pedestrian 2 position gets to top of screen


if (p2ay>239){
p2ay=39;}//reset to top of screen

//if pedestrian 3 position gets to bottom of screen


if (p3ay>239){
p3ay=39;}//reset to top of screen

//if pedestrian 4 position gets to bottom of screen


if (p4ay>239){
p4ay=39;}//reset to top of screen

} //end of while-loop

LCD.Clear();//clear screen

LCD.Write("Touch screen to continue");

//while-loop to wait for touch


while (!LCD.Touch(&x_position,&y_position)){
Sleep(25);

A9
} //end while-loop when touched
while (LCD.Touch(&x_position, &y_position)){
Sleep(1);
} //end while-loop when released

//return high score value


return (highscore);

} //end game function

//PRINT OVAL FUNCTION


void printoval()
{
//declare variables
int path1=50, path2=122, path3=194, path4=266, pathwidth=36;

//print oval layout screen


LCD.SetBackgroundColor(DARKGREEN); //set background color as green
LCD.Clear();
LCD.SetFontColor(TAN); //set path color to taan
LCD.FillRectangle(0,94,319, 50); //horizontal pathway Brutus walks along
LCD.FillRectangle(path1, 0, pathwidth, 239); //vertical path for pedestrians
LCD.FillRectangle(path2, 0, pathwidth, 239); //vertical path for pedestrians
LCD.FillRectangle(path3, 0, pathwidth, 239); //vertical path for pedestrians
LCD.FillRectangle(path4, 0, pathwidth, 239); //vertical path for pedestrians
} //end oval function

//PRINT BRUTUS FUNCTION


void printbrutus(int brutusx, int brutusyin, int brutusyout)
{
printoval(); //print oval layout to screen
//print Brutus in origin to screen (35,119)
LCD.SetFontColor(SADDLEBROWN); //set color for outer circle
LCD.FillCircle(brutusx,brutusyout,20); //fill outer circle
LCD.SetFontColor(WHEAT); //set color for inner circle
LCD.FillCircle(brutusx,brutusyin,10); //fill inner circle
} //end brutus function

//START SCREEN FUNCTION


int startscreen()
{
//declare variables
int status;
float xposition, yposition, a, b;

A10
//print options to screen
LCD.SetBackgroundColor(GRAY); //set background color as white
LCD.Clear();
LCD.SetFontColor(SCARLET);
LCD.DrawVerticalLine(147,0,239);
LCD.DrawHorizontalLine(120,0,319);
LCD.WriteAt("Play the",0,0);
LCD.WriteAt("game!",0,20);
LCD.WriteAt("Rules and",0,150);
LCD.WriteAt("Instructions",0,170);
LCD.WriteAt("Statistics",150,0);
LCD.WriteAt("Credits", 150,150);

//while-loop to wait for touch


while (!LCD.Touch(&xposition, &yposition)){
Sleep(25);
} //end while-loop when touched
while (LCD.Touch(&a, &b)){
Sleep(1);
} //end while-loop when released

//if statement for different parts of screen


//for play
if (xposition<115&&yposition<142){
status=1;
}

//for rules and instructions


if (xposition<115&&yposition>152){
status=2;
}

//for statistics
if (xposition>125&&yposition<142){
status=3;
}

//for credits
if (xposition>125&&yposition>152){
status=4;
}
return(status);
} //end start screen function

A11

S-ar putea să vă placă și