Doxygen comments added

Dependencies:   mbed Gamepad N5110

main.cpp

Committer:
rafeh
Date:
2019-05-01
Revision:
4:e98b22e5d5e8
Parent:
3:5409b50b01b0
Child:
5:3a0948f56de0

File content as of revision 4:e98b22e5d5e8:

/*
ELEC2645 Embedded Systems Project
School of Electronic & Electrical Engineering
University of Leeds
Name: Rafeh Ishtiaq
Username: el17ri
Student ID Number: 201062291
Date: 20/03/2019
*/

#include "mbed.h"
#include "N5110.h"
#include "Gamepad.h"
#include "Pipes.h"
//#include "Bird.h"

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

    const int intro [40][40] =  
     {
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,1,0,1,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0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1,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

};

const int moving [6][6] = 
{
    0,0,1,1,0,0,
    0,1,0,1,1,0,
    1,0,1,1,1,1,
    1,1,1,1,1,0,
    0,1,1,1,1,0,
    0,0,0,0,0,0,
    
    };

void welcome();
void checkcollisions(int hor, int ver);


int xaxis=25;
int yaxis=20;

int main() {
    lcd.init();
    pad.init();
    lcd.clear();
   lcd.setContrast(0.5);
   welcome();
   if (pad.check_event(Gamepad::START_PRESSED) == false) {
       lcd.clear();
       
       int xvalue=84;
       int height = rand() % (19 + 1 - 0) + 0;
    int score = 0;
    char scoredisplay[3];
   while(1) {
    lcd.drawRect(0,45,84,3,FILL_BLACK);
    
     //lcd.drawRect(xvalue,0,5,height,FILL_BLACK);
      //lcd.drawRect(xvalue,(height+20),5,(84-(height+20)),FILL_BLACK);
      //pipes.init(xvalue,height);
      pipes.init(xvalue,height);
      pipes.draw(lcd);
      xvalue=xvalue-1;
      sprintf(scoredisplay,"%d",score);
      lcd.printString(scoredisplay,60,0);
     
      if(xvalue<20 && xvalue>17) {
          score=score+1;
          }
         
          
      if(xvalue<1) {
          height=rand() % (19 + 1 - 0) + 0;
          xvalue=84;
          }
          
    //pipes(xvalue,height);
    //bird.init(xaxis,yaxis);
    //bird.draw(lcd);
   lcd.drawSprite(xaxis,yaxis,6,6,(int*)moving);
   yaxis=yaxis+2;
   if (pad.check_event(Gamepad::A_PRESSED) == true) {
       yaxis=yaxis-14;
       }
   
       wait(0.075);
       xvalue=xvalue-1;

       //checkcollisions(xaxis,yaxis);
   //wait(0.1);
   lcd.refresh();
   lcd.clear();
   }
       }
       
      
       }



void welcome() {
     lcd.drawSprite(0,0,40,40,(int*)intro);
    lcd.printString(" Flappy   ",40,0); 
    lcd.printString(" Bird   ",40,1); 
    lcd.printString(" Press  ",40,3);  
    lcd.printString(" Start  ",40,4);
     lcd.refresh();
     while ( pad.check_event(Gamepad::START_PRESSED) == false) {
        pad.leds_on();
        wait(0.1);
        pad.leds_off();
        wait(0.1);
    }
    }

void checkcollisions(int hor , int ver) {
    if(lcd.getPixel((hor+3),ver)|| lcd.getPixel(hor+4,ver)) { welcome();}
    if(lcd.getPixel((hor+1),(ver+1)) || lcd.getPixel((hor+4),(ver+1))) { welcome();}
    if(lcd.getPixel((hor),(ver+2)) || lcd.getPixel((hor+5),(ver+2))) {welcome();}
    if(lcd.getPixel((hor),(ver+3)) || lcd.getPixel((hor+4),(ver+3))) {welcome();}
    if(lcd.getPixel((hor+1),(ver+4)) || lcd.getPixel((hor+4),(ver+4))) {welcome();}
    }