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.
main.cpp
- Committer:
- joshdavy
- Date:
- 2019-04-19
- Revision:
- 8:21b6d4dbce44
- Parent:
- 7:68e06dda79f7
- Child:
- 9:96969b1c6bde
File content as of revision 8:21b6d4dbce44:
/*
ELEC2645 Embedded Systems Project
School of Electronic & Electrical Engineering
University of Leeds
Name: Joshua Davy
Username: el17jd
Student ID Number: 201148379
Date: 12/03/2019
*/
const int fps = 15;
///////// pre-processor directives ////////
#include "mbed.h"
#include "Gamepad.h"
#include "N5110.h"
#include "Sprite.h"
#include "Game.h"
#include "Music.h"
#include "SoundData.h"
#include "SplashScreen.h"
#include "MenuScreen.h"
Timer game_timer;
Timer music_timer;
////// Constants //////
/////////////// objects ///////////////
N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
Gamepad pad;
Game game;
Music play;
///////////// prototypes ///////////////
void init();
void welcome();
// initialies all classes and libraries
void init()
{
// need to initialise LCD and Gamepad
lcd.init();
lcd.setContrast(0.4);
pad.init();
play.init(data1,NUM_ELEMENTS);
game.init();
}
// simple splash screen displayed on start-up
void welcome()
{
lcd.drawSprite(0,0,48,84, (int *) splashScreen);
lcd.refresh();
// wait flashing LEDs until start button is pressed
while ( pad.check_event(Gamepad::START_PRESSED) == false) {
pad.leds_on();
wait(0.1);
pad.leds_off();
wait(0.1);
printf("Welcome\n");
}
}
void how_to_play()
{
}
void menu()
{
int menu_option = 1;
while ( !pad.check_event(Gamepad::A_PRESSED) ) {
if (pad.get_coord().y> 0.7f) {
menu_option = 1;
}
if (pad.get_coord().y < -0.7f) {
menu_option = 0;
}
lcd.drawSprite(0,0,48,84, (int *) menuScreen);
if (menu_option == 1) {
lcd.drawSprite(40,10,7,4, (int *) arrow);
} else {
lcd.drawSprite(40,25,7,4, (int *) arrow);
}
lcd.refresh();
}
if (menu_option == 1) {
how_to_play();
}
}
int main()
{
init(); // initialise and then display welcome screen...
welcome(); // waiting for the user to start
menu(); // main menu
// game loop - read input, update the game state and render the display
game.init();
game_timer.reset();
music_timer.reset();
game_timer.start();
music_timer.start();
const int MUSIC_TICK_TIME = 100; //125 microseconds
const int GAME_TICK_TIME = 100; // 100 millieconds
while (1) {
if (game_timer.read_ms() > GAME_TICK_TIME) {
game.read_input(pad);
game.update(pad);
game.draw(lcd);
game_timer.reset();
}
if (music_timer.read_us() > MUSIC_TICK_TIME) {
play.play_next();
music_timer.reset();
}
}
}