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.
Dependencies: mbed
Bat/Bat.cpp@20:9d21599fe350, 2019-04-30 (annotated)
- Committer:
- shahidsajid
- Date:
- Tue Apr 30 10:27:23 2019 +0000
- Revision:
- 20:9d21599fe350
- Parent:
- 19:e1ded5acb64a
- Child:
- 21:a0904159e183
Created starting menus with correct button functionality;
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| shahidsajid | 4:55a0509c4874 | 1 | #include "Bat.h" |
| shahidsajid | 4:55a0509c4874 | 2 | |
| shahidsajid | 4:55a0509c4874 | 3 | |
| shahidsajid | 4:55a0509c4874 | 4 | Bat::Bat() |
| shahidsajid | 4:55a0509c4874 | 5 | { |
| shahidsajid | 4:55a0509c4874 | 6 | |
| shahidsajid | 4:55a0509c4874 | 7 | } |
| shahidsajid | 4:55a0509c4874 | 8 | |
| shahidsajid | 4:55a0509c4874 | 9 | Bat::~Bat() |
| shahidsajid | 4:55a0509c4874 | 10 | { |
| shahidsajid | 4:55a0509c4874 | 11 | |
| shahidsajid | 4:55a0509c4874 | 12 | } |
| shahidsajid | 4:55a0509c4874 | 13 | void Bat::init(int x,int y) |
| shahidsajid | 6:3e50f2cf4366 | 14 | { |
| shahidsajid | 6:3e50f2cf4366 | 15 | batPad.init(); |
| shahidsajid | 4:55a0509c4874 | 16 | _x = 42; |
| shahidsajid | 4:55a0509c4874 | 17 | _y = 15; |
| shahidsajid | 6:3e50f2cf4366 | 18 | _hitBall=0; |
| shahidsajid | 20:9d21599fe350 | 19 | _button_pressed=false; |
| shahidsajid | 4:55a0509c4874 | 20 | } |
| shahidsajid | 13:924891519a95 | 21 | void Bat::reset(){ |
| shahidsajid | 13:924891519a95 | 22 | _hitBall=0; |
| shahidsajid | 13:924891519a95 | 23 | _loft_ball=0; |
| shahidsajid | 13:924891519a95 | 24 | } |
| shahidsajid | 4:55a0509c4874 | 25 | void Bat::draw(N5110 &lcd){ |
| shahidsajid | 4:55a0509c4874 | 26 | lcd.drawLine(38,36,41,36,1); |
| shahidsajid | 4:55a0509c4874 | 27 | lcd.drawRect(41,35,6,3,FILL_BLACK); |
| shahidsajid | 12:954da4f4e565 | 28 | //ball1.draw(); |
| shahidsajid | 4:55a0509c4874 | 29 | } |
| shahidsajid | 6:3e50f2cf4366 | 30 | int Bat::get_hitBall(){ |
| shahidsajid | 6:3e50f2cf4366 | 31 | if (batPad.check_event(Gamepad::A_PRESSED) == true){ |
| shahidsajid | 6:3e50f2cf4366 | 32 | _hitBall=1; |
| shahidsajid | 6:3e50f2cf4366 | 33 | } |
| shahidsajid | 6:3e50f2cf4366 | 34 | return _hitBall; |
| shahidsajid | 6:3e50f2cf4366 | 35 | } |
| shahidsajid | 13:924891519a95 | 36 | int Bat::get_loft_ball(){ |
| shahidsajid | 13:924891519a95 | 37 | if (batPad.check_event(Gamepad::L_PRESSED) == true){ |
| shahidsajid | 15:81a3aaf52647 | 38 | //badPad.tone(750.0,0.1); |
| shahidsajid | 13:924891519a95 | 39 | _loft_ball=1; |
| shahidsajid | 13:924891519a95 | 40 | } |
| shahidsajid | 13:924891519a95 | 41 | return _loft_ball; |
| shahidsajid | 6:3e50f2cf4366 | 42 | } |
| shahidsajid | 20:9d21599fe350 | 43 | void Bat::first_menu(N5110 &menu_lcd,Gamepad &pad){ |
| shahidsajid | 15:81a3aaf52647 | 44 | menu_lcd.clear(); |
| shahidsajid | 15:81a3aaf52647 | 45 | menu_lcd.printString("HERO CRICKET",5,1); |
| shahidsajid | 15:81a3aaf52647 | 46 | menu_lcd.refresh(); |
| shahidsajid | 15:81a3aaf52647 | 47 | menu_lcd.printString("game by el17szs",2,3); |
| shahidsajid | 15:81a3aaf52647 | 48 | wait(1); |
| shahidsajid | 15:81a3aaf52647 | 49 | menu_lcd.refresh(); |
| shahidsajid | 15:81a3aaf52647 | 50 | menu_lcd.printString("PRESS START..",1,5); |
| shahidsajid | 15:81a3aaf52647 | 51 | wait(1); |
| shahidsajid | 15:81a3aaf52647 | 52 | menu_lcd.refresh(); |
| shahidsajid | 15:81a3aaf52647 | 53 | while (batPad.check_event(Gamepad::START_PRESSED) == false) { |
| shahidsajid | 15:81a3aaf52647 | 54 | printf("2"); |
| shahidsajid | 15:81a3aaf52647 | 55 | batPad.leds_on(); |
| shahidsajid | 15:81a3aaf52647 | 56 | wait(0.1); |
| shahidsajid | 15:81a3aaf52647 | 57 | batPad.leds_off(); |
| shahidsajid | 15:81a3aaf52647 | 58 | wait(0.1); |
| shahidsajid | 15:81a3aaf52647 | 59 | } |
| shahidsajid | 15:81a3aaf52647 | 60 | second_menu(menu_lcd); |
| shahidsajid | 15:81a3aaf52647 | 61 | batPad.leds_off(); |
| shahidsajid | 15:81a3aaf52647 | 62 | } |
| shahidsajid | 15:81a3aaf52647 | 63 | void Bat::second_menu(N5110 &menu_lcd){ |
| shahidsajid | 20:9d21599fe350 | 64 | while (_button_pressed==false){ |
| shahidsajid | 20:9d21599fe350 | 65 | batPad.leds_off(); |
| shahidsajid | 20:9d21599fe350 | 66 | menu_lcd.clear(); |
| shahidsajid | 20:9d21599fe350 | 67 | menu_lcd.drawRect(0,0,WIDTH,HEIGHT,FILL_TRANSPARENT); |
| shahidsajid | 20:9d21599fe350 | 68 | menu_lcd.printString("START GAME",2,1); |
| shahidsajid | 20:9d21599fe350 | 69 | menu_lcd.printString("A",70,1); |
| shahidsajid | 20:9d21599fe350 | 70 | menu_lcd.drawCircle(72,11,5,FILL_TRANSPARENT); |
| shahidsajid | 20:9d21599fe350 | 71 | menu_lcd.printString("RULES",2,3); |
| shahidsajid | 20:9d21599fe350 | 72 | menu_lcd.printString("B",70,3); |
| shahidsajid | 20:9d21599fe350 | 73 | menu_lcd.drawCircle(72,27,5,FILL_TRANSPARENT); |
| shahidsajid | 20:9d21599fe350 | 74 | menu_lcd.printString("CONTROLS",2,5); |
| shahidsajid | 20:9d21599fe350 | 75 | menu_lcd.printString("Y",70,5); |
| shahidsajid | 20:9d21599fe350 | 76 | menu_lcd.drawCircle(72,42,5,FILL_TRANSPARENT); |
| shahidsajid | 20:9d21599fe350 | 77 | menu_lcd.refresh(); |
| shahidsajid | 20:9d21599fe350 | 78 | if (batPad.check_event(Gamepad::A_PRESSED) == true){ |
| shahidsajid | 20:9d21599fe350 | 79 | _button_pressed=true; |
| shahidsajid | 20:9d21599fe350 | 80 | } |
| shahidsajid | 20:9d21599fe350 | 81 | } |
| shahidsajid | 15:81a3aaf52647 | 82 | |
| shahidsajid | 15:81a3aaf52647 | 83 | } |
| shahidsajid | 15:81a3aaf52647 | 84 | |
| shahidsajid | 15:81a3aaf52647 | 85 | void Bat::game_over(string message){ |
| shahidsajid | 15:81a3aaf52647 | 86 | //char buffer[14]; |
| shahidsajid | 15:81a3aaf52647 | 87 | //int length=sprintf(buffer,"%s",message); |
| shahidsajid | 15:81a3aaf52647 | 88 | //menu_lcd.printString(buffer,3,1); |
| shahidsajid | 15:81a3aaf52647 | 89 | } |
| shahidsajid | 15:81a3aaf52647 | 90 | |
| shahidsajid | 18:a260ce8db9e7 | 91 | void Bat::game_over_menu(N5110 &menu_lcd,int option){ |
| shahidsajid | 18:a260ce8db9e7 | 92 | if (option==1){ |
| shahidsajid | 18:a260ce8db9e7 | 93 | menu_lcd.clear(); |
| shahidsajid | 18:a260ce8db9e7 | 94 | menu_lcd.printString("GAME LOST",2,1); |
| shahidsajid | 18:a260ce8db9e7 | 95 | menu_lcd.printString("NO MORE BALLS LEFT",2,3); |
| shahidsajid | 18:a260ce8db9e7 | 96 | menu_lcd.refresh(); |
| shahidsajid | 18:a260ce8db9e7 | 97 | wait(5); |
| shahidsajid | 18:a260ce8db9e7 | 98 | } |
| shahidsajid | 19:e1ded5acb64a | 99 | if (option==2){ |
| shahidsajid | 19:e1ded5acb64a | 100 | menu_lcd.clear(); |
| shahidsajid | 19:e1ded5acb64a | 101 | menu_lcd.printString("GAME LOST",2,1); |
| shahidsajid | 19:e1ded5acb64a | 102 | menu_lcd.printString("BOWLED",2,3); |
| shahidsajid | 19:e1ded5acb64a | 103 | menu_lcd.refresh(); |
| shahidsajid | 19:e1ded5acb64a | 104 | wait(5); |
| shahidsajid | 19:e1ded5acb64a | 105 | } |
| shahidsajid | 19:e1ded5acb64a | 106 | if (option==3){ |
| shahidsajid | 19:e1ded5acb64a | 107 | menu_lcd.clear(); |
| shahidsajid | 19:e1ded5acb64a | 108 | menu_lcd.printString("GAME LOST",2,1); |
| shahidsajid | 19:e1ded5acb64a | 109 | menu_lcd.printString("CAUGHT",2,3); |
| shahidsajid | 19:e1ded5acb64a | 110 | menu_lcd.refresh(); |
| shahidsajid | 19:e1ded5acb64a | 111 | wait(5); |
| shahidsajid | 19:e1ded5acb64a | 112 | } |
| shahidsajid | 19:e1ded5acb64a | 113 | |
| shahidsajid | 18:a260ce8db9e7 | 114 | } |
| shahidsajid | 18:a260ce8db9e7 | 115 | void Bat::victory_menu(N5110 &menu_lcd){ |
| shahidsajid | 18:a260ce8db9e7 | 116 | menu_lcd.clear(); |
| shahidsajid | 18:a260ce8db9e7 | 117 | menu_lcd.printString("CONGRATS!!",2,1); |
| shahidsajid | 18:a260ce8db9e7 | 118 | menu_lcd.printString("YOU HAVE WON",2,3); |
| shahidsajid | 18:a260ce8db9e7 | 119 | menu_lcd.refresh(); |
| shahidsajid | 18:a260ce8db9e7 | 120 | wait(5); |
| shahidsajid | 18:a260ce8db9e7 | 121 | } |
| shahidsajid | 18:a260ce8db9e7 | 122 | void Bat::info_screen(N5110 &menu_lcd, int target){ |
| shahidsajid | 18:a260ce8db9e7 | 123 | menu_lcd.clear(); |
| shahidsajid | 20:9d21599fe350 | 124 | menu_lcd.printString("YOU ARE GIVEN",2,1); |
| shahidsajid | 20:9d21599fe350 | 125 | menu_lcd.printString("10 BALLS ",3,2); |
| shahidsajid | 19:e1ded5acb64a | 126 | menu_lcd.refresh(); |
| shahidsajid | 20:9d21599fe350 | 127 | wait(0.5); |
| shahidsajid | 18:a260ce8db9e7 | 128 | char buffer[5]; |
| shahidsajid | 18:a260ce8db9e7 | 129 | int length=sprintf(buffer,"SCORE %i RUNS",target); |
| shahidsajid | 20:9d21599fe350 | 130 | menu_lcd.printString(buffer,2,4); |
| shahidsajid | 20:9d21599fe350 | 131 | menu_lcd.refresh(); |
| shahidsajid | 20:9d21599fe350 | 132 | wait(0.5); |
| shahidsajid | 20:9d21599fe350 | 133 | menu_lcd.printString("GOOD LUCK!!!",0,5); |
| shahidsajid | 18:a260ce8db9e7 | 134 | menu_lcd.refresh(); |
| shahidsajid | 19:e1ded5acb64a | 135 | int i=0; |
| shahidsajid | 20:9d21599fe350 | 136 | /* |
| shahidsajid | 19:e1ded5acb64a | 137 | while (i<=10){ |
| shahidsajid | 19:e1ded5acb64a | 138 | batPad.leds_on(); |
| shahidsajid | 19:e1ded5acb64a | 139 | wait(0.1); |
| shahidsajid | 19:e1ded5acb64a | 140 | batPad.leds_off(); |
| shahidsajid | 19:e1ded5acb64a | 141 | wait(0.1); |
| shahidsajid | 19:e1ded5acb64a | 142 | i++; |
| shahidsajid | 19:e1ded5acb64a | 143 | } |
| shahidsajid | 20:9d21599fe350 | 144 | */ |
| shahidsajid | 19:e1ded5acb64a | 145 | wait(3); |
| shahidsajid | 19:e1ded5acb64a | 146 | |
| shahidsajid | 18:a260ce8db9e7 | 147 | } |
| shahidsajid | 18:a260ce8db9e7 | 148 |