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
- Committer:
- shahidsajid
- Date:
- 2019-04-30
- Revision:
- 20:9d21599fe350
- Parent:
- 19:e1ded5acb64a
- Child:
- 21:a0904159e183
File content as of revision 20:9d21599fe350:
#include "Bat.h"
Bat::Bat()
{
}
Bat::~Bat()
{
}
void Bat::init(int x,int y)
{
batPad.init();
_x = 42;
_y = 15;
_hitBall=0;
_button_pressed=false;
}
void Bat::reset(){
_hitBall=0;
_loft_ball=0;
}
void Bat::draw(N5110 &lcd){
lcd.drawLine(38,36,41,36,1);
lcd.drawRect(41,35,6,3,FILL_BLACK);
//ball1.draw();
}
int Bat::get_hitBall(){
if (batPad.check_event(Gamepad::A_PRESSED) == true){
_hitBall=1;
}
return _hitBall;
}
int Bat::get_loft_ball(){
if (batPad.check_event(Gamepad::L_PRESSED) == true){
//badPad.tone(750.0,0.1);
_loft_ball=1;
}
return _loft_ball;
}
void Bat::first_menu(N5110 &menu_lcd,Gamepad &pad){
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();
while (batPad.check_event(Gamepad::START_PRESSED) == false) {
printf("2");
batPad.leds_on();
wait(0.1);
batPad.leds_off();
wait(0.1);
}
second_menu(menu_lcd);
batPad.leds_off();
}
void Bat::second_menu(N5110 &menu_lcd){
while (_button_pressed==false){
batPad.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();
if (batPad.check_event(Gamepad::A_PRESSED) == true){
_button_pressed=true;
}
}
}
void Bat::game_over(string message){
//char buffer[14];
//int length=sprintf(buffer,"%s",message);
//menu_lcd.printString(buffer,3,1);
}
void Bat::game_over_menu(N5110 &menu_lcd,int option){
if (option==1){
menu_lcd.clear();
menu_lcd.printString("GAME LOST",2,1);
menu_lcd.printString("NO MORE BALLS LEFT",2,3);
menu_lcd.refresh();
wait(5);
}
if (option==2){
menu_lcd.clear();
menu_lcd.printString("GAME LOST",2,1);
menu_lcd.printString("BOWLED",2,3);
menu_lcd.refresh();
wait(5);
}
if (option==3){
menu_lcd.clear();
menu_lcd.printString("GAME LOST",2,1);
menu_lcd.printString("CAUGHT",2,3);
menu_lcd.refresh();
wait(5);
}
}
void Bat::victory_menu(N5110 &menu_lcd){
menu_lcd.clear();
menu_lcd.printString("CONGRATS!!",2,1);
menu_lcd.printString("YOU HAVE WON",2,3);
menu_lcd.refresh();
wait(5);
}
void Bat::info_screen(N5110 &menu_lcd, int target){
menu_lcd.clear();
menu_lcd.printString("YOU ARE GIVEN",2,1);
menu_lcd.printString("10 BALLS ",3,2);
menu_lcd.refresh();
wait(0.5);
char buffer[5];
int length=sprintf(buffer,"SCORE %i RUNS",target);
menu_lcd.printString(buffer,2,4);
menu_lcd.refresh();
wait(0.5);
menu_lcd.printString("GOOD LUCK!!!",0,5);
menu_lcd.refresh();
int i=0;
/*
while (i<=10){
batPad.leds_on();
wait(0.1);
batPad.leds_off();
wait(0.1);
i++;
}
*/
wait(3);
}