mRackitBall - the single player pong

Dependencies:   4DGL-uLCD-SE mbed-rtos mbed

Committer:
hrodriguez8
Date:
Wed Oct 22 18:48:34 2014 +0000
Revision:
0:3c93e7a26a42
mRackitBall is essentially a single player pong.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hrodriguez8 0:3c93e7a26a42 1 #include "mbed.h"
hrodriguez8 0:3c93e7a26a42 2 //#include "rtos.h"
hrodriguez8 0:3c93e7a26a42 3 #include "stdio.h"
hrodriguez8 0:3c93e7a26a42 4 #include "uLCD_4DGL.h"
hrodriguez8 0:3c93e7a26a42 5
hrodriguez8 0:3c93e7a26a42 6 #define boldOn uLCD.text_bold(ON)
hrodriguez8 0:3c93e7a26a42 7 #define boldOff uLCD.text_bold(OFF)
hrodriguez8 0:3c93e7a26a42 8
hrodriguez8 0:3c93e7a26a42 9 /*Setting up required pins, global variables and other required items*/
hrodriguez8 0:3c93e7a26a42 10
hrodriguez8 0:3c93e7a26a42 11 //Debugging Options
hrodriguez8 0:3c93e7a26a42 12 int lcdjoystickDebug = 0; //1=on, 0=off
hrodriguez8 0:3c93e7a26a42 13
hrodriguez8 0:3c93e7a26a42 14
hrodriguez8 0:3c93e7a26a42 15 /* ----- Status Led ----- */
hrodriguez8 0:3c93e7a26a42 16 //DigitalOut statusLed(LED1); //if off - in menu ... if on - in game ... if flashing - paused?
hrodriguez8 0:3c93e7a26a42 17
hrodriguez8 0:3c93e7a26a42 18 /* ----- Pushbuttons ----- */
hrodriguez8 0:3c93e7a26a42 19 InterruptIn pbSelect(p22); //right pb - select
hrodriguez8 0:3c93e7a26a42 20 InterruptIn pbPause(p21); //left pb - pause/resume game
hrodriguez8 0:3c93e7a26a42 21
hrodriguez8 0:3c93e7a26a42 22 /* ----- LCD screen ----- */
hrodriguez8 0:3c93e7a26a42 23 uLCD_4DGL uLCD(p9, p10, p11); // create a lcd object
hrodriguez8 0:3c93e7a26a42 24 //Mutex lcd_mutex; //used to lock the lcd
hrodriguez8 0:3c93e7a26a42 25
hrodriguez8 0:3c93e7a26a42 26 /* ----- Joystick ----- */
hrodriguez8 0:3c93e7a26a42 27 static const float lcdWidth = 128; //Lcd screen is 128x128
hrodriguez8 0:3c93e7a26a42 28 static const float lcdHeight = 128;
hrodriguez8 0:3c93e7a26a42 29 AnalogIn joystickX(p15);
hrodriguez8 0:3c93e7a26a42 30 AnalogIn joystickY(p16);
hrodriguez8 0:3c93e7a26a42 31
hrodriguez8 0:3c93e7a26a42 32 volatile float joystickXReading; //Read joystick x
hrodriguez8 0:3c93e7a26a42 33 volatile float joystickYReading; //Read joystick y
hrodriguez8 0:3c93e7a26a42 34 volatile unsigned int Xpos; //joystick x pos after calc
hrodriguez8 0:3c93e7a26a42 35 volatile unsigned int Ypos; //joystick y pos after calc
hrodriguez8 0:3c93e7a26a42 36
hrodriguez8 0:3c93e7a26a42 37 /* ----- States for game and menus ----- */
hrodriguez8 0:3c93e7a26a42 38 //Probably a way to optimize this to limit the usage of global variables
hrodriguez8 0:3c93e7a26a42 39
hrodriguez8 0:3c93e7a26a42 40 volatile int currentState = 1; //State starts in menu -- 1=menu -- 2=options -- 3=start game -- 4=pause game
hrodriguez8 0:3c93e7a26a42 41 volatile int mainMenuSelection = 1; //Determines which menu option is currently highlighted 1=Start , 2=Options
hrodriguez8 0:3c93e7a26a42 42
hrodriguez8 0:3c93e7a26a42 43 volatile int optionsMenuSelection = 1; //Determines which option is highlighted
hrodriguez8 0:3c93e7a26a42 44 volatile int optionsChoice = 1; //Determines which # is highlighted on each item
hrodriguez8 0:3c93e7a26a42 45
hrodriguez8 0:3c93e7a26a42 46
hrodriguez8 0:3c93e7a26a42 47 /* ----- Functions/Prototypes ----- */
hrodriguez8 0:3c93e7a26a42 48 void mainMenu();
hrodriguez8 0:3c93e7a26a42 49 void optionsMenu();
hrodriguez8 0:3c93e7a26a42 50 void helpMenu();
hrodriguez8 0:3c93e7a26a42 51 void startGame();
hrodriguez8 0:3c93e7a26a42 52
hrodriguez8 0:3c93e7a26a42 53 void drawDesign();
hrodriguez8 0:3c93e7a26a42 54
hrodriguez8 0:3c93e7a26a42 55 /* ----- End Functions/Prototypes ----- */
hrodriguez8 0:3c93e7a26a42 56
hrodriguez8 0:3c93e7a26a42 57
hrodriguez8 0:3c93e7a26a42 58 /* ----- Changeable Options ----- */
hrodriguez8 0:3c93e7a26a42 59 //When drawing the menu, drawing the player paddle or drawing the ball on the screen
hrodriguez8 0:3c93e7a26a42 60 //use these variables
hrodriguez8 0:3c93e7a26a42 61
hrodriguez8 0:3c93e7a26a42 62 int textColorMain = GREEN; // Changes the main text color
hrodriguez8 0:3c93e7a26a42 63 int textColorSecondary = RED; //This is the color of text when highlighted
hrodriguez8 0:3c93e7a26a42 64 int playerColor = GREEN; // Changes the player paddle color -- 1=green, 2=blue
hrodriguez8 0:3c93e7a26a42 65 int ballColor = WHITE; //Changes the ball color -- 1=white, 2=red
hrodriguez8 0:3c93e7a26a42 66 int borderDesign = 1; //Changes the main menu's border design -- 1=none, 2=square with lines
hrodriguez8 0:3c93e7a26a42 67
hrodriguez8 0:3c93e7a26a42 68 /* ----- End Changeable Options ----- */
hrodriguez8 0:3c93e7a26a42 69
hrodriguez8 0:3c93e7a26a42 70
hrodriguez8 0:3c93e7a26a42 71 /* ----- Game Variables And Functions ----- */
hrodriguez8 0:3c93e7a26a42 72
hrodriguez8 0:3c93e7a26a42 73 //For player paddle
hrodriguez8 0:3c93e7a26a42 74 int playerxPos, playeryPos, playerLength, playerThickness;
hrodriguez8 0:3c93e7a26a42 75 void movePlayer(); //moving the padddle
hrodriguez8 0:3c93e7a26a42 76
hrodriguez8 0:3c93e7a26a42 77 //For ball
hrodriguez8 0:3c93e7a26a42 78 int ballxPos, ballyPos, ballRadius;
hrodriguez8 0:3c93e7a26a42 79 float fx, fy,vx,vy;
hrodriguez8 0:3c93e7a26a42 80 void moveBall(); //moving the ball
hrodriguez8 0:3c93e7a26a42 81
hrodriguez8 0:3c93e7a26a42 82
hrodriguez8 0:3c93e7a26a42 83 /* ----- End In-game Variables ----- */
hrodriguez8 0:3c93e7a26a42 84
hrodriguez8 0:3c93e7a26a42 85
hrodriguez8 0:3c93e7a26a42 86
hrodriguez8 0:3c93e7a26a42 87
hrodriguez8 0:3c93e7a26a42 88 /* ----- Main ----- */
hrodriguez8 0:3c93e7a26a42 89 int main() {
hrodriguez8 0:3c93e7a26a42 90
hrodriguez8 0:3c93e7a26a42 91 pbSelect.mode(PullUp); // PullUp mode for pushbuttons
hrodriguez8 0:3c93e7a26a42 92 pbPause.mode(PullUp);
hrodriguez8 0:3c93e7a26a42 93
hrodriguez8 0:3c93e7a26a42 94 uLCD.baudrate(3000000); //overclock LCD
hrodriguez8 0:3c93e7a26a42 95 uLCD.cls();
hrodriguez8 0:3c93e7a26a42 96
hrodriguez8 0:3c93e7a26a42 97 playerxPos = 50; playeryPos = 124;
hrodriguez8 0:3c93e7a26a42 98 playerLength = 78; playerThickness = 126;
hrodriguez8 0:3c93e7a26a42 99
hrodriguez8 0:3c93e7a26a42 100 fx=60.0, fy=115.0, vx=1.0, vy=0.5;
hrodriguez8 0:3c93e7a26a42 101 ballxPos = 60; ballyPos = 115; ballRadius = 3;
hrodriguez8 0:3c93e7a26a42 102
hrodriguez8 0:3c93e7a26a42 103 while(true) {
hrodriguez8 0:3c93e7a26a42 104
hrodriguez8 0:3c93e7a26a42 105 joystickXReading = joystickX; //Joystick calculations
hrodriguez8 0:3c93e7a26a42 106 joystickYReading = 1.0f - joystickY;
hrodriguez8 0:3c93e7a26a42 107
hrodriguez8 0:3c93e7a26a42 108 Xpos = (unsigned int)(lcdWidth * joystickXReading);
hrodriguez8 0:3c93e7a26a42 109 Ypos = (unsigned int)(lcdHeight * joystickYReading);
hrodriguez8 0:3c93e7a26a42 110
hrodriguez8 0:3c93e7a26a42 111 switch(currentState){ //States for the game -- 1=menu -- 2=options -- 3=help -- 4=start game -- 5=pause game
hrodriguez8 0:3c93e7a26a42 112
hrodriguez8 0:3c93e7a26a42 113 case 1: //MENU
hrodriguez8 0:3c93e7a26a42 114 mainMenu();
hrodriguez8 0:3c93e7a26a42 115 wait(.15); //delay for selecting
hrodriguez8 0:3c93e7a26a42 116 break;
hrodriguez8 0:3c93e7a26a42 117
hrodriguez8 0:3c93e7a26a42 118 case 2: //OPTIONS
hrodriguez8 0:3c93e7a26a42 119 optionsMenu();
hrodriguez8 0:3c93e7a26a42 120 wait(.15);
hrodriguez8 0:3c93e7a26a42 121 break;
hrodriguez8 0:3c93e7a26a42 122
hrodriguez8 0:3c93e7a26a42 123 case 3: //HELP
hrodriguez8 0:3c93e7a26a42 124 helpMenu();
hrodriguez8 0:3c93e7a26a42 125 wait(.15);
hrodriguez8 0:3c93e7a26a42 126 break;
hrodriguez8 0:3c93e7a26a42 127
hrodriguez8 0:3c93e7a26a42 128 case 4: //START GAME
hrodriguez8 0:3c93e7a26a42 129 startGame();
hrodriguez8 0:3c93e7a26a42 130 wait(.15);
hrodriguez8 0:3c93e7a26a42 131 break;
hrodriguez8 0:3c93e7a26a42 132
hrodriguez8 0:3c93e7a26a42 133 case 5: //PAUSE GAME
hrodriguez8 0:3c93e7a26a42 134 boldOn;
hrodriguez8 0:3c93e7a26a42 135 uLCD.text_string("Paused", 6, 7, FONT_5X7, textColorMain);
hrodriguez8 0:3c93e7a26a42 136 boldOff;
hrodriguez8 0:3c93e7a26a42 137 while(pbPause);
hrodriguez8 0:3c93e7a26a42 138 uLCD.text_string(" ", 6, 7, FONT_5X7, BLACK);
hrodriguez8 0:3c93e7a26a42 139 currentState = 4; //Stay in above loop unless pressed
hrodriguez8 0:3c93e7a26a42 140 wait(.15);
hrodriguez8 0:3c93e7a26a42 141 break;
hrodriguez8 0:3c93e7a26a42 142
hrodriguez8 0:3c93e7a26a42 143 }//End switch for states
hrodriguez8 0:3c93e7a26a42 144
hrodriguez8 0:3c93e7a26a42 145 }//End While
hrodriguez8 0:3c93e7a26a42 146
hrodriguez8 0:3c93e7a26a42 147 }//End Main
hrodriguez8 0:3c93e7a26a42 148
hrodriguez8 0:3c93e7a26a42 149 /* ----- End Main ----- */
hrodriguez8 0:3c93e7a26a42 150
hrodriguez8 0:3c93e7a26a42 151
hrodriguez8 0:3c93e7a26a42 152
hrodriguez8 0:3c93e7a26a42 153 /* ----- Full Functions ----- */
hrodriguez8 0:3c93e7a26a42 154
hrodriguez8 0:3c93e7a26a42 155 ////////////////////
hrodriguez8 0:3c93e7a26a42 156 // --- mainMenu --- //
hrodriguez8 0:3c93e7a26a42 157 void mainMenu(){ //This will show which option the player has selected by highlighting it based on mainMenuSelection
hrodriguez8 0:3c93e7a26a42 158
hrodriguez8 0:3c93e7a26a42 159 if( Xpos > 70 ) { //We are scrolling down, 66 is when joystick isn't moving
hrodriguez8 0:3c93e7a26a42 160 mainMenuSelection++;
hrodriguez8 0:3c93e7a26a42 161 if(mainMenuSelection > 3) mainMenuSelection = 1; //If there were more options you could change (> 2) to (> # of selections)
hrodriguez8 0:3c93e7a26a42 162 }
hrodriguez8 0:3c93e7a26a42 163
hrodriguez8 0:3c93e7a26a42 164 if( Xpos < 62 ) { //We are scrolling up
hrodriguez8 0:3c93e7a26a42 165 mainMenuSelection--;
hrodriguez8 0:3c93e7a26a42 166 if(mainMenuSelection < 1) mainMenuSelection = 3; //If there were more options you could change (menuSelection # of selections)
hrodriguez8 0:3c93e7a26a42 167 }
hrodriguez8 0:3c93e7a26a42 168
hrodriguez8 0:3c93e7a26a42 169 uLCD.locate(4,0);
hrodriguez8 0:3c93e7a26a42 170 uLCD.printf("mRackitBall");
hrodriguez8 0:3c93e7a26a42 171
hrodriguez8 0:3c93e7a26a42 172 if(borderDesign != 1) drawDesign(); //If borderDesign doesn't equal one then there is a design, draw it
hrodriguez8 0:3c93e7a26a42 173
hrodriguez8 0:3c93e7a26a42 174 if(mainMenuSelection == 1) {
hrodriguez8 0:3c93e7a26a42 175 boldOn;
hrodriguez8 0:3c93e7a26a42 176 uLCD.text_string("Start", 6, 4, FONT_5X7, textColorSecondary);
hrodriguez8 0:3c93e7a26a42 177 boldOff;
hrodriguez8 0:3c93e7a26a42 178 }
hrodriguez8 0:3c93e7a26a42 179 else {
hrodriguez8 0:3c93e7a26a42 180 uLCD.text_string("Start", 6, 4, FONT_5X7, textColorMain);
hrodriguez8 0:3c93e7a26a42 181 }
hrodriguez8 0:3c93e7a26a42 182
hrodriguez8 0:3c93e7a26a42 183 if(mainMenuSelection == 2) {
hrodriguez8 0:3c93e7a26a42 184 boldOn;
hrodriguez8 0:3c93e7a26a42 185 uLCD.text_string("Options", 6, 7, FONT_5X7, textColorSecondary);
hrodriguez8 0:3c93e7a26a42 186 boldOff;
hrodriguez8 0:3c93e7a26a42 187 }
hrodriguez8 0:3c93e7a26a42 188 else {
hrodriguez8 0:3c93e7a26a42 189 uLCD.text_string("Options", 6, 7, FONT_5X7, textColorMain);
hrodriguez8 0:3c93e7a26a42 190 }
hrodriguez8 0:3c93e7a26a42 191
hrodriguez8 0:3c93e7a26a42 192 if(mainMenuSelection == 3) {
hrodriguez8 0:3c93e7a26a42 193 boldOn;
hrodriguez8 0:3c93e7a26a42 194 uLCD.text_string("Help", 6, 10, FONT_5X7, textColorSecondary);
hrodriguez8 0:3c93e7a26a42 195 boldOff;
hrodriguez8 0:3c93e7a26a42 196 }
hrodriguez8 0:3c93e7a26a42 197 else {
hrodriguez8 0:3c93e7a26a42 198 uLCD.text_string("Help", 6, 10, FONT_5X7, textColorMain);
hrodriguez8 0:3c93e7a26a42 199 }
hrodriguez8 0:3c93e7a26a42 200
hrodriguez8 0:3c93e7a26a42 201 uLCD.text_string("", 7, 10, FONT_5X7, textColorMain); //Prevents other text from gettin wrong colors (how to fix..)
hrodriguez8 0:3c93e7a26a42 202
hrodriguez8 0:3c93e7a26a42 203
hrodriguez8 0:3c93e7a26a42 204
hrodriguez8 0:3c93e7a26a42 205 if(!pbSelect) { //When the select(right) button is pressed currentState will change
hrodriguez8 0:3c93e7a26a42 206 if(mainMenuSelection == 1) { //Start the game -- 4=start game
hrodriguez8 0:3c93e7a26a42 207 currentState = 4;
hrodriguez8 0:3c93e7a26a42 208 uLCD.cls();
hrodriguez8 0:3c93e7a26a42 209 }
hrodriguez8 0:3c93e7a26a42 210 if(mainMenuSelection == 2) { //Open options menu -- 2=options
hrodriguez8 0:3c93e7a26a42 211 currentState = 2;
hrodriguez8 0:3c93e7a26a42 212 uLCD.cls();
hrodriguez8 0:3c93e7a26a42 213 }
hrodriguez8 0:3c93e7a26a42 214 if(mainMenuSelection == 3) { //Open help menu -- 3=help
hrodriguez8 0:3c93e7a26a42 215 currentState = 3;
hrodriguez8 0:3c93e7a26a42 216 uLCD.cls();
hrodriguez8 0:3c93e7a26a42 217 }
hrodriguez8 0:3c93e7a26a42 218 } // End pushButton selection
hrodriguez8 0:3c93e7a26a42 219
hrodriguez8 0:3c93e7a26a42 220 } // End Menu Function
hrodriguez8 0:3c93e7a26a42 221 ////////////////////
hrodriguez8 0:3c93e7a26a42 222
hrodriguez8 0:3c93e7a26a42 223
hrodriguez8 0:3c93e7a26a42 224 ////////////////////
hrodriguez8 0:3c93e7a26a42 225 // --- Options Menu
hrodriguez8 0:3c93e7a26a42 226
hrodriguez8 0:3c93e7a26a42 227 void optionsMenu() {
hrodriguez8 0:3c93e7a26a42 228
hrodriguez8 0:3c93e7a26a42 229 uLCD.text_string("Options", 5, 0, FONT_5X7, textColorMain);
hrodriguez8 0:3c93e7a26a42 230
hrodriguez8 0:3c93e7a26a42 231 //These determine how many options are in each highlighted options, each option will change accordingly
hrodriguez8 0:3c93e7a26a42 232 //Example: If you want 3 text options, make numTextOptions = 3 and then add the new text color
hrodriguez8 0:3c93e7a26a42 233 // to the correct section of the code. Although due to LCD width constraints you may be only
hrodriguez8 0:3c93e7a26a42 234 // able to add 4 different options.
hrodriguez8 0:3c93e7a26a42 235
hrodriguez8 0:3c93e7a26a42 236 //Changes these variables according to how many options you want to have.
hrodriguez8 0:3c93e7a26a42 237 int numTextOptions = 2; //green, white
hrodriguez8 0:3c93e7a26a42 238 int numPlayerOptions = 2; //green, blue
hrodriguez8 0:3c93e7a26a42 239 int numBallColorOptions = 2; //white, red
hrodriguez8 0:3c93e7a26a42 240 int numMainMenuDesigns = 3; //none, squares with lines, squares with double lines
hrodriguez8 0:3c93e7a26a42 241
hrodriguez8 0:3c93e7a26a42 242 //-- This is for the options menu determining which option is highlighted
hrodriguez8 0:3c93e7a26a42 243 if( Xpos > 70 ) { //We are scrolling down, 66 is when joystick isn't moving -- This is for the options menu determining which option is highlighted
hrodriguez8 0:3c93e7a26a42 244 optionsMenuSelection++;
hrodriguez8 0:3c93e7a26a42 245 if(optionsMenuSelection > 5) optionsMenuSelection = 1; //If there were more options you could change (> 2) to (> # of selections)
hrodriguez8 0:3c93e7a26a42 246 }
hrodriguez8 0:3c93e7a26a42 247 if( Xpos < 62 ) { //We are scrolling up
hrodriguez8 0:3c93e7a26a42 248 optionsMenuSelection--;
hrodriguez8 0:3c93e7a26a42 249 if(optionsMenuSelection < 1) optionsMenuSelection = 5; //If there were more options you could change (menuSelection # of selections)
hrodriguez8 0:3c93e7a26a42 250 }
hrodriguez8 0:3c93e7a26a42 251 if( Ypos < 70 ) { //We are scrolling right
hrodriguez8 0:3c93e7a26a42 252 optionsChoice++;
hrodriguez8 0:3c93e7a26a42 253 }
hrodriguez8 0:3c93e7a26a42 254 if( Ypos > 62 ) { //We are scrolling left
hrodriguez8 0:3c93e7a26a42 255 optionsChoice--;
hrodriguez8 0:3c93e7a26a42 256 }
hrodriguez8 0:3c93e7a26a42 257
hrodriguez8 0:3c93e7a26a42 258 ////
hrodriguez8 0:3c93e7a26a42 259 //Begin Option Selection and Changing
hrodriguez8 0:3c93e7a26a42 260 ////
hrodriguez8 0:3c93e7a26a42 261
hrodriguez8 0:3c93e7a26a42 262 //--TextColor Change
hrodriguez8 0:3c93e7a26a42 263 if( optionsMenuSelection == 1 ) {
hrodriguez8 0:3c93e7a26a42 264
hrodriguez8 0:3c93e7a26a42 265
hrodriguez8 0:3c93e7a26a42 266 if(optionsChoice > numTextOptions) { optionsChoice = numTextOptions; } //Don't go past the max number of options. No wrap around.
hrodriguez8 0:3c93e7a26a42 267 if(optionsChoice < 0) { optionsChoice = 1; }
hrodriguez8 0:3c93e7a26a42 268
hrodriguez8 0:3c93e7a26a42 269 boldOn;
hrodriguez8 0:3c93e7a26a42 270 uLCD.text_string("TextColor", 0, 2, FONT_5X7, textColorSecondary);
hrodriguez8 0:3c93e7a26a42 271 boldOff;
hrodriguez8 0:3c93e7a26a42 272
hrodriguez8 0:3c93e7a26a42 273 if(optionsChoice == 1) { //highlight textColor 1 -- green
hrodriguez8 0:3c93e7a26a42 274 boldOn;
hrodriguez8 0:3c93e7a26a42 275 uLCD.text_string("1", 10, 2, FONT_5X7, textColorMain);
hrodriguez8 0:3c93e7a26a42 276 boldOff;
hrodriguez8 0:3c93e7a26a42 277 }
hrodriguez8 0:3c93e7a26a42 278 else {
hrodriguez8 0:3c93e7a26a42 279 uLCD.text_string("1", 10, 2, FONT_5X7, textColorMain);
hrodriguez8 0:3c93e7a26a42 280 }
hrodriguez8 0:3c93e7a26a42 281
hrodriguez8 0:3c93e7a26a42 282 if(optionsChoice == 2) { //highlight textColor 2 -- white
hrodriguez8 0:3c93e7a26a42 283 boldOn;
hrodriguez8 0:3c93e7a26a42 284 uLCD.text_string("2", 12, 2, FONT_5X7, textColorMain);
hrodriguez8 0:3c93e7a26a42 285 boldOff;
hrodriguez8 0:3c93e7a26a42 286 }
hrodriguez8 0:3c93e7a26a42 287 else {
hrodriguez8 0:3c93e7a26a42 288 uLCD.text_string("2", 12, 2, FONT_5X7, textColorMain);
hrodriguez8 0:3c93e7a26a42 289 }
hrodriguez8 0:3c93e7a26a42 290
hrodriguez8 0:3c93e7a26a42 291 //From the example above, you would add more colors here.
hrodriguez8 0:3c93e7a26a42 292
hrodriguez8 0:3c93e7a26a42 293 //Press pushbutton to select the option
hrodriguez8 0:3c93e7a26a42 294 if(!pbSelect){
hrodriguez8 0:3c93e7a26a42 295 if(optionsChoice == 1) { textColorMain = GREEN; }
hrodriguez8 0:3c93e7a26a42 296 if(optionsChoice == 2) { textColorMain = WHITE; }
hrodriguez8 0:3c93e7a26a42 297 }
hrodriguez8 0:3c93e7a26a42 298 }
hrodriguez8 0:3c93e7a26a42 299
hrodriguez8 0:3c93e7a26a42 300 else { //if not selected, just display it
hrodriguez8 0:3c93e7a26a42 301 uLCD.text_string("TextColor", 0, 2, FONT_5X7, textColorMain);
hrodriguez8 0:3c93e7a26a42 302
hrodriguez8 0:3c93e7a26a42 303 //This will keep the option bolded in the options Menu -- showing which option is currently selected
hrodriguez8 0:3c93e7a26a42 304 if(textColorMain == GREEN) { //keep 1 bolded
hrodriguez8 0:3c93e7a26a42 305 boldOn;
hrodriguez8 0:3c93e7a26a42 306 uLCD.text_string("1", 10, 2, FONT_5X7, textColorMain);
hrodriguez8 0:3c93e7a26a42 307 boldOff;
hrodriguez8 0:3c93e7a26a42 308 }
hrodriguez8 0:3c93e7a26a42 309 else {
hrodriguez8 0:3c93e7a26a42 310 uLCD.text_string("1", 10, 2, FONT_5X7, textColorMain);
hrodriguez8 0:3c93e7a26a42 311 }
hrodriguez8 0:3c93e7a26a42 312
hrodriguez8 0:3c93e7a26a42 313 if(textColorMain == WHITE) { //keep 2 bolded
hrodriguez8 0:3c93e7a26a42 314 boldOn;
hrodriguez8 0:3c93e7a26a42 315 uLCD.text_string("2", 12, 2, FONT_5X7, textColorMain);
hrodriguez8 0:3c93e7a26a42 316 boldOff;
hrodriguez8 0:3c93e7a26a42 317 }
hrodriguez8 0:3c93e7a26a42 318 else {
hrodriguez8 0:3c93e7a26a42 319 uLCD.text_string("2", 12, 2, FONT_5X7, textColorMain);
hrodriguez8 0:3c93e7a26a42 320 }
hrodriguez8 0:3c93e7a26a42 321
hrodriguez8 0:3c93e7a26a42 322 //From the example above, you would add more colors here aswell.
hrodriguez8 0:3c93e7a26a42 323
hrodriguez8 0:3c93e7a26a42 324 }
hrodriguez8 0:3c93e7a26a42 325 //--End TextColor Change
hrodriguez8 0:3c93e7a26a42 326
hrodriguez8 0:3c93e7a26a42 327
hrodriguez8 0:3c93e7a26a42 328 //--Player Color
hrodriguez8 0:3c93e7a26a42 329 if( optionsMenuSelection == 2 ) {
hrodriguez8 0:3c93e7a26a42 330
hrodriguez8 0:3c93e7a26a42 331 if(optionsChoice > numPlayerOptions) { optionsChoice = numPlayerOptions; } //Don't go past the max number of options. No wrap around.
hrodriguez8 0:3c93e7a26a42 332 if(optionsChoice < 0) { optionsChoice = 1; }
hrodriguez8 0:3c93e7a26a42 333
hrodriguez8 0:3c93e7a26a42 334 boldOn;
hrodriguez8 0:3c93e7a26a42 335 uLCD.text_string("PlayerCol", 0, 4, FONT_5X7, textColorSecondary);
hrodriguez8 0:3c93e7a26a42 336 boldOff;
hrodriguez8 0:3c93e7a26a42 337
hrodriguez8 0:3c93e7a26a42 338 if(optionsChoice == 1) { //highlight textColor 1 -- green
hrodriguez8 0:3c93e7a26a42 339 boldOn;
hrodriguez8 0:3c93e7a26a42 340 uLCD.text_string("1", 10, 4, FONT_5X7, textColorMain);
hrodriguez8 0:3c93e7a26a42 341 boldOff;
hrodriguez8 0:3c93e7a26a42 342 }
hrodriguez8 0:3c93e7a26a42 343 else {
hrodriguez8 0:3c93e7a26a42 344 uLCD.text_string("1", 10, 4, FONT_5X7, textColorMain);
hrodriguez8 0:3c93e7a26a42 345 }
hrodriguez8 0:3c93e7a26a42 346
hrodriguez8 0:3c93e7a26a42 347 if(optionsChoice == 2) { //highlight textColor 2 -- blue
hrodriguez8 0:3c93e7a26a42 348 boldOn;
hrodriguez8 0:3c93e7a26a42 349 uLCD.text_string("2", 12, 4, FONT_5X7, textColorMain);
hrodriguez8 0:3c93e7a26a42 350 boldOff;
hrodriguez8 0:3c93e7a26a42 351 }
hrodriguez8 0:3c93e7a26a42 352 else {
hrodriguez8 0:3c93e7a26a42 353 uLCD.text_string("2", 12, 4, FONT_5X7, textColorMain);
hrodriguez8 0:3c93e7a26a42 354 }
hrodriguez8 0:3c93e7a26a42 355
hrodriguez8 0:3c93e7a26a42 356 //add more player colors above
hrodriguez8 0:3c93e7a26a42 357
hrodriguez8 0:3c93e7a26a42 358 //Press pushbutton to select the option
hrodriguez8 0:3c93e7a26a42 359 if(!pbSelect){
hrodriguez8 0:3c93e7a26a42 360 if(optionsChoice == 1) { playerColor = GREEN; }
hrodriguez8 0:3c93e7a26a42 361 if(optionsChoice == 2) { playerColor = BLUE; }
hrodriguez8 0:3c93e7a26a42 362 }
hrodriguez8 0:3c93e7a26a42 363 }
hrodriguez8 0:3c93e7a26a42 364
hrodriguez8 0:3c93e7a26a42 365 else { //if not selected, just display it
hrodriguez8 0:3c93e7a26a42 366 uLCD.text_string("PlayerCol", 0, 4, FONT_5X7, textColorMain);
hrodriguez8 0:3c93e7a26a42 367
hrodriguez8 0:3c93e7a26a42 368 //This will keep the option bolded in the options Menu -- showing which option is currently selected
hrodriguez8 0:3c93e7a26a42 369 if(playerColor == GREEN) { //keep 1 bolded
hrodriguez8 0:3c93e7a26a42 370 boldOn;
hrodriguez8 0:3c93e7a26a42 371 uLCD.text_string("1", 10, 4, FONT_5X7, textColorMain);
hrodriguez8 0:3c93e7a26a42 372 boldOff;
hrodriguez8 0:3c93e7a26a42 373 }
hrodriguez8 0:3c93e7a26a42 374 else {
hrodriguez8 0:3c93e7a26a42 375 uLCD.text_string("1", 10, 4, FONT_5X7, textColorMain);
hrodriguez8 0:3c93e7a26a42 376 }
hrodriguez8 0:3c93e7a26a42 377
hrodriguez8 0:3c93e7a26a42 378 if(playerColor == BLUE) { //keep 2 bolded
hrodriguez8 0:3c93e7a26a42 379 boldOn;
hrodriguez8 0:3c93e7a26a42 380 uLCD.text_string("2", 12, 4, FONT_5X7, textColorMain);
hrodriguez8 0:3c93e7a26a42 381 boldOff;
hrodriguez8 0:3c93e7a26a42 382 }
hrodriguez8 0:3c93e7a26a42 383 else {
hrodriguez8 0:3c93e7a26a42 384 uLCD.text_string("2", 12, 4, FONT_5X7, textColorMain);
hrodriguez8 0:3c93e7a26a42 385 }
hrodriguez8 0:3c93e7a26a42 386
hrodriguez8 0:3c93e7a26a42 387 //add more player colors above
hrodriguez8 0:3c93e7a26a42 388 }
hrodriguez8 0:3c93e7a26a42 389 //--End Player Color
hrodriguez8 0:3c93e7a26a42 390
hrodriguez8 0:3c93e7a26a42 391
hrodriguez8 0:3c93e7a26a42 392 //--Ball Color
hrodriguez8 0:3c93e7a26a42 393 if( optionsMenuSelection == 3 ) {
hrodriguez8 0:3c93e7a26a42 394
hrodriguez8 0:3c93e7a26a42 395 if(optionsChoice > numBallColorOptions) { optionsChoice = numBallColorOptions; } //Don't go past the max number of options. No wrap around.
hrodriguez8 0:3c93e7a26a42 396 if(optionsChoice < 0) { optionsChoice = 1; }
hrodriguez8 0:3c93e7a26a42 397
hrodriguez8 0:3c93e7a26a42 398 boldOn;
hrodriguez8 0:3c93e7a26a42 399 uLCD.text_string("BallColor", 0, 6, FONT_5X7, textColorSecondary);
hrodriguez8 0:3c93e7a26a42 400 boldOff;
hrodriguez8 0:3c93e7a26a42 401
hrodriguez8 0:3c93e7a26a42 402 if(optionsChoice == 1) { //highlight textColor 1 -- green
hrodriguez8 0:3c93e7a26a42 403 boldOn;
hrodriguez8 0:3c93e7a26a42 404 uLCD.text_string("1", 10, 6, FONT_5X7, textColorMain);
hrodriguez8 0:3c93e7a26a42 405 boldOff;
hrodriguez8 0:3c93e7a26a42 406 }
hrodriguez8 0:3c93e7a26a42 407 else {
hrodriguez8 0:3c93e7a26a42 408 uLCD.text_string("1", 10, 6, FONT_5X7, textColorMain);
hrodriguez8 0:3c93e7a26a42 409 }
hrodriguez8 0:3c93e7a26a42 410
hrodriguez8 0:3c93e7a26a42 411 if(optionsChoice == 2) { //highlight textColor 2 -- red
hrodriguez8 0:3c93e7a26a42 412 boldOn;
hrodriguez8 0:3c93e7a26a42 413 uLCD.text_string("2", 12, 6, FONT_5X7, textColorMain);
hrodriguez8 0:3c93e7a26a42 414 boldOff;
hrodriguez8 0:3c93e7a26a42 415 }
hrodriguez8 0:3c93e7a26a42 416 else {
hrodriguez8 0:3c93e7a26a42 417 uLCD.text_string("2", 12, 6, FONT_5X7, textColorMain);
hrodriguez8 0:3c93e7a26a42 418 }
hrodriguez8 0:3c93e7a26a42 419
hrodriguez8 0:3c93e7a26a42 420 //add more ball colors above
hrodriguez8 0:3c93e7a26a42 421
hrodriguez8 0:3c93e7a26a42 422 //Press pushbutton to select the option
hrodriguez8 0:3c93e7a26a42 423 if(!pbSelect){
hrodriguez8 0:3c93e7a26a42 424 if(optionsChoice == 1) { ballColor = WHITE; }
hrodriguez8 0:3c93e7a26a42 425 if(optionsChoice == 2) { ballColor = RED; }
hrodriguez8 0:3c93e7a26a42 426 }
hrodriguez8 0:3c93e7a26a42 427 }
hrodriguez8 0:3c93e7a26a42 428
hrodriguez8 0:3c93e7a26a42 429 else { //if not selected, just display it
hrodriguez8 0:3c93e7a26a42 430 uLCD.text_string("BallColor", 0, 6, FONT_5X7, textColorMain);
hrodriguez8 0:3c93e7a26a42 431
hrodriguez8 0:3c93e7a26a42 432 //This will keep the option bolded in the options Menu -- showing which option is currently selected
hrodriguez8 0:3c93e7a26a42 433 if(ballColor == WHITE) { //keep 1 bolded
hrodriguez8 0:3c93e7a26a42 434 boldOn;
hrodriguez8 0:3c93e7a26a42 435 uLCD.text_string("1", 10, 6, FONT_5X7, textColorMain);
hrodriguez8 0:3c93e7a26a42 436 boldOff;
hrodriguez8 0:3c93e7a26a42 437 }
hrodriguez8 0:3c93e7a26a42 438 else {
hrodriguez8 0:3c93e7a26a42 439 uLCD.text_string("1", 10, 6, FONT_5X7, textColorMain);
hrodriguez8 0:3c93e7a26a42 440 }
hrodriguez8 0:3c93e7a26a42 441
hrodriguez8 0:3c93e7a26a42 442 if(ballColor == RED) { //keep 2 bolded
hrodriguez8 0:3c93e7a26a42 443 boldOn;
hrodriguez8 0:3c93e7a26a42 444 uLCD.text_string("2", 12, 6, FONT_5X7, textColorMain);
hrodriguez8 0:3c93e7a26a42 445 boldOff;
hrodriguez8 0:3c93e7a26a42 446 }
hrodriguez8 0:3c93e7a26a42 447 else {
hrodriguez8 0:3c93e7a26a42 448 uLCD.text_string("2", 12, 6, FONT_5X7, textColorMain);
hrodriguez8 0:3c93e7a26a42 449 }
hrodriguez8 0:3c93e7a26a42 450
hrodriguez8 0:3c93e7a26a42 451 //add more ball colors above
hrodriguez8 0:3c93e7a26a42 452 }
hrodriguez8 0:3c93e7a26a42 453
hrodriguez8 0:3c93e7a26a42 454 //--End Ball Color
hrodriguez8 0:3c93e7a26a42 455
hrodriguez8 0:3c93e7a26a42 456
hrodriguez8 0:3c93e7a26a42 457 //--Main Menu Design
hrodriguez8 0:3c93e7a26a42 458 if( optionsMenuSelection == 4 ) {
hrodriguez8 0:3c93e7a26a42 459
hrodriguez8 0:3c93e7a26a42 460
hrodriguez8 0:3c93e7a26a42 461 if(optionsChoice > numMainMenuDesigns) { optionsChoice = numMainMenuDesigns; } //Don't go past the max number of options. No wrap around.
hrodriguez8 0:3c93e7a26a42 462 if(optionsChoice < 0) { optionsChoice = 1; }
hrodriguez8 0:3c93e7a26a42 463
hrodriguez8 0:3c93e7a26a42 464
hrodriguez8 0:3c93e7a26a42 465 boldOn;
hrodriguez8 0:3c93e7a26a42 466 uLCD.text_string("Design", 0, 8, FONT_5X7, textColorSecondary);
hrodriguez8 0:3c93e7a26a42 467 boldOff;
hrodriguez8 0:3c93e7a26a42 468
hrodriguez8 0:3c93e7a26a42 469 if(optionsChoice == 1) { //highlight design 1 - no design
hrodriguez8 0:3c93e7a26a42 470 boldOn;
hrodriguez8 0:3c93e7a26a42 471 uLCD.text_string("1", 10, 8, FONT_5X7, textColorMain);
hrodriguez8 0:3c93e7a26a42 472 boldOff;
hrodriguez8 0:3c93e7a26a42 473 }
hrodriguez8 0:3c93e7a26a42 474 else {
hrodriguez8 0:3c93e7a26a42 475 uLCD.text_string("1", 10, 8, FONT_5X7, textColorMain);
hrodriguez8 0:3c93e7a26a42 476 }
hrodriguez8 0:3c93e7a26a42 477
hrodriguez8 0:3c93e7a26a42 478 if(optionsChoice == 2) { //highlight design 2 -- rectangles with lines
hrodriguez8 0:3c93e7a26a42 479 boldOn;
hrodriguez8 0:3c93e7a26a42 480 uLCD.text_string("2", 12, 8, FONT_5X7, textColorMain);
hrodriguez8 0:3c93e7a26a42 481 boldOff;
hrodriguez8 0:3c93e7a26a42 482 }
hrodriguez8 0:3c93e7a26a42 483 else {
hrodriguez8 0:3c93e7a26a42 484 uLCD.text_string("2", 12, 8, FONT_5X7, textColorMain);
hrodriguez8 0:3c93e7a26a42 485 }
hrodriguez8 0:3c93e7a26a42 486
hrodriguez8 0:3c93e7a26a42 487 if(optionsChoice == 3) { // highlight design 3 -- rectangles with double lines
hrodriguez8 0:3c93e7a26a42 488 boldOn;
hrodriguez8 0:3c93e7a26a42 489 uLCD.text_string("3", 14, 8, FONT_5X7, textColorMain);
hrodriguez8 0:3c93e7a26a42 490 boldOff;
hrodriguez8 0:3c93e7a26a42 491 }
hrodriguez8 0:3c93e7a26a42 492 else {
hrodriguez8 0:3c93e7a26a42 493 uLCD.text_string("3", 14, 8, FONT_5X7, textColorMain);
hrodriguez8 0:3c93e7a26a42 494 }
hrodriguez8 0:3c93e7a26a42 495
hrodriguez8 0:3c93e7a26a42 496 //Add new designs above here
hrodriguez8 0:3c93e7a26a42 497 //Press pushbutton to select the option
hrodriguez8 0:3c93e7a26a42 498 if(!pbSelect){
hrodriguez8 0:3c93e7a26a42 499 if(optionsChoice == 1) { borderDesign = 1; }
hrodriguez8 0:3c93e7a26a42 500 if(optionsChoice == 2) { borderDesign = 2; }
hrodriguez8 0:3c93e7a26a42 501 if(optionsChoice == 3) { borderDesign = 3; }
hrodriguez8 0:3c93e7a26a42 502 }
hrodriguez8 0:3c93e7a26a42 503 }
hrodriguez8 0:3c93e7a26a42 504
hrodriguez8 0:3c93e7a26a42 505 else {
hrodriguez8 0:3c93e7a26a42 506 uLCD.text_string("Design", 0, 8, FONT_5X7, textColorMain);
hrodriguez8 0:3c93e7a26a42 507
hrodriguez8 0:3c93e7a26a42 508 //This will keep the option bolded in the options Menu -- showing which option is currently selected
hrodriguez8 0:3c93e7a26a42 509 if(borderDesign == 1) { //keep 1 bolded
hrodriguez8 0:3c93e7a26a42 510 boldOn;
hrodriguez8 0:3c93e7a26a42 511 uLCD.text_string("1", 10, 8, FONT_5X7, textColorMain);
hrodriguez8 0:3c93e7a26a42 512 boldOff;
hrodriguez8 0:3c93e7a26a42 513 }
hrodriguez8 0:3c93e7a26a42 514 else {
hrodriguez8 0:3c93e7a26a42 515 uLCD.text_string("1", 10, 8, FONT_5X7, textColorMain);
hrodriguez8 0:3c93e7a26a42 516 }
hrodriguez8 0:3c93e7a26a42 517
hrodriguez8 0:3c93e7a26a42 518 if(borderDesign == 2) { //keep 2 bolded
hrodriguez8 0:3c93e7a26a42 519 boldOn;
hrodriguez8 0:3c93e7a26a42 520 uLCD.text_string("2", 12, 8, FONT_5X7, textColorMain);
hrodriguez8 0:3c93e7a26a42 521 boldOff;
hrodriguez8 0:3c93e7a26a42 522 }
hrodriguez8 0:3c93e7a26a42 523 else {
hrodriguez8 0:3c93e7a26a42 524 uLCD.text_string("2", 12, 8, FONT_5X7, textColorMain);
hrodriguez8 0:3c93e7a26a42 525 }
hrodriguez8 0:3c93e7a26a42 526
hrodriguez8 0:3c93e7a26a42 527 if(borderDesign == 3) { //keep 3 bolded
hrodriguez8 0:3c93e7a26a42 528 boldOn;
hrodriguez8 0:3c93e7a26a42 529 uLCD.text_string("3", 14, 8, FONT_5X7, textColorMain);
hrodriguez8 0:3c93e7a26a42 530 boldOff;
hrodriguez8 0:3c93e7a26a42 531 }
hrodriguez8 0:3c93e7a26a42 532 else {
hrodriguez8 0:3c93e7a26a42 533 uLCD.text_string("3", 14, 8, FONT_5X7, textColorMain);
hrodriguez8 0:3c93e7a26a42 534 }
hrodriguez8 0:3c93e7a26a42 535
hrodriguez8 0:3c93e7a26a42 536 //Add new designs above here
hrodriguez8 0:3c93e7a26a42 537 }//end else
hrodriguez8 0:3c93e7a26a42 538
hrodriguez8 0:3c93e7a26a42 539 //--End MainMenu Design
hrodriguez8 0:3c93e7a26a42 540
hrodriguez8 0:3c93e7a26a42 541
hrodriguez8 0:3c93e7a26a42 542
hrodriguez8 0:3c93e7a26a42 543 //--Back
hrodriguez8 0:3c93e7a26a42 544 if( optionsMenuSelection == 5 ) { //Go Back to mainMenu state
hrodriguez8 0:3c93e7a26a42 545 boldOn;
hrodriguez8 0:3c93e7a26a42 546 uLCD.text_string("Back", 0, 13, FONT_5X7, textColorSecondary);
hrodriguez8 0:3c93e7a26a42 547 boldOff;
hrodriguez8 0:3c93e7a26a42 548 uLCD.text_string("", 1, 13, FONT_5X7, textColorMain);
hrodriguez8 0:3c93e7a26a42 549
hrodriguez8 0:3c93e7a26a42 550 if(!pbSelect) { //When pushbutton is pressed go back to mainmenu state
hrodriguez8 0:3c93e7a26a42 551 currentState = 1;
hrodriguez8 0:3c93e7a26a42 552 optionsMenuSelection = 1; //reset is back to 1 for next entry
hrodriguez8 0:3c93e7a26a42 553 uLCD.cls();
hrodriguez8 0:3c93e7a26a42 554 }
hrodriguez8 0:3c93e7a26a42 555 }
hrodriguez8 0:3c93e7a26a42 556 else {
hrodriguez8 0:3c93e7a26a42 557 uLCD.text_string("Back", 0, 13, FONT_5X7, textColorMain);
hrodriguez8 0:3c93e7a26a42 558 }
hrodriguez8 0:3c93e7a26a42 559
hrodriguez8 0:3c93e7a26a42 560 //--End Back
hrodriguez8 0:3c93e7a26a42 561
hrodriguez8 0:3c93e7a26a42 562 }
hrodriguez8 0:3c93e7a26a42 563 // --- End Options Menu
hrodriguez8 0:3c93e7a26a42 564 ////////////////////
hrodriguez8 0:3c93e7a26a42 565
hrodriguez8 0:3c93e7a26a42 566
hrodriguez8 0:3c93e7a26a42 567 ////////////////////
hrodriguez8 0:3c93e7a26a42 568 // --- Help Menu
hrodriguez8 0:3c93e7a26a42 569
hrodriguez8 0:3c93e7a26a42 570 void helpMenu(){
hrodriguez8 0:3c93e7a26a42 571
hrodriguez8 0:3c93e7a26a42 572 uLCD.text_string("Help", 6, 0, FONT_5X7, textColorMain);
hrodriguez8 0:3c93e7a26a42 573
hrodriguez8 0:3c93e7a26a42 574 uLCD.text_string("Joystick", 0, 2, FONT_5X7, textColorMain);
hrodriguez8 0:3c93e7a26a42 575 uLCD.text_string("Used to move", 1, 3, FONT_5X7, textColorMain);
hrodriguez8 0:3c93e7a26a42 576
hrodriguez8 0:3c93e7a26a42 577 uLCD.text_string("Left Button", 0, 5, FONT_5X7, textColorMain);
hrodriguez8 0:3c93e7a26a42 578 uLCD.text_string("Used to pause", 1, 6, FONT_5X7, textColorMain);
hrodriguez8 0:3c93e7a26a42 579
hrodriguez8 0:3c93e7a26a42 580 uLCD.text_string("Right Button", 0, 8, FONT_5X7, textColorMain);
hrodriguez8 0:3c93e7a26a42 581 uLCD.text_string("Used to select", 1, 9, FONT_5X7, textColorMain);
hrodriguez8 0:3c93e7a26a42 582
hrodriguez8 0:3c93e7a26a42 583 boldOn;
hrodriguez8 0:3c93e7a26a42 584 uLCD.text_string("Back", 0, 13, FONT_5X7, textColorSecondary);
hrodriguez8 0:3c93e7a26a42 585 boldOff;
hrodriguez8 0:3c93e7a26a42 586 uLCD.text_string("", 1, 13, FONT_5X7, textColorMain);
hrodriguez8 0:3c93e7a26a42 587
hrodriguez8 0:3c93e7a26a42 588 if(!pbSelect) { // When Back is selected go back to the main menu state -- 1=main menu
hrodriguez8 0:3c93e7a26a42 589 currentState = 1;
hrodriguez8 0:3c93e7a26a42 590 uLCD.cls();
hrodriguez8 0:3c93e7a26a42 591 }
hrodriguez8 0:3c93e7a26a42 592 }
hrodriguez8 0:3c93e7a26a42 593 // --- End Help Menu
hrodriguez8 0:3c93e7a26a42 594 ////////////////////
hrodriguez8 0:3c93e7a26a42 595
hrodriguez8 0:3c93e7a26a42 596
hrodriguez8 0:3c93e7a26a42 597 ////////////////////
hrodriguez8 0:3c93e7a26a42 598 // --- drawDesign (border for mainmenu)
hrodriguez8 0:3c93e7a26a42 599 void drawDesign() {
hrodriguez8 0:3c93e7a26a42 600
hrodriguez8 0:3c93e7a26a42 601 if(borderDesign == 2) {
hrodriguez8 0:3c93e7a26a42 602 uLCD.line(0, 0, 0, 127, textColorMain);
hrodriguez8 0:3c93e7a26a42 603 uLCD.line(127, 0, 127, 127, textColorMain);
hrodriguez8 0:3c93e7a26a42 604 uLCD.line(0, 127, 127, 127, textColorMain);
hrodriguez8 0:3c93e7a26a42 605 uLCD.filled_rectangle(0, 0, 5, 5, textColorMain);
hrodriguez8 0:3c93e7a26a42 606 uLCD.filled_rectangle(122, 0, 127, 5, textColorMain);
hrodriguez8 0:3c93e7a26a42 607 uLCD.filled_rectangle(0, 122, 5, 127, textColorMain);
hrodriguez8 0:3c93e7a26a42 608 uLCD.filled_rectangle(122, 122, 127, 127, textColorMain);
hrodriguez8 0:3c93e7a26a42 609 }
hrodriguez8 0:3c93e7a26a42 610
hrodriguez8 0:3c93e7a26a42 611 if(borderDesign == 3) {
hrodriguez8 0:3c93e7a26a42 612 uLCD.line(0, 0, 0, 127, textColorMain);
hrodriguez8 0:3c93e7a26a42 613 uLCD.line(127, 0, 127, 127, textColorMain);
hrodriguez8 0:3c93e7a26a42 614 uLCD.line(0, 127, 127, 127, textColorMain);
hrodriguez8 0:3c93e7a26a42 615
hrodriguez8 0:3c93e7a26a42 616 uLCD.line(5, 0, 5, 127, textColorMain);
hrodriguez8 0:3c93e7a26a42 617 uLCD.line(122, 0, 122, 127, textColorMain);
hrodriguez8 0:3c93e7a26a42 618 uLCD.line(0, 122, 127, 122, textColorMain);
hrodriguez8 0:3c93e7a26a42 619
hrodriguez8 0:3c93e7a26a42 620 uLCD.filled_rectangle(0, 0, 5, 5, textColorMain);
hrodriguez8 0:3c93e7a26a42 621 uLCD.filled_rectangle(122, 0, 127, 5, textColorMain);
hrodriguez8 0:3c93e7a26a42 622 uLCD.filled_rectangle(0, 122, 5, 127, textColorMain);
hrodriguez8 0:3c93e7a26a42 623 uLCD.filled_rectangle(122, 122, 127, 127, textColorMain);
hrodriguez8 0:3c93e7a26a42 624 }
hrodriguez8 0:3c93e7a26a42 625
hrodriguez8 0:3c93e7a26a42 626 }
hrodriguez8 0:3c93e7a26a42 627 // --- drawDesign
hrodriguez8 0:3c93e7a26a42 628 ////////////////////
hrodriguez8 0:3c93e7a26a42 629
hrodriguez8 0:3c93e7a26a42 630
hrodriguez8 0:3c93e7a26a42 631 ////////////////////
hrodriguez8 0:3c93e7a26a42 632 // --- Start Game
hrodriguez8 0:3c93e7a26a42 633
hrodriguez8 0:3c93e7a26a42 634 void startGame() {
hrodriguez8 0:3c93e7a26a42 635
hrodriguez8 0:3c93e7a26a42 636 if(!pbSelect) {
hrodriguez8 0:3c93e7a26a42 637
hrodriguez8 0:3c93e7a26a42 638 currentState = 1; //Reset and go to menu if rightbutton is pressed
hrodriguez8 0:3c93e7a26a42 639
hrodriguez8 0:3c93e7a26a42 640 playerxPos = 50; playeryPos = 124; //Reset the variables for next run
hrodriguez8 0:3c93e7a26a42 641 playerLength = 78; playerThickness = 126;
hrodriguez8 0:3c93e7a26a42 642
hrodriguez8 0:3c93e7a26a42 643 fx=60.0, fy=115.0, vx=1.0, vy=0.5;
hrodriguez8 0:3c93e7a26a42 644 ballxPos = 60; ballyPos = 115; ballRadius = 3;
hrodriguez8 0:3c93e7a26a42 645
hrodriguez8 0:3c93e7a26a42 646 uLCD.cls();
hrodriguez8 0:3c93e7a26a42 647 wait(.2);
hrodriguez8 0:3c93e7a26a42 648 return;
hrodriguez8 0:3c93e7a26a42 649 }
hrodriguez8 0:3c93e7a26a42 650 if(!pbPause) {
hrodriguez8 0:3c93e7a26a42 651 wait(.15);
hrodriguez8 0:3c93e7a26a42 652 currentState = 5; //Pause the game
hrodriguez8 0:3c93e7a26a42 653 return;
hrodriguez8 0:3c93e7a26a42 654 }
hrodriguez8 0:3c93e7a26a42 655
hrodriguez8 0:3c93e7a26a42 656 //uLCD.filled_circle(64, 115, 3, ballColor); //ball
hrodriguez8 0:3c93e7a26a42 657
hrodriguez8 0:3c93e7a26a42 658 movePlayer(); //move the paddle
hrodriguez8 0:3c93e7a26a42 659 moveBall();
hrodriguez8 0:3c93e7a26a42 660
hrodriguez8 0:3c93e7a26a42 661
hrodriguez8 0:3c93e7a26a42 662
hrodriguez8 0:3c93e7a26a42 663
hrodriguez8 0:3c93e7a26a42 664 }
hrodriguez8 0:3c93e7a26a42 665 // --- End Start Game
hrodriguez8 0:3c93e7a26a42 666 ////////////////////
hrodriguez8 0:3c93e7a26a42 667
hrodriguez8 0:3c93e7a26a42 668
hrodriguez8 0:3c93e7a26a42 669 ////////////////////
hrodriguez8 0:3c93e7a26a42 670 // --- movePlayer
hrodriguez8 0:3c93e7a26a42 671
hrodriguez8 0:3c93e7a26a42 672 //For player paddle
hrodriguez8 0:3c93e7a26a42 673 //int playerxPos, playeryPos, playerLength, playerThickness;
hrodriguez8 0:3c93e7a26a42 674
hrodriguez8 0:3c93e7a26a42 675 void movePlayer() {
hrodriguez8 0:3c93e7a26a42 676 //Draw paddle
hrodriguez8 0:3c93e7a26a42 677 uLCD.filled_rectangle(playerxPos, playeryPos, playerLength, playerThickness, playerColor); //player paddle
hrodriguez8 0:3c93e7a26a42 678
hrodriguez8 0:3c93e7a26a42 679 int playerSpeedModifier = 3;
hrodriguez8 0:3c93e7a26a42 680
hrodriguez8 0:3c93e7a26a42 681 if( Ypos < 70 && playerLength < 126) { //scrolling left, increasing x, and not at the border
hrodriguez8 0:3c93e7a26a42 682 playerxPos += playerSpeedModifier; //Changes these numbers to increase scrolling speed
hrodriguez8 0:3c93e7a26a42 683 playerLength += playerSpeedModifier;
hrodriguez8 0:3c93e7a26a42 684 //color to the left
hrodriguez8 0:3c93e7a26a42 685 uLCD.filled_rectangle(playerxPos-(playerSpeedModifier), playeryPos, playerxPos, playerThickness, BLACK);
hrodriguez8 0:3c93e7a26a42 686 }
hrodriguez8 0:3c93e7a26a42 687 if( Ypos > 62 && playerxPos > 0) { //scrolling right, decreaseing x, and not at the border
hrodriguez8 0:3c93e7a26a42 688 playerxPos -= playerSpeedModifier; //Changes these numbers to increase scrolling speed
hrodriguez8 0:3c93e7a26a42 689 playerLength -= playerSpeedModifier;
hrodriguez8 0:3c93e7a26a42 690 //color to the right
hrodriguez8 0:3c93e7a26a42 691 uLCD.filled_rectangle(playerLength, playeryPos, playerLength+(playerSpeedModifier), playerThickness, BLACK);
hrodriguez8 0:3c93e7a26a42 692 }
hrodriguez8 0:3c93e7a26a42 693
hrodriguez8 0:3c93e7a26a42 694 }
hrodriguez8 0:3c93e7a26a42 695 // --- End Move
hrodriguez8 0:3c93e7a26a42 696 ////////////////////
hrodriguez8 0:3c93e7a26a42 697
hrodriguez8 0:3c93e7a26a42 698 ////////////////////
hrodriguez8 0:3c93e7a26a42 699 // --- moveball
hrodriguez8 0:3c93e7a26a42 700 /*
hrodriguez8 0:3c93e7a26a42 701 //For ball
hrodriguez8 0:3c93e7a26a42 702 int ballxPos, ballyPos, ballWidth, ballHeight, ballxSpeed, ballySpeed;
hrodriguez8 0:3c93e7a26a42 703 void moveBall(); //moving the ball
hrodriguez8 0:3c93e7a26a42 704 */
hrodriguez8 0:3c93e7a26a42 705
hrodriguez8 0:3c93e7a26a42 706 void moveBall() {
hrodriguez8 0:3c93e7a26a42 707 uLCD.filled_circle(ballxPos, ballyPos, ballRadius, BLACK); //ball
hrodriguez8 0:3c93e7a26a42 708
hrodriguez8 0:3c93e7a26a42 709 if( (ballxPos <= ballRadius+1) || (ballxPos>=127-ballRadius) ) {
hrodriguez8 0:3c93e7a26a42 710 vx = -vx*2;
hrodriguez8 0:3c93e7a26a42 711 }
hrodriguez8 0:3c93e7a26a42 712
hrodriguez8 0:3c93e7a26a42 713 if( (ballyPos <= ballRadius+1) || (ballyPos>=127-ballRadius) ) {
hrodriguez8 0:3c93e7a26a42 714 if(ballyPos >= playeryPos && ( (ballxPos <= playerxPos)||(ballxPos >= playerLength) ) ) {
hrodriguez8 0:3c93e7a26a42 715 uLCD.text_string("Game over", 6,4, FONT_5X7, textColorMain);
hrodriguez8 0:3c93e7a26a42 716 currentState = 1;
hrodriguez8 0:3c93e7a26a42 717 wait(4);
hrodriguez8 0:3c93e7a26a42 718 uLCD.cls();
hrodriguez8 0:3c93e7a26a42 719
hrodriguez8 0:3c93e7a26a42 720 playerxPos = 50; playeryPos = 124; //Reset the variables for next run
hrodriguez8 0:3c93e7a26a42 721 playerLength = 78; playerThickness = 126;
hrodriguez8 0:3c93e7a26a42 722
hrodriguez8 0:3c93e7a26a42 723 fx=60.0, fy=115.0, vx=1.0, vy=0.5;
hrodriguez8 0:3c93e7a26a42 724 ballxPos = 60; ballyPos = 115; ballRadius = 3;
hrodriguez8 0:3c93e7a26a42 725
hrodriguez8 0:3c93e7a26a42 726 return;
hrodriguez8 0:3c93e7a26a42 727 }
hrodriguez8 0:3c93e7a26a42 728 vy = -vy*2;
hrodriguez8 0:3c93e7a26a42 729 }
hrodriguez8 0:3c93e7a26a42 730
hrodriguez8 0:3c93e7a26a42 731 if(vy > 6 ) { vy = 6; } //These determine how fast the ball will go and when it will cap off
hrodriguez8 0:3c93e7a26a42 732 else if( vy < -6 ) { vy = -6; }
hrodriguez8 0:3c93e7a26a42 733
hrodriguez8 0:3c93e7a26a42 734 if(vx > 6 ){ vx = 6; }
hrodriguez8 0:3c93e7a26a42 735 else if( vx < -6 ) { vx = -6; }
hrodriguez8 0:3c93e7a26a42 736
hrodriguez8 0:3c93e7a26a42 737 if(lcdjoystickDebug){
hrodriguez8 0:3c93e7a26a42 738 uLCD.locate(0,0);
hrodriguez8 0:3c93e7a26a42 739 uLCD.printf("px%3d, py%3d",playerxPos, playeryPos);
hrodriguez8 0:3c93e7a26a42 740 uLCD.locate(0,1);
hrodriguez8 0:3c93e7a26a42 741 uLCD.printf("l%3d, t%3d", playerLength, playerThickness);
hrodriguez8 0:3c93e7a26a42 742 uLCD.locate(0,2);
hrodriguez8 0:3c93e7a26a42 743 uLCD.printf("bx%3d, by%3d",ballxPos,ballyPos);
hrodriguez8 0:3c93e7a26a42 744 }
hrodriguez8 0:3c93e7a26a42 745
hrodriguez8 0:3c93e7a26a42 746 fx=fx+vx;
hrodriguez8 0:3c93e7a26a42 747 fy=fy+vy;
hrodriguez8 0:3c93e7a26a42 748 ballxPos = (int)fx;
hrodriguez8 0:3c93e7a26a42 749 ballyPos = (int)fy;
hrodriguez8 0:3c93e7a26a42 750
hrodriguez8 0:3c93e7a26a42 751 uLCD.filled_circle(ballxPos, ballyPos, ballRadius, ballColor); //ball
hrodriguez8 0:3c93e7a26a42 752
hrodriguez8 0:3c93e7a26a42 753 }
hrodriguez8 0:3c93e7a26a42 754 // --- End moveBall
hrodriguez8 0:3c93e7a26a42 755 ////////////////////
hrodriguez8 0:3c93e7a26a42 756
hrodriguez8 0:3c93e7a26a42 757
hrodriguez8 0:3c93e7a26a42 758 //End of Main Code
hrodriguez8 0:3c93e7a26a42 759 //////////////////////////////////////////////////////////////////////
hrodriguez8 0:3c93e7a26a42 760
hrodriguez8 0:3c93e7a26a42 761
hrodriguez8 0:3c93e7a26a42 762