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@19:e1ded5acb64a, 2019-04-27 (annotated)
- Committer:
- shahidsajid
- Date:
- Sat Apr 27 18:16:59 2019 +0000
- Revision:
- 19:e1ded5acb64a
- Parent:
- 18:a260ce8db9e7
- Child:
- 20:9d21599fe350
Created a starting info screen
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 | 4:55a0509c4874 | 19 | } |
| shahidsajid | 13:924891519a95 | 20 | void Bat::reset(){ |
| shahidsajid | 13:924891519a95 | 21 | _hitBall=0; |
| shahidsajid | 13:924891519a95 | 22 | _loft_ball=0; |
| shahidsajid | 13:924891519a95 | 23 | } |
| shahidsajid | 4:55a0509c4874 | 24 | void Bat::draw(N5110 &lcd){ |
| shahidsajid | 4:55a0509c4874 | 25 | lcd.drawLine(38,36,41,36,1); |
| shahidsajid | 4:55a0509c4874 | 26 | lcd.drawRect(41,35,6,3,FILL_BLACK); |
| shahidsajid | 12:954da4f4e565 | 27 | //ball1.draw(); |
| shahidsajid | 4:55a0509c4874 | 28 | } |
| shahidsajid | 6:3e50f2cf4366 | 29 | int Bat::get_hitBall(){ |
| shahidsajid | 6:3e50f2cf4366 | 30 | if (batPad.check_event(Gamepad::A_PRESSED) == true){ |
| shahidsajid | 6:3e50f2cf4366 | 31 | _hitBall=1; |
| shahidsajid | 6:3e50f2cf4366 | 32 | } |
| shahidsajid | 6:3e50f2cf4366 | 33 | return _hitBall; |
| shahidsajid | 6:3e50f2cf4366 | 34 | } |
| shahidsajid | 13:924891519a95 | 35 | int Bat::get_loft_ball(){ |
| shahidsajid | 13:924891519a95 | 36 | if (batPad.check_event(Gamepad::L_PRESSED) == true){ |
| shahidsajid | 15:81a3aaf52647 | 37 | //badPad.tone(750.0,0.1); |
| shahidsajid | 13:924891519a95 | 38 | _loft_ball=1; |
| shahidsajid | 13:924891519a95 | 39 | } |
| shahidsajid | 13:924891519a95 | 40 | return _loft_ball; |
| shahidsajid | 6:3e50f2cf4366 | 41 | } |
| shahidsajid | 15:81a3aaf52647 | 42 | void Bat::first_menu(N5110 &menu_lcd){ |
| shahidsajid | 15:81a3aaf52647 | 43 | menu_lcd.clear(); |
| shahidsajid | 15:81a3aaf52647 | 44 | menu_lcd.printString("HERO CRICKET",5,1); |
| shahidsajid | 15:81a3aaf52647 | 45 | menu_lcd.refresh(); |
| shahidsajid | 15:81a3aaf52647 | 46 | menu_lcd.printString("game by el17szs",2,3); |
| shahidsajid | 15:81a3aaf52647 | 47 | wait(1); |
| shahidsajid | 15:81a3aaf52647 | 48 | menu_lcd.refresh(); |
| shahidsajid | 15:81a3aaf52647 | 49 | menu_lcd.printString("PRESS START..",1,5); |
| shahidsajid | 15:81a3aaf52647 | 50 | wait(1); |
| shahidsajid | 15:81a3aaf52647 | 51 | menu_lcd.refresh(); |
| shahidsajid | 15:81a3aaf52647 | 52 | |
| shahidsajid | 15:81a3aaf52647 | 53 | menu_lcd.refresh(); |
| shahidsajid | 15:81a3aaf52647 | 54 | while (batPad.check_event(Gamepad::START_PRESSED) == false) { |
| shahidsajid | 15:81a3aaf52647 | 55 | printf("2"); |
| shahidsajid | 15:81a3aaf52647 | 56 | batPad.leds_on(); |
| shahidsajid | 15:81a3aaf52647 | 57 | wait(0.1); |
| shahidsajid | 15:81a3aaf52647 | 58 | batPad.leds_off(); |
| shahidsajid | 15:81a3aaf52647 | 59 | wait(0.1); |
| shahidsajid | 15:81a3aaf52647 | 60 | } |
| shahidsajid | 15:81a3aaf52647 | 61 | second_menu(menu_lcd); |
| shahidsajid | 15:81a3aaf52647 | 62 | batPad.leds_off(); |
| shahidsajid | 15:81a3aaf52647 | 63 | |
| shahidsajid | 15:81a3aaf52647 | 64 | |
| shahidsajid | 15:81a3aaf52647 | 65 | |
| shahidsajid | 15:81a3aaf52647 | 66 | } |
| shahidsajid | 15:81a3aaf52647 | 67 | void Bat::second_menu(N5110 &menu_lcd){ |
| shahidsajid | 15:81a3aaf52647 | 68 | batPad.leds_off(); |
| shahidsajid | 15:81a3aaf52647 | 69 | menu_lcd.clear(); |
| shahidsajid | 15:81a3aaf52647 | 70 | menu_lcd.drawRect(0,0,WIDTH,HEIGHT,FILL_TRANSPARENT); |
| shahidsajid | 15:81a3aaf52647 | 71 | menu_lcd.printString("START GAME",2,1); |
| shahidsajid | 15:81a3aaf52647 | 72 | menu_lcd.printString("A",70,1); |
| shahidsajid | 15:81a3aaf52647 | 73 | menu_lcd.drawCircle(72,11,5,FILL_TRANSPARENT); |
| shahidsajid | 15:81a3aaf52647 | 74 | menu_lcd.printString("RULES",2,3); |
| shahidsajid | 15:81a3aaf52647 | 75 | menu_lcd.printString("B",70,3); |
| shahidsajid | 18:a260ce8db9e7 | 76 | menu_lcd.drawCircle(72,27,5,FILL_TRANSPARENT); |
| shahidsajid | 15:81a3aaf52647 | 77 | menu_lcd.printString("CONTROLS",2,5); |
| shahidsajid | 15:81a3aaf52647 | 78 | menu_lcd.printString("Y",70,5); |
| shahidsajid | 18:a260ce8db9e7 | 79 | menu_lcd.drawCircle(72,42,5,FILL_TRANSPARENT); |
| shahidsajid | 15:81a3aaf52647 | 80 | |
| shahidsajid | 15:81a3aaf52647 | 81 | menu_lcd.refresh(); |
| 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 | 19:e1ded5acb64a | 124 | menu_lcd.printString("YOU ARE GIVEN",0,0); |
| shahidsajid | 19:e1ded5acb64a | 125 | menu_lcd.printString("10 BALLS ",3,1); |
| shahidsajid | 19:e1ded5acb64a | 126 | menu_lcd.refresh(); |
| shahidsajid | 19:e1ded5acb64a | 127 | wait(3); |
| shahidsajid | 19:e1ded5acb64a | 128 | menu_lcd.clear(); |
| shahidsajid | 18:a260ce8db9e7 | 129 | char buffer[5]; |
| shahidsajid | 18:a260ce8db9e7 | 130 | int length=sprintf(buffer,"SCORE %i RUNS",target); |
| shahidsajid | 18:a260ce8db9e7 | 131 | menu_lcd.printString(buffer,0,1); |
| shahidsajid | 18:a260ce8db9e7 | 132 | menu_lcd.printString("GOOD LUCK!!!",0,4); |
| shahidsajid | 18:a260ce8db9e7 | 133 | menu_lcd.refresh(); |
| shahidsajid | 19:e1ded5acb64a | 134 | int i=0; |
| shahidsajid | 19:e1ded5acb64a | 135 | while (i<=10){ |
| shahidsajid | 19:e1ded5acb64a | 136 | batPad.leds_on(); |
| shahidsajid | 19:e1ded5acb64a | 137 | wait(0.1); |
| shahidsajid | 19:e1ded5acb64a | 138 | batPad.leds_off(); |
| shahidsajid | 19:e1ded5acb64a | 139 | wait(0.1); |
| shahidsajid | 19:e1ded5acb64a | 140 | i++; |
| shahidsajid | 19:e1ded5acb64a | 141 | } |
| shahidsajid | 19:e1ded5acb64a | 142 | wait(3); |
| shahidsajid | 19:e1ded5acb64a | 143 | |
| shahidsajid | 18:a260ce8db9e7 | 144 | } |
| shahidsajid | 18:a260ce8db9e7 | 145 |