ELEC2645 (2018/19) / Mbed 2 deprecated el17szs

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
shahidsajid
Date:
Sat Apr 27 11:45:11 2019 +0000
Parent:
15:81a3aaf52647
Commit message:
Created A game over function

Changed in this revision

Bat/Bat.cpp Show annotated file Show diff for this revision Revisions of this file
Cricket/Cricket.cpp Show annotated file Show diff for this revision Revisions of this file
Menus/Menus.cpp Show annotated file Show diff for this revision Revisions of this file
Menus/Menus.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Bat/Bat.cpp	Wed Apr 24 21:17:22 2019 +0000
+++ b/Bat/Bat.cpp	Sat Apr 27 11:45:11 2019 +0000
@@ -51,20 +51,20 @@
     menu_lcd.refresh();
     
     menu_lcd.refresh();
-    while (batPad.check_event(Gamepad::START_PRESSED) == false) {
+    while ( batPad.check_event(Gamepad::START_PRESSED) == false) {
             printf("2");
-            batPad.leds_on();
+             batPad.leds_on();
             wait(0.1);
-            batPad.leds_off();
+             batPad.leds_off();
             wait(0.1);
         }
         second_menu(menu_lcd);
-        batPad.leds_off();
-        
+         batPad.leds_off();
        
 
 }
 void Bat::second_menu(N5110 &menu_lcd){
+    while( batPad.check_event(Gamepad::A_PRESSED) == false){
     batPad.leds_off();
     menu_lcd.clear();
     menu_lcd.drawRect(0,0,WIDTH,HEIGHT,FILL_TRANSPARENT);
@@ -73,18 +73,12 @@
     menu_lcd.drawCircle(72,11,5,FILL_TRANSPARENT);
     menu_lcd.printString("RULES",2,3);
     menu_lcd.printString("B",70,3);
-     menu_lcd.drawCircle(72,27,5,FILL_TRANSPARENT);
+    menu_lcd.drawCircle(72,27,5,FILL_TRANSPARENT);
     menu_lcd.printString("CONTROLS",2,5);
     menu_lcd.printString("Y",70,5);
-     menu_lcd.drawCircle(72,42,5,FILL_TRANSPARENT);
-    
+    menu_lcd.drawCircle(72,42,5,FILL_TRANSPARENT);
     menu_lcd.refresh();
+    }
     
 }
 
-void Bat::game_over(string message){
-    //char buffer[14];
-    //int length=sprintf(buffer,"%s",message);
-    //menu_lcd.printString(buffer,3,1);
-}  
-
--- a/Cricket/Cricket.cpp	Wed Apr 24 21:17:22 2019 +0000
+++ b/Cricket/Cricket.cpp	Sat Apr 27 11:45:11 2019 +0000
@@ -129,7 +129,7 @@
     scoreboard.reset();
     new_round=1;
     pad.led(1,1.0);
-    pad.tone(750.0,0.5);
+    //pad.tone(750.0,0.5);
     wait(2);
 }    
 void Cricket::draw(N5110 &lcd){
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Menus/Menus.cpp	Sat Apr 27 11:45:11 2019 +0000
@@ -0,0 +1,61 @@
+#include "Menus.h"
+
+
+Menus::Menus()
+{
+
+}
+
+Menus::~Menus()
+{
+
+}
+void Menus::init(){
+     //menu_lcd.init();
+     menu_pad.init();
+     
+}
+void Menus::first_menu(N5110 &menu_lcd){
+    menu_pad.init();
+    menu_lcd.clear();
+    menu_lcd.printString("HERO CRICKET",5,1);
+    menu_lcd.refresh();
+    menu_lcd.printString("game by el17szs",2,3);
+    wait(1);
+    menu_lcd.refresh();
+    menu_lcd.printString("PRESS START..",1,5);
+    wait(1);
+    menu_lcd.refresh();
+    
+    menu_lcd.refresh();
+    while (menu_pad.check_event(Gamepad::START_PRESSED) == false) {
+            printf("2");
+            menu_pad.leds_on();
+            wait(0.1);
+            menu_pad.leds_off();
+            wait(0.1);
+        }
+        second_menu(menu_lcd);
+        menu_pad.leds_off();
+       
+
+}
+void Menus::second_menu(N5110 &menu_lcd){
+    menu_pad.init();
+    while(menu_pad.check_event(Gamepad::A_PRESSED) == false){
+    menu_pad.leds_off();
+    menu_lcd.clear();
+    menu_lcd.drawRect(0,0,WIDTH,HEIGHT,FILL_TRANSPARENT);
+    menu_lcd.printString("START GAME",2,1);
+    menu_lcd.printString("A",70,1);
+    menu_lcd.drawCircle(72,11,5,FILL_TRANSPARENT);
+    menu_lcd.printString("RULES",2,3);
+    menu_lcd.printString("B",70,3);
+    menu_lcd.drawCircle(72,27,5,FILL_TRANSPARENT);
+    menu_lcd.printString("CONTROLS",2,5);
+    menu_lcd.printString("Y",70,5);
+    menu_lcd.drawCircle(72,42,5,FILL_TRANSPARENT);
+    menu_lcd.refresh();
+    }
+    
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Menus/Menus.h	Sat Apr 27 11:45:11 2019 +0000
@@ -0,0 +1,29 @@
+
+#ifndef MENUS_H
+#define MENUS_H
+
+#include "mbed.h"
+#include "N5110.h"
+#include "Gamepad.h"
+
+/** Ball Class
+@author Dr Craig A. Evans, University of Leeds
+@brief Controls the ball in the Pong game 
+@date Febraury 2017
+*/ 
+class Menus
+{
+
+public:
+    Menus();
+    ~Menus();
+    void init();
+    void first_menu(N5110 &menu_lcd);
+    void second_menu(N5110 &menu_lcd);
+private:
+  
+   Gamepad menu_pad;
+   
+    
+};
+#endif
\ No newline at end of file
--- a/main.cpp	Wed Apr 24 21:17:22 2019 +0000
+++ b/main.cpp	Sat Apr 27 11:45:11 2019 +0000
@@ -14,32 +14,39 @@
 #include "Ball.h"
 #include "Bat.h"
 #include "Cricket.h"
+#include "Menus.h"
 
 
 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
 Gamepad pad;
 Cricket cricket;
+Menus menu;
+Bat bat;
 
 
 void init();
 
-//void welcome();
+void welcome();
 void draw();
 void ball_test();
 
 int main(){
     int fps=10;
     init();
+    //bat.first_menu(lcd);
+   // welcome();
    // welcome();
     draw();
     //float f; 
     //int status=0;
+    ///*
     while(1){
         //Direction dir=pad.get_direction();
         cricket.game(lcd,pad);
         draw();
         wait(1.0f/fps);                
     }
+    //*/
     /*
     while(1){
         ball.reset();
@@ -58,6 +65,7 @@
 void init(){
     lcd.init();
     pad.init();
+    menu.init();
     //ball1.init(2,4);
     cricket.init();
     //bat1.init();