Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed N5110 ShiftReg PinDetect
GameOver.cpp
00001 #include "GameOver.h " 00002 00003 /// @file GameOver.cpp 00004 00005 int GameOver::currentState = SELECT_PLAY; 00006 00007 void GameOver::init() 00008 { 00009 input->addBtnPressInterrupt(Input::ButtonA, &btnAPress); 00010 input->addBtnPressInterrupt(Input::ButtonC, &btnCPress); 00011 } 00012 00013 void GameOver::update(float dt) 00014 { 00015 switch (currentState) 00016 { 00017 case LOAD_GAME: 00018 requestStateChange(GAME); 00019 break; 00020 00021 case LOAD_MAIN_MENU: 00022 requestStateChange(MAIN_MENU); 00023 break; 00024 } 00025 } 00026 00027 void GameOver::btnAPress() 00028 { 00029 switch(GameOver::currentState) 00030 { 00031 case SELECT_PLAY: 00032 currentState = LOAD_GAME; 00033 break; 00034 00035 case SELECT_MAIN_MENU: 00036 currentState = LOAD_MAIN_MENU; 00037 break; 00038 } 00039 } 00040 00041 void GameOver::btnCPress() 00042 { 00043 ++currentState %= 2; // go to next state (only 2 states in total) 00044 } 00045 00046 void GameOver::render() 00047 { 00048 // Draw border 00049 for (int i = 0; i < HEIGHT/3; ++i) 00050 { 00051 drawImage(Image::Pattern3, 0, 3*i); // left border 00052 drawImage(Image::Pattern3, (WIDTH-3), 3*i); // right border 00053 } 00054 00055 for (int j = 0; j < WIDTH/3; ++j) 00056 { 00057 drawImage(Image::Pattern3, 3 * j, (HEIGHT-3)); // bottom border 00058 drawImage(Image::Pattern3, 3 * j, 0); // top border 00059 } 00060 00061 // Draw text 00062 int xMargin = 8; 00063 lcd->printString("Game Over!", xMargin, 1); 00064 00065 switch (currentState) 00066 { 00067 case SELECT_PLAY: 00068 lcd->printString(">Play again", xMargin, 3); 00069 lcd->printString("Menu", xMargin, 4); 00070 break; 00071 00072 case SELECT_MAIN_MENU: 00073 lcd->printString("Play again", xMargin, 3); 00074 lcd->printString(">Menu", xMargin, 4); 00075 break; 00076 00077 case LOAD_GAME: 00078 case LOAD_MAIN_MENU: 00079 lcd->printString("Loading...", 0, 2); 00080 break; 00081 } 00082 }
Generated on Tue Jul 12 2022 21:30:55 by
