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
main.cpp
- Committer:
- ChenZirui
- Date:
- 2020-05-29
- Revision:
- 15:7ca2d1b2bd0e
- Parent:
- 8:5f0190b282f7
File content as of revision 15:7ca2d1b2bd0e:
///////// pre-processor directives ////////
#include "mbed.h"
#include "Gamepad.h"
#include "N5110.h"
#include "Touch.h"
#include "Bitmap.h"
#ifdef WITH_TESTING
# include "tests.h"
#endif
#define BOARD_WIDTH 2
#define BOARD_LENGTH 8
#define BULLET_SIZE 2
#define BULLET_SPEED 3
#define BOARD_X 42
#define BOARD_Y 24
/////////////// structs /////////////////
struct UserInput {
Direction d;
float mag;
};
/////////////// objects ///////////////
N5110 lcd;
Gamepad pad;
Touch touch;
///////////// prototypes ///////////////
void init();
void update_game(UserInput input);
void render();
void welcome();
///////////// functions ////////////////
int main()
{
#ifdef WITH_TESTING
int number_of_failures = run_all_tests();
//test part
if(number_of_failures > 0) return number_of_failures;
#endif
int fps = 6; // frames per second
init(); // initialise
welcome(); // welcome screen for user to start
render(); // first draw the initial frame
wait(1.0f/fps); // and wait for one frame period
pad.leds_on(); //turn on all leds as 'lives' showing
while (1) //while loop, execute reading, updating, drawing,juding part frequentrly
{
touch.reading(pad);
touch.update(pad,lcd);
render();
if(touch._leds>=6)
{
break; // if all lives finish , you will lsot game
}
wait(1.0f/fps);
}
lcd.init();
pad.init();
lcd.printString(" You fail ",0,1);
lcd.printString(" Press reset ",0,4); // the reminder of game lost
lcd.refresh(); //function to refresh the display
}
// initialies all classes and libraries
void init()
{
lcd.init();
pad.init();
touch.init(BOARD_WIDTH,BOARD_LENGTH,BULLET_SIZE,BULLET_SPEED,lcd,BOARD_X,BOARD_Y);
}
//clearing record before and drawing frames
void render()
{
lcd.clear();
touch.draw(lcd);
lcd.refresh();
}
//welcome screen
void welcome() {
lcd.printString(" STOP BULLET ",0,1);
lcd.printString(" Press Start ",0,4);
lcd.refresh();
// wait flashing LEDs until start button is pressed
while ( pad.start_pressed() == false) {
lcd.setContrast( pad.read_pot1());
pad.leds_on();
wait(0.1);
pad.leds_off();
wait(0.1);
}
}