ELEC2645 (2018/19) / Mbed 2 deprecated el17mtu_

Dependencies:   mbed

ModeA/ModeA.cpp

Committer:
el17mtu
Date:
2019-05-08
Revision:
7:9a30314fa41f
Parent:
6:f7484a2f32fd

File content as of revision 7:9a30314fa41f:

#include "ModeA.h"

ModeA::ModeA()
{

}

ModeA::~ModeA()
{

}

void ModeA::screen(N5110 &lcd)
{

    lcd.clear();
    lcd.printString("GAME",0,0);
    lcd.printString("Back:Rules",0,2);
    
    };
    
 void ModeA::initialise(N5110 &lcd)
 {
      x_position = 5;
 y_position = 18;
  //  speed = pad.read_pot();
    gravity = 1;
    
    screen_width = 80;
    bar_width = 6;
    
    speed = 1;
    bar_speed = 2;
    
 size_top = 10;
  size_bottom = 7;
  
  srand(time(NULL));
  size_top = rand() % 48;
   srand(time(NULL));
  size_bottom = rand() % 48;
  
   
     }
 
   
void ModeA::Bird(N5110 &lcd)
      
{
   
  
    lcd.drawRect(x_position, y_position,6,6,FILL_BLACK);
     //lcd.drawRect(screen_width,0,bar_width,size_top,FILL_BLACK);
     //lcd.drawRect(screen_width,48-size_bottom,bar_width,size_bottom,FILL_BLACK);
    lcd.refresh();
    

               
       if ( pad.check_event(Gamepad::Y_PRESSED) == true) {
           
           speed = speed - gravity*5;
          
        }
        
        if (y_position > 42) {
               
                lcd.clear();
          lcd.printString("GAME OVER",6,2);
          lcd.printString("Press BACK",6,4);
          pad.tone(2000.0,0.3);
          lcd.refresh();
          bar_speed = 0;
          speed = 0;
          gravity = 0;
          y_position = 48;
          bar_width = 0;
          size_top = 0;
          size_bottom = 0;
          
          wait(0.5);
                
                }
                
                
                 if (screen_width == 3) {
           srand(time(NULL));
         size_top = rand() % 48;
            srand(time(NULL));
            size_bottom = rand() % 48;
               }
        
       if (y_position < 0) {
                y_position = 0;
                speed = 0;
                }
        
         speed = speed + gravity;
        y_position = y_position + speed;
        wait(0.1);
        
        
   //  lcd.drawRect(screen_width,0,bar_width,size_top,FILL_BLACK);
  // lcd.drawRect(screen_width,48-size_bottom,bar_width,size_bottom,FILL_BLACK);
   //lcd.refresh();
        
     //   if (bar_width > 50) {
       //      srand(time(NULL));
       // size_top = rand() % 48;
    //srand(time(NULL));
      //  size_bottom = rand() % 48;
           //  bar_width = 50;
            //   bar_speed = 0;
               //}
        
     
               
               
      if ((size_top > (y_position - 6)) && (screen_width == 11)) {
          lcd.clear();
          lcd.printString("GAME OVER",6,2);
          lcd.printString("Press BACK",6,4);
          pad.tone(2000.0,0.3);
          lcd.refresh();
          bar_speed = 0;
          speed = 0;
          gravity = 0;
          y_position = 48;
          wait(0.5);
          
          }
          
          
        //  if (screen_width == 3) {
     //      srand(time(NULL));
    //     size_top = rand() % 48;
     //       srand(time(NULL));
    //        size_bottom = rand() % 48;
      //         }
      
     screen_width = screen_width - bar_speed;
      wait(0.1);
      
        lcd.drawRect(screen_width,0,bar_width,size_top,FILL_BLACK);
   lcd.drawRect(screen_width,48-size_bottom,bar_width,size_bottom,FILL_BLACK);
  
   lcd.refresh();
 
      
   //   if (screen_width == 3) {
  //         srand(time(NULL));
  //       size_top = rand() % 48;
   //         srand(time(NULL));
   //         size_bottom = rand() % 48;
      //         }
     //  screen_width = screen_width - bar_speed;
      wait(0.1);
     
    
    }