ELEC2645 (2018/19) / Mbed 2 deprecated el17szs

Dependencies:   mbed

Committer:
shahidsajid
Date:
Sat Apr 27 15:42:36 2019 +0000
Revision:
18:a260ce8db9e7
Parent:
14:122eaa3b7a50
Child:
20:9d21599fe350
Created no. of balls completed; created a target; printed the target and no. of balls onto the screen; Created displays for when game is won and game is lost

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shahidsajid 0:bed27dc63dea 1 /*
shahidsajid 0:bed27dc63dea 2 ELEC2645 Embedded Systems Project
shahidsajid 0:bed27dc63dea 3 School of Electronic & Electrical Engineering
shahidsajid 0:bed27dc63dea 4 University of Leeds
shahidsajid 1:ce0d477de314 5 Name: Shahid Zubin Sajid
shahidsajid 1:ce0d477de314 6 Username: el17szs
shahidsajid 1:ce0d477de314 7 Student ID Number: 201197609
shahidsajid 1:ce0d477de314 8 Date: 21/03/2019
shahidsajid 1:ce0d477de314 9 */
shahidsajid 1:ce0d477de314 10
shahidsajid 1:ce0d477de314 11 #include "mbed.h"
shahidsajid 1:ce0d477de314 12 #include "Gamepad.h"
shahidsajid 1:ce0d477de314 13 #include "N5110.h"
shahidsajid 3:bd3465a70a5a 14 #include "Ball.h"
shahidsajid 4:55a0509c4874 15 #include "Bat.h"
shahidsajid 10:6c6e09023942 16 #include "Cricket.h"
shahidsajid 1:ce0d477de314 17
shahidsajid 1:ce0d477de314 18
shahidsajid 1:ce0d477de314 19 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
shahidsajid 10:6c6e09023942 20 Gamepad pad;
shahidsajid 10:6c6e09023942 21 Cricket cricket;
shahidsajid 1:ce0d477de314 22
shahidsajid 12:954da4f4e565 23
shahidsajid 1:ce0d477de314 24 void init();
shahidsajid 1:ce0d477de314 25
shahidsajid 6:3e50f2cf4366 26 //void welcome();
shahidsajid 3:bd3465a70a5a 27 void draw();
shahidsajid 3:bd3465a70a5a 28 void ball_test();
shahidsajid 1:ce0d477de314 29
shahidsajid 1:ce0d477de314 30 int main(){
shahidsajid 14:122eaa3b7a50 31 int fps=10;
shahidsajid 1:ce0d477de314 32 init();
shahidsajid 18:a260ce8db9e7 33
shahidsajid 6:3e50f2cf4366 34 // welcome();
shahidsajid 3:bd3465a70a5a 35 draw();
shahidsajid 12:954da4f4e565 36 //float f;
shahidsajid 12:954da4f4e565 37 //int status=0;
shahidsajid 3:bd3465a70a5a 38 while(1){
shahidsajid 12:954da4f4e565 39 //Direction dir=pad.get_direction();
shahidsajid 11:f481ec642cc5 40 cricket.game(lcd,pad);
shahidsajid 10:6c6e09023942 41 draw();
shahidsajid 11:f481ec642cc5 42 wait(1.0f/fps);
shahidsajid 10:6c6e09023942 43 }
shahidsajid 10:6c6e09023942 44 /*
shahidsajid 10:6c6e09023942 45 while(1){
shahidsajid 9:a81db6a703b7 46 ball.reset();
shahidsajid 10:6c6e09023942 47 field.set_field(lcd);
shahidsajid 10:6c6e09023942 48 draw();
shahidsajid 9:a81db6a703b7 49 while (status!=1){
shahidsajid 9:a81db6a703b7 50 f= pad1.get_mag();
shahidsajid 9:a81db6a703b7 51 int lol=bat.get_hitBall();
shahidsajid 10:6c6e09023942 52 ball.start(lcd,lol,pad.get_direction());
shahidsajid 9:a81db6a703b7 53 draw();
shahidsajid 9:a81db6a703b7 54 wait(1.0f/fps);
shahidsajid 10:6c6e09023942 55 }
shahidsajid 3:bd3465a70a5a 56 }
shahidsajid 10:6c6e09023942 57 */
shahidsajid 1:ce0d477de314 58 }
shahidsajid 1:ce0d477de314 59 void init(){
shahidsajid 1:ce0d477de314 60 lcd.init();
shahidsajid 10:6c6e09023942 61 pad.init();
shahidsajid 12:954da4f4e565 62 //ball1.init(2,4);
shahidsajid 10:6c6e09023942 63 cricket.init();
shahidsajid 12:954da4f4e565 64 //bat1.init();
shahidsajid 1:ce0d477de314 65 lcd.setContrast(0.4);
shahidsajid 1:ce0d477de314 66 lcd.normalMode(); // normal colour mode
shahidsajid 1:ce0d477de314 67 lcd.setBrightness(0.5);
shahidsajid 1:ce0d477de314 68 lcd.clear();
shahidsajid 1:ce0d477de314 69
shahidsajid 1:ce0d477de314 70 }
shahidsajid 1:ce0d477de314 71 void welcome() {
shahidsajid 2:e9ac69c17a75 72 lcd.printString(" CRICKET GAME ",0,1);
shahidsajid 2:e9ac69c17a75 73 lcd.printString(" SHAHID SAJID",0,2);
shahidsajid 1:ce0d477de314 74 lcd.printString(" el17szs ",0,3);
shahidsajid 1:ce0d477de314 75 lcd.printString(" Press Start ",0,4);
shahidsajid 1:ce0d477de314 76 lcd.refresh();
shahidsajid 1:ce0d477de314 77 // wait flashing LEDs until start button is pressed
shahidsajid 10:6c6e09023942 78 while ( pad.check_event(Gamepad::START_PRESSED) == false) {
shahidsajid 10:6c6e09023942 79 pad.leds_on();
shahidsajid 1:ce0d477de314 80 wait(0.1);
shahidsajid 10:6c6e09023942 81 pad.leds_off();
shahidsajid 1:ce0d477de314 82 wait(0.1);
shahidsajid 1:ce0d477de314 83 }
shahidsajid 1:ce0d477de314 84
shahidsajid 2:e9ac69c17a75 85 }
shahidsajid 3:bd3465a70a5a 86 void draw(){
shahidsajid 2:e9ac69c17a75 87 lcd.clear();
shahidsajid 10:6c6e09023942 88 cricket.draw(lcd);
shahidsajid 12:954da4f4e565 89 //ball1.draw(lcd);
shahidsajid 12:954da4f4e565 90 //bat1.draw(lcd);
shahidsajid 2:e9ac69c17a75 91 lcd.refresh();
shahidsajid 3:bd3465a70a5a 92 }
shahidsajid 10:6c6e09023942 93 /*void ball_test(){
shahidsajid 3:bd3465a70a5a 94 Vector2D ball_pos = ball.get_pos();
shahidsajid 3:bd3465a70a5a 95 Vector2D ball_velocity = ball.get_velocity();
shahidsajid 3:bd3465a70a5a 96 ball.update();
shahidsajid 3:bd3465a70a5a 97 ball.set_velocity(ball_velocity);
shahidsajid 3:bd3465a70a5a 98 ball.set_pos(ball_pos);
shahidsajid 3:bd3465a70a5a 99 ball.update();
shahidsajid 10:6c6e09023942 100 }
shahidsajid 10:6c6e09023942 101 */