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.
BreakoutEngine/BreakoutEngine.cpp@34:07ded1f83c59, 2019-04-25 (annotated)
- Committer:
- jamesheavey
- Date:
- Thu Apr 25 20:26:50 2019 +0000
- Revision:
- 34:07ded1f83c59
- Parent:
- 33:e47f6fa1d9ce
- Child:
- 35:3a614d539a54
LIST WORKS!
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| jamesheavey | 27:1b5038b0a7a2 | 1 | #include "BreakoutEngine.h" |
| jamesheavey | 27:1b5038b0a7a2 | 2 | |
| jamesheavey | 27:1b5038b0a7a2 | 3 | |
| jamesheavey | 27:1b5038b0a7a2 | 4 | |
| jamesheavey | 27:1b5038b0a7a2 | 5 | BreakoutEngine::BreakoutEngine() |
| jamesheavey | 27:1b5038b0a7a2 | 6 | { |
| jamesheavey | 27:1b5038b0a7a2 | 7 | |
| jamesheavey | 27:1b5038b0a7a2 | 8 | } |
| jamesheavey | 27:1b5038b0a7a2 | 9 | |
| jamesheavey | 27:1b5038b0a7a2 | 10 | BreakoutEngine::~BreakoutEngine() |
| jamesheavey | 27:1b5038b0a7a2 | 11 | { |
| jamesheavey | 27:1b5038b0a7a2 | 12 | |
| jamesheavey | 27:1b5038b0a7a2 | 13 | } |
| jamesheavey | 27:1b5038b0a7a2 | 14 | |
| jamesheavey | 27:1b5038b0a7a2 | 15 | void BreakoutEngine::init(int paddle_width,int paddle_height,int ball_size,int speed) |
| jamesheavey | 27:1b5038b0a7a2 | 16 | { |
| jamesheavey | 27:1b5038b0a7a2 | 17 | // initialise the game parameters |
| jamesheavey | 27:1b5038b0a7a2 | 18 | _paddle_width = paddle_width; |
| jamesheavey | 27:1b5038b0a7a2 | 19 | _paddle_height = paddle_height; |
| jamesheavey | 27:1b5038b0a7a2 | 20 | _ball_size = ball_size; |
| jamesheavey | 27:1b5038b0a7a2 | 21 | _speed = speed; |
| jamesheavey | 27:1b5038b0a7a2 | 22 | _number_left = 18; |
| jamesheavey | 30:e3d2f0ca416f | 23 | _index = 0; |
| jamesheavey | 27:1b5038b0a7a2 | 24 | |
| jamesheavey | 27:1b5038b0a7a2 | 25 | // y position on screen - WIDTH is defined in N5110.h |
| jamesheavey | 27:1b5038b0a7a2 | 26 | _p1y = HEIGHT - GAP; |
| jamesheavey | 27:1b5038b0a7a2 | 27 | |
| jamesheavey | 27:1b5038b0a7a2 | 28 | // puts paddles and ball in middle |
| jamesheavey | 27:1b5038b0a7a2 | 29 | _p1.init(_p1y,_paddle_height,_paddle_width); |
| jamesheavey | 27:1b5038b0a7a2 | 30 | _ball.init(_ball_size,_speed); |
| jamesheavey | 27:1b5038b0a7a2 | 31 | |
| jamesheavey | 27:1b5038b0a7a2 | 32 | _brick11.init(3,GAP+1,BRICK_HEIGHT,BRICK_WIDTH); // need to figure out how to make a list of these |
| jamesheavey | 27:1b5038b0a7a2 | 33 | _brick12.init(16,GAP+1,BRICK_HEIGHT,BRICK_WIDTH); |
| jamesheavey | 27:1b5038b0a7a2 | 34 | _brick13.init(29,GAP+1,BRICK_HEIGHT,BRICK_WIDTH); |
| jamesheavey | 27:1b5038b0a7a2 | 35 | _brick14.init(42,GAP+1,BRICK_HEIGHT,BRICK_WIDTH); |
| jamesheavey | 27:1b5038b0a7a2 | 36 | _brick15.init(55,GAP+1,BRICK_HEIGHT,BRICK_WIDTH); |
| jamesheavey | 27:1b5038b0a7a2 | 37 | _brick16.init(68,GAP+1,BRICK_HEIGHT,BRICK_WIDTH); |
| jamesheavey | 27:1b5038b0a7a2 | 38 | |
| jamesheavey | 27:1b5038b0a7a2 | 39 | _brick21.init(3,GAP+BRICK_HEIGHT+2,BRICK_HEIGHT,BRICK_WIDTH); // need to figure out how to make a list of these |
| jamesheavey | 27:1b5038b0a7a2 | 40 | _brick22.init(16,GAP+BRICK_HEIGHT+2,BRICK_HEIGHT,BRICK_WIDTH); |
| jamesheavey | 27:1b5038b0a7a2 | 41 | _brick23.init(29,GAP+BRICK_HEIGHT+2,BRICK_HEIGHT,BRICK_WIDTH); |
| jamesheavey | 27:1b5038b0a7a2 | 42 | _brick24.init(42,GAP+BRICK_HEIGHT+2,BRICK_HEIGHT,BRICK_WIDTH); |
| jamesheavey | 27:1b5038b0a7a2 | 43 | _brick25.init(55,GAP+BRICK_HEIGHT+2,BRICK_HEIGHT,BRICK_WIDTH); |
| jamesheavey | 27:1b5038b0a7a2 | 44 | _brick26.init(68,GAP+BRICK_HEIGHT+2,BRICK_HEIGHT,BRICK_WIDTH); |
| jamesheavey | 27:1b5038b0a7a2 | 45 | |
| jamesheavey | 27:1b5038b0a7a2 | 46 | _brick31.init(3,GAP+1+((BRICK_HEIGHT+1)*2),BRICK_HEIGHT,BRICK_WIDTH); // need to figure out how to make a list of these |
| jamesheavey | 27:1b5038b0a7a2 | 47 | _brick32.init(16,GAP+1+((BRICK_HEIGHT+1)*2),BRICK_HEIGHT,BRICK_WIDTH); |
| jamesheavey | 27:1b5038b0a7a2 | 48 | _brick33.init(29,GAP+1+((BRICK_HEIGHT+1)*2),BRICK_HEIGHT,BRICK_WIDTH); |
| jamesheavey | 27:1b5038b0a7a2 | 49 | _brick34.init(42,GAP+1+((BRICK_HEIGHT+1)*2),BRICK_HEIGHT,BRICK_WIDTH); |
| jamesheavey | 27:1b5038b0a7a2 | 50 | _brick35.init(55,GAP+1+((BRICK_HEIGHT+1)*2),BRICK_HEIGHT,BRICK_WIDTH); |
| jamesheavey | 27:1b5038b0a7a2 | 51 | _brick36.init(68,GAP+1+((BRICK_HEIGHT+1)*2),BRICK_HEIGHT,BRICK_WIDTH); |
| jamesheavey | 27:1b5038b0a7a2 | 52 | |
| jamesheavey | 34:07ded1f83c59 | 53 | listofBricks.push_back(_brick11); //maybe be able yo iterate through and this.draw(), maybe useful if i figure out how to delete objects aswell |
| jamesheavey | 34:07ded1f83c59 | 54 | listofBricks.push_back(_brick12); |
| jamesheavey | 34:07ded1f83c59 | 55 | listofBricks.push_back(_brick13); |
| jamesheavey | 34:07ded1f83c59 | 56 | listofBricks.push_back(_brick14); |
| jamesheavey | 34:07ded1f83c59 | 57 | listofBricks.push_back(_brick15); |
| jamesheavey | 34:07ded1f83c59 | 58 | listofBricks.push_back(_brick16); |
| jamesheavey | 34:07ded1f83c59 | 59 | listofBricks.push_back(_brick21); |
| jamesheavey | 34:07ded1f83c59 | 60 | listofBricks.push_back(_brick22); |
| jamesheavey | 34:07ded1f83c59 | 61 | listofBricks.push_back(_brick23); |
| jamesheavey | 34:07ded1f83c59 | 62 | listofBricks.push_back(_brick24); |
| jamesheavey | 34:07ded1f83c59 | 63 | listofBricks.push_back(_brick25); |
| jamesheavey | 34:07ded1f83c59 | 64 | listofBricks.push_back(_brick26); |
| jamesheavey | 34:07ded1f83c59 | 65 | listofBricks.push_back(_brick31); |
| jamesheavey | 34:07ded1f83c59 | 66 | listofBricks.push_back(_brick32); |
| jamesheavey | 34:07ded1f83c59 | 67 | listofBricks.push_back(_brick33); |
| jamesheavey | 34:07ded1f83c59 | 68 | listofBricks.push_back(_brick34); |
| jamesheavey | 34:07ded1f83c59 | 69 | listofBricks.push_back(_brick35); |
| jamesheavey | 34:07ded1f83c59 | 70 | listofBricks.push_back(_brick36); |
| jamesheavey | 34:07ded1f83c59 | 71 | |
| jamesheavey | 30:e3d2f0ca416f | 72 | _laser1.init(-10); |
| jamesheavey | 30:e3d2f0ca416f | 73 | _laser2.init(-10); |
| jamesheavey | 30:e3d2f0ca416f | 74 | _laser3.init(-10); |
| jamesheavey | 27:1b5038b0a7a2 | 75 | } |
| jamesheavey | 27:1b5038b0a7a2 | 76 | |
| jamesheavey | 27:1b5038b0a7a2 | 77 | void BreakoutEngine::read_input(Gamepad &pad, bool x) |
| jamesheavey | 27:1b5038b0a7a2 | 78 | { |
| jamesheavey | 27:1b5038b0a7a2 | 79 | _d = pad.get_direction(); |
| jamesheavey | 27:1b5038b0a7a2 | 80 | _mag = pad.get_mag(); |
| jamesheavey | 27:1b5038b0a7a2 | 81 | |
| jamesheavey | 27:1b5038b0a7a2 | 82 | if (x == true) { |
| jamesheavey | 27:1b5038b0a7a2 | 83 | _p1.set_tilt(); |
| jamesheavey | 27:1b5038b0a7a2 | 84 | } |
| jamesheavey | 27:1b5038b0a7a2 | 85 | else { |
| jamesheavey | 27:1b5038b0a7a2 | 86 | _p1.set_joy(); |
| jamesheavey | 27:1b5038b0a7a2 | 87 | } |
| jamesheavey | 31:516d4e27765a | 88 | if (pad.check_event(Gamepad::B_PRESSED)) { // max of 3 lasers on screen at once |
| jamesheavey | 29:5168318d3e88 | 89 | |
| jamesheavey | 29:5168318d3e88 | 90 | Vector2D p_pos = _p1.get_pos(); |
| jamesheavey | 30:e3d2f0ca416f | 91 | switch(_index){ |
| jamesheavey | 30:e3d2f0ca416f | 92 | case 0: |
| jamesheavey | 30:e3d2f0ca416f | 93 | Vector2D laser1_pos = _laser1.get_pos(); |
| jamesheavey | 30:e3d2f0ca416f | 94 | laser1_pos.x = p_pos.x+7; |
| jamesheavey | 30:e3d2f0ca416f | 95 | laser1_pos.y = p_pos.y; |
| jamesheavey | 30:e3d2f0ca416f | 96 | _laser1.set_pos(laser1_pos); |
| jamesheavey | 30:e3d2f0ca416f | 97 | inc_index(); |
| jamesheavey | 30:e3d2f0ca416f | 98 | break; |
| jamesheavey | 30:e3d2f0ca416f | 99 | case 1: |
| jamesheavey | 30:e3d2f0ca416f | 100 | Vector2D laser2_pos = _laser2.get_pos(); |
| jamesheavey | 30:e3d2f0ca416f | 101 | laser2_pos.x = p_pos.x+7; |
| jamesheavey | 30:e3d2f0ca416f | 102 | laser2_pos.y = p_pos.y; |
| jamesheavey | 30:e3d2f0ca416f | 103 | _laser2.set_pos(laser2_pos); |
| jamesheavey | 30:e3d2f0ca416f | 104 | inc_index(); |
| jamesheavey | 30:e3d2f0ca416f | 105 | break; |
| jamesheavey | 30:e3d2f0ca416f | 106 | case 2: |
| jamesheavey | 30:e3d2f0ca416f | 107 | Vector2D laser3_pos = _laser3.get_pos(); |
| jamesheavey | 30:e3d2f0ca416f | 108 | laser3_pos.x = p_pos.x+7; |
| jamesheavey | 30:e3d2f0ca416f | 109 | laser3_pos.y = p_pos.y; |
| jamesheavey | 30:e3d2f0ca416f | 110 | _laser3.set_pos(laser3_pos); |
| jamesheavey | 30:e3d2f0ca416f | 111 | reset_index(); |
| jamesheavey | 30:e3d2f0ca416f | 112 | break; |
| jamesheavey | 30:e3d2f0ca416f | 113 | } |
| jamesheavey | 29:5168318d3e88 | 114 | } |
| jamesheavey | 27:1b5038b0a7a2 | 115 | } |
| jamesheavey | 27:1b5038b0a7a2 | 116 | |
| jamesheavey | 30:e3d2f0ca416f | 117 | void BreakoutEngine::inc_index() { |
| jamesheavey | 30:e3d2f0ca416f | 118 | _index ++; |
| jamesheavey | 30:e3d2f0ca416f | 119 | } |
| jamesheavey | 30:e3d2f0ca416f | 120 | |
| jamesheavey | 30:e3d2f0ca416f | 121 | void BreakoutEngine::reset_index() { |
| jamesheavey | 30:e3d2f0ca416f | 122 | _index = 0; |
| jamesheavey | 30:e3d2f0ca416f | 123 | } |
| jamesheavey | 30:e3d2f0ca416f | 124 | |
| jamesheavey | 27:1b5038b0a7a2 | 125 | void BreakoutEngine::draw(N5110 &lcd) |
| jamesheavey | 27:1b5038b0a7a2 | 126 | { |
| jamesheavey | 27:1b5038b0a7a2 | 127 | // draw the elements in the LCD buffer |
| jamesheavey | 27:1b5038b0a7a2 | 128 | // pitch |
| jamesheavey | 27:1b5038b0a7a2 | 129 | lcd.drawRect(0,0,WIDTH,HEIGHT,FILL_TRANSPARENT); |
| jamesheavey | 27:1b5038b0a7a2 | 130 | //score |
| jamesheavey | 27:1b5038b0a7a2 | 131 | //print_scores(lcd); |
| jamesheavey | 27:1b5038b0a7a2 | 132 | // paddles |
| jamesheavey | 27:1b5038b0a7a2 | 133 | _p1.draw(lcd); |
| jamesheavey | 27:1b5038b0a7a2 | 134 | // ball |
| jamesheavey | 27:1b5038b0a7a2 | 135 | _ball.draw(lcd); |
| jamesheavey | 27:1b5038b0a7a2 | 136 | |
| jamesheavey | 27:1b5038b0a7a2 | 137 | //print_scores(lcd); |
| jamesheavey | 27:1b5038b0a7a2 | 138 | |
| jamesheavey | 34:07ded1f83c59 | 139 | for (it = listofBricks.begin(); it != listofBricks.end(); ++it){ |
| jamesheavey | 34:07ded1f83c59 | 140 | it->draw(lcd); |
| jamesheavey | 34:07ded1f83c59 | 141 | } |
| jamesheavey | 27:1b5038b0a7a2 | 142 | |
| jamesheavey | 30:e3d2f0ca416f | 143 | _laser1.draw(lcd); |
| jamesheavey | 30:e3d2f0ca416f | 144 | _laser2.draw(lcd); |
| jamesheavey | 30:e3d2f0ca416f | 145 | _laser3.draw(lcd); |
| jamesheavey | 27:1b5038b0a7a2 | 146 | |
| jamesheavey | 27:1b5038b0a7a2 | 147 | } |
| jamesheavey | 27:1b5038b0a7a2 | 148 | |
| jamesheavey | 27:1b5038b0a7a2 | 149 | |
| jamesheavey | 27:1b5038b0a7a2 | 150 | void BreakoutEngine::update(Gamepad &pad) |
| jamesheavey | 27:1b5038b0a7a2 | 151 | { |
| jamesheavey | 27:1b5038b0a7a2 | 152 | check_goal(pad); |
| jamesheavey | 27:1b5038b0a7a2 | 153 | // important to update paddles and ball before checking collisions so can |
| jamesheavey | 27:1b5038b0a7a2 | 154 | // correct for it before updating the display |
| jamesheavey | 27:1b5038b0a7a2 | 155 | _p1.update(_d,_mag); |
| jamesheavey | 27:1b5038b0a7a2 | 156 | _ball.update(); |
| jamesheavey | 30:e3d2f0ca416f | 157 | _laser1.update(); |
| jamesheavey | 30:e3d2f0ca416f | 158 | _laser2.update(); |
| jamesheavey | 30:e3d2f0ca416f | 159 | _laser3.update(); |
| jamesheavey | 27:1b5038b0a7a2 | 160 | lives_leds(pad); |
| jamesheavey | 27:1b5038b0a7a2 | 161 | |
| jamesheavey | 27:1b5038b0a7a2 | 162 | check_wall_collision(pad); |
| jamesheavey | 27:1b5038b0a7a2 | 163 | check_paddle_collisions(pad); |
| jamesheavey | 27:1b5038b0a7a2 | 164 | check_brick_collisions(pad); |
| jamesheavey | 34:07ded1f83c59 | 165 | //check_laser_collisions(pad); |
| jamesheavey | 27:1b5038b0a7a2 | 166 | } |
| jamesheavey | 27:1b5038b0a7a2 | 167 | |
| jamesheavey | 27:1b5038b0a7a2 | 168 | void BreakoutEngine::lives_leds(Gamepad &pad) |
| jamesheavey | 27:1b5038b0a7a2 | 169 | { |
| jamesheavey | 27:1b5038b0a7a2 | 170 | if (_p1.get_lives() == 0) { |
| jamesheavey | 27:1b5038b0a7a2 | 171 | pad.leds_off(); |
| jamesheavey | 27:1b5038b0a7a2 | 172 | } |
| jamesheavey | 27:1b5038b0a7a2 | 173 | |
| jamesheavey | 27:1b5038b0a7a2 | 174 | else if (_p1.get_lives() == 1) { |
| jamesheavey | 27:1b5038b0a7a2 | 175 | //turn leftmost led on |
| jamesheavey | 27:1b5038b0a7a2 | 176 | pad.leds_off(); |
| jamesheavey | 27:1b5038b0a7a2 | 177 | pad.led(1,1); |
| jamesheavey | 27:1b5038b0a7a2 | 178 | } |
| jamesheavey | 27:1b5038b0a7a2 | 179 | |
| jamesheavey | 27:1b5038b0a7a2 | 180 | else if (_p1.get_lives() == 2) { |
| jamesheavey | 27:1b5038b0a7a2 | 181 | //turn leftmost led on |
| jamesheavey | 27:1b5038b0a7a2 | 182 | pad.leds_off(); |
| jamesheavey | 27:1b5038b0a7a2 | 183 | pad.led(1,1); |
| jamesheavey | 27:1b5038b0a7a2 | 184 | pad.led(2,1); |
| jamesheavey | 27:1b5038b0a7a2 | 185 | } |
| jamesheavey | 27:1b5038b0a7a2 | 186 | |
| jamesheavey | 27:1b5038b0a7a2 | 187 | else if (_p1.get_lives() == 3) { |
| jamesheavey | 27:1b5038b0a7a2 | 188 | //turn leftmost led on |
| jamesheavey | 27:1b5038b0a7a2 | 189 | pad.leds_off(); |
| jamesheavey | 27:1b5038b0a7a2 | 190 | pad.led(1,1); |
| jamesheavey | 27:1b5038b0a7a2 | 191 | pad.led(2,1); |
| jamesheavey | 27:1b5038b0a7a2 | 192 | pad.led(3,1); |
| jamesheavey | 27:1b5038b0a7a2 | 193 | } |
| jamesheavey | 27:1b5038b0a7a2 | 194 | |
| jamesheavey | 27:1b5038b0a7a2 | 195 | else if (_p1.get_lives() == 4) { |
| jamesheavey | 27:1b5038b0a7a2 | 196 | pad.leds_on(); |
| jamesheavey | 27:1b5038b0a7a2 | 197 | pad.led(5,0); |
| jamesheavey | 27:1b5038b0a7a2 | 198 | pad.led(6,0); |
| jamesheavey | 27:1b5038b0a7a2 | 199 | } |
| jamesheavey | 27:1b5038b0a7a2 | 200 | |
| jamesheavey | 27:1b5038b0a7a2 | 201 | else if (_p1.get_lives() == 5) { |
| jamesheavey | 27:1b5038b0a7a2 | 202 | pad.leds_on(); |
| jamesheavey | 27:1b5038b0a7a2 | 203 | pad.led(6,0); |
| jamesheavey | 27:1b5038b0a7a2 | 204 | } |
| jamesheavey | 27:1b5038b0a7a2 | 205 | |
| jamesheavey | 27:1b5038b0a7a2 | 206 | else if (_p1.get_lives() == 6) { |
| jamesheavey | 27:1b5038b0a7a2 | 207 | pad.leds_on(); |
| jamesheavey | 27:1b5038b0a7a2 | 208 | } |
| jamesheavey | 27:1b5038b0a7a2 | 209 | } |
| jamesheavey | 27:1b5038b0a7a2 | 210 | |
| jamesheavey | 27:1b5038b0a7a2 | 211 | int BreakoutEngine::get_lives() { |
| jamesheavey | 27:1b5038b0a7a2 | 212 | return _p1.get_lives(); |
| jamesheavey | 27:1b5038b0a7a2 | 213 | } |
| jamesheavey | 27:1b5038b0a7a2 | 214 | |
| jamesheavey | 27:1b5038b0a7a2 | 215 | void BreakoutEngine::check_wall_collision(Gamepad &pad) |
| jamesheavey | 27:1b5038b0a7a2 | 216 | { |
| jamesheavey | 27:1b5038b0a7a2 | 217 | // read current ball attributes |
| jamesheavey | 27:1b5038b0a7a2 | 218 | Vector2D ball_pos = _ball.get_pos(); |
| jamesheavey | 27:1b5038b0a7a2 | 219 | Vector2D ball_velocity = _ball.get_velocity(); |
| jamesheavey | 27:1b5038b0a7a2 | 220 | |
| jamesheavey | 27:1b5038b0a7a2 | 221 | if (ball_pos.y <= 1) { // 1 due to 1 pixel boundary |
| jamesheavey | 27:1b5038b0a7a2 | 222 | ball_pos.y = 1; // bounce off ceiling without going off screen |
| jamesheavey | 27:1b5038b0a7a2 | 223 | ball_velocity.y = -ball_velocity.y; |
| jamesheavey | 27:1b5038b0a7a2 | 224 | // audio feedback |
| jamesheavey | 27:1b5038b0a7a2 | 225 | pad.tone(750.0,0.1); |
| jamesheavey | 27:1b5038b0a7a2 | 226 | } |
| jamesheavey | 27:1b5038b0a7a2 | 227 | |
| jamesheavey | 27:1b5038b0a7a2 | 228 | else if (ball_pos.x <= 1) { // 1 due to 1 pixel boundary |
| jamesheavey | 27:1b5038b0a7a2 | 229 | ball_pos.x = 1; // bounce off ceiling without going off screen |
| jamesheavey | 27:1b5038b0a7a2 | 230 | ball_velocity.x = -ball_velocity.x; |
| jamesheavey | 27:1b5038b0a7a2 | 231 | // audio feedback |
| jamesheavey | 27:1b5038b0a7a2 | 232 | pad.tone(750.0,0.1); |
| jamesheavey | 27:1b5038b0a7a2 | 233 | } |
| jamesheavey | 27:1b5038b0a7a2 | 234 | |
| jamesheavey | 27:1b5038b0a7a2 | 235 | // check if hit bottom wall |
| jamesheavey | 27:1b5038b0a7a2 | 236 | else if (ball_pos.x + _ball_size >= (WIDTH-1) ) { // bottom pixel is 47 |
| jamesheavey | 27:1b5038b0a7a2 | 237 | // hit bottom |
| jamesheavey | 27:1b5038b0a7a2 | 238 | ball_pos.x = (WIDTH-1) - _ball_size; // stops ball going off screen |
| jamesheavey | 27:1b5038b0a7a2 | 239 | ball_velocity.x = -ball_velocity.x; |
| jamesheavey | 27:1b5038b0a7a2 | 240 | // audio feedback |
| jamesheavey | 27:1b5038b0a7a2 | 241 | pad.tone(750.0,0.1); |
| jamesheavey | 27:1b5038b0a7a2 | 242 | } |
| jamesheavey | 27:1b5038b0a7a2 | 243 | |
| jamesheavey | 27:1b5038b0a7a2 | 244 | // update ball parameters |
| jamesheavey | 27:1b5038b0a7a2 | 245 | _ball.set_velocity(ball_velocity); |
| jamesheavey | 27:1b5038b0a7a2 | 246 | _ball.set_pos(ball_pos); |
| jamesheavey | 27:1b5038b0a7a2 | 247 | |
| jamesheavey | 27:1b5038b0a7a2 | 248 | } |
| jamesheavey | 27:1b5038b0a7a2 | 249 | |
| jamesheavey | 27:1b5038b0a7a2 | 250 | void BreakoutEngine::check_paddle_collisions(Gamepad &pad) |
| jamesheavey | 27:1b5038b0a7a2 | 251 | { |
| jamesheavey | 27:1b5038b0a7a2 | 252 | // read current ball attributes |
| jamesheavey | 27:1b5038b0a7a2 | 253 | Vector2D ball_pos = _ball.get_pos(); |
| jamesheavey | 27:1b5038b0a7a2 | 254 | Vector2D ball_velocity = _ball.get_velocity(); |
| jamesheavey | 27:1b5038b0a7a2 | 255 | |
| jamesheavey | 27:1b5038b0a7a2 | 256 | // check p1 first |
| jamesheavey | 27:1b5038b0a7a2 | 257 | Vector2D p1_pos = _p1.get_pos(); |
| jamesheavey | 27:1b5038b0a7a2 | 258 | |
| jamesheavey | 27:1b5038b0a7a2 | 259 | // see if ball has hit the paddle by checking for overlaps |
| jamesheavey | 27:1b5038b0a7a2 | 260 | if ( |
| jamesheavey | 27:1b5038b0a7a2 | 261 | (ball_pos.x >= p1_pos.x) && //left |
| jamesheavey | 27:1b5038b0a7a2 | 262 | (ball_pos.x <= p1_pos.x + _paddle_width) && //right |
| jamesheavey | 27:1b5038b0a7a2 | 263 | (ball_pos.y >= _p1y) && //bottom |
| jamesheavey | 27:1b5038b0a7a2 | 264 | (ball_pos.y <= _p1y + _paddle_height) //top |
| jamesheavey | 27:1b5038b0a7a2 | 265 | ) { // edit this so that if it hits the middle, reflect, else change angle depending on how far off centre (add angle to ball) |
| jamesheavey | 27:1b5038b0a7a2 | 266 | // if it has, fix position and reflect x velocity |
| jamesheavey | 27:1b5038b0a7a2 | 267 | pad.tone(1000.0,0.1); |
| jamesheavey | 27:1b5038b0a7a2 | 268 | ball_pos.y = _p1y + _paddle_height - 1; |
| jamesheavey | 27:1b5038b0a7a2 | 269 | ball_velocity.y = -ball_velocity.y; |
| jamesheavey | 27:1b5038b0a7a2 | 270 | |
| jamesheavey | 27:1b5038b0a7a2 | 271 | // if (ball_pos.x == p1_pos.x + PADDLE_WIDTH/2) { // check ballxpos in relation to paddle xpos. translate the distance from the centre to an angle between 30 and 60 degrees in that direction |
| jamesheavey | 27:1b5038b0a7a2 | 272 | // ball_pos.y = _p1y + _paddle_height - 1; |
| jamesheavey | 27:1b5038b0a7a2 | 273 | // ball_velocity.y = -ball_velocity.y; |
| jamesheavey | 27:1b5038b0a7a2 | 274 | // } |
| jamesheavey | 27:1b5038b0a7a2 | 275 | // else if (ball_pos.x <= p1_pos.x + PADDLE_WIDTH/2) { |
| jamesheavey | 27:1b5038b0a7a2 | 276 | // float ang = 40*(((p1_pos.x + PADDLE_WIDTH/2)-ball_pos.x)/(PADDLE_WIDTH/2 - p1_pos.x)) + 30; //converts the distance from the centre to an angle between 30 and 60 |
| jamesheavey | 27:1b5038b0a7a2 | 277 | // if (ball_velocity.x > 0) { |
| jamesheavey | 27:1b5038b0a7a2 | 278 | // ball_velocity.x = -ball_velocity.x; |
| jamesheavey | 27:1b5038b0a7a2 | 279 | // } |
| jamesheavey | 27:1b5038b0a7a2 | 280 | // ball_pos.y = _p1y + _paddle_heigh - 1; |
| jamesheavey | 27:1b5038b0a7a2 | 281 | // ball_velocity.y = -tan(ang); |
| jamesheavey | 27:1b5038b0a7a2 | 282 | // } |
| jamesheavey | 27:1b5038b0a7a2 | 283 | // else if (ball_pos.x >= p1_pos.x + PADDLE_WIDTH/2) { |
| jamesheavey | 27:1b5038b0a7a2 | 284 | // float ang = 40*(((p1_pos.x + PADDLE_WIDTH/2)-ball_pos.x)/(PADDLE_WIDTH/2 - p1_pos.x)) + 30; //converts the distance from the centre to an angle between 30 and 60 |
| jamesheavey | 27:1b5038b0a7a2 | 285 | // if (ball_velocity.x < 0) { |
| jamesheavey | 27:1b5038b0a7a2 | 286 | // ball_velocity.x = -ball_velocity.x; |
| jamesheavey | 27:1b5038b0a7a2 | 287 | // } |
| jamesheavey | 27:1b5038b0a7a2 | 288 | // ball_pos.y = _p1y + _paddle_height - 1; |
| jamesheavey | 27:1b5038b0a7a2 | 289 | // ball_velocity.y = -tan(ang); |
| jamesheavey | 27:1b5038b0a7a2 | 290 | // } |
| jamesheavey | 27:1b5038b0a7a2 | 291 | } |
| jamesheavey | 27:1b5038b0a7a2 | 292 | |
| jamesheavey | 27:1b5038b0a7a2 | 293 | // write new attributes |
| jamesheavey | 27:1b5038b0a7a2 | 294 | _ball.set_velocity(ball_velocity); |
| jamesheavey | 27:1b5038b0a7a2 | 295 | _ball.set_pos(ball_pos); |
| jamesheavey | 27:1b5038b0a7a2 | 296 | } |
| jamesheavey | 27:1b5038b0a7a2 | 297 | |
| jamesheavey | 27:1b5038b0a7a2 | 298 | void BreakoutEngine::check_brick_collisions(Gamepad &pad) |
| jamesheavey | 27:1b5038b0a7a2 | 299 | { |
| jamesheavey | 27:1b5038b0a7a2 | 300 | // read current ball attributes |
| jamesheavey | 27:1b5038b0a7a2 | 301 | Vector2D ball_pos = _ball.get_pos(); |
| jamesheavey | 27:1b5038b0a7a2 | 302 | Vector2D ball_velocity = _ball.get_velocity(); |
| jamesheavey | 27:1b5038b0a7a2 | 303 | |
| jamesheavey | 34:07ded1f83c59 | 304 | for (it = listofBricks.begin(); it != listofBricks.end(); ++it){ |
| jamesheavey | 34:07ded1f83c59 | 305 | if ( |
| jamesheavey | 34:07ded1f83c59 | 306 | (ball_pos.x >= it -> get_x()) && //left |
| jamesheavey | 34:07ded1f83c59 | 307 | (ball_pos.x <= it -> get_x() + BRICK_WIDTH) && //right |
| jamesheavey | 34:07ded1f83c59 | 308 | (ball_pos.y >= it -> get_y()) && //bottom |
| jamesheavey | 34:07ded1f83c59 | 309 | (ball_pos.y <= it -> get_y() + BRICK_HEIGHT) //top |
| jamesheavey | 34:07ded1f83c59 | 310 | ) { // edit this so that if it hits the middle, reflect, else change angle depending on how far off centre (add angle to ball) |
| jamesheavey | 34:07ded1f83c59 | 311 | // if it has, fix position and reflect x velocity |
| jamesheavey | 34:07ded1f83c59 | 312 | ball_pos.y = it -> get_y() + BRICK_HEIGHT; |
| jamesheavey | 34:07ded1f83c59 | 313 | ball_velocity.y = -ball_velocity.y; |
| jamesheavey | 34:07ded1f83c59 | 314 | // audio feedback |
| jamesheavey | 34:07ded1f83c59 | 315 | pad.tone(1000.0,0.1); |
| jamesheavey | 34:07ded1f83c59 | 316 | it -> hit(); |
| jamesheavey | 34:07ded1f83c59 | 317 | it -> hit(); |
| jamesheavey | 34:07ded1f83c59 | 318 | //delete _brick11; |
| jamesheavey | 34:07ded1f83c59 | 319 | it -> set_posx(-100); |
| jamesheavey | 34:07ded1f83c59 | 320 | it -> set_posy(-100); |
| jamesheavey | 34:07ded1f83c59 | 321 | one_less(); |
| jamesheavey | 34:07ded1f83c59 | 322 | } |
| jamesheavey | 27:1b5038b0a7a2 | 323 | } |
| jamesheavey | 27:1b5038b0a7a2 | 324 | // write new attributes |
| jamesheavey | 27:1b5038b0a7a2 | 325 | _ball.set_velocity(ball_velocity); |
| jamesheavey | 27:1b5038b0a7a2 | 326 | _ball.set_pos(ball_pos); |
| jamesheavey | 27:1b5038b0a7a2 | 327 | } |
| jamesheavey | 34:07ded1f83c59 | 328 | /* |
| jamesheavey | 32:4dba7a85dbb2 | 329 | void BreakoutEngine::check_laser_collisions(Gamepad &pad) |
| jamesheavey | 32:4dba7a85dbb2 | 330 | { |
| jamesheavey | 32:4dba7a85dbb2 | 331 | // read current ball attributes |
| jamesheavey | 32:4dba7a85dbb2 | 332 | Vector2D laser1_pos = _laser1.get_pos(); |
| jamesheavey | 32:4dba7a85dbb2 | 333 | Vector2D laser2_pos = _laser2.get_pos(); |
| jamesheavey | 32:4dba7a85dbb2 | 334 | Vector2D laser3_pos = _laser3.get_pos(); |
| jamesheavey | 34:07ded1f83c59 | 335 | // check p1 first |
| jamesheavey | 32:4dba7a85dbb2 | 336 | |
| jamesheavey | 34:07ded1f83c59 | 337 | for (it = listofBricks.begin(); it != listofBricks.end(); ++it){ |
| jamesheavey | 34:07ded1f83c59 | 338 | if ( |
| jamesheavey | 34:07ded1f83c59 | 339 | (ball_pos.x >= it -> get_x()) && //left |
| jamesheavey | 34:07ded1f83c59 | 340 | (ball_pos.x <= it -> get_x() + BRICK_WIDTH) && //right |
| jamesheavey | 34:07ded1f83c59 | 341 | (ball_pos.y >= it -> get_y()) && //bottom |
| jamesheavey | 34:07ded1f83c59 | 342 | (ball_pos.y <= it -> get_y() + BRICK_HEIGHT) //top |
| jamesheavey | 34:07ded1f83c59 | 343 | ) { // edit this so that if it hits the middle, reflect, else change angle depending on how far off centre (add angle to ball) |
| jamesheavey | 34:07ded1f83c59 | 344 | // if it has, fix position and reflect x velocity |
| jamesheavey | 34:07ded1f83c59 | 345 | ball_pos.y = it -> get_y() + BRICK_HEIGHT; |
| jamesheavey | 34:07ded1f83c59 | 346 | ball_velocity.y = -ball_velocity.y; |
| jamesheavey | 34:07ded1f83c59 | 347 | // audio feedback |
| jamesheavey | 34:07ded1f83c59 | 348 | pad.tone(1000.0,0.1); |
| jamesheavey | 34:07ded1f83c59 | 349 | it -> hit(); |
| jamesheavey | 34:07ded1f83c59 | 350 | it -> hit(); |
| jamesheavey | 34:07ded1f83c59 | 351 | //delete _brick11; |
| jamesheavey | 34:07ded1f83c59 | 352 | it -> set_posx(-100); |
| jamesheavey | 34:07ded1f83c59 | 353 | it -> set_posy(-100); |
| jamesheavey | 34:07ded1f83c59 | 354 | one_less(); |
| jamesheavey | 34:07ded1f83c59 | 355 | } |
| jamesheavey | 34:07ded1f83c59 | 356 | } |
| jamesheavey | 32:4dba7a85dbb2 | 357 | |
| jamesheavey | 32:4dba7a85dbb2 | 358 | // see if ball has hit the paddle by checking for overlaps |
| jamesheavey | 32:4dba7a85dbb2 | 359 | if ( |
| jamesheavey | 32:4dba7a85dbb2 | 360 | (laser1_pos.x >= _brick11_pos.x) && //left |
| jamesheavey | 32:4dba7a85dbb2 | 361 | (laser1_pos.x <= _brick11_pos.x + BRICK_WIDTH) && //right |
| jamesheavey | 32:4dba7a85dbb2 | 362 | (laser1_pos.y >= _brick11_pos.y) && //bottom |
| jamesheavey | 32:4dba7a85dbb2 | 363 | (laser1_pos.y <= _brick11_pos.y + BRICK_HEIGHT) //top |
| jamesheavey | 32:4dba7a85dbb2 | 364 | ) { // edit this so that if it hits the middle, reflect, else change angle depending on how far off centre (add angle to ball) |
| jamesheavey | 32:4dba7a85dbb2 | 365 | // if it has, fix position and reflect x velocity |
| jamesheavey | 32:4dba7a85dbb2 | 366 | laser1_pos.x = -10; |
| jamesheavey | 32:4dba7a85dbb2 | 367 | // audio feedback |
| jamesheavey | 32:4dba7a85dbb2 | 368 | pad.tone(1000.0,0.1); |
| jamesheavey | 33:e47f6fa1d9ce | 369 | //if(_brick11.hit() == true) { |
| jamesheavey | 32:4dba7a85dbb2 | 370 | _brick11_pos.x = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 371 | _brick11_pos.y = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 372 | _brick11.set_pos(_brick11_pos); |
| jamesheavey | 32:4dba7a85dbb2 | 373 | one_less(); |
| jamesheavey | 33:e47f6fa1d9ce | 374 | //} |
| jamesheavey | 32:4dba7a85dbb2 | 375 | //delete _brick11; |
| jamesheavey | 32:4dba7a85dbb2 | 376 | |
| jamesheavey | 32:4dba7a85dbb2 | 377 | } |
| jamesheavey | 32:4dba7a85dbb2 | 378 | // check p1 first |
| jamesheavey | 32:4dba7a85dbb2 | 379 | Vector2D _brick12_pos = _brick12.get_pos(); |
| jamesheavey | 32:4dba7a85dbb2 | 380 | |
| jamesheavey | 32:4dba7a85dbb2 | 381 | // see if ball has hit the paddle by checking for overlaps |
| jamesheavey | 32:4dba7a85dbb2 | 382 | if ( |
| jamesheavey | 32:4dba7a85dbb2 | 383 | (laser1_pos.x >= _brick12_pos.x) && //left |
| jamesheavey | 32:4dba7a85dbb2 | 384 | (laser1_pos.x <= _brick12_pos.x + BRICK_WIDTH) && //right |
| jamesheavey | 32:4dba7a85dbb2 | 385 | (laser1_pos.y >= _brick12_pos.y) && //bottom |
| jamesheavey | 32:4dba7a85dbb2 | 386 | (laser1_pos.y <= _brick12_pos.y + BRICK_HEIGHT) //top |
| jamesheavey | 32:4dba7a85dbb2 | 387 | ) { // edit this so that if it hits the middle, reflect, else change angle depending on how far off centre (add angle to ball) |
| jamesheavey | 32:4dba7a85dbb2 | 388 | // if it has, fix position and reflect x velocity |
| jamesheavey | 32:4dba7a85dbb2 | 389 | laser1_pos.x = -10; |
| jamesheavey | 32:4dba7a85dbb2 | 390 | // audio feedback |
| jamesheavey | 32:4dba7a85dbb2 | 391 | pad.tone(1000.0,0.1); |
| jamesheavey | 33:e47f6fa1d9ce | 392 | //if(_brick12.hit() == true) { |
| jamesheavey | 32:4dba7a85dbb2 | 393 | _brick12_pos.x = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 394 | _brick12_pos.y = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 395 | _brick12.set_pos(_brick11_pos); |
| jamesheavey | 32:4dba7a85dbb2 | 396 | one_less(); |
| jamesheavey | 33:e47f6fa1d9ce | 397 | //} |
| jamesheavey | 32:4dba7a85dbb2 | 398 | } |
| jamesheavey | 32:4dba7a85dbb2 | 399 | // check p1 first |
| jamesheavey | 32:4dba7a85dbb2 | 400 | Vector2D _brick13_pos = _brick13.get_pos(); |
| jamesheavey | 32:4dba7a85dbb2 | 401 | |
| jamesheavey | 32:4dba7a85dbb2 | 402 | // see if ball has hit the paddle by checking for overlaps |
| jamesheavey | 32:4dba7a85dbb2 | 403 | if ( |
| jamesheavey | 32:4dba7a85dbb2 | 404 | (laser1_pos.x >= _brick13_pos.x) && //left |
| jamesheavey | 32:4dba7a85dbb2 | 405 | (laser1_pos.x <= _brick13_pos.x + BRICK_WIDTH) && //right |
| jamesheavey | 32:4dba7a85dbb2 | 406 | (laser1_pos.y >= _brick13_pos.y) && //bottom |
| jamesheavey | 32:4dba7a85dbb2 | 407 | (laser1_pos.y <= _brick13_pos.y + BRICK_HEIGHT) //top |
| jamesheavey | 32:4dba7a85dbb2 | 408 | ) { // edit this so that if it hits the middle, reflect, else change angle depending on how far off centre (add angle to ball) |
| jamesheavey | 32:4dba7a85dbb2 | 409 | // if it has, fix position and reflect x velocity |
| jamesheavey | 32:4dba7a85dbb2 | 410 | laser1_pos.x = -10; |
| jamesheavey | 32:4dba7a85dbb2 | 411 | // audio feedback |
| jamesheavey | 32:4dba7a85dbb2 | 412 | pad.tone(1000.0,0.1); |
| jamesheavey | 33:e47f6fa1d9ce | 413 | //if(_brick13.hit() == true) { |
| jamesheavey | 32:4dba7a85dbb2 | 414 | _brick13_pos.x = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 415 | _brick13_pos.y = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 416 | _brick13.set_pos(_brick11_pos); |
| jamesheavey | 32:4dba7a85dbb2 | 417 | one_less(); |
| jamesheavey | 33:e47f6fa1d9ce | 418 | //} |
| jamesheavey | 32:4dba7a85dbb2 | 419 | } |
| jamesheavey | 32:4dba7a85dbb2 | 420 | // check p1 first |
| jamesheavey | 32:4dba7a85dbb2 | 421 | Vector2D _brick14_pos = _brick14.get_pos(); |
| jamesheavey | 32:4dba7a85dbb2 | 422 | |
| jamesheavey | 32:4dba7a85dbb2 | 423 | // see if ball has hit the paddle by checking for overlaps |
| jamesheavey | 32:4dba7a85dbb2 | 424 | if ( |
| jamesheavey | 32:4dba7a85dbb2 | 425 | (laser1_pos.x >= _brick14_pos.x) && //left |
| jamesheavey | 32:4dba7a85dbb2 | 426 | (laser1_pos.x <= _brick14_pos.x + BRICK_WIDTH) && //right |
| jamesheavey | 32:4dba7a85dbb2 | 427 | (laser1_pos.y >= _brick14_pos.y) && //bottom |
| jamesheavey | 32:4dba7a85dbb2 | 428 | (laser1_pos.y <= _brick14_pos.y + BRICK_HEIGHT) //top |
| jamesheavey | 32:4dba7a85dbb2 | 429 | ) { // edit this so that if it hits the middle, reflect, else change angle depending on how far off centre (add angle to ball) |
| jamesheavey | 32:4dba7a85dbb2 | 430 | // if it has, fix position and reflect x velocity |
| jamesheavey | 32:4dba7a85dbb2 | 431 | laser1_pos.x = -10; |
| jamesheavey | 32:4dba7a85dbb2 | 432 | // audio feedback |
| jamesheavey | 32:4dba7a85dbb2 | 433 | pad.tone(1000.0,0.1); |
| jamesheavey | 33:e47f6fa1d9ce | 434 | //if(_brick14.hit() == true) { |
| jamesheavey | 32:4dba7a85dbb2 | 435 | _brick14_pos.x = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 436 | _brick14_pos.y = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 437 | _brick14.set_pos(_brick11_pos); |
| jamesheavey | 32:4dba7a85dbb2 | 438 | one_less(); |
| jamesheavey | 33:e47f6fa1d9ce | 439 | //} |
| jamesheavey | 32:4dba7a85dbb2 | 440 | } |
| jamesheavey | 32:4dba7a85dbb2 | 441 | // check p1 first |
| jamesheavey | 32:4dba7a85dbb2 | 442 | Vector2D _brick15_pos = _brick15.get_pos(); |
| jamesheavey | 32:4dba7a85dbb2 | 443 | |
| jamesheavey | 32:4dba7a85dbb2 | 444 | // see if ball has hit the paddle by checking for overlaps |
| jamesheavey | 32:4dba7a85dbb2 | 445 | if ( |
| jamesheavey | 32:4dba7a85dbb2 | 446 | (laser1_pos.x >= _brick15_pos.x) && //left |
| jamesheavey | 32:4dba7a85dbb2 | 447 | (laser1_pos.x <= _brick15_pos.x + BRICK_WIDTH) && //right |
| jamesheavey | 32:4dba7a85dbb2 | 448 | (laser1_pos.y >= _brick15_pos.y) && //bottom |
| jamesheavey | 32:4dba7a85dbb2 | 449 | (laser1_pos.y <= _brick15_pos.y + BRICK_HEIGHT) //top |
| jamesheavey | 32:4dba7a85dbb2 | 450 | ) { // edit this so that if it hits the middle, reflect, else change angle depending on how far off centre (add angle to ball) |
| jamesheavey | 32:4dba7a85dbb2 | 451 | // if it has, fix position and reflect x velocity |
| jamesheavey | 32:4dba7a85dbb2 | 452 | laser1_pos.x = -10; |
| jamesheavey | 32:4dba7a85dbb2 | 453 | // audio feedback |
| jamesheavey | 32:4dba7a85dbb2 | 454 | pad.tone(1000.0,0.1); |
| jamesheavey | 33:e47f6fa1d9ce | 455 | //if(_brick15.hit() == true) { |
| jamesheavey | 32:4dba7a85dbb2 | 456 | _brick15_pos.x = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 457 | _brick15_pos.y = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 458 | _brick15.set_pos(_brick11_pos); |
| jamesheavey | 32:4dba7a85dbb2 | 459 | one_less(); |
| jamesheavey | 33:e47f6fa1d9ce | 460 | //} |
| jamesheavey | 32:4dba7a85dbb2 | 461 | } |
| jamesheavey | 32:4dba7a85dbb2 | 462 | // check p1 first |
| jamesheavey | 32:4dba7a85dbb2 | 463 | Vector2D _brick16_pos = _brick16.get_pos(); |
| jamesheavey | 32:4dba7a85dbb2 | 464 | |
| jamesheavey | 32:4dba7a85dbb2 | 465 | // see if ball has hit the paddle by checking for overlaps |
| jamesheavey | 32:4dba7a85dbb2 | 466 | if ( |
| jamesheavey | 32:4dba7a85dbb2 | 467 | (laser1_pos.x >= _brick16_pos.x) && //left |
| jamesheavey | 32:4dba7a85dbb2 | 468 | (laser1_pos.x <= _brick16_pos.x + BRICK_WIDTH) && //right |
| jamesheavey | 32:4dba7a85dbb2 | 469 | (laser1_pos.y >= _brick16_pos.y) && //bottom |
| jamesheavey | 32:4dba7a85dbb2 | 470 | (laser1_pos.y <= _brick16_pos.y + BRICK_HEIGHT) //top |
| jamesheavey | 32:4dba7a85dbb2 | 471 | ) { // edit this so that if it hits the middle, reflect, else change angle depending on how far off centre (add angle to ball) |
| jamesheavey | 32:4dba7a85dbb2 | 472 | // if it has, fix position and reflect x velocity |
| jamesheavey | 32:4dba7a85dbb2 | 473 | laser1_pos.x = -10; |
| jamesheavey | 32:4dba7a85dbb2 | 474 | // audio feedback |
| jamesheavey | 32:4dba7a85dbb2 | 475 | pad.tone(1000.0,0.1); |
| jamesheavey | 33:e47f6fa1d9ce | 476 | //if(_brick16.hit() == true) { |
| jamesheavey | 32:4dba7a85dbb2 | 477 | _brick16_pos.x = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 478 | _brick16_pos.y = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 479 | _brick16.set_pos(_brick11_pos); |
| jamesheavey | 32:4dba7a85dbb2 | 480 | one_less(); |
| jamesheavey | 33:e47f6fa1d9ce | 481 | //} |
| jamesheavey | 32:4dba7a85dbb2 | 482 | } |
| jamesheavey | 32:4dba7a85dbb2 | 483 | // check p1 first |
| jamesheavey | 32:4dba7a85dbb2 | 484 | Vector2D _brick21_pos = _brick21.get_pos(); |
| jamesheavey | 32:4dba7a85dbb2 | 485 | |
| jamesheavey | 32:4dba7a85dbb2 | 486 | // see if ball has hit the paddle by checking for overlaps |
| jamesheavey | 32:4dba7a85dbb2 | 487 | if ( |
| jamesheavey | 32:4dba7a85dbb2 | 488 | (laser1_pos.x >= _brick21_pos.x) && //left |
| jamesheavey | 32:4dba7a85dbb2 | 489 | (laser1_pos.x <= _brick21_pos.x + BRICK_WIDTH) && //right |
| jamesheavey | 32:4dba7a85dbb2 | 490 | (laser1_pos.y >= _brick21_pos.y) && //bottom |
| jamesheavey | 32:4dba7a85dbb2 | 491 | (laser1_pos.y <= _brick21_pos.y + BRICK_HEIGHT) //top |
| jamesheavey | 32:4dba7a85dbb2 | 492 | ) { // edit this so that if it hits the middle, reflect, else change angle depending on how far off centre (add angle to ball) |
| jamesheavey | 32:4dba7a85dbb2 | 493 | // if it has, fix position and reflect x velocity |
| jamesheavey | 32:4dba7a85dbb2 | 494 | laser1_pos.x = -10; |
| jamesheavey | 32:4dba7a85dbb2 | 495 | // audio feedback |
| jamesheavey | 32:4dba7a85dbb2 | 496 | pad.tone(1000.0,0.1); |
| jamesheavey | 33:e47f6fa1d9ce | 497 | //if(_brick21.hit() == true) { |
| jamesheavey | 32:4dba7a85dbb2 | 498 | _brick21_pos.x = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 499 | _brick21_pos.y = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 500 | _brick21.set_pos(_brick11_pos); |
| jamesheavey | 32:4dba7a85dbb2 | 501 | one_less(); |
| jamesheavey | 33:e47f6fa1d9ce | 502 | //} |
| jamesheavey | 32:4dba7a85dbb2 | 503 | } |
| jamesheavey | 32:4dba7a85dbb2 | 504 | // check p1 first |
| jamesheavey | 32:4dba7a85dbb2 | 505 | Vector2D _brick22_pos = _brick22.get_pos(); |
| jamesheavey | 32:4dba7a85dbb2 | 506 | |
| jamesheavey | 32:4dba7a85dbb2 | 507 | // see if ball has hit the paddle by checking for overlaps |
| jamesheavey | 32:4dba7a85dbb2 | 508 | if ( |
| jamesheavey | 32:4dba7a85dbb2 | 509 | (laser1_pos.x >= _brick22_pos.x) && //left |
| jamesheavey | 32:4dba7a85dbb2 | 510 | (laser1_pos.x <= _brick22_pos.x + BRICK_WIDTH) && //right |
| jamesheavey | 32:4dba7a85dbb2 | 511 | (laser1_pos.y >= _brick22_pos.y) && //bottom |
| jamesheavey | 32:4dba7a85dbb2 | 512 | (laser1_pos.y <= _brick22_pos.y + BRICK_HEIGHT) //top |
| jamesheavey | 32:4dba7a85dbb2 | 513 | ) { // edit this so that if it hits the middle, reflect, else change angle depending on how far off centre (add angle to ball) |
| jamesheavey | 32:4dba7a85dbb2 | 514 | // if it has, fix position and reflect x velocity |
| jamesheavey | 32:4dba7a85dbb2 | 515 | laser1_pos.x = -10; |
| jamesheavey | 32:4dba7a85dbb2 | 516 | // audio feedback |
| jamesheavey | 32:4dba7a85dbb2 | 517 | pad.tone(1000.0,0.1); |
| jamesheavey | 33:e47f6fa1d9ce | 518 | //if(_brick22.hit() == true) { |
| jamesheavey | 32:4dba7a85dbb2 | 519 | _brick22_pos.x = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 520 | _brick22_pos.y = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 521 | _brick22.set_pos(_brick11_pos); |
| jamesheavey | 32:4dba7a85dbb2 | 522 | one_less(); |
| jamesheavey | 33:e47f6fa1d9ce | 523 | //} |
| jamesheavey | 32:4dba7a85dbb2 | 524 | } |
| jamesheavey | 32:4dba7a85dbb2 | 525 | // check p1 first |
| jamesheavey | 32:4dba7a85dbb2 | 526 | Vector2D _brick23_pos = _brick23.get_pos(); |
| jamesheavey | 32:4dba7a85dbb2 | 527 | |
| jamesheavey | 32:4dba7a85dbb2 | 528 | // see if ball has hit the paddle by checking for overlaps |
| jamesheavey | 32:4dba7a85dbb2 | 529 | if ( |
| jamesheavey | 32:4dba7a85dbb2 | 530 | (laser1_pos.x >= _brick23_pos.x) && //left |
| jamesheavey | 32:4dba7a85dbb2 | 531 | (laser1_pos.x <= _brick23_pos.x + BRICK_WIDTH) && //right |
| jamesheavey | 32:4dba7a85dbb2 | 532 | (laser1_pos.y >= _brick23_pos.y) && //bottom |
| jamesheavey | 32:4dba7a85dbb2 | 533 | (laser1_pos.y <= _brick23_pos.y + BRICK_HEIGHT) //top |
| jamesheavey | 32:4dba7a85dbb2 | 534 | ) { // edit this so that if it hits the middle, reflect, else change angle depending on how far off centre (add angle to ball) |
| jamesheavey | 32:4dba7a85dbb2 | 535 | // if it has, fix position and reflect x velocity |
| jamesheavey | 32:4dba7a85dbb2 | 536 | laser1_pos.x = -10; |
| jamesheavey | 32:4dba7a85dbb2 | 537 | // audio feedback |
| jamesheavey | 32:4dba7a85dbb2 | 538 | pad.tone(1000.0,0.1); |
| jamesheavey | 33:e47f6fa1d9ce | 539 | //if(_brick23.hit() == true) { |
| jamesheavey | 32:4dba7a85dbb2 | 540 | _brick23_pos.x = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 541 | _brick23_pos.y = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 542 | _brick23.set_pos(_brick11_pos); |
| jamesheavey | 32:4dba7a85dbb2 | 543 | one_less(); |
| jamesheavey | 33:e47f6fa1d9ce | 544 | //} |
| jamesheavey | 32:4dba7a85dbb2 | 545 | } |
| jamesheavey | 32:4dba7a85dbb2 | 546 | // check p1 first |
| jamesheavey | 32:4dba7a85dbb2 | 547 | Vector2D _brick24_pos = _brick24.get_pos(); |
| jamesheavey | 32:4dba7a85dbb2 | 548 | |
| jamesheavey | 32:4dba7a85dbb2 | 549 | // see if ball has hit the paddle by checking for overlaps |
| jamesheavey | 32:4dba7a85dbb2 | 550 | if ( |
| jamesheavey | 32:4dba7a85dbb2 | 551 | (laser1_pos.x >= _brick24_pos.x) && //left |
| jamesheavey | 32:4dba7a85dbb2 | 552 | (laser1_pos.x <= _brick24_pos.x + BRICK_WIDTH) && //right |
| jamesheavey | 32:4dba7a85dbb2 | 553 | (laser1_pos.y >= _brick24_pos.y) && //bottom |
| jamesheavey | 32:4dba7a85dbb2 | 554 | (laser1_pos.y <= _brick24_pos.y + BRICK_HEIGHT) //top |
| jamesheavey | 32:4dba7a85dbb2 | 555 | ) { // edit this so that if it hits the middle, reflect, else change angle depending on how far off centre (add angle to ball) |
| jamesheavey | 32:4dba7a85dbb2 | 556 | // if it has, fix position and reflect x velocity |
| jamesheavey | 32:4dba7a85dbb2 | 557 | laser1_pos.x = -10; |
| jamesheavey | 32:4dba7a85dbb2 | 558 | // audio feedback |
| jamesheavey | 32:4dba7a85dbb2 | 559 | pad.tone(1000.0,0.1); |
| jamesheavey | 33:e47f6fa1d9ce | 560 | //if(_brick24.hit() == true) { |
| jamesheavey | 32:4dba7a85dbb2 | 561 | _brick24_pos.x = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 562 | _brick24_pos.y = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 563 | _brick24.set_pos(_brick11_pos); |
| jamesheavey | 32:4dba7a85dbb2 | 564 | one_less(); |
| jamesheavey | 33:e47f6fa1d9ce | 565 | //} |
| jamesheavey | 32:4dba7a85dbb2 | 566 | } |
| jamesheavey | 32:4dba7a85dbb2 | 567 | // check p1 first |
| jamesheavey | 32:4dba7a85dbb2 | 568 | Vector2D _brick25_pos = _brick25.get_pos(); |
| jamesheavey | 32:4dba7a85dbb2 | 569 | |
| jamesheavey | 32:4dba7a85dbb2 | 570 | // see if ball has hit the paddle by checking for overlaps |
| jamesheavey | 32:4dba7a85dbb2 | 571 | if ( |
| jamesheavey | 32:4dba7a85dbb2 | 572 | (laser1_pos.x >= _brick25_pos.x) && //left |
| jamesheavey | 32:4dba7a85dbb2 | 573 | (laser1_pos.x <= _brick25_pos.x + BRICK_WIDTH) && //right |
| jamesheavey | 32:4dba7a85dbb2 | 574 | (laser1_pos.y >= _brick25_pos.y) && //bottom |
| jamesheavey | 32:4dba7a85dbb2 | 575 | (laser1_pos.y <= _brick25_pos.y + BRICK_HEIGHT) //top |
| jamesheavey | 32:4dba7a85dbb2 | 576 | ) { // edit this so that if it hits the middle, reflect, else change angle depending on how far off centre (add angle to ball) |
| jamesheavey | 32:4dba7a85dbb2 | 577 | // if it has, fix position and reflect x velocity |
| jamesheavey | 32:4dba7a85dbb2 | 578 | laser1_pos.x = -10; |
| jamesheavey | 32:4dba7a85dbb2 | 579 | // audio feedback |
| jamesheavey | 32:4dba7a85dbb2 | 580 | pad.tone(1000.0,0.1); |
| jamesheavey | 33:e47f6fa1d9ce | 581 | //if(_brick25.hit() == true) { |
| jamesheavey | 32:4dba7a85dbb2 | 582 | _brick25_pos.x = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 583 | _brick25_pos.y = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 584 | _brick25.set_pos(_brick11_pos); |
| jamesheavey | 32:4dba7a85dbb2 | 585 | one_less(); |
| jamesheavey | 33:e47f6fa1d9ce | 586 | //} |
| jamesheavey | 32:4dba7a85dbb2 | 587 | } |
| jamesheavey | 32:4dba7a85dbb2 | 588 | // check p1 first |
| jamesheavey | 32:4dba7a85dbb2 | 589 | Vector2D _brick26_pos = _brick26.get_pos(); |
| jamesheavey | 32:4dba7a85dbb2 | 590 | |
| jamesheavey | 32:4dba7a85dbb2 | 591 | // see if ball has hit the paddle by checking for overlaps |
| jamesheavey | 32:4dba7a85dbb2 | 592 | if ( |
| jamesheavey | 32:4dba7a85dbb2 | 593 | (laser1_pos.x >= _brick26_pos.x) && //left |
| jamesheavey | 32:4dba7a85dbb2 | 594 | (laser1_pos.x <= _brick26_pos.x + BRICK_WIDTH) && //right |
| jamesheavey | 32:4dba7a85dbb2 | 595 | (laser1_pos.y >= _brick26_pos.y) && //bottom |
| jamesheavey | 32:4dba7a85dbb2 | 596 | (laser1_pos.y <= _brick26_pos.y + BRICK_HEIGHT) //top |
| jamesheavey | 32:4dba7a85dbb2 | 597 | ) { // edit this so that if it hits the middle, reflect, else change angle depending on how far off centre (add angle to ball) |
| jamesheavey | 32:4dba7a85dbb2 | 598 | // if it has, fix position and reflect x velocity |
| jamesheavey | 32:4dba7a85dbb2 | 599 | laser1_pos.x = -10; |
| jamesheavey | 32:4dba7a85dbb2 | 600 | // audio feedback |
| jamesheavey | 32:4dba7a85dbb2 | 601 | pad.tone(1000.0,0.1); |
| jamesheavey | 33:e47f6fa1d9ce | 602 | //if(_brick26.hit() == true) { |
| jamesheavey | 32:4dba7a85dbb2 | 603 | _brick26_pos.x = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 604 | _brick26_pos.y = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 605 | _brick26.set_pos(_brick11_pos); |
| jamesheavey | 32:4dba7a85dbb2 | 606 | one_less(); |
| jamesheavey | 33:e47f6fa1d9ce | 607 | //} |
| jamesheavey | 32:4dba7a85dbb2 | 608 | } |
| jamesheavey | 32:4dba7a85dbb2 | 609 | // check p1 first |
| jamesheavey | 32:4dba7a85dbb2 | 610 | Vector2D _brick31_pos = _brick31.get_pos(); |
| jamesheavey | 32:4dba7a85dbb2 | 611 | |
| jamesheavey | 32:4dba7a85dbb2 | 612 | // see if ball has hit the paddle by checking for overlaps |
| jamesheavey | 32:4dba7a85dbb2 | 613 | if ( |
| jamesheavey | 32:4dba7a85dbb2 | 614 | (laser1_pos.x >= _brick31_pos.x) && //left |
| jamesheavey | 32:4dba7a85dbb2 | 615 | (laser1_pos.x <= _brick31_pos.x + BRICK_WIDTH) && //right |
| jamesheavey | 32:4dba7a85dbb2 | 616 | (laser1_pos.y >= _brick31_pos.y) && //bottom |
| jamesheavey | 32:4dba7a85dbb2 | 617 | (laser1_pos.y <= _brick31_pos.y + BRICK_HEIGHT) //top |
| jamesheavey | 32:4dba7a85dbb2 | 618 | ) { // edit this so that if it hits the middle, reflect, else change angle depending on how far off centre (add angle to ball) |
| jamesheavey | 32:4dba7a85dbb2 | 619 | // if it has, fix position and reflect x velocity |
| jamesheavey | 32:4dba7a85dbb2 | 620 | laser1_pos.x = -10; |
| jamesheavey | 32:4dba7a85dbb2 | 621 | // audio feedback |
| jamesheavey | 32:4dba7a85dbb2 | 622 | pad.tone(1000.0,0.1); |
| jamesheavey | 33:e47f6fa1d9ce | 623 | //if(_brick31.hit() == true) { |
| jamesheavey | 32:4dba7a85dbb2 | 624 | _brick31_pos.x = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 625 | _brick31_pos.y = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 626 | _brick31.set_pos(_brick11_pos); |
| jamesheavey | 32:4dba7a85dbb2 | 627 | one_less(); |
| jamesheavey | 33:e47f6fa1d9ce | 628 | //} |
| jamesheavey | 32:4dba7a85dbb2 | 629 | } |
| jamesheavey | 32:4dba7a85dbb2 | 630 | // check p1 first |
| jamesheavey | 32:4dba7a85dbb2 | 631 | Vector2D _brick32_pos = _brick32.get_pos(); |
| jamesheavey | 32:4dba7a85dbb2 | 632 | |
| jamesheavey | 32:4dba7a85dbb2 | 633 | // see if ball has hit the paddle by checking for overlaps |
| jamesheavey | 32:4dba7a85dbb2 | 634 | if ( |
| jamesheavey | 32:4dba7a85dbb2 | 635 | (laser1_pos.x >= _brick32_pos.x) && //left |
| jamesheavey | 32:4dba7a85dbb2 | 636 | (laser1_pos.x <= _brick32_pos.x + BRICK_WIDTH) && //right |
| jamesheavey | 32:4dba7a85dbb2 | 637 | (laser1_pos.y >= _brick32_pos.y) && //bottom |
| jamesheavey | 32:4dba7a85dbb2 | 638 | (laser1_pos.y <= _brick32_pos.y + BRICK_HEIGHT) //top |
| jamesheavey | 32:4dba7a85dbb2 | 639 | ) { // edit this so that if it hits the middle, reflect, else change angle depending on how far off centre (add angle to ball) |
| jamesheavey | 32:4dba7a85dbb2 | 640 | // if it has, fix position and reflect x velocity |
| jamesheavey | 32:4dba7a85dbb2 | 641 | laser1_pos.x = -10; |
| jamesheavey | 32:4dba7a85dbb2 | 642 | // audio feedback |
| jamesheavey | 32:4dba7a85dbb2 | 643 | pad.tone(1000.0,0.1); |
| jamesheavey | 33:e47f6fa1d9ce | 644 | //if(_brick32.hit() == true) { |
| jamesheavey | 32:4dba7a85dbb2 | 645 | _brick32_pos.x = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 646 | _brick32_pos.y = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 647 | _brick32.set_pos(_brick11_pos); |
| jamesheavey | 32:4dba7a85dbb2 | 648 | one_less(); |
| jamesheavey | 33:e47f6fa1d9ce | 649 | //} |
| jamesheavey | 32:4dba7a85dbb2 | 650 | } |
| jamesheavey | 32:4dba7a85dbb2 | 651 | // check p1 first |
| jamesheavey | 32:4dba7a85dbb2 | 652 | Vector2D _brick33_pos = _brick33.get_pos(); |
| jamesheavey | 32:4dba7a85dbb2 | 653 | |
| jamesheavey | 32:4dba7a85dbb2 | 654 | // see if ball has hit the paddle by checking for overlaps |
| jamesheavey | 32:4dba7a85dbb2 | 655 | if ( |
| jamesheavey | 32:4dba7a85dbb2 | 656 | (laser1_pos.x >= _brick33_pos.x) && //left |
| jamesheavey | 32:4dba7a85dbb2 | 657 | (laser1_pos.x <= _brick33_pos.x + BRICK_WIDTH) && //right |
| jamesheavey | 32:4dba7a85dbb2 | 658 | (laser1_pos.y >= _brick33_pos.y) && //bottom |
| jamesheavey | 32:4dba7a85dbb2 | 659 | (laser1_pos.y <= _brick33_pos.y + BRICK_HEIGHT) //top |
| jamesheavey | 32:4dba7a85dbb2 | 660 | ) { // edit this so that if it hits the middle, reflect, else change angle depending on how far off centre (add angle to ball) |
| jamesheavey | 32:4dba7a85dbb2 | 661 | // if it has, fix position and reflect x velocity |
| jamesheavey | 32:4dba7a85dbb2 | 662 | laser1_pos.x = -10; |
| jamesheavey | 32:4dba7a85dbb2 | 663 | // audio feedback |
| jamesheavey | 32:4dba7a85dbb2 | 664 | pad.tone(1000.0,0.1); |
| jamesheavey | 33:e47f6fa1d9ce | 665 | //if(_brick33.hit() == true) { |
| jamesheavey | 32:4dba7a85dbb2 | 666 | _brick33_pos.x = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 667 | _brick33_pos.y = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 668 | _brick33.set_pos(_brick11_pos); |
| jamesheavey | 32:4dba7a85dbb2 | 669 | one_less(); |
| jamesheavey | 33:e47f6fa1d9ce | 670 | //} |
| jamesheavey | 32:4dba7a85dbb2 | 671 | } |
| jamesheavey | 32:4dba7a85dbb2 | 672 | // check p1 first |
| jamesheavey | 32:4dba7a85dbb2 | 673 | Vector2D _brick34_pos = _brick34.get_pos(); |
| jamesheavey | 32:4dba7a85dbb2 | 674 | |
| jamesheavey | 32:4dba7a85dbb2 | 675 | // see if ball has hit the paddle by checking for overlaps |
| jamesheavey | 32:4dba7a85dbb2 | 676 | if ( |
| jamesheavey | 32:4dba7a85dbb2 | 677 | (laser1_pos.x >= _brick34_pos.x) && //left |
| jamesheavey | 32:4dba7a85dbb2 | 678 | (laser1_pos.x <= _brick34_pos.x + BRICK_WIDTH) && //right |
| jamesheavey | 32:4dba7a85dbb2 | 679 | (laser1_pos.y >= _brick34_pos.y) && //bottom |
| jamesheavey | 32:4dba7a85dbb2 | 680 | (laser1_pos.y <= _brick34_pos.y + BRICK_HEIGHT) //top |
| jamesheavey | 32:4dba7a85dbb2 | 681 | ) { // edit this so that if it hits the middle, reflect, else change angle depending on how far off centre (add angle to ball) |
| jamesheavey | 32:4dba7a85dbb2 | 682 | // if it has, fix position and reflect x velocity |
| jamesheavey | 32:4dba7a85dbb2 | 683 | laser1_pos.x = -10; |
| jamesheavey | 32:4dba7a85dbb2 | 684 | // audio feedback |
| jamesheavey | 32:4dba7a85dbb2 | 685 | pad.tone(1000.0,0.1); |
| jamesheavey | 33:e47f6fa1d9ce | 686 | //if(_brick34.hit() == true) { |
| jamesheavey | 32:4dba7a85dbb2 | 687 | _brick34_pos.x = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 688 | _brick34_pos.y = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 689 | _brick34.set_pos(_brick11_pos); |
| jamesheavey | 32:4dba7a85dbb2 | 690 | one_less(); |
| jamesheavey | 33:e47f6fa1d9ce | 691 | //} |
| jamesheavey | 32:4dba7a85dbb2 | 692 | } |
| jamesheavey | 32:4dba7a85dbb2 | 693 | // check p1 first |
| jamesheavey | 32:4dba7a85dbb2 | 694 | Vector2D _brick35_pos = _brick35.get_pos(); |
| jamesheavey | 32:4dba7a85dbb2 | 695 | |
| jamesheavey | 32:4dba7a85dbb2 | 696 | // see if ball has hit the paddle by checking for overlaps |
| jamesheavey | 32:4dba7a85dbb2 | 697 | if ( |
| jamesheavey | 32:4dba7a85dbb2 | 698 | (laser1_pos.x >= _brick35_pos.x) && //left |
| jamesheavey | 32:4dba7a85dbb2 | 699 | (laser1_pos.x <= _brick35_pos.x + BRICK_WIDTH) && //right |
| jamesheavey | 32:4dba7a85dbb2 | 700 | (laser1_pos.y >= _brick35_pos.y) && //bottom |
| jamesheavey | 32:4dba7a85dbb2 | 701 | (laser1_pos.y <= _brick35_pos.y + BRICK_HEIGHT) //top |
| jamesheavey | 32:4dba7a85dbb2 | 702 | ) { // edit this so that if it hits the middle, reflect, else change angle depending on how far off centre (add angle to ball) |
| jamesheavey | 32:4dba7a85dbb2 | 703 | // if it has, fix position and reflect x velocity |
| jamesheavey | 32:4dba7a85dbb2 | 704 | laser1_pos.x = -10; |
| jamesheavey | 32:4dba7a85dbb2 | 705 | // audio feedback |
| jamesheavey | 32:4dba7a85dbb2 | 706 | pad.tone(1000.0,0.1); |
| jamesheavey | 33:e47f6fa1d9ce | 707 | //if(_brick35.hit() == true) { |
| jamesheavey | 32:4dba7a85dbb2 | 708 | _brick35_pos.x = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 709 | _brick35_pos.y = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 710 | _brick35.set_pos(_brick11_pos); |
| jamesheavey | 32:4dba7a85dbb2 | 711 | one_less(); |
| jamesheavey | 33:e47f6fa1d9ce | 712 | //} |
| jamesheavey | 32:4dba7a85dbb2 | 713 | } |
| jamesheavey | 32:4dba7a85dbb2 | 714 | // check p1 first |
| jamesheavey | 32:4dba7a85dbb2 | 715 | Vector2D _brick36_pos = _brick36.get_pos(); |
| jamesheavey | 32:4dba7a85dbb2 | 716 | |
| jamesheavey | 32:4dba7a85dbb2 | 717 | // see if ball has hit the paddle by checking for overlaps |
| jamesheavey | 32:4dba7a85dbb2 | 718 | if ( |
| jamesheavey | 32:4dba7a85dbb2 | 719 | (laser1_pos.x >= _brick36_pos.x) && //left |
| jamesheavey | 32:4dba7a85dbb2 | 720 | (laser1_pos.x <= _brick36_pos.x + BRICK_WIDTH) && //right |
| jamesheavey | 32:4dba7a85dbb2 | 721 | (laser1_pos.y >= _brick36_pos.y) && //bottom |
| jamesheavey | 32:4dba7a85dbb2 | 722 | (laser1_pos.y <= _brick36_pos.y + BRICK_HEIGHT) //top |
| jamesheavey | 32:4dba7a85dbb2 | 723 | ) { // edit this so that if it hits the middle, reflect, else change angle depending on how far off centre (add angle to ball) |
| jamesheavey | 32:4dba7a85dbb2 | 724 | // if it has, fix position and reflect x velocity |
| jamesheavey | 32:4dba7a85dbb2 | 725 | laser1_pos.x = -10; |
| jamesheavey | 32:4dba7a85dbb2 | 726 | // audio feedback |
| jamesheavey | 32:4dba7a85dbb2 | 727 | pad.tone(1000.0,0.1); |
| jamesheavey | 33:e47f6fa1d9ce | 728 | //if(_brick36.hit() == true) { |
| jamesheavey | 32:4dba7a85dbb2 | 729 | _brick36_pos.x = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 730 | _brick36_pos.y = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 731 | _brick36.set_pos(_brick11_pos); |
| jamesheavey | 32:4dba7a85dbb2 | 732 | one_less(); |
| jamesheavey | 33:e47f6fa1d9ce | 733 | //} |
| jamesheavey | 32:4dba7a85dbb2 | 734 | } |
| jamesheavey | 32:4dba7a85dbb2 | 735 | |
| jamesheavey | 32:4dba7a85dbb2 | 736 | // write new attributes |
| jamesheavey | 32:4dba7a85dbb2 | 737 | _laser1.set_pos(laser1_pos); |
| jamesheavey | 32:4dba7a85dbb2 | 738 | } |
| jamesheavey | 34:07ded1f83c59 | 739 | */ |
| jamesheavey | 27:1b5038b0a7a2 | 740 | bool BreakoutEngine::check_goal(Gamepad &pad) |
| jamesheavey | 27:1b5038b0a7a2 | 741 | { |
| jamesheavey | 27:1b5038b0a7a2 | 742 | Vector2D ball_pos = _ball.get_pos(); |
| jamesheavey | 27:1b5038b0a7a2 | 743 | // P1 has scored |
| jamesheavey | 27:1b5038b0a7a2 | 744 | if (ball_pos.y > HEIGHT) { |
| jamesheavey | 27:1b5038b0a7a2 | 745 | _p1.lose_life(); |
| jamesheavey | 27:1b5038b0a7a2 | 746 | //lose_screen(); // go to loss screen then initialise again |
| jamesheavey | 27:1b5038b0a7a2 | 747 | |
| jamesheavey | 27:1b5038b0a7a2 | 748 | _ball.init(_ball_size,_speed); |
| jamesheavey | 27:1b5038b0a7a2 | 749 | pad.tone(1500.0,0.5); |
| jamesheavey | 27:1b5038b0a7a2 | 750 | return true; |
| jamesheavey | 27:1b5038b0a7a2 | 751 | } |
| jamesheavey | 27:1b5038b0a7a2 | 752 | else { |
| jamesheavey | 27:1b5038b0a7a2 | 753 | return false; |
| jamesheavey | 27:1b5038b0a7a2 | 754 | } |
| jamesheavey | 27:1b5038b0a7a2 | 755 | } |
| jamesheavey | 27:1b5038b0a7a2 | 756 | |
| jamesheavey | 27:1b5038b0a7a2 | 757 | |
| jamesheavey | 27:1b5038b0a7a2 | 758 | |
| jamesheavey | 34:07ded1f83c59 | 759 | void BreakoutEngine::print_scores(N5110 &lcd) //maybe add to oneless |
| jamesheavey | 27:1b5038b0a7a2 | 760 | { |
| jamesheavey | 27:1b5038b0a7a2 | 761 | // get scores from paddles |
| jamesheavey | 27:1b5038b0a7a2 | 762 | int p1_score = _p1.get_lives(); |
| jamesheavey | 27:1b5038b0a7a2 | 763 | |
| jamesheavey | 27:1b5038b0a7a2 | 764 | // print to LCD i |
| jamesheavey | 27:1b5038b0a7a2 | 765 | char buffer1[14]; |
| jamesheavey | 27:1b5038b0a7a2 | 766 | sprintf(buffer1,"%2d",p1_score); |
| jamesheavey | 27:1b5038b0a7a2 | 767 | lcd.printString(buffer1,WIDTH/2 -8,4); // font is 8 wide, so leave 4 pixel gape from middle assuming two digits |
| jamesheavey | 27:1b5038b0a7a2 | 768 | } |
| jamesheavey | 27:1b5038b0a7a2 | 769 | |
| jamesheavey | 27:1b5038b0a7a2 | 770 | int BreakoutEngine::get_num_left(){ |
| jamesheavey | 27:1b5038b0a7a2 | 771 | return _number_left; |
| jamesheavey | 27:1b5038b0a7a2 | 772 | } |
| jamesheavey | 27:1b5038b0a7a2 | 773 | void BreakoutEngine::one_less() { |
| jamesheavey | 27:1b5038b0a7a2 | 774 | _number_left -= 1; |
| jamesheavey | 27:1b5038b0a7a2 | 775 | } |