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
main.cpp@6:3e50f2cf4366, 2019-04-18 (annotated)
- Committer:
- shahidsajid
- Date:
- Thu Apr 18 09:31:52 2019 +0000
- Revision:
- 6:3e50f2cf4366
- Parent:
- 5:915bcac4e9b9
- Child:
- 7:a1a6bff238c1
Checks for collision (ball hitting bat)
Who changed what in which revision?
| User | Revision | Line number | New 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 | 1:ce0d477de314 | 16 | |
| shahidsajid | 1:ce0d477de314 | 17 | |
| shahidsajid | 1:ce0d477de314 | 18 | N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); |
| shahidsajid | 6:3e50f2cf4366 | 19 | Gamepad pad1; |
| shahidsajid | 3:bd3465a70a5a | 20 | Ball ball; |
| shahidsajid | 4:55a0509c4874 | 21 | Bat bat; |
| shahidsajid | 1:ce0d477de314 | 22 | |
| shahidsajid | 1:ce0d477de314 | 23 | void init(); |
| shahidsajid | 1:ce0d477de314 | 24 | |
| shahidsajid | 6:3e50f2cf4366 | 25 | //void welcome(); |
| shahidsajid | 3:bd3465a70a5a | 26 | void draw(); |
| shahidsajid | 3:bd3465a70a5a | 27 | void ball_test(); |
| shahidsajid | 1:ce0d477de314 | 28 | |
| shahidsajid | 1:ce0d477de314 | 29 | int main(){ |
| shahidsajid | 1:ce0d477de314 | 30 | int fps=8; |
| shahidsajid | 1:ce0d477de314 | 31 | init(); |
| shahidsajid | 6:3e50f2cf4366 | 32 | // welcome(); |
| shahidsajid | 3:bd3465a70a5a | 33 | draw(); |
| shahidsajid | 3:bd3465a70a5a | 34 | /* |
| shahidsajid | 3:bd3465a70a5a | 35 | while (1){ |
| shahidsajid | 3:bd3465a70a5a | 36 | draw(); |
| shahidsajid | 3:bd3465a70a5a | 37 | wait(1.0f/fps); |
| shahidsajid | 3:bd3465a70a5a | 38 | } |
| shahidsajid | 3:bd3465a70a5a | 39 | */ |
| shahidsajid | 5:915bcac4e9b9 | 40 | float f; |
| shahidsajid | 3:bd3465a70a5a | 41 | while(1){ |
| shahidsajid | 6:3e50f2cf4366 | 42 | f= pad1.get_mag(); |
| shahidsajid | 5:915bcac4e9b9 | 43 | printf("MAG %f \n",f); |
| shahidsajid | 6:3e50f2cf4366 | 44 | int lol=bat.get_hitBall(); |
| shahidsajid | 6:3e50f2cf4366 | 45 | ball.start(lcd,lol); |
| shahidsajid | 3:bd3465a70a5a | 46 | draw(); |
| shahidsajid | 3:bd3465a70a5a | 47 | wait(1.0f/fps); |
| shahidsajid | 3:bd3465a70a5a | 48 | } |
| shahidsajid | 3:bd3465a70a5a | 49 | |
| shahidsajid | 3:bd3465a70a5a | 50 | |
| shahidsajid | 3:bd3465a70a5a | 51 | |
| shahidsajid | 1:ce0d477de314 | 52 | } |
| shahidsajid | 1:ce0d477de314 | 53 | void init(){ |
| shahidsajid | 1:ce0d477de314 | 54 | lcd.init(); |
| shahidsajid | 6:3e50f2cf4366 | 55 | pad1.init(); |
| shahidsajid | 4:55a0509c4874 | 56 | bat.init(4,5); |
| shahidsajid | 4:55a0509c4874 | 57 | ball.init(2,3); |
| shahidsajid | 3:bd3465a70a5a | 58 | //field.init(); |
| shahidsajid | 1:ce0d477de314 | 59 | lcd.setContrast(0.4); |
| shahidsajid | 1:ce0d477de314 | 60 | lcd.normalMode(); // normal colour mode |
| shahidsajid | 1:ce0d477de314 | 61 | lcd.setBrightness(0.5); |
| shahidsajid | 1:ce0d477de314 | 62 | lcd.clear(); |
| shahidsajid | 1:ce0d477de314 | 63 | |
| shahidsajid | 1:ce0d477de314 | 64 | } |
| shahidsajid | 1:ce0d477de314 | 65 | void welcome() { |
| shahidsajid | 2:e9ac69c17a75 | 66 | lcd.printString(" CRICKET GAME ",0,1); |
| shahidsajid | 2:e9ac69c17a75 | 67 | lcd.printString(" SHAHID SAJID",0,2); |
| shahidsajid | 1:ce0d477de314 | 68 | lcd.printString(" el17szs ",0,3); |
| shahidsajid | 1:ce0d477de314 | 69 | lcd.printString(" Press Start ",0,4); |
| shahidsajid | 1:ce0d477de314 | 70 | lcd.refresh(); |
| shahidsajid | 1:ce0d477de314 | 71 | // wait flashing LEDs until start button is pressed |
| shahidsajid | 6:3e50f2cf4366 | 72 | while ( pad1.check_event(Gamepad::START_PRESSED) == false) { |
| shahidsajid | 6:3e50f2cf4366 | 73 | pad1.leds_on(); |
| shahidsajid | 1:ce0d477de314 | 74 | wait(0.1); |
| shahidsajid | 6:3e50f2cf4366 | 75 | pad1.leds_off(); |
| shahidsajid | 1:ce0d477de314 | 76 | wait(0.1); |
| shahidsajid | 1:ce0d477de314 | 77 | } |
| shahidsajid | 1:ce0d477de314 | 78 | |
| shahidsajid | 2:e9ac69c17a75 | 79 | } |
| shahidsajid | 3:bd3465a70a5a | 80 | void draw(){ |
| shahidsajid | 2:e9ac69c17a75 | 81 | lcd.clear(); |
| shahidsajid | 3:bd3465a70a5a | 82 | lcd.drawCircle((WIDTH/2),HEIGHT/2,23,FILL_TRANSPARENT); |
| shahidsajid | 3:bd3465a70a5a | 83 | lcd.drawRect(37,11,12,30,FILL_TRANSPARENT); |
| shahidsajid | 3:bd3465a70a5a | 84 | ball.draw(lcd); |
| shahidsajid | 3:bd3465a70a5a | 85 | ball.set_field(lcd); |
| shahidsajid | 4:55a0509c4874 | 86 | bat.draw(lcd); |
| shahidsajid | 2:e9ac69c17a75 | 87 | lcd.refresh(); |
| shahidsajid | 3:bd3465a70a5a | 88 | } |
| shahidsajid | 3:bd3465a70a5a | 89 | void ball_test(){ |
| shahidsajid | 3:bd3465a70a5a | 90 | Vector2D ball_pos = ball.get_pos(); |
| shahidsajid | 3:bd3465a70a5a | 91 | Vector2D ball_velocity = ball.get_velocity(); |
| shahidsajid | 3:bd3465a70a5a | 92 | ball.update(); |
| shahidsajid | 3:bd3465a70a5a | 93 | |
| shahidsajid | 3:bd3465a70a5a | 94 | ball.set_velocity(ball_velocity); |
| shahidsajid | 3:bd3465a70a5a | 95 | ball.set_pos(ball_pos); |
| shahidsajid | 3:bd3465a70a5a | 96 | ball.update(); |
| shahidsajid | 1:ce0d477de314 | 97 | } |