yang junyao / Mbed 2 deprecated 2645_Project

Dependencies:   mbed Gamepad FLAPPY_BIRD

Embed: (wiki syntax)

« Back to documentation index

Bird Class Reference

Bird Class Reference

Bird Class. More...

#include <Bird.h>

Public Member Functions

void init ()
 Initialize all the parameter.
void welcome (N5110 &lcd)
 Welcome.
void mode (N5110 &lcd, Gamepad &pad)
 Difficulty choosing.
void score (N5110 &lcd)
 Display score.
void pause (N5110 &lcd, Gamepad &pad)
 Pause screen.
void stru (N5110 &lcd)
 Game start structure.
void barrier (N5110 &lcd)
 Random barrier.
void flyup (N5110 &lcd)
 Bird fly up.
void flydown (N5110 &lcd)
 Bird fly down.
void check ()
 Random number.
void fail (N5110 &lcd, Gamepad &pad)
 Failure screen.
void ready (N5110 &lcd)
 Ready screen.
bool coll ()
 If collided.

Detailed Description

Bird Class.

Library for the function used in the Game Under the foundation of the LCD(N5110) and Gamepad Display welcome, mode choosing and playing screen Refresh for the speed at 1.0/fps

Revision 1.0

Author:
Junyao. Yang
Date:
6th May 2019
#include "Bird.h"




// Objects
N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
Gamepad pad;
Bird bird;

// Prototypes
void init();
void welcome();
void mode1();
void start(int fps);
void play(int fps);
void failure();



int main()
{
    // set the frame per second
    int fps = 5;
    // first need to initialise the display
    init();
    // these are default settings so not strictly needed
    lcd.normalMode();      // normal colour mode
    lcd.setBrightness(0.6); // put LED backlight on 60%
    // change set contrast in range 0.0 to 1.0
    // 0.5 appears to be a good starting point
    lcd.setContrast(0.5);      
    lcd.clear();

    // welcome screen that waiting the player to  start
    welcome();
    // Mode choosing, to determine the barrier speed
    mode1();

    // game start, draw the bird and the barrier
    start(fps);
    
    while(1){
        // playing procedure
        play(fps);
    
    // failure screen, to ask user to play again 
        failure();
    
    }
    
    
}

void init()
{
    // initialise lcd and gamepad
    lcd.init();
    pad.init();
    bird.init();
}

void welcome()
{
    // print welcome screen 
    bird.welcome(lcd);
    lcd.refresh();
    
    // move to game while start button is pressed
    while ( pad.check_event(Gamepad::START_PRESSED) == false) {
        pad.leds_on();
        wait(0.1);
        pad.leds_off();
        wait(0.1);
    }
}

void mode1()
{      
    // choosing difficulty
    while (pad.check_event(Gamepad::A_PRESSED) == false) {
    bird.mode(lcd, pad);
    }
}

void start(int fps)
{
    // draw the first bird and barrier, 
    // and giving the last 3 seconds to prepare
    bird.ready(lcd);

}

void play(int fps)
{
    lcd.clear(); 
    if(pad.check_event(Gamepad::A_PRESSED)){
    bird.flyup(lcd);    
    }
    else {bird.flydown(lcd);}
    bird.barrier(lcd);
    bird.score(lcd);
    bird.pause(lcd,pad); 
    lcd.refresh();
    wait(1.0/fps); 
}

void failure()
{
    bird.fail(lcd, pad);
}

Definition at line 139 of file Bird.h.


Member Function Documentation

void barrier ( N5110 &  lcd )

Random barrier.

Using N5110 random barrier produced move in the speed be given

Definition at line 382 of file Bird.cpp.

void check (  )

Random number.

random number between 1-4 to determine different barrier type

Definition at line 438 of file Bird.cpp.

bool coll (  )

If collided.

return true if collided return false if not

Definition at line 487 of file Bird.cpp.

void fail ( N5110 &  lcd,
Gamepad &  pad 
)

Failure screen.

Using N5110, Gamepad show failure as collided ask if play again

Definition at line 458 of file Bird.cpp.

void flydown ( N5110 &  lcd )

Bird fly down.

Using N5110 run each time screen refresh drop 2 pixel each time

Definition at line 426 of file Bird.cpp.

void flyup ( N5110 &  lcd )

Bird fly up.

Using N5110 run as button A is pressed bird fly up 8 pixel each time

Definition at line 414 of file Bird.cpp.

void init (  )

Initialize all the parameter.

initialise each time the procedure run

Definition at line 8 of file Bird.cpp.

void mode ( N5110 &  lcd,
Gamepad &  pad 
)

Difficulty choosing.

Using N5110, Gamepad Choose difficulty determine the speed of barrier vb

Definition at line 262 of file Bird.cpp.

void pause ( N5110 &  lcd,
Gamepad &  pad 
)

Pause screen.

Using N5110, Gamepad run if button back is pressed return game if press again

Definition at line 317 of file Bird.cpp.

void ready ( N5110 &  lcd )

Ready screen.

Using N5110 give three seconds to prepare play game later

Definition at line 348 of file Bird.cpp.

void score ( N5110 &  lcd )

Display score.

Using N5110 start at 0 plus 1 each time pass the barrier

Definition at line 297 of file Bird.cpp.

void stru ( N5110 &  lcd )

Game start structure.

Using N5110 draw out the basic structure

Definition at line 332 of file Bird.cpp.

void welcome ( N5110 &  lcd )

Welcome.

Print welcome screen wait until start button is pressed

Definition at line 22 of file Bird.cpp.