Using Namespace: #Include #Include #Include #Include #Include
Using Namespace: #Include #Include #Include #Include #Include
h>
#include <FEHIO.h>
#include <FEHUtility.h>
#include <cstdlib>
#include <ctime>
//Function begins the game and continues until the player dies
void start_game(scorekeeper *score_obj)
{
//All variables used are initialized here
float x, y; //Used to check for touch on the screen
int score = 0, sleep_counter = 0; //Used to keep track of the score and
to modulate the time interval of the function
int bird_x = 30, bird_y = 120; //Saves the initial position values of the
bird to variables
//Only three walls will ever be present on the screen at once, so each is
initialized. With no width or height these are at first invisible
int wall1 = 0, wall2 = 0, wall_gap = 0, wall_x = 300; //Initializes the
values of the first wall
int wall1_2 = 0, wall2_2 = 0, wall_gap_2 = 0, wall_x2 = 120;
//Initializes the values of the second wall
int wall1_3 = 0, wall2_3 = 0, wall_gap_3 = 0, wall_x3 = 220;
//Initializes the values of the third wall
double start_time; //Declares the start time variable to be used for an
initial time
//The font color is set to black and the score is displayed and
updated on screen
LCD.SetFontColor(BLACK);
LCD.WriteRC("Score", 13, 0);
LCD.WriteRC(score, 13, 6);
//Death parameters
//This is also one of many instances of logical operators in the
program
if ((bird_x >= wall_x && bird_x <= (wall_x+20))) //If the x position
of the bird is within the width of the walls
{ //and the y position
is within the height of the walls, the loop exits and ends the game
if ((bird_y >= 0 && bird_y <= (wall1)) || (bird_y >= wall_gap &&
bird_y <= 240))
{
break;
}
}
LCD.SetFontColor(BLUE);
LCD.FillRectangle(wall_x, 0, 20, wall1);
LCD.FillRectangle(wall_x, wall_gap, 20, wall2); //This will clear
the first wall at its previous position
wall_x2 -= 15;
LCD.SetFontColor(GREEN);
LCD.FillRectangle(wall_x2, 0, 20, wall1_2);
LCD.FillRectangle(wall_x2, wall_gap_2, 20, wall2_2);
}
wall_x3 -= 15;
LCD.SetFontColor(GREEN);
LCD.FillRectangle(wall_x3, 0, 20, wall1_3);
LCD.FillRectangle(wall_x3, wall_gap_3, 20, wall2_3);
}
if (wall_x == 0) //If any of the walls reach the right hand side,
they disappear
{
LCD.SetFontColor(BLUE);
LCD.FillRectangle(wall_x, 0, 20, wall1);
LCD.FillRectangle(wall_x, wall_gap, 20, wall2);
if (wall_x2 == 0)
{
LCD.SetFontColor(BLUE);
LCD.FillRectangle(wall_x2, 0, 20, wall1_2);
LCD.FillRectangle(wall_x2, wall_gap_2, 20, wall2_2);
wall_x2 = 0;
wall1_2 = 0;
wall2_2 = 0;
wall_gap_2 = 0;
}
if (wall_x3 == 0)
{
LCD.SetFontColor(BLUE);
LCD.FillRectangle(wall_x3, 0, 20, wall1_3);
LCD.FillRectangle(wall_x3, wall_gap_3, 20, wall2_3);
wall_x3 = 0;
wall1_3 = 0;
wall2_3 = 0;
wall_gap_3 = 0;
}
//Creates an object for the scorekeeper class and calls the sort
function, passing it the score value
(*score_obj).sort_hscore(&score);
LCD.Clear();
(*score_obj).display_hscores(); //Screen is cleared and the display high
scores function is called
wait(); //The screen stays on high scores until the player clicks the
left button
wait(); //Waits for the user to left click before going back to the start
menu
}
wait(); //Waits for the player to left click before moving back to the
main menu
}
wait(); //Waits for the player to left click before moving to page 2
LCD.Clear();
LCD.WriteRC("-------Credits-------", 3, 1);
LCD.WriteRC("Contributor: Peter Schmitz", 5, 0);
LCD.WriteRC("Contributor: Alex Jacobs", 7, 1);
LCD.WriteRC("Project Overseer:", 9, 1);
LCD.WriteRC(" Dr. Philip Schlosser", 11, 1);
wait(); //Waits for left click before moving back to main menu
}
//Wait function waits for the user to press and release the left button
void wait()
{
while (!buttons.LeftPressed()); //Game repeats an infinite loop while the
button is not pressed
//Once the button is pressed, the game
leaves the previous loop and enters the next one
while (buttons.LeftPressed()); //Game repeats an infinite loop while the
button remains pressed, and exits when the button is no longer pressed
}
//Scroll function takes an integer input and changes the font color of the
selection screen to match the user scrolling
void scroll(int *option)
{
switch (*option)
//if (*option == 1) //If the option variable is 1, make start game red
and the others white
{
case 1:
LCD.Clear();
LCD.SetFontColor(RED);
LCD.WriteRC("Start Game", 4, 9);
LCD.SetFontColor(WHITE);
LCD.WriteRC("Instructions", 6, 9);
LCD.WriteRC("Scores", 8, 9);
LCD.WriteRC("Credits", 10, 9);
break;
//}
//else if (*option == 2) //If the option variable is 2, make instructions
red and the others white
//{
case 2:
LCD.Clear();
LCD.SetFontColor(WHITE);
LCD.WriteRC("Start Game", 4, 9);
LCD.SetFontColor(RED);
LCD.WriteRC("Instructions", 6, 9);
LCD.SetFontColor(WHITE);
LCD.WriteRC("Scores", 8, 9);
LCD.WriteRC("Credits", 10, 9);
break;
//}
//else if (*option == 3) //Repeat for scores
//{
case 3:
LCD.Clear();
LCD.SetFontColor(WHITE);
LCD.WriteRC("Start Game", 4, 9);
LCD.WriteRC("Instructions", 6, 9);
LCD.SetFontColor(RED);
LCD.WriteRC("Scores", 8, 9);
LCD.SetFontColor(WHITE);
LCD.WriteRC("Credits", 10, 9);
break;
//}
//else if (*option == 4) //Repeat for credits
//{
case 4:
LCD.Clear();
LCD.SetFontColor(WHITE);
LCD.WriteRC("Start Game", 4, 9);
LCD.WriteRC("Instructions", 6, 9);
LCD.WriteRC("Scores", 8, 9);
LCD.SetFontColor(RED);
LCD.WriteRC("Credits", 10, 9);
break;
}
}
//Function generates the intro screen and the start menu and all its options
void start_menu()
{
//Create a scorekeeper object to pass to score function and start game
function
scorekeeper score_obj;
// Introduction screen to the game; Set screen to black and font to white
LCD.Clear(FEHLCD::Black);
LCD.SetFontColor(FEHLCD::White);
wait(); //Waits for the user to left click the button board
//This displays the game options, with start game as the default
selection in red
LCD.Clear();
LCD.SetFontColor(RED);
LCD.WriteRC("Start Game", 4, 9);
LCD.SetFontColor(WHITE);
LCD.WriteRC("Instructions", 6, 9);
LCD.WriteRC("Scores", 8, 9);
LCD.WriteRC("Credits", 10, 9);
//while (true)
//This will execute infinitely
for (;;)
{
if (buttons.LeftPressed()) //If the left button is pressed, execute
{
if (buttons.LeftReleased()) //If the left button is released,
execute
{
//if (option == 1)
switch (option) //This switch case executes each option
depending on the value of option at this instance
{
case 1: //If the value of option is 1, the start game
function is called to start the game
start_game(&score_obj);
LCD.Clear(); //After the player dies, the screen is
cleared and restored to the selection menu with start game as default
selection
LCD.SetFontColor(RED);
LCD.WriteRC("Start Game", 4, 9);
LCD.SetFontColor(WHITE);
LCD.WriteRC("Instructions", 6, 9);
LCD.WriteRC("Scores", 8, 9);
LCD.WriteRC("Credits", 10, 9);
break;
//}
//else if (option == 2)
case 2: //If the value of option is 2, the instructions
function is called to display instructions for the game
//{
instructions();
LCD.Clear(); //After the player exits, the screen is
restored to the selection menu, with instructions still selected
LCD.SetFontColor(WHITE);
LCD.WriteRC("Start Game", 4, 9);
LCD.SetFontColor(RED);
LCD.WriteRC("Instructions", 6, 9);
LCD.SetFontColor(WHITE);
LCD.WriteRC("Scores", 8, 9);
LCD.WriteRC("Credits", 10, 9);
break;
//}
//else if (option == 3)
//{
case 3: //If the value of option is 3, the scores
function is called to display the scores
scores(&score_obj);
LCD.Clear(); //After the player exits, the screen is
restored to the selection menu, with scores still selected
LCD.SetFontColor(WHITE);
LCD.WriteRC("Start Game", 4, 9);
LCD.WriteRC("Instructions", 6, 9);
LCD.SetFontColor(RED);
LCD.WriteRC("Scores", 8, 9);
LCD.SetFontColor(WHITE);
LCD.WriteRC("Credits", 10, 9);
break;
//}
//else if (option == 4)
//{
case 4: //If the value of option is 4, the credits
function is called to display the credits
credits();
LCD.Clear(); //After the player exits, the screen is
restored to the selection menu, with credits still selected
LCD.SetFontColor(WHITE);
LCD.WriteRC("Start Game", 4, 9);
LCD.WriteRC("Instructions", 6, 9);
LCD.WriteRC("Scores", 8, 9);
LCD.SetFontColor(RED);
LCD.WriteRC("Credits", 10, 9);
break;
}
}
}
else if (buttons.MiddlePressed()) //If the middle button is pressed,
execute
{
if (buttons.MiddleReleased()) //If the middle button is released,
execute
{
if (option < 4) //If the variable option is currently less
than 4, add one to it
{
option += 1;
}
scroll(&option); //Pass the increased option value to the
scroll function, which then changes the font of the options to imitate
scrolling down
}
}
else if (buttons.RightPressed()) //If the right button is pressed,
execute
{
if (buttons.RightReleased()) //If the right button is released
execute
{
if (option > 1) //If the variable is currently greater than
1, subtract one from it
{
option -= 1;
}
scroll (&option); //Pass the decreased option value to the
scroll function, which then changes the font of the options to imitate
scrolling up
}
}
}
}
//Main function of the program, mostly to call the start menu function
int main(void)
{
start_menu(); //Calls the start menu, program will end when the proteus
is shut down
}