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@33:e47f6fa1d9ce, 2019-04-25 (annotated)
- Committer:
- jamesheavey
- Date:
- Thu Apr 25 18:51:59 2019 +0000
- Revision:
- 33:e47f6fa1d9ce
- Parent:
- 32:4dba7a85dbb2
- Child:
- 34:07ded1f83c59
pre list cp
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 | 30:e3d2f0ca416f | 53 | _laser1.init(-10); |
| jamesheavey | 30:e3d2f0ca416f | 54 | _laser2.init(-10); |
| jamesheavey | 30:e3d2f0ca416f | 55 | _laser3.init(-10); |
| jamesheavey | 29:5168318d3e88 | 56 | |
| jamesheavey | 27:1b5038b0a7a2 | 57 | //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 | 27:1b5038b0a7a2 | 58 | //listofBricks.push_back(_brick12); |
| jamesheavey | 27:1b5038b0a7a2 | 59 | //listofBricks.push_back(_brick13); |
| jamesheavey | 27:1b5038b0a7a2 | 60 | //listofBricks.push_back(_brick14); |
| jamesheavey | 27:1b5038b0a7a2 | 61 | //listofBricks.push_back(_brick15); |
| jamesheavey | 27:1b5038b0a7a2 | 62 | //listofBricks.push_back(_brick16); |
| jamesheavey | 27:1b5038b0a7a2 | 63 | |
| jamesheavey | 27:1b5038b0a7a2 | 64 | //listofBricks.push_back(_brick21); |
| jamesheavey | 27:1b5038b0a7a2 | 65 | //listofBricks.push_back(_brick22); |
| jamesheavey | 27:1b5038b0a7a2 | 66 | //listofBricks.push_back(_brick23); |
| jamesheavey | 27:1b5038b0a7a2 | 67 | //listofBricks.push_back(_brick24); |
| jamesheavey | 27:1b5038b0a7a2 | 68 | //listofBricks.push_back(_brick25); |
| jamesheavey | 27:1b5038b0a7a2 | 69 | //listofBricks.push_back(_brick26); |
| jamesheavey | 27:1b5038b0a7a2 | 70 | |
| jamesheavey | 27:1b5038b0a7a2 | 71 | //listofBricks.push_back(_brick31); |
| jamesheavey | 27:1b5038b0a7a2 | 72 | //listofBricks.push_back(_brick32); |
| jamesheavey | 27:1b5038b0a7a2 | 73 | //listofBricks.push_back(_brick33); |
| jamesheavey | 27:1b5038b0a7a2 | 74 | //listofBricks.push_back(_brick34); |
| jamesheavey | 27:1b5038b0a7a2 | 75 | //listofBricks.push_back(_brick35); |
| jamesheavey | 27:1b5038b0a7a2 | 76 | //listofBricks.push_back(_brick36); |
| jamesheavey | 27:1b5038b0a7a2 | 77 | } |
| jamesheavey | 27:1b5038b0a7a2 | 78 | |
| jamesheavey | 27:1b5038b0a7a2 | 79 | void BreakoutEngine::read_input(Gamepad &pad, bool x) |
| jamesheavey | 27:1b5038b0a7a2 | 80 | { |
| jamesheavey | 27:1b5038b0a7a2 | 81 | _d = pad.get_direction(); |
| jamesheavey | 27:1b5038b0a7a2 | 82 | _mag = pad.get_mag(); |
| jamesheavey | 27:1b5038b0a7a2 | 83 | |
| jamesheavey | 27:1b5038b0a7a2 | 84 | if (x == true) { |
| jamesheavey | 27:1b5038b0a7a2 | 85 | _p1.set_tilt(); |
| jamesheavey | 27:1b5038b0a7a2 | 86 | } |
| jamesheavey | 27:1b5038b0a7a2 | 87 | else { |
| jamesheavey | 27:1b5038b0a7a2 | 88 | _p1.set_joy(); |
| jamesheavey | 27:1b5038b0a7a2 | 89 | } |
| jamesheavey | 31:516d4e27765a | 90 | if (pad.check_event(Gamepad::B_PRESSED)) { // max of 3 lasers on screen at once |
| jamesheavey | 29:5168318d3e88 | 91 | |
| jamesheavey | 29:5168318d3e88 | 92 | Vector2D p_pos = _p1.get_pos(); |
| jamesheavey | 30:e3d2f0ca416f | 93 | switch(_index){ |
| jamesheavey | 30:e3d2f0ca416f | 94 | case 0: |
| jamesheavey | 30:e3d2f0ca416f | 95 | Vector2D laser1_pos = _laser1.get_pos(); |
| jamesheavey | 30:e3d2f0ca416f | 96 | laser1_pos.x = p_pos.x+7; |
| jamesheavey | 30:e3d2f0ca416f | 97 | laser1_pos.y = p_pos.y; |
| jamesheavey | 30:e3d2f0ca416f | 98 | _laser1.set_pos(laser1_pos); |
| jamesheavey | 30:e3d2f0ca416f | 99 | inc_index(); |
| jamesheavey | 30:e3d2f0ca416f | 100 | break; |
| jamesheavey | 30:e3d2f0ca416f | 101 | case 1: |
| jamesheavey | 30:e3d2f0ca416f | 102 | Vector2D laser2_pos = _laser2.get_pos(); |
| jamesheavey | 30:e3d2f0ca416f | 103 | laser2_pos.x = p_pos.x+7; |
| jamesheavey | 30:e3d2f0ca416f | 104 | laser2_pos.y = p_pos.y; |
| jamesheavey | 30:e3d2f0ca416f | 105 | _laser2.set_pos(laser2_pos); |
| jamesheavey | 30:e3d2f0ca416f | 106 | inc_index(); |
| jamesheavey | 30:e3d2f0ca416f | 107 | break; |
| jamesheavey | 30:e3d2f0ca416f | 108 | case 2: |
| jamesheavey | 30:e3d2f0ca416f | 109 | Vector2D laser3_pos = _laser3.get_pos(); |
| jamesheavey | 30:e3d2f0ca416f | 110 | laser3_pos.x = p_pos.x+7; |
| jamesheavey | 30:e3d2f0ca416f | 111 | laser3_pos.y = p_pos.y; |
| jamesheavey | 30:e3d2f0ca416f | 112 | _laser3.set_pos(laser3_pos); |
| jamesheavey | 30:e3d2f0ca416f | 113 | reset_index(); |
| jamesheavey | 30:e3d2f0ca416f | 114 | break; |
| jamesheavey | 30:e3d2f0ca416f | 115 | } |
| jamesheavey | 29:5168318d3e88 | 116 | } |
| jamesheavey | 27:1b5038b0a7a2 | 117 | } |
| jamesheavey | 27:1b5038b0a7a2 | 118 | |
| jamesheavey | 30:e3d2f0ca416f | 119 | void BreakoutEngine::inc_index() { |
| jamesheavey | 30:e3d2f0ca416f | 120 | _index ++; |
| jamesheavey | 30:e3d2f0ca416f | 121 | } |
| jamesheavey | 30:e3d2f0ca416f | 122 | |
| jamesheavey | 30:e3d2f0ca416f | 123 | void BreakoutEngine::reset_index() { |
| jamesheavey | 30:e3d2f0ca416f | 124 | _index = 0; |
| jamesheavey | 30:e3d2f0ca416f | 125 | } |
| jamesheavey | 30:e3d2f0ca416f | 126 | |
| jamesheavey | 27:1b5038b0a7a2 | 127 | void BreakoutEngine::draw(N5110 &lcd) |
| jamesheavey | 27:1b5038b0a7a2 | 128 | { |
| jamesheavey | 27:1b5038b0a7a2 | 129 | // draw the elements in the LCD buffer |
| jamesheavey | 27:1b5038b0a7a2 | 130 | // pitch |
| jamesheavey | 27:1b5038b0a7a2 | 131 | lcd.drawRect(0,0,WIDTH,HEIGHT,FILL_TRANSPARENT); |
| jamesheavey | 27:1b5038b0a7a2 | 132 | //score |
| jamesheavey | 27:1b5038b0a7a2 | 133 | //print_scores(lcd); |
| jamesheavey | 27:1b5038b0a7a2 | 134 | // paddles |
| jamesheavey | 27:1b5038b0a7a2 | 135 | _p1.draw(lcd); |
| jamesheavey | 27:1b5038b0a7a2 | 136 | // ball |
| jamesheavey | 27:1b5038b0a7a2 | 137 | _ball.draw(lcd); |
| jamesheavey | 27:1b5038b0a7a2 | 138 | |
| jamesheavey | 27:1b5038b0a7a2 | 139 | //print_scores(lcd); |
| jamesheavey | 27:1b5038b0a7a2 | 140 | |
| jamesheavey | 27:1b5038b0a7a2 | 141 | _brick11.draw(lcd); |
| jamesheavey | 27:1b5038b0a7a2 | 142 | _brick12.draw(lcd); |
| jamesheavey | 27:1b5038b0a7a2 | 143 | _brick13.draw(lcd); |
| jamesheavey | 27:1b5038b0a7a2 | 144 | _brick14.draw(lcd); |
| jamesheavey | 27:1b5038b0a7a2 | 145 | _brick15.draw(lcd); |
| jamesheavey | 27:1b5038b0a7a2 | 146 | _brick16.draw(lcd); |
| jamesheavey | 27:1b5038b0a7a2 | 147 | |
| jamesheavey | 27:1b5038b0a7a2 | 148 | _brick21.draw(lcd); |
| jamesheavey | 27:1b5038b0a7a2 | 149 | _brick22.draw(lcd); |
| jamesheavey | 27:1b5038b0a7a2 | 150 | _brick23.draw(lcd); |
| jamesheavey | 27:1b5038b0a7a2 | 151 | _brick24.draw(lcd); |
| jamesheavey | 27:1b5038b0a7a2 | 152 | _brick25.draw(lcd); |
| jamesheavey | 27:1b5038b0a7a2 | 153 | _brick26.draw(lcd); |
| jamesheavey | 27:1b5038b0a7a2 | 154 | |
| jamesheavey | 27:1b5038b0a7a2 | 155 | _brick31.draw(lcd); |
| jamesheavey | 27:1b5038b0a7a2 | 156 | _brick32.draw(lcd); |
| jamesheavey | 27:1b5038b0a7a2 | 157 | _brick33.draw(lcd); |
| jamesheavey | 27:1b5038b0a7a2 | 158 | _brick34.draw(lcd); |
| jamesheavey | 27:1b5038b0a7a2 | 159 | _brick35.draw(lcd); |
| jamesheavey | 27:1b5038b0a7a2 | 160 | _brick36.draw(lcd); |
| jamesheavey | 27:1b5038b0a7a2 | 161 | |
| jamesheavey | 30:e3d2f0ca416f | 162 | _laser1.draw(lcd); |
| jamesheavey | 30:e3d2f0ca416f | 163 | _laser2.draw(lcd); |
| jamesheavey | 30:e3d2f0ca416f | 164 | _laser3.draw(lcd); |
| jamesheavey | 27:1b5038b0a7a2 | 165 | |
| jamesheavey | 27:1b5038b0a7a2 | 166 | |
| jamesheavey | 27:1b5038b0a7a2 | 167 | // for (it = listofBricks.begin(); it != listofBricks.end(); it++) |
| jamesheavey | 27:1b5038b0a7a2 | 168 | // { |
| jamesheavey | 27:1b5038b0a7a2 | 169 | // int x = it->_x; |
| jamesheavey | 27:1b5038b0a7a2 | 170 | // int y = it->_y; |
| jamesheavey | 27:1b5038b0a7a2 | 171 | |
| jamesheavey | 27:1b5038b0a7a2 | 172 | // lcd.drawRect(_x,_y,_width,_height,FILL_TRANSPARENT); |
| jamesheavey | 27:1b5038b0a7a2 | 173 | // } |
| jamesheavey | 27:1b5038b0a7a2 | 174 | |
| jamesheavey | 27:1b5038b0a7a2 | 175 | |
| jamesheavey | 27:1b5038b0a7a2 | 176 | |
| jamesheavey | 27:1b5038b0a7a2 | 177 | |
| jamesheavey | 27:1b5038b0a7a2 | 178 | |
| jamesheavey | 27:1b5038b0a7a2 | 179 | // for(int i = GAP+1; i <= WIDTH; i+= BRICK_WIDTH + 1){ |
| jamesheavey | 27:1b5038b0a7a2 | 180 | // for(int j = GAP+1; j <= (BRICK_HEIGHT + 1)*3; j+= BRICK_HEIGHT + 1){ |
| jamesheavey | 27:1b5038b0a7a2 | 181 | // Vector2D _grid[i][j]= _brick.init(i, j,BRICK_WIDTH,BRICK_HEIGHT); |
| jamesheavey | 27:1b5038b0a7a2 | 182 | // } |
| jamesheavey | 27:1b5038b0a7a2 | 183 | // } |
| jamesheavey | 27:1b5038b0a7a2 | 184 | } |
| jamesheavey | 27:1b5038b0a7a2 | 185 | |
| jamesheavey | 27:1b5038b0a7a2 | 186 | |
| jamesheavey | 27:1b5038b0a7a2 | 187 | void BreakoutEngine::update(Gamepad &pad) |
| jamesheavey | 27:1b5038b0a7a2 | 188 | { |
| jamesheavey | 27:1b5038b0a7a2 | 189 | check_goal(pad); |
| jamesheavey | 27:1b5038b0a7a2 | 190 | // important to update paddles and ball before checking collisions so can |
| jamesheavey | 27:1b5038b0a7a2 | 191 | // correct for it before updating the display |
| jamesheavey | 27:1b5038b0a7a2 | 192 | _p1.update(_d,_mag); |
| jamesheavey | 27:1b5038b0a7a2 | 193 | _ball.update(); |
| jamesheavey | 30:e3d2f0ca416f | 194 | _laser1.update(); |
| jamesheavey | 30:e3d2f0ca416f | 195 | _laser2.update(); |
| jamesheavey | 30:e3d2f0ca416f | 196 | _laser3.update(); |
| jamesheavey | 27:1b5038b0a7a2 | 197 | lives_leds(pad); |
| jamesheavey | 27:1b5038b0a7a2 | 198 | |
| jamesheavey | 27:1b5038b0a7a2 | 199 | check_wall_collision(pad); |
| jamesheavey | 27:1b5038b0a7a2 | 200 | check_paddle_collisions(pad); |
| jamesheavey | 27:1b5038b0a7a2 | 201 | check_brick_collisions(pad); |
| jamesheavey | 33:e47f6fa1d9ce | 202 | check_laser_collisions(pad); |
| jamesheavey | 27:1b5038b0a7a2 | 203 | } |
| jamesheavey | 27:1b5038b0a7a2 | 204 | |
| jamesheavey | 27:1b5038b0a7a2 | 205 | void BreakoutEngine::lives_leds(Gamepad &pad) |
| jamesheavey | 27:1b5038b0a7a2 | 206 | { |
| jamesheavey | 27:1b5038b0a7a2 | 207 | if (_p1.get_lives() == 0) { |
| jamesheavey | 27:1b5038b0a7a2 | 208 | pad.leds_off(); |
| jamesheavey | 27:1b5038b0a7a2 | 209 | } |
| jamesheavey | 27:1b5038b0a7a2 | 210 | |
| jamesheavey | 27:1b5038b0a7a2 | 211 | else if (_p1.get_lives() == 1) { |
| jamesheavey | 27:1b5038b0a7a2 | 212 | //turn leftmost led on |
| jamesheavey | 27:1b5038b0a7a2 | 213 | pad.leds_off(); |
| jamesheavey | 27:1b5038b0a7a2 | 214 | pad.led(1,1); |
| jamesheavey | 27:1b5038b0a7a2 | 215 | } |
| jamesheavey | 27:1b5038b0a7a2 | 216 | |
| jamesheavey | 27:1b5038b0a7a2 | 217 | else if (_p1.get_lives() == 2) { |
| jamesheavey | 27:1b5038b0a7a2 | 218 | //turn leftmost led on |
| jamesheavey | 27:1b5038b0a7a2 | 219 | pad.leds_off(); |
| jamesheavey | 27:1b5038b0a7a2 | 220 | pad.led(1,1); |
| jamesheavey | 27:1b5038b0a7a2 | 221 | pad.led(2,1); |
| jamesheavey | 27:1b5038b0a7a2 | 222 | } |
| jamesheavey | 27:1b5038b0a7a2 | 223 | |
| jamesheavey | 27:1b5038b0a7a2 | 224 | else if (_p1.get_lives() == 3) { |
| jamesheavey | 27:1b5038b0a7a2 | 225 | //turn leftmost led on |
| jamesheavey | 27:1b5038b0a7a2 | 226 | pad.leds_off(); |
| jamesheavey | 27:1b5038b0a7a2 | 227 | pad.led(1,1); |
| jamesheavey | 27:1b5038b0a7a2 | 228 | pad.led(2,1); |
| jamesheavey | 27:1b5038b0a7a2 | 229 | pad.led(3,1); |
| jamesheavey | 27:1b5038b0a7a2 | 230 | } |
| jamesheavey | 27:1b5038b0a7a2 | 231 | |
| jamesheavey | 27:1b5038b0a7a2 | 232 | else if (_p1.get_lives() == 4) { |
| jamesheavey | 27:1b5038b0a7a2 | 233 | pad.leds_on(); |
| jamesheavey | 27:1b5038b0a7a2 | 234 | pad.led(5,0); |
| jamesheavey | 27:1b5038b0a7a2 | 235 | pad.led(6,0); |
| jamesheavey | 27:1b5038b0a7a2 | 236 | } |
| jamesheavey | 27:1b5038b0a7a2 | 237 | |
| jamesheavey | 27:1b5038b0a7a2 | 238 | else if (_p1.get_lives() == 5) { |
| jamesheavey | 27:1b5038b0a7a2 | 239 | pad.leds_on(); |
| jamesheavey | 27:1b5038b0a7a2 | 240 | pad.led(6,0); |
| jamesheavey | 27:1b5038b0a7a2 | 241 | } |
| jamesheavey | 27:1b5038b0a7a2 | 242 | |
| jamesheavey | 27:1b5038b0a7a2 | 243 | else if (_p1.get_lives() == 6) { |
| jamesheavey | 27:1b5038b0a7a2 | 244 | pad.leds_on(); |
| jamesheavey | 27:1b5038b0a7a2 | 245 | } |
| jamesheavey | 27:1b5038b0a7a2 | 246 | } |
| jamesheavey | 27:1b5038b0a7a2 | 247 | |
| jamesheavey | 27:1b5038b0a7a2 | 248 | int BreakoutEngine::get_lives() { |
| jamesheavey | 27:1b5038b0a7a2 | 249 | return _p1.get_lives(); |
| jamesheavey | 27:1b5038b0a7a2 | 250 | } |
| jamesheavey | 27:1b5038b0a7a2 | 251 | |
| jamesheavey | 27:1b5038b0a7a2 | 252 | void BreakoutEngine::check_wall_collision(Gamepad &pad) |
| jamesheavey | 27:1b5038b0a7a2 | 253 | { |
| jamesheavey | 27:1b5038b0a7a2 | 254 | // read current ball attributes |
| jamesheavey | 27:1b5038b0a7a2 | 255 | Vector2D ball_pos = _ball.get_pos(); |
| jamesheavey | 27:1b5038b0a7a2 | 256 | Vector2D ball_velocity = _ball.get_velocity(); |
| jamesheavey | 27:1b5038b0a7a2 | 257 | |
| jamesheavey | 27:1b5038b0a7a2 | 258 | if (ball_pos.y <= 1) { // 1 due to 1 pixel boundary |
| jamesheavey | 27:1b5038b0a7a2 | 259 | ball_pos.y = 1; // bounce off ceiling without going off screen |
| jamesheavey | 27:1b5038b0a7a2 | 260 | ball_velocity.y = -ball_velocity.y; |
| jamesheavey | 27:1b5038b0a7a2 | 261 | // audio feedback |
| jamesheavey | 27:1b5038b0a7a2 | 262 | pad.tone(750.0,0.1); |
| jamesheavey | 27:1b5038b0a7a2 | 263 | } |
| jamesheavey | 27:1b5038b0a7a2 | 264 | |
| jamesheavey | 27:1b5038b0a7a2 | 265 | else if (ball_pos.x <= 1) { // 1 due to 1 pixel boundary |
| jamesheavey | 27:1b5038b0a7a2 | 266 | ball_pos.x = 1; // bounce off ceiling without going off screen |
| jamesheavey | 27:1b5038b0a7a2 | 267 | ball_velocity.x = -ball_velocity.x; |
| jamesheavey | 27:1b5038b0a7a2 | 268 | // audio feedback |
| jamesheavey | 27:1b5038b0a7a2 | 269 | pad.tone(750.0,0.1); |
| jamesheavey | 27:1b5038b0a7a2 | 270 | } |
| jamesheavey | 27:1b5038b0a7a2 | 271 | |
| jamesheavey | 27:1b5038b0a7a2 | 272 | // check if hit bottom wall |
| jamesheavey | 27:1b5038b0a7a2 | 273 | else if (ball_pos.x + _ball_size >= (WIDTH-1) ) { // bottom pixel is 47 |
| jamesheavey | 27:1b5038b0a7a2 | 274 | // hit bottom |
| jamesheavey | 27:1b5038b0a7a2 | 275 | ball_pos.x = (WIDTH-1) - _ball_size; // stops ball going off screen |
| jamesheavey | 27:1b5038b0a7a2 | 276 | ball_velocity.x = -ball_velocity.x; |
| jamesheavey | 27:1b5038b0a7a2 | 277 | // audio feedback |
| jamesheavey | 27:1b5038b0a7a2 | 278 | pad.tone(750.0,0.1); |
| jamesheavey | 27:1b5038b0a7a2 | 279 | } |
| jamesheavey | 27:1b5038b0a7a2 | 280 | |
| jamesheavey | 27:1b5038b0a7a2 | 281 | // update ball parameters |
| jamesheavey | 27:1b5038b0a7a2 | 282 | _ball.set_velocity(ball_velocity); |
| jamesheavey | 27:1b5038b0a7a2 | 283 | _ball.set_pos(ball_pos); |
| jamesheavey | 27:1b5038b0a7a2 | 284 | |
| jamesheavey | 27:1b5038b0a7a2 | 285 | } |
| jamesheavey | 27:1b5038b0a7a2 | 286 | |
| jamesheavey | 27:1b5038b0a7a2 | 287 | void BreakoutEngine::check_paddle_collisions(Gamepad &pad) |
| jamesheavey | 27:1b5038b0a7a2 | 288 | { |
| jamesheavey | 27:1b5038b0a7a2 | 289 | // read current ball attributes |
| jamesheavey | 27:1b5038b0a7a2 | 290 | Vector2D ball_pos = _ball.get_pos(); |
| jamesheavey | 27:1b5038b0a7a2 | 291 | Vector2D ball_velocity = _ball.get_velocity(); |
| jamesheavey | 27:1b5038b0a7a2 | 292 | |
| jamesheavey | 27:1b5038b0a7a2 | 293 | // check p1 first |
| jamesheavey | 27:1b5038b0a7a2 | 294 | Vector2D p1_pos = _p1.get_pos(); |
| jamesheavey | 27:1b5038b0a7a2 | 295 | |
| jamesheavey | 27:1b5038b0a7a2 | 296 | // see if ball has hit the paddle by checking for overlaps |
| jamesheavey | 27:1b5038b0a7a2 | 297 | if ( |
| jamesheavey | 27:1b5038b0a7a2 | 298 | (ball_pos.x >= p1_pos.x) && //left |
| jamesheavey | 27:1b5038b0a7a2 | 299 | (ball_pos.x <= p1_pos.x + _paddle_width) && //right |
| jamesheavey | 27:1b5038b0a7a2 | 300 | (ball_pos.y >= _p1y) && //bottom |
| jamesheavey | 27:1b5038b0a7a2 | 301 | (ball_pos.y <= _p1y + _paddle_height) //top |
| jamesheavey | 27:1b5038b0a7a2 | 302 | ) { // 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 | 303 | // if it has, fix position and reflect x velocity |
| jamesheavey | 27:1b5038b0a7a2 | 304 | pad.tone(1000.0,0.1); |
| jamesheavey | 27:1b5038b0a7a2 | 305 | ball_pos.y = _p1y + _paddle_height - 1; |
| jamesheavey | 27:1b5038b0a7a2 | 306 | ball_velocity.y = -ball_velocity.y; |
| jamesheavey | 27:1b5038b0a7a2 | 307 | |
| jamesheavey | 27:1b5038b0a7a2 | 308 | // 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 | 309 | // ball_pos.y = _p1y + _paddle_height - 1; |
| jamesheavey | 27:1b5038b0a7a2 | 310 | // ball_velocity.y = -ball_velocity.y; |
| jamesheavey | 27:1b5038b0a7a2 | 311 | // } |
| jamesheavey | 27:1b5038b0a7a2 | 312 | // else if (ball_pos.x <= p1_pos.x + PADDLE_WIDTH/2) { |
| jamesheavey | 27:1b5038b0a7a2 | 313 | // 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 | 314 | // if (ball_velocity.x > 0) { |
| jamesheavey | 27:1b5038b0a7a2 | 315 | // ball_velocity.x = -ball_velocity.x; |
| jamesheavey | 27:1b5038b0a7a2 | 316 | // } |
| jamesheavey | 27:1b5038b0a7a2 | 317 | // ball_pos.y = _p1y + _paddle_heigh - 1; |
| jamesheavey | 27:1b5038b0a7a2 | 318 | // ball_velocity.y = -tan(ang); |
| jamesheavey | 27:1b5038b0a7a2 | 319 | // } |
| jamesheavey | 27:1b5038b0a7a2 | 320 | // else if (ball_pos.x >= p1_pos.x + PADDLE_WIDTH/2) { |
| jamesheavey | 27:1b5038b0a7a2 | 321 | // 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 | 322 | // if (ball_velocity.x < 0) { |
| jamesheavey | 27:1b5038b0a7a2 | 323 | // ball_velocity.x = -ball_velocity.x; |
| jamesheavey | 27:1b5038b0a7a2 | 324 | // } |
| jamesheavey | 27:1b5038b0a7a2 | 325 | // ball_pos.y = _p1y + _paddle_height - 1; |
| jamesheavey | 27:1b5038b0a7a2 | 326 | // ball_velocity.y = -tan(ang); |
| jamesheavey | 27:1b5038b0a7a2 | 327 | // } |
| jamesheavey | 27:1b5038b0a7a2 | 328 | } |
| jamesheavey | 27:1b5038b0a7a2 | 329 | |
| jamesheavey | 27:1b5038b0a7a2 | 330 | // write new attributes |
| jamesheavey | 27:1b5038b0a7a2 | 331 | _ball.set_velocity(ball_velocity); |
| jamesheavey | 27:1b5038b0a7a2 | 332 | _ball.set_pos(ball_pos); |
| jamesheavey | 27:1b5038b0a7a2 | 333 | } |
| jamesheavey | 27:1b5038b0a7a2 | 334 | |
| jamesheavey | 27:1b5038b0a7a2 | 335 | void BreakoutEngine::check_brick_collisions(Gamepad &pad) |
| jamesheavey | 27:1b5038b0a7a2 | 336 | { |
| jamesheavey | 27:1b5038b0a7a2 | 337 | // read current ball attributes |
| jamesheavey | 27:1b5038b0a7a2 | 338 | Vector2D ball_pos = _ball.get_pos(); |
| jamesheavey | 27:1b5038b0a7a2 | 339 | Vector2D ball_velocity = _ball.get_velocity(); |
| jamesheavey | 27:1b5038b0a7a2 | 340 | |
| jamesheavey | 27:1b5038b0a7a2 | 341 | // check p1 first |
| jamesheavey | 27:1b5038b0a7a2 | 342 | Vector2D _brick11_pos = _brick11.get_pos(); |
| jamesheavey | 27:1b5038b0a7a2 | 343 | |
| jamesheavey | 27:1b5038b0a7a2 | 344 | // see if ball has hit the paddle by checking for overlaps |
| jamesheavey | 27:1b5038b0a7a2 | 345 | if ( |
| jamesheavey | 27:1b5038b0a7a2 | 346 | (ball_pos.x >= _brick11_pos.x) && //left |
| jamesheavey | 27:1b5038b0a7a2 | 347 | (ball_pos.x <= _brick11_pos.x + BRICK_WIDTH) && //right |
| jamesheavey | 27:1b5038b0a7a2 | 348 | (ball_pos.y >= _brick11_pos.y) && //bottom |
| jamesheavey | 27:1b5038b0a7a2 | 349 | (ball_pos.y <= _brick11_pos.y + BRICK_HEIGHT) //top |
| jamesheavey | 27:1b5038b0a7a2 | 350 | ) { // 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 | 351 | // if it has, fix position and reflect x velocity |
| jamesheavey | 27:1b5038b0a7a2 | 352 | ball_pos.y = _brick11_pos.y + BRICK_HEIGHT; |
| jamesheavey | 27:1b5038b0a7a2 | 353 | ball_velocity.y = -ball_velocity.y; |
| jamesheavey | 27:1b5038b0a7a2 | 354 | // audio feedback |
| jamesheavey | 27:1b5038b0a7a2 | 355 | pad.tone(1000.0,0.1); |
| jamesheavey | 27:1b5038b0a7a2 | 356 | _brick11.hit(); |
| jamesheavey | 32:4dba7a85dbb2 | 357 | _brick11.hit(); |
| jamesheavey | 27:1b5038b0a7a2 | 358 | //delete _brick11; |
| jamesheavey | 27:1b5038b0a7a2 | 359 | _brick11_pos.x = -100; |
| jamesheavey | 27:1b5038b0a7a2 | 360 | _brick11_pos.y = -100; |
| jamesheavey | 27:1b5038b0a7a2 | 361 | _brick11.set_pos(_brick11_pos); |
| jamesheavey | 27:1b5038b0a7a2 | 362 | one_less(); |
| jamesheavey | 27:1b5038b0a7a2 | 363 | } |
| jamesheavey | 27:1b5038b0a7a2 | 364 | // check p1 first |
| jamesheavey | 27:1b5038b0a7a2 | 365 | Vector2D _brick12_pos = _brick12.get_pos(); |
| jamesheavey | 27:1b5038b0a7a2 | 366 | |
| jamesheavey | 27:1b5038b0a7a2 | 367 | // see if ball has hit the paddle by checking for overlaps |
| jamesheavey | 27:1b5038b0a7a2 | 368 | if ( |
| jamesheavey | 27:1b5038b0a7a2 | 369 | (ball_pos.x >= _brick12_pos.x) && //left |
| jamesheavey | 27:1b5038b0a7a2 | 370 | (ball_pos.x <= _brick12_pos.x + BRICK_WIDTH) && //right |
| jamesheavey | 27:1b5038b0a7a2 | 371 | (ball_pos.y >= _brick12_pos.y) && //bottom |
| jamesheavey | 27:1b5038b0a7a2 | 372 | (ball_pos.y <= _brick12_pos.y + BRICK_HEIGHT) //top |
| jamesheavey | 27:1b5038b0a7a2 | 373 | ) { // 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 | 374 | // if it has, fix position and reflect x velocity |
| jamesheavey | 27:1b5038b0a7a2 | 375 | ball_pos.y = _brick12_pos.y + BRICK_HEIGHT; |
| jamesheavey | 27:1b5038b0a7a2 | 376 | ball_velocity.y = -ball_velocity.y; |
| jamesheavey | 27:1b5038b0a7a2 | 377 | // audio feedback |
| jamesheavey | 27:1b5038b0a7a2 | 378 | pad.tone(1000.0,0.1); |
| jamesheavey | 27:1b5038b0a7a2 | 379 | _brick12.hit(); |
| jamesheavey | 32:4dba7a85dbb2 | 380 | _brick12.hit(); |
| jamesheavey | 27:1b5038b0a7a2 | 381 | //delete _brick12; |
| jamesheavey | 27:1b5038b0a7a2 | 382 | _brick12_pos.x = -100; |
| jamesheavey | 27:1b5038b0a7a2 | 383 | _brick12_pos.y = -100; |
| jamesheavey | 27:1b5038b0a7a2 | 384 | _brick12.set_pos(_brick12_pos); |
| jamesheavey | 27:1b5038b0a7a2 | 385 | one_less(); |
| jamesheavey | 27:1b5038b0a7a2 | 386 | } |
| jamesheavey | 27:1b5038b0a7a2 | 387 | // check p1 first |
| jamesheavey | 27:1b5038b0a7a2 | 388 | Vector2D _brick13_pos = _brick13.get_pos(); |
| jamesheavey | 27:1b5038b0a7a2 | 389 | |
| jamesheavey | 27:1b5038b0a7a2 | 390 | // see if ball has hit the paddle by checking for overlaps |
| jamesheavey | 27:1b5038b0a7a2 | 391 | if ( |
| jamesheavey | 27:1b5038b0a7a2 | 392 | (ball_pos.x >= _brick13_pos.x) && //left |
| jamesheavey | 27:1b5038b0a7a2 | 393 | (ball_pos.x <= _brick13_pos.x + BRICK_WIDTH) && //right |
| jamesheavey | 27:1b5038b0a7a2 | 394 | (ball_pos.y >= _brick13_pos.y) && //bottom |
| jamesheavey | 27:1b5038b0a7a2 | 395 | (ball_pos.y <= _brick13_pos.y + BRICK_HEIGHT) //top |
| jamesheavey | 27:1b5038b0a7a2 | 396 | ) { // 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 | 397 | // if it has, fix position and reflect x velocity |
| jamesheavey | 27:1b5038b0a7a2 | 398 | ball_pos.y = _brick13_pos.y+ BRICK_HEIGHT; |
| jamesheavey | 27:1b5038b0a7a2 | 399 | ball_velocity.y = -ball_velocity.y; |
| jamesheavey | 27:1b5038b0a7a2 | 400 | // audio feedback |
| jamesheavey | 27:1b5038b0a7a2 | 401 | pad.tone(1000.0,0.1); |
| jamesheavey | 27:1b5038b0a7a2 | 402 | _brick13.hit(); |
| jamesheavey | 32:4dba7a85dbb2 | 403 | _brick13.hit(); |
| jamesheavey | 27:1b5038b0a7a2 | 404 | //delete _brick13; |
| jamesheavey | 27:1b5038b0a7a2 | 405 | _brick13_pos.x = -100; |
| jamesheavey | 27:1b5038b0a7a2 | 406 | _brick13_pos.y = -100; |
| jamesheavey | 27:1b5038b0a7a2 | 407 | _brick13.set_pos(_brick13_pos); |
| jamesheavey | 27:1b5038b0a7a2 | 408 | one_less(); |
| jamesheavey | 27:1b5038b0a7a2 | 409 | } |
| jamesheavey | 27:1b5038b0a7a2 | 410 | // check p1 first |
| jamesheavey | 27:1b5038b0a7a2 | 411 | Vector2D _brick14_pos = _brick14.get_pos(); |
| jamesheavey | 27:1b5038b0a7a2 | 412 | |
| jamesheavey | 27:1b5038b0a7a2 | 413 | // see if ball has hit the paddle by checking for overlaps |
| jamesheavey | 27:1b5038b0a7a2 | 414 | if ( |
| jamesheavey | 27:1b5038b0a7a2 | 415 | (ball_pos.x >= _brick14_pos.x) && //left |
| jamesheavey | 27:1b5038b0a7a2 | 416 | (ball_pos.x <= _brick14_pos.x + BRICK_WIDTH) && //right |
| jamesheavey | 27:1b5038b0a7a2 | 417 | (ball_pos.y >= _brick14_pos.y) && //bottom |
| jamesheavey | 27:1b5038b0a7a2 | 418 | (ball_pos.y <= _brick14_pos.y + BRICK_HEIGHT) //top |
| jamesheavey | 27:1b5038b0a7a2 | 419 | ) { // 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 | 420 | // if it has, fix position and reflect x velocity |
| jamesheavey | 27:1b5038b0a7a2 | 421 | ball_pos.y = _brick14_pos.y+ BRICK_HEIGHT; |
| jamesheavey | 27:1b5038b0a7a2 | 422 | ball_velocity.y = -ball_velocity.y; |
| jamesheavey | 27:1b5038b0a7a2 | 423 | // audio feedback |
| jamesheavey | 27:1b5038b0a7a2 | 424 | pad.tone(1000.0,0.1); |
| jamesheavey | 27:1b5038b0a7a2 | 425 | _brick14.hit(); |
| jamesheavey | 32:4dba7a85dbb2 | 426 | _brick14.hit(); |
| jamesheavey | 27:1b5038b0a7a2 | 427 | //delete _brick14; |
| jamesheavey | 27:1b5038b0a7a2 | 428 | _brick14_pos.x = -100; |
| jamesheavey | 27:1b5038b0a7a2 | 429 | _brick14_pos.y = -100; |
| jamesheavey | 27:1b5038b0a7a2 | 430 | _brick14.set_pos(_brick14_pos); |
| jamesheavey | 27:1b5038b0a7a2 | 431 | one_less(); |
| jamesheavey | 27:1b5038b0a7a2 | 432 | } |
| jamesheavey | 27:1b5038b0a7a2 | 433 | // check p1 first |
| jamesheavey | 27:1b5038b0a7a2 | 434 | Vector2D _brick15_pos = _brick15.get_pos(); |
| jamesheavey | 27:1b5038b0a7a2 | 435 | |
| jamesheavey | 27:1b5038b0a7a2 | 436 | // see if ball has hit the paddle by checking for overlaps |
| jamesheavey | 27:1b5038b0a7a2 | 437 | if ( |
| jamesheavey | 27:1b5038b0a7a2 | 438 | (ball_pos.x >= _brick15_pos.x) && //left |
| jamesheavey | 27:1b5038b0a7a2 | 439 | (ball_pos.x <= _brick15_pos.x + BRICK_WIDTH) && //right |
| jamesheavey | 27:1b5038b0a7a2 | 440 | (ball_pos.y >= _brick15_pos.y) && //bottom |
| jamesheavey | 27:1b5038b0a7a2 | 441 | (ball_pos.y <= _brick15_pos.y + BRICK_HEIGHT) //top |
| jamesheavey | 27:1b5038b0a7a2 | 442 | ) { // 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 | 443 | // if it has, fix position and reflect x velocity |
| jamesheavey | 27:1b5038b0a7a2 | 444 | ball_pos.y = _brick15_pos.y+ BRICK_HEIGHT; |
| jamesheavey | 27:1b5038b0a7a2 | 445 | ball_velocity.y = -ball_velocity.y; |
| jamesheavey | 27:1b5038b0a7a2 | 446 | // audio feedback |
| jamesheavey | 27:1b5038b0a7a2 | 447 | pad.tone(1000.0,0.1); |
| jamesheavey | 27:1b5038b0a7a2 | 448 | _brick15.hit(); |
| jamesheavey | 32:4dba7a85dbb2 | 449 | _brick15.hit(); |
| jamesheavey | 27:1b5038b0a7a2 | 450 | //delete _brick15; |
| jamesheavey | 27:1b5038b0a7a2 | 451 | _brick15_pos.x = -100; |
| jamesheavey | 27:1b5038b0a7a2 | 452 | _brick15_pos.y = -100; |
| jamesheavey | 27:1b5038b0a7a2 | 453 | _brick15.set_pos(_brick15_pos); |
| jamesheavey | 27:1b5038b0a7a2 | 454 | one_less(); |
| jamesheavey | 27:1b5038b0a7a2 | 455 | } |
| jamesheavey | 27:1b5038b0a7a2 | 456 | // check p1 first |
| jamesheavey | 27:1b5038b0a7a2 | 457 | Vector2D _brick16_pos = _brick16.get_pos(); |
| jamesheavey | 27:1b5038b0a7a2 | 458 | |
| jamesheavey | 27:1b5038b0a7a2 | 459 | // see if ball has hit the paddle by checking for overlaps |
| jamesheavey | 27:1b5038b0a7a2 | 460 | if ( |
| jamesheavey | 27:1b5038b0a7a2 | 461 | (ball_pos.x >= _brick16_pos.x) && //left |
| jamesheavey | 27:1b5038b0a7a2 | 462 | (ball_pos.x <= _brick16_pos.x + BRICK_WIDTH) && //right |
| jamesheavey | 27:1b5038b0a7a2 | 463 | (ball_pos.y >= _brick16_pos.y) && //bottom |
| jamesheavey | 27:1b5038b0a7a2 | 464 | (ball_pos.y <= _brick16_pos.y + BRICK_HEIGHT) //top |
| jamesheavey | 27:1b5038b0a7a2 | 465 | ) { // 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 | 466 | // if it has, fix position and reflect x velocity |
| jamesheavey | 27:1b5038b0a7a2 | 467 | ball_pos.y = _brick16_pos.y+ BRICK_HEIGHT; |
| jamesheavey | 27:1b5038b0a7a2 | 468 | ball_velocity.y = -ball_velocity.y; |
| jamesheavey | 27:1b5038b0a7a2 | 469 | // audio feedback |
| jamesheavey | 27:1b5038b0a7a2 | 470 | pad.tone(1000.0,0.1); |
| jamesheavey | 27:1b5038b0a7a2 | 471 | _brick16.hit(); |
| jamesheavey | 32:4dba7a85dbb2 | 472 | _brick16.hit(); |
| jamesheavey | 27:1b5038b0a7a2 | 473 | //delete _brick16; |
| jamesheavey | 27:1b5038b0a7a2 | 474 | _brick16_pos.x = -100; |
| jamesheavey | 27:1b5038b0a7a2 | 475 | _brick16_pos.y = -100; |
| jamesheavey | 27:1b5038b0a7a2 | 476 | _brick16.set_pos(_brick16_pos); |
| jamesheavey | 27:1b5038b0a7a2 | 477 | one_less(); |
| jamesheavey | 27:1b5038b0a7a2 | 478 | } |
| jamesheavey | 27:1b5038b0a7a2 | 479 | // check p1 first |
| jamesheavey | 27:1b5038b0a7a2 | 480 | Vector2D _brick21_pos = _brick21.get_pos(); |
| jamesheavey | 27:1b5038b0a7a2 | 481 | |
| jamesheavey | 27:1b5038b0a7a2 | 482 | // see if ball has hit the paddle by checking for overlaps |
| jamesheavey | 27:1b5038b0a7a2 | 483 | if ( |
| jamesheavey | 27:1b5038b0a7a2 | 484 | (ball_pos.x >= _brick21_pos.x) && //left |
| jamesheavey | 27:1b5038b0a7a2 | 485 | (ball_pos.x <= _brick21_pos.x + BRICK_WIDTH) && //right |
| jamesheavey | 27:1b5038b0a7a2 | 486 | (ball_pos.y >= _brick21_pos.y) && //bottom |
| jamesheavey | 27:1b5038b0a7a2 | 487 | (ball_pos.y <= _brick21_pos.y + BRICK_HEIGHT) //top |
| jamesheavey | 27:1b5038b0a7a2 | 488 | ) { // 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 | 489 | // if it has, fix position and reflect x velocity |
| jamesheavey | 27:1b5038b0a7a2 | 490 | ball_pos.y = _brick21_pos.y+ BRICK_HEIGHT; |
| jamesheavey | 27:1b5038b0a7a2 | 491 | ball_velocity.y = -ball_velocity.y; |
| jamesheavey | 27:1b5038b0a7a2 | 492 | // audio feedback |
| jamesheavey | 27:1b5038b0a7a2 | 493 | pad.tone(1000.0,0.1); |
| jamesheavey | 27:1b5038b0a7a2 | 494 | _brick21.hit(); |
| jamesheavey | 32:4dba7a85dbb2 | 495 | _brick21.hit(); |
| jamesheavey | 27:1b5038b0a7a2 | 496 | //delete _brick21; |
| jamesheavey | 27:1b5038b0a7a2 | 497 | _brick21_pos.x = -100; |
| jamesheavey | 27:1b5038b0a7a2 | 498 | _brick21_pos.y = -100; |
| jamesheavey | 27:1b5038b0a7a2 | 499 | _brick21.set_pos(_brick21_pos); |
| jamesheavey | 27:1b5038b0a7a2 | 500 | one_less(); |
| jamesheavey | 27:1b5038b0a7a2 | 501 | } |
| jamesheavey | 27:1b5038b0a7a2 | 502 | // check p1 first |
| jamesheavey | 27:1b5038b0a7a2 | 503 | Vector2D _brick22_pos = _brick22.get_pos(); |
| jamesheavey | 27:1b5038b0a7a2 | 504 | |
| jamesheavey | 27:1b5038b0a7a2 | 505 | // see if ball has hit the paddle by checking for overlaps |
| jamesheavey | 27:1b5038b0a7a2 | 506 | if ( |
| jamesheavey | 27:1b5038b0a7a2 | 507 | (ball_pos.x >= _brick22_pos.x) && //left |
| jamesheavey | 27:1b5038b0a7a2 | 508 | (ball_pos.x <= _brick22_pos.x + BRICK_WIDTH) && //right |
| jamesheavey | 27:1b5038b0a7a2 | 509 | (ball_pos.y >= _brick22_pos.y) && //bottom |
| jamesheavey | 27:1b5038b0a7a2 | 510 | (ball_pos.y <= _brick22_pos.y + BRICK_HEIGHT) //top |
| jamesheavey | 27:1b5038b0a7a2 | 511 | ) { // 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 | 512 | // if it has, fix position and reflect x velocity |
| jamesheavey | 27:1b5038b0a7a2 | 513 | ball_pos.y = _brick22_pos.y+ BRICK_HEIGHT; |
| jamesheavey | 27:1b5038b0a7a2 | 514 | ball_velocity.y = -ball_velocity.y; |
| jamesheavey | 27:1b5038b0a7a2 | 515 | // audio feedback |
| jamesheavey | 27:1b5038b0a7a2 | 516 | pad.tone(1000.0,0.1); |
| jamesheavey | 27:1b5038b0a7a2 | 517 | _brick22.hit(); |
| jamesheavey | 32:4dba7a85dbb2 | 518 | _brick22.hit(); |
| jamesheavey | 27:1b5038b0a7a2 | 519 | //delete _brick22; |
| jamesheavey | 27:1b5038b0a7a2 | 520 | _brick22_pos.x = -100; |
| jamesheavey | 27:1b5038b0a7a2 | 521 | _brick22_pos.y = -100; |
| jamesheavey | 27:1b5038b0a7a2 | 522 | _brick22.set_pos(_brick22_pos); |
| jamesheavey | 27:1b5038b0a7a2 | 523 | one_less(); |
| jamesheavey | 27:1b5038b0a7a2 | 524 | } |
| jamesheavey | 27:1b5038b0a7a2 | 525 | // check p1 first |
| jamesheavey | 27:1b5038b0a7a2 | 526 | Vector2D _brick23_pos = _brick23.get_pos(); |
| jamesheavey | 27:1b5038b0a7a2 | 527 | |
| jamesheavey | 27:1b5038b0a7a2 | 528 | // see if ball has hit the paddle by checking for overlaps |
| jamesheavey | 27:1b5038b0a7a2 | 529 | if ( |
| jamesheavey | 27:1b5038b0a7a2 | 530 | (ball_pos.x >= _brick23_pos.x) && //left |
| jamesheavey | 27:1b5038b0a7a2 | 531 | (ball_pos.x <= _brick23_pos.x + BRICK_WIDTH) && //right |
| jamesheavey | 27:1b5038b0a7a2 | 532 | (ball_pos.y >= _brick23_pos.y) && //bottom |
| jamesheavey | 27:1b5038b0a7a2 | 533 | (ball_pos.y <= _brick23_pos.y + BRICK_HEIGHT) //top |
| jamesheavey | 27:1b5038b0a7a2 | 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 | 27:1b5038b0a7a2 | 535 | // if it has, fix position and reflect x velocity |
| jamesheavey | 27:1b5038b0a7a2 | 536 | ball_pos.y = _brick23_pos.y+ BRICK_HEIGHT; |
| jamesheavey | 27:1b5038b0a7a2 | 537 | ball_velocity.y = -ball_velocity.y; |
| jamesheavey | 27:1b5038b0a7a2 | 538 | // audio feedback |
| jamesheavey | 27:1b5038b0a7a2 | 539 | pad.tone(1000.0,0.1); |
| jamesheavey | 27:1b5038b0a7a2 | 540 | _brick23.hit(); |
| jamesheavey | 32:4dba7a85dbb2 | 541 | _brick23.hit(); |
| jamesheavey | 27:1b5038b0a7a2 | 542 | //delete _brick23; |
| jamesheavey | 27:1b5038b0a7a2 | 543 | _brick23_pos.x = -100; |
| jamesheavey | 27:1b5038b0a7a2 | 544 | _brick23_pos.y = -100; |
| jamesheavey | 27:1b5038b0a7a2 | 545 | _brick23.set_pos(_brick23_pos); |
| jamesheavey | 27:1b5038b0a7a2 | 546 | one_less(); |
| jamesheavey | 27:1b5038b0a7a2 | 547 | } |
| jamesheavey | 27:1b5038b0a7a2 | 548 | // check p1 first |
| jamesheavey | 27:1b5038b0a7a2 | 549 | Vector2D _brick24_pos = _brick24.get_pos(); |
| jamesheavey | 27:1b5038b0a7a2 | 550 | |
| jamesheavey | 27:1b5038b0a7a2 | 551 | // see if ball has hit the paddle by checking for overlaps |
| jamesheavey | 27:1b5038b0a7a2 | 552 | if ( |
| jamesheavey | 27:1b5038b0a7a2 | 553 | (ball_pos.x >= _brick24_pos.x) && //left |
| jamesheavey | 27:1b5038b0a7a2 | 554 | (ball_pos.x <= _brick24_pos.x + BRICK_WIDTH) && //right |
| jamesheavey | 27:1b5038b0a7a2 | 555 | (ball_pos.y >= _brick24_pos.y) && //bottom |
| jamesheavey | 27:1b5038b0a7a2 | 556 | (ball_pos.y <= _brick24_pos.y + BRICK_HEIGHT) //top |
| jamesheavey | 27:1b5038b0a7a2 | 557 | ) { // 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 | 558 | // if it has, fix position and reflect x velocity |
| jamesheavey | 27:1b5038b0a7a2 | 559 | ball_pos.y = _brick24_pos.y+ BRICK_HEIGHT; |
| jamesheavey | 27:1b5038b0a7a2 | 560 | ball_velocity.y = -ball_velocity.y; |
| jamesheavey | 27:1b5038b0a7a2 | 561 | // audio feedback |
| jamesheavey | 27:1b5038b0a7a2 | 562 | pad.tone(1000.0,0.1); |
| jamesheavey | 27:1b5038b0a7a2 | 563 | _brick24.hit(); |
| jamesheavey | 32:4dba7a85dbb2 | 564 | _brick24.hit(); |
| jamesheavey | 27:1b5038b0a7a2 | 565 | //delete _brick24; |
| jamesheavey | 27:1b5038b0a7a2 | 566 | _brick24_pos.x = -100; |
| jamesheavey | 27:1b5038b0a7a2 | 567 | _brick24_pos.y = -100; |
| jamesheavey | 27:1b5038b0a7a2 | 568 | _brick24.set_pos(_brick24_pos); |
| jamesheavey | 27:1b5038b0a7a2 | 569 | one_less(); |
| jamesheavey | 27:1b5038b0a7a2 | 570 | } |
| jamesheavey | 27:1b5038b0a7a2 | 571 | // check p1 first |
| jamesheavey | 27:1b5038b0a7a2 | 572 | Vector2D _brick25_pos = _brick25.get_pos(); |
| jamesheavey | 27:1b5038b0a7a2 | 573 | |
| jamesheavey | 27:1b5038b0a7a2 | 574 | // see if ball has hit the paddle by checking for overlaps |
| jamesheavey | 27:1b5038b0a7a2 | 575 | if ( |
| jamesheavey | 27:1b5038b0a7a2 | 576 | (ball_pos.x >= _brick25_pos.x) && //left |
| jamesheavey | 27:1b5038b0a7a2 | 577 | (ball_pos.x <= _brick25_pos.x + BRICK_WIDTH) && //right |
| jamesheavey | 27:1b5038b0a7a2 | 578 | (ball_pos.y >= _brick25_pos.y) && //bottom |
| jamesheavey | 27:1b5038b0a7a2 | 579 | (ball_pos.y <= _brick25_pos.y + BRICK_HEIGHT) //top |
| jamesheavey | 27:1b5038b0a7a2 | 580 | ) { // 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 | 581 | // if it has, fix position and reflect x velocity |
| jamesheavey | 27:1b5038b0a7a2 | 582 | ball_pos.y = _brick25_pos.y+ BRICK_HEIGHT; |
| jamesheavey | 27:1b5038b0a7a2 | 583 | ball_velocity.y = -ball_velocity.y; |
| jamesheavey | 27:1b5038b0a7a2 | 584 | // audio feedback |
| jamesheavey | 27:1b5038b0a7a2 | 585 | pad.tone(1000.0,0.1); |
| jamesheavey | 27:1b5038b0a7a2 | 586 | _brick25.hit(); |
| jamesheavey | 32:4dba7a85dbb2 | 587 | _brick25.hit(); |
| jamesheavey | 27:1b5038b0a7a2 | 588 | //delete _brick25; |
| jamesheavey | 27:1b5038b0a7a2 | 589 | _brick25_pos.x = -100; |
| jamesheavey | 27:1b5038b0a7a2 | 590 | _brick25_pos.y = -100; |
| jamesheavey | 27:1b5038b0a7a2 | 591 | _brick25.set_pos(_brick25_pos); |
| jamesheavey | 27:1b5038b0a7a2 | 592 | one_less(); |
| jamesheavey | 27:1b5038b0a7a2 | 593 | } |
| jamesheavey | 27:1b5038b0a7a2 | 594 | // check p1 first |
| jamesheavey | 27:1b5038b0a7a2 | 595 | Vector2D _brick26_pos = _brick26.get_pos(); |
| jamesheavey | 27:1b5038b0a7a2 | 596 | |
| jamesheavey | 27:1b5038b0a7a2 | 597 | // see if ball has hit the paddle by checking for overlaps |
| jamesheavey | 27:1b5038b0a7a2 | 598 | if ( |
| jamesheavey | 27:1b5038b0a7a2 | 599 | (ball_pos.x >= _brick26_pos.x) && //left |
| jamesheavey | 27:1b5038b0a7a2 | 600 | (ball_pos.x <= _brick26_pos.x + BRICK_WIDTH) && //right |
| jamesheavey | 27:1b5038b0a7a2 | 601 | (ball_pos.y >= _brick26_pos.y) && //bottom |
| jamesheavey | 27:1b5038b0a7a2 | 602 | (ball_pos.y <= _brick26_pos.y + BRICK_HEIGHT) //top |
| jamesheavey | 27:1b5038b0a7a2 | 603 | ) { // 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 | 604 | // if it has, fix position and reflect x velocity |
| jamesheavey | 27:1b5038b0a7a2 | 605 | ball_pos.y = _brick26_pos.y+ BRICK_HEIGHT; |
| jamesheavey | 27:1b5038b0a7a2 | 606 | ball_velocity.y = -ball_velocity.y; |
| jamesheavey | 27:1b5038b0a7a2 | 607 | // audio feedback |
| jamesheavey | 27:1b5038b0a7a2 | 608 | pad.tone(1000.0,0.1); |
| jamesheavey | 27:1b5038b0a7a2 | 609 | _brick26.hit(); |
| jamesheavey | 32:4dba7a85dbb2 | 610 | _brick26.hit(); |
| jamesheavey | 27:1b5038b0a7a2 | 611 | //delete _brick26; |
| jamesheavey | 27:1b5038b0a7a2 | 612 | _brick26_pos.x = -100; |
| jamesheavey | 27:1b5038b0a7a2 | 613 | _brick26_pos.y = -100; |
| jamesheavey | 27:1b5038b0a7a2 | 614 | _brick26.set_pos(_brick26_pos); |
| jamesheavey | 27:1b5038b0a7a2 | 615 | one_less(); |
| jamesheavey | 27:1b5038b0a7a2 | 616 | } |
| jamesheavey | 27:1b5038b0a7a2 | 617 | // check p1 first |
| jamesheavey | 27:1b5038b0a7a2 | 618 | Vector2D _brick31_pos = _brick31.get_pos(); |
| jamesheavey | 27:1b5038b0a7a2 | 619 | |
| jamesheavey | 27:1b5038b0a7a2 | 620 | // see if ball has hit the paddle by checking for overlaps |
| jamesheavey | 27:1b5038b0a7a2 | 621 | if ( |
| jamesheavey | 27:1b5038b0a7a2 | 622 | (ball_pos.x >= _brick31_pos.x) && //left |
| jamesheavey | 27:1b5038b0a7a2 | 623 | (ball_pos.x <= _brick31_pos.x + BRICK_WIDTH) && //right |
| jamesheavey | 27:1b5038b0a7a2 | 624 | (ball_pos.y >= _brick31_pos.y) && //bottom |
| jamesheavey | 27:1b5038b0a7a2 | 625 | (ball_pos.y <= _brick31_pos.y + BRICK_HEIGHT) //top |
| jamesheavey | 27:1b5038b0a7a2 | 626 | ) { // 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 | 627 | // if it has, fix position and reflect x velocity |
| jamesheavey | 27:1b5038b0a7a2 | 628 | ball_pos.y = _brick31_pos.y+ BRICK_HEIGHT; |
| jamesheavey | 27:1b5038b0a7a2 | 629 | ball_velocity.y = -ball_velocity.y; |
| jamesheavey | 27:1b5038b0a7a2 | 630 | // audio feedback |
| jamesheavey | 27:1b5038b0a7a2 | 631 | pad.tone(1000.0,0.1); |
| jamesheavey | 27:1b5038b0a7a2 | 632 | _brick31.hit(); |
| jamesheavey | 32:4dba7a85dbb2 | 633 | _brick31.hit(); |
| jamesheavey | 27:1b5038b0a7a2 | 634 | //delete _brick31; |
| jamesheavey | 27:1b5038b0a7a2 | 635 | _brick31_pos.x = -100; |
| jamesheavey | 27:1b5038b0a7a2 | 636 | _brick31_pos.y = -100; |
| jamesheavey | 27:1b5038b0a7a2 | 637 | _brick31.set_pos(_brick31_pos); |
| jamesheavey | 27:1b5038b0a7a2 | 638 | one_less(); |
| jamesheavey | 27:1b5038b0a7a2 | 639 | } |
| jamesheavey | 27:1b5038b0a7a2 | 640 | // check p1 first |
| jamesheavey | 27:1b5038b0a7a2 | 641 | Vector2D _brick32_pos = _brick32.get_pos(); |
| jamesheavey | 27:1b5038b0a7a2 | 642 | |
| jamesheavey | 27:1b5038b0a7a2 | 643 | // see if ball has hit the paddle by checking for overlaps |
| jamesheavey | 27:1b5038b0a7a2 | 644 | if ( |
| jamesheavey | 27:1b5038b0a7a2 | 645 | (ball_pos.x >= _brick32_pos.x) && //left |
| jamesheavey | 27:1b5038b0a7a2 | 646 | (ball_pos.x <= _brick32_pos.x + BRICK_WIDTH) && //right |
| jamesheavey | 27:1b5038b0a7a2 | 647 | (ball_pos.y >= _brick32_pos.y) && //bottom |
| jamesheavey | 27:1b5038b0a7a2 | 648 | (ball_pos.y <= _brick32_pos.y + BRICK_HEIGHT) //top |
| jamesheavey | 27:1b5038b0a7a2 | 649 | ) { // 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 | 650 | // if it has, fix position and reflect x velocity |
| jamesheavey | 27:1b5038b0a7a2 | 651 | ball_pos.y = _brick32_pos.y+ BRICK_HEIGHT; |
| jamesheavey | 27:1b5038b0a7a2 | 652 | ball_velocity.y = -ball_velocity.y; |
| jamesheavey | 27:1b5038b0a7a2 | 653 | // audio feedback |
| jamesheavey | 27:1b5038b0a7a2 | 654 | pad.tone(1000.0,0.1); |
| jamesheavey | 27:1b5038b0a7a2 | 655 | _brick32.hit(); |
| jamesheavey | 32:4dba7a85dbb2 | 656 | _brick32.hit(); |
| jamesheavey | 27:1b5038b0a7a2 | 657 | //delete _brick32; |
| jamesheavey | 27:1b5038b0a7a2 | 658 | _brick32_pos.x = -100; |
| jamesheavey | 27:1b5038b0a7a2 | 659 | _brick32_pos.y = -100; |
| jamesheavey | 27:1b5038b0a7a2 | 660 | _brick32.set_pos(_brick32_pos); |
| jamesheavey | 27:1b5038b0a7a2 | 661 | one_less(); |
| jamesheavey | 27:1b5038b0a7a2 | 662 | } |
| jamesheavey | 27:1b5038b0a7a2 | 663 | // check p1 first |
| jamesheavey | 27:1b5038b0a7a2 | 664 | Vector2D _brick33_pos = _brick33.get_pos(); |
| jamesheavey | 27:1b5038b0a7a2 | 665 | |
| jamesheavey | 27:1b5038b0a7a2 | 666 | // see if ball has hit the paddle by checking for overlaps |
| jamesheavey | 27:1b5038b0a7a2 | 667 | if ( |
| jamesheavey | 27:1b5038b0a7a2 | 668 | (ball_pos.x >= _brick33_pos.x) && //left |
| jamesheavey | 27:1b5038b0a7a2 | 669 | (ball_pos.x <= _brick33_pos.x + BRICK_WIDTH) && //right |
| jamesheavey | 27:1b5038b0a7a2 | 670 | (ball_pos.y >= _brick33_pos.y) && //bottom |
| jamesheavey | 27:1b5038b0a7a2 | 671 | (ball_pos.y <= _brick33_pos.y + BRICK_HEIGHT) //top |
| jamesheavey | 27:1b5038b0a7a2 | 672 | ) { // 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 | 673 | // if it has, fix position and reflect x velocity |
| jamesheavey | 27:1b5038b0a7a2 | 674 | ball_pos.y = _brick33_pos.y+ BRICK_HEIGHT; |
| jamesheavey | 27:1b5038b0a7a2 | 675 | ball_velocity.y = -ball_velocity.y; |
| jamesheavey | 27:1b5038b0a7a2 | 676 | // audio feedback |
| jamesheavey | 27:1b5038b0a7a2 | 677 | pad.tone(1000.0,0.1); |
| jamesheavey | 27:1b5038b0a7a2 | 678 | _brick33.hit(); |
| jamesheavey | 32:4dba7a85dbb2 | 679 | _brick33.hit(); |
| jamesheavey | 27:1b5038b0a7a2 | 680 | //delete _brick33; |
| jamesheavey | 27:1b5038b0a7a2 | 681 | _brick33_pos.x = -100; |
| jamesheavey | 27:1b5038b0a7a2 | 682 | _brick33_pos.y = -100; |
| jamesheavey | 27:1b5038b0a7a2 | 683 | _brick33.set_pos(_brick33_pos); |
| jamesheavey | 27:1b5038b0a7a2 | 684 | one_less(); |
| jamesheavey | 27:1b5038b0a7a2 | 685 | } |
| jamesheavey | 27:1b5038b0a7a2 | 686 | // check p1 first |
| jamesheavey | 27:1b5038b0a7a2 | 687 | Vector2D _brick34_pos = _brick34.get_pos(); |
| jamesheavey | 27:1b5038b0a7a2 | 688 | |
| jamesheavey | 27:1b5038b0a7a2 | 689 | // see if ball has hit the paddle by checking for overlaps |
| jamesheavey | 27:1b5038b0a7a2 | 690 | if ( |
| jamesheavey | 27:1b5038b0a7a2 | 691 | (ball_pos.x >= _brick34_pos.x) && //left |
| jamesheavey | 27:1b5038b0a7a2 | 692 | (ball_pos.x <= _brick34_pos.x + BRICK_WIDTH) && //right |
| jamesheavey | 27:1b5038b0a7a2 | 693 | (ball_pos.y >= _brick34_pos.y) && //bottom |
| jamesheavey | 27:1b5038b0a7a2 | 694 | (ball_pos.y <= _brick34_pos.y + BRICK_HEIGHT) //top |
| jamesheavey | 27:1b5038b0a7a2 | 695 | ) { // 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 | 696 | // if it has, fix position and reflect x velocity |
| jamesheavey | 27:1b5038b0a7a2 | 697 | ball_pos.y = _brick34_pos.y+ BRICK_HEIGHT; |
| jamesheavey | 27:1b5038b0a7a2 | 698 | ball_velocity.y = -ball_velocity.y; |
| jamesheavey | 27:1b5038b0a7a2 | 699 | // audio feedback |
| jamesheavey | 27:1b5038b0a7a2 | 700 | pad.tone(1000.0,0.1); |
| jamesheavey | 27:1b5038b0a7a2 | 701 | _brick34.hit(); |
| jamesheavey | 32:4dba7a85dbb2 | 702 | _brick34.hit(); |
| jamesheavey | 27:1b5038b0a7a2 | 703 | //delete _brick34; |
| jamesheavey | 27:1b5038b0a7a2 | 704 | _brick34_pos.x = -100; |
| jamesheavey | 27:1b5038b0a7a2 | 705 | _brick34_pos.y = -100; |
| jamesheavey | 27:1b5038b0a7a2 | 706 | _brick34.set_pos(_brick34_pos); |
| jamesheavey | 27:1b5038b0a7a2 | 707 | one_less(); |
| jamesheavey | 27:1b5038b0a7a2 | 708 | } |
| jamesheavey | 27:1b5038b0a7a2 | 709 | // check p1 first |
| jamesheavey | 27:1b5038b0a7a2 | 710 | Vector2D _brick35_pos = _brick35.get_pos(); |
| jamesheavey | 27:1b5038b0a7a2 | 711 | |
| jamesheavey | 27:1b5038b0a7a2 | 712 | // see if ball has hit the paddle by checking for overlaps |
| jamesheavey | 27:1b5038b0a7a2 | 713 | if ( |
| jamesheavey | 27:1b5038b0a7a2 | 714 | (ball_pos.x >= _brick35_pos.x) && //left |
| jamesheavey | 27:1b5038b0a7a2 | 715 | (ball_pos.x <= _brick35_pos.x + BRICK_WIDTH) && //right |
| jamesheavey | 27:1b5038b0a7a2 | 716 | (ball_pos.y >= _brick35_pos.y) && //bottom |
| jamesheavey | 27:1b5038b0a7a2 | 717 | (ball_pos.y <= _brick35_pos.y + BRICK_HEIGHT) //top |
| jamesheavey | 27:1b5038b0a7a2 | 718 | ) { // 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 | 719 | // if it has, fix position and reflect x velocity |
| jamesheavey | 27:1b5038b0a7a2 | 720 | ball_pos.y = _brick35_pos.y+ BRICK_HEIGHT; |
| jamesheavey | 27:1b5038b0a7a2 | 721 | ball_velocity.y = -ball_velocity.y; |
| jamesheavey | 27:1b5038b0a7a2 | 722 | // audio feedback |
| jamesheavey | 27:1b5038b0a7a2 | 723 | pad.tone(1000.0,0.1); |
| jamesheavey | 27:1b5038b0a7a2 | 724 | _brick35.hit(); |
| jamesheavey | 32:4dba7a85dbb2 | 725 | _brick35.hit(); |
| jamesheavey | 27:1b5038b0a7a2 | 726 | //delete _brick35; |
| jamesheavey | 27:1b5038b0a7a2 | 727 | _brick35_pos.x = -100; |
| jamesheavey | 27:1b5038b0a7a2 | 728 | _brick35_pos.y = -100; |
| jamesheavey | 27:1b5038b0a7a2 | 729 | _brick35.set_pos(_brick35_pos); |
| jamesheavey | 27:1b5038b0a7a2 | 730 | one_less(); |
| jamesheavey | 27:1b5038b0a7a2 | 731 | } |
| jamesheavey | 27:1b5038b0a7a2 | 732 | // check p1 first |
| jamesheavey | 27:1b5038b0a7a2 | 733 | Vector2D _brick36_pos = _brick36.get_pos(); |
| jamesheavey | 27:1b5038b0a7a2 | 734 | |
| jamesheavey | 27:1b5038b0a7a2 | 735 | // see if ball has hit the paddle by checking for overlaps |
| jamesheavey | 27:1b5038b0a7a2 | 736 | if ( |
| jamesheavey | 27:1b5038b0a7a2 | 737 | (ball_pos.x >= _brick36_pos.x) && //left |
| jamesheavey | 27:1b5038b0a7a2 | 738 | (ball_pos.x <= _brick36_pos.x + BRICK_WIDTH) && //right |
| jamesheavey | 27:1b5038b0a7a2 | 739 | (ball_pos.y >= _brick36_pos.y) && //bottom |
| jamesheavey | 27:1b5038b0a7a2 | 740 | (ball_pos.y <= _brick36_pos.y + BRICK_HEIGHT) //top |
| jamesheavey | 27:1b5038b0a7a2 | 741 | ) { // 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 | 742 | // if it has, fix position and reflect x velocity |
| jamesheavey | 27:1b5038b0a7a2 | 743 | ball_pos.y = _brick36_pos.y+ BRICK_HEIGHT; |
| jamesheavey | 27:1b5038b0a7a2 | 744 | ball_velocity.y = -ball_velocity.y; |
| jamesheavey | 27:1b5038b0a7a2 | 745 | // audio feedback |
| jamesheavey | 27:1b5038b0a7a2 | 746 | pad.tone(1000.0,0.1); |
| jamesheavey | 27:1b5038b0a7a2 | 747 | _brick36.hit(); |
| jamesheavey | 32:4dba7a85dbb2 | 748 | _brick36.hit(); |
| jamesheavey | 27:1b5038b0a7a2 | 749 | //delete _brick36; |
| jamesheavey | 27:1b5038b0a7a2 | 750 | _brick36_pos.x = -100; |
| jamesheavey | 27:1b5038b0a7a2 | 751 | _brick36_pos.y = -100; |
| jamesheavey | 27:1b5038b0a7a2 | 752 | _brick36.set_pos(_brick36_pos); |
| jamesheavey | 27:1b5038b0a7a2 | 753 | one_less(); |
| jamesheavey | 27:1b5038b0a7a2 | 754 | } |
| jamesheavey | 27:1b5038b0a7a2 | 755 | |
| jamesheavey | 27:1b5038b0a7a2 | 756 | // write new attributes |
| jamesheavey | 27:1b5038b0a7a2 | 757 | _ball.set_velocity(ball_velocity); |
| jamesheavey | 27:1b5038b0a7a2 | 758 | _ball.set_pos(ball_pos); |
| jamesheavey | 27:1b5038b0a7a2 | 759 | } |
| jamesheavey | 27:1b5038b0a7a2 | 760 | |
| jamesheavey | 33:e47f6fa1d9ce | 761 | |
| jamesheavey | 32:4dba7a85dbb2 | 762 | void BreakoutEngine::check_laser_collisions(Gamepad &pad) |
| jamesheavey | 32:4dba7a85dbb2 | 763 | { |
| jamesheavey | 32:4dba7a85dbb2 | 764 | // read current ball attributes |
| jamesheavey | 32:4dba7a85dbb2 | 765 | Vector2D laser1_pos = _laser1.get_pos(); |
| jamesheavey | 32:4dba7a85dbb2 | 766 | Vector2D laser2_pos = _laser2.get_pos(); |
| jamesheavey | 32:4dba7a85dbb2 | 767 | Vector2D laser3_pos = _laser3.get_pos(); |
| jamesheavey | 32:4dba7a85dbb2 | 768 | |
| jamesheavey | 32:4dba7a85dbb2 | 769 | Vector2D ball_velocity = _ball.get_velocity(); |
| jamesheavey | 32:4dba7a85dbb2 | 770 | |
| jamesheavey | 32:4dba7a85dbb2 | 771 | // check p1 first |
| jamesheavey | 32:4dba7a85dbb2 | 772 | Vector2D _brick11_pos = _brick11.get_pos(); |
| jamesheavey | 32:4dba7a85dbb2 | 773 | |
| jamesheavey | 32:4dba7a85dbb2 | 774 | // see if ball has hit the paddle by checking for overlaps |
| jamesheavey | 32:4dba7a85dbb2 | 775 | if ( |
| jamesheavey | 32:4dba7a85dbb2 | 776 | (laser1_pos.x >= _brick11_pos.x) && //left |
| jamesheavey | 32:4dba7a85dbb2 | 777 | (laser1_pos.x <= _brick11_pos.x + BRICK_WIDTH) && //right |
| jamesheavey | 32:4dba7a85dbb2 | 778 | (laser1_pos.y >= _brick11_pos.y) && //bottom |
| jamesheavey | 32:4dba7a85dbb2 | 779 | (laser1_pos.y <= _brick11_pos.y + BRICK_HEIGHT) //top |
| jamesheavey | 32:4dba7a85dbb2 | 780 | ) { // 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 | 781 | // if it has, fix position and reflect x velocity |
| jamesheavey | 32:4dba7a85dbb2 | 782 | laser1_pos.x = -10; |
| jamesheavey | 32:4dba7a85dbb2 | 783 | // audio feedback |
| jamesheavey | 32:4dba7a85dbb2 | 784 | pad.tone(1000.0,0.1); |
| jamesheavey | 33:e47f6fa1d9ce | 785 | //if(_brick11.hit() == true) { |
| jamesheavey | 32:4dba7a85dbb2 | 786 | _brick11_pos.x = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 787 | _brick11_pos.y = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 788 | _brick11.set_pos(_brick11_pos); |
| jamesheavey | 32:4dba7a85dbb2 | 789 | one_less(); |
| jamesheavey | 33:e47f6fa1d9ce | 790 | //} |
| jamesheavey | 32:4dba7a85dbb2 | 791 | //delete _brick11; |
| jamesheavey | 32:4dba7a85dbb2 | 792 | |
| jamesheavey | 32:4dba7a85dbb2 | 793 | } |
| jamesheavey | 32:4dba7a85dbb2 | 794 | // check p1 first |
| jamesheavey | 32:4dba7a85dbb2 | 795 | Vector2D _brick12_pos = _brick12.get_pos(); |
| jamesheavey | 32:4dba7a85dbb2 | 796 | |
| jamesheavey | 32:4dba7a85dbb2 | 797 | // see if ball has hit the paddle by checking for overlaps |
| jamesheavey | 32:4dba7a85dbb2 | 798 | if ( |
| jamesheavey | 32:4dba7a85dbb2 | 799 | (laser1_pos.x >= _brick12_pos.x) && //left |
| jamesheavey | 32:4dba7a85dbb2 | 800 | (laser1_pos.x <= _brick12_pos.x + BRICK_WIDTH) && //right |
| jamesheavey | 32:4dba7a85dbb2 | 801 | (laser1_pos.y >= _brick12_pos.y) && //bottom |
| jamesheavey | 32:4dba7a85dbb2 | 802 | (laser1_pos.y <= _brick12_pos.y + BRICK_HEIGHT) //top |
| jamesheavey | 32:4dba7a85dbb2 | 803 | ) { // 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 | 804 | // if it has, fix position and reflect x velocity |
| jamesheavey | 32:4dba7a85dbb2 | 805 | laser1_pos.x = -10; |
| jamesheavey | 32:4dba7a85dbb2 | 806 | // audio feedback |
| jamesheavey | 32:4dba7a85dbb2 | 807 | pad.tone(1000.0,0.1); |
| jamesheavey | 33:e47f6fa1d9ce | 808 | //if(_brick12.hit() == true) { |
| jamesheavey | 32:4dba7a85dbb2 | 809 | _brick12_pos.x = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 810 | _brick12_pos.y = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 811 | _brick12.set_pos(_brick11_pos); |
| jamesheavey | 32:4dba7a85dbb2 | 812 | one_less(); |
| jamesheavey | 33:e47f6fa1d9ce | 813 | //} |
| jamesheavey | 32:4dba7a85dbb2 | 814 | } |
| jamesheavey | 32:4dba7a85dbb2 | 815 | // check p1 first |
| jamesheavey | 32:4dba7a85dbb2 | 816 | Vector2D _brick13_pos = _brick13.get_pos(); |
| jamesheavey | 32:4dba7a85dbb2 | 817 | |
| jamesheavey | 32:4dba7a85dbb2 | 818 | // see if ball has hit the paddle by checking for overlaps |
| jamesheavey | 32:4dba7a85dbb2 | 819 | if ( |
| jamesheavey | 32:4dba7a85dbb2 | 820 | (laser1_pos.x >= _brick13_pos.x) && //left |
| jamesheavey | 32:4dba7a85dbb2 | 821 | (laser1_pos.x <= _brick13_pos.x + BRICK_WIDTH) && //right |
| jamesheavey | 32:4dba7a85dbb2 | 822 | (laser1_pos.y >= _brick13_pos.y) && //bottom |
| jamesheavey | 32:4dba7a85dbb2 | 823 | (laser1_pos.y <= _brick13_pos.y + BRICK_HEIGHT) //top |
| jamesheavey | 32:4dba7a85dbb2 | 824 | ) { // 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 | 825 | // if it has, fix position and reflect x velocity |
| jamesheavey | 32:4dba7a85dbb2 | 826 | laser1_pos.x = -10; |
| jamesheavey | 32:4dba7a85dbb2 | 827 | // audio feedback |
| jamesheavey | 32:4dba7a85dbb2 | 828 | pad.tone(1000.0,0.1); |
| jamesheavey | 33:e47f6fa1d9ce | 829 | //if(_brick13.hit() == true) { |
| jamesheavey | 32:4dba7a85dbb2 | 830 | _brick13_pos.x = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 831 | _brick13_pos.y = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 832 | _brick13.set_pos(_brick11_pos); |
| jamesheavey | 32:4dba7a85dbb2 | 833 | one_less(); |
| jamesheavey | 33:e47f6fa1d9ce | 834 | //} |
| jamesheavey | 32:4dba7a85dbb2 | 835 | } |
| jamesheavey | 32:4dba7a85dbb2 | 836 | // check p1 first |
| jamesheavey | 32:4dba7a85dbb2 | 837 | Vector2D _brick14_pos = _brick14.get_pos(); |
| jamesheavey | 32:4dba7a85dbb2 | 838 | |
| jamesheavey | 32:4dba7a85dbb2 | 839 | // see if ball has hit the paddle by checking for overlaps |
| jamesheavey | 32:4dba7a85dbb2 | 840 | if ( |
| jamesheavey | 32:4dba7a85dbb2 | 841 | (laser1_pos.x >= _brick14_pos.x) && //left |
| jamesheavey | 32:4dba7a85dbb2 | 842 | (laser1_pos.x <= _brick14_pos.x + BRICK_WIDTH) && //right |
| jamesheavey | 32:4dba7a85dbb2 | 843 | (laser1_pos.y >= _brick14_pos.y) && //bottom |
| jamesheavey | 32:4dba7a85dbb2 | 844 | (laser1_pos.y <= _brick14_pos.y + BRICK_HEIGHT) //top |
| jamesheavey | 32:4dba7a85dbb2 | 845 | ) { // 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 | 846 | // if it has, fix position and reflect x velocity |
| jamesheavey | 32:4dba7a85dbb2 | 847 | laser1_pos.x = -10; |
| jamesheavey | 32:4dba7a85dbb2 | 848 | // audio feedback |
| jamesheavey | 32:4dba7a85dbb2 | 849 | pad.tone(1000.0,0.1); |
| jamesheavey | 33:e47f6fa1d9ce | 850 | //if(_brick14.hit() == true) { |
| jamesheavey | 32:4dba7a85dbb2 | 851 | _brick14_pos.x = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 852 | _brick14_pos.y = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 853 | _brick14.set_pos(_brick11_pos); |
| jamesheavey | 32:4dba7a85dbb2 | 854 | one_less(); |
| jamesheavey | 33:e47f6fa1d9ce | 855 | //} |
| jamesheavey | 32:4dba7a85dbb2 | 856 | } |
| jamesheavey | 32:4dba7a85dbb2 | 857 | // check p1 first |
| jamesheavey | 32:4dba7a85dbb2 | 858 | Vector2D _brick15_pos = _brick15.get_pos(); |
| jamesheavey | 32:4dba7a85dbb2 | 859 | |
| jamesheavey | 32:4dba7a85dbb2 | 860 | // see if ball has hit the paddle by checking for overlaps |
| jamesheavey | 32:4dba7a85dbb2 | 861 | if ( |
| jamesheavey | 32:4dba7a85dbb2 | 862 | (laser1_pos.x >= _brick15_pos.x) && //left |
| jamesheavey | 32:4dba7a85dbb2 | 863 | (laser1_pos.x <= _brick15_pos.x + BRICK_WIDTH) && //right |
| jamesheavey | 32:4dba7a85dbb2 | 864 | (laser1_pos.y >= _brick15_pos.y) && //bottom |
| jamesheavey | 32:4dba7a85dbb2 | 865 | (laser1_pos.y <= _brick15_pos.y + BRICK_HEIGHT) //top |
| jamesheavey | 32:4dba7a85dbb2 | 866 | ) { // 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 | 867 | // if it has, fix position and reflect x velocity |
| jamesheavey | 32:4dba7a85dbb2 | 868 | laser1_pos.x = -10; |
| jamesheavey | 32:4dba7a85dbb2 | 869 | // audio feedback |
| jamesheavey | 32:4dba7a85dbb2 | 870 | pad.tone(1000.0,0.1); |
| jamesheavey | 33:e47f6fa1d9ce | 871 | //if(_brick15.hit() == true) { |
| jamesheavey | 32:4dba7a85dbb2 | 872 | _brick15_pos.x = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 873 | _brick15_pos.y = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 874 | _brick15.set_pos(_brick11_pos); |
| jamesheavey | 32:4dba7a85dbb2 | 875 | one_less(); |
| jamesheavey | 33:e47f6fa1d9ce | 876 | //} |
| jamesheavey | 32:4dba7a85dbb2 | 877 | } |
| jamesheavey | 32:4dba7a85dbb2 | 878 | // check p1 first |
| jamesheavey | 32:4dba7a85dbb2 | 879 | Vector2D _brick16_pos = _brick16.get_pos(); |
| jamesheavey | 32:4dba7a85dbb2 | 880 | |
| jamesheavey | 32:4dba7a85dbb2 | 881 | // see if ball has hit the paddle by checking for overlaps |
| jamesheavey | 32:4dba7a85dbb2 | 882 | if ( |
| jamesheavey | 32:4dba7a85dbb2 | 883 | (laser1_pos.x >= _brick16_pos.x) && //left |
| jamesheavey | 32:4dba7a85dbb2 | 884 | (laser1_pos.x <= _brick16_pos.x + BRICK_WIDTH) && //right |
| jamesheavey | 32:4dba7a85dbb2 | 885 | (laser1_pos.y >= _brick16_pos.y) && //bottom |
| jamesheavey | 32:4dba7a85dbb2 | 886 | (laser1_pos.y <= _brick16_pos.y + BRICK_HEIGHT) //top |
| jamesheavey | 32:4dba7a85dbb2 | 887 | ) { // 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 | 888 | // if it has, fix position and reflect x velocity |
| jamesheavey | 32:4dba7a85dbb2 | 889 | laser1_pos.x = -10; |
| jamesheavey | 32:4dba7a85dbb2 | 890 | // audio feedback |
| jamesheavey | 32:4dba7a85dbb2 | 891 | pad.tone(1000.0,0.1); |
| jamesheavey | 33:e47f6fa1d9ce | 892 | //if(_brick16.hit() == true) { |
| jamesheavey | 32:4dba7a85dbb2 | 893 | _brick16_pos.x = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 894 | _brick16_pos.y = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 895 | _brick16.set_pos(_brick11_pos); |
| jamesheavey | 32:4dba7a85dbb2 | 896 | one_less(); |
| jamesheavey | 33:e47f6fa1d9ce | 897 | //} |
| jamesheavey | 32:4dba7a85dbb2 | 898 | } |
| jamesheavey | 32:4dba7a85dbb2 | 899 | // check p1 first |
| jamesheavey | 32:4dba7a85dbb2 | 900 | Vector2D _brick21_pos = _brick21.get_pos(); |
| jamesheavey | 32:4dba7a85dbb2 | 901 | |
| jamesheavey | 32:4dba7a85dbb2 | 902 | // see if ball has hit the paddle by checking for overlaps |
| jamesheavey | 32:4dba7a85dbb2 | 903 | if ( |
| jamesheavey | 32:4dba7a85dbb2 | 904 | (laser1_pos.x >= _brick21_pos.x) && //left |
| jamesheavey | 32:4dba7a85dbb2 | 905 | (laser1_pos.x <= _brick21_pos.x + BRICK_WIDTH) && //right |
| jamesheavey | 32:4dba7a85dbb2 | 906 | (laser1_pos.y >= _brick21_pos.y) && //bottom |
| jamesheavey | 32:4dba7a85dbb2 | 907 | (laser1_pos.y <= _brick21_pos.y + BRICK_HEIGHT) //top |
| jamesheavey | 32:4dba7a85dbb2 | 908 | ) { // 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 | 909 | // if it has, fix position and reflect x velocity |
| jamesheavey | 32:4dba7a85dbb2 | 910 | laser1_pos.x = -10; |
| jamesheavey | 32:4dba7a85dbb2 | 911 | // audio feedback |
| jamesheavey | 32:4dba7a85dbb2 | 912 | pad.tone(1000.0,0.1); |
| jamesheavey | 33:e47f6fa1d9ce | 913 | //if(_brick21.hit() == true) { |
| jamesheavey | 32:4dba7a85dbb2 | 914 | _brick21_pos.x = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 915 | _brick21_pos.y = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 916 | _brick21.set_pos(_brick11_pos); |
| jamesheavey | 32:4dba7a85dbb2 | 917 | one_less(); |
| jamesheavey | 33:e47f6fa1d9ce | 918 | //} |
| jamesheavey | 32:4dba7a85dbb2 | 919 | } |
| jamesheavey | 32:4dba7a85dbb2 | 920 | // check p1 first |
| jamesheavey | 32:4dba7a85dbb2 | 921 | Vector2D _brick22_pos = _brick22.get_pos(); |
| jamesheavey | 32:4dba7a85dbb2 | 922 | |
| jamesheavey | 32:4dba7a85dbb2 | 923 | // see if ball has hit the paddle by checking for overlaps |
| jamesheavey | 32:4dba7a85dbb2 | 924 | if ( |
| jamesheavey | 32:4dba7a85dbb2 | 925 | (laser1_pos.x >= _brick22_pos.x) && //left |
| jamesheavey | 32:4dba7a85dbb2 | 926 | (laser1_pos.x <= _brick22_pos.x + BRICK_WIDTH) && //right |
| jamesheavey | 32:4dba7a85dbb2 | 927 | (laser1_pos.y >= _brick22_pos.y) && //bottom |
| jamesheavey | 32:4dba7a85dbb2 | 928 | (laser1_pos.y <= _brick22_pos.y + BRICK_HEIGHT) //top |
| jamesheavey | 32:4dba7a85dbb2 | 929 | ) { // 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 | 930 | // if it has, fix position and reflect x velocity |
| jamesheavey | 32:4dba7a85dbb2 | 931 | laser1_pos.x = -10; |
| jamesheavey | 32:4dba7a85dbb2 | 932 | // audio feedback |
| jamesheavey | 32:4dba7a85dbb2 | 933 | pad.tone(1000.0,0.1); |
| jamesheavey | 33:e47f6fa1d9ce | 934 | //if(_brick22.hit() == true) { |
| jamesheavey | 32:4dba7a85dbb2 | 935 | _brick22_pos.x = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 936 | _brick22_pos.y = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 937 | _brick22.set_pos(_brick11_pos); |
| jamesheavey | 32:4dba7a85dbb2 | 938 | one_less(); |
| jamesheavey | 33:e47f6fa1d9ce | 939 | //} |
| jamesheavey | 32:4dba7a85dbb2 | 940 | } |
| jamesheavey | 32:4dba7a85dbb2 | 941 | // check p1 first |
| jamesheavey | 32:4dba7a85dbb2 | 942 | Vector2D _brick23_pos = _brick23.get_pos(); |
| jamesheavey | 32:4dba7a85dbb2 | 943 | |
| jamesheavey | 32:4dba7a85dbb2 | 944 | // see if ball has hit the paddle by checking for overlaps |
| jamesheavey | 32:4dba7a85dbb2 | 945 | if ( |
| jamesheavey | 32:4dba7a85dbb2 | 946 | (laser1_pos.x >= _brick23_pos.x) && //left |
| jamesheavey | 32:4dba7a85dbb2 | 947 | (laser1_pos.x <= _brick23_pos.x + BRICK_WIDTH) && //right |
| jamesheavey | 32:4dba7a85dbb2 | 948 | (laser1_pos.y >= _brick23_pos.y) && //bottom |
| jamesheavey | 32:4dba7a85dbb2 | 949 | (laser1_pos.y <= _brick23_pos.y + BRICK_HEIGHT) //top |
| jamesheavey | 32:4dba7a85dbb2 | 950 | ) { // 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 | 951 | // if it has, fix position and reflect x velocity |
| jamesheavey | 32:4dba7a85dbb2 | 952 | laser1_pos.x = -10; |
| jamesheavey | 32:4dba7a85dbb2 | 953 | // audio feedback |
| jamesheavey | 32:4dba7a85dbb2 | 954 | pad.tone(1000.0,0.1); |
| jamesheavey | 33:e47f6fa1d9ce | 955 | //if(_brick23.hit() == true) { |
| jamesheavey | 32:4dba7a85dbb2 | 956 | _brick23_pos.x = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 957 | _brick23_pos.y = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 958 | _brick23.set_pos(_brick11_pos); |
| jamesheavey | 32:4dba7a85dbb2 | 959 | one_less(); |
| jamesheavey | 33:e47f6fa1d9ce | 960 | //} |
| jamesheavey | 32:4dba7a85dbb2 | 961 | } |
| jamesheavey | 32:4dba7a85dbb2 | 962 | // check p1 first |
| jamesheavey | 32:4dba7a85dbb2 | 963 | Vector2D _brick24_pos = _brick24.get_pos(); |
| jamesheavey | 32:4dba7a85dbb2 | 964 | |
| jamesheavey | 32:4dba7a85dbb2 | 965 | // see if ball has hit the paddle by checking for overlaps |
| jamesheavey | 32:4dba7a85dbb2 | 966 | if ( |
| jamesheavey | 32:4dba7a85dbb2 | 967 | (laser1_pos.x >= _brick24_pos.x) && //left |
| jamesheavey | 32:4dba7a85dbb2 | 968 | (laser1_pos.x <= _brick24_pos.x + BRICK_WIDTH) && //right |
| jamesheavey | 32:4dba7a85dbb2 | 969 | (laser1_pos.y >= _brick24_pos.y) && //bottom |
| jamesheavey | 32:4dba7a85dbb2 | 970 | (laser1_pos.y <= _brick24_pos.y + BRICK_HEIGHT) //top |
| jamesheavey | 32:4dba7a85dbb2 | 971 | ) { // 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 | 972 | // if it has, fix position and reflect x velocity |
| jamesheavey | 32:4dba7a85dbb2 | 973 | laser1_pos.x = -10; |
| jamesheavey | 32:4dba7a85dbb2 | 974 | // audio feedback |
| jamesheavey | 32:4dba7a85dbb2 | 975 | pad.tone(1000.0,0.1); |
| jamesheavey | 33:e47f6fa1d9ce | 976 | //if(_brick24.hit() == true) { |
| jamesheavey | 32:4dba7a85dbb2 | 977 | _brick24_pos.x = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 978 | _brick24_pos.y = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 979 | _brick24.set_pos(_brick11_pos); |
| jamesheavey | 32:4dba7a85dbb2 | 980 | one_less(); |
| jamesheavey | 33:e47f6fa1d9ce | 981 | //} |
| jamesheavey | 32:4dba7a85dbb2 | 982 | } |
| jamesheavey | 32:4dba7a85dbb2 | 983 | // check p1 first |
| jamesheavey | 32:4dba7a85dbb2 | 984 | Vector2D _brick25_pos = _brick25.get_pos(); |
| jamesheavey | 32:4dba7a85dbb2 | 985 | |
| jamesheavey | 32:4dba7a85dbb2 | 986 | // see if ball has hit the paddle by checking for overlaps |
| jamesheavey | 32:4dba7a85dbb2 | 987 | if ( |
| jamesheavey | 32:4dba7a85dbb2 | 988 | (laser1_pos.x >= _brick25_pos.x) && //left |
| jamesheavey | 32:4dba7a85dbb2 | 989 | (laser1_pos.x <= _brick25_pos.x + BRICK_WIDTH) && //right |
| jamesheavey | 32:4dba7a85dbb2 | 990 | (laser1_pos.y >= _brick25_pos.y) && //bottom |
| jamesheavey | 32:4dba7a85dbb2 | 991 | (laser1_pos.y <= _brick25_pos.y + BRICK_HEIGHT) //top |
| jamesheavey | 32:4dba7a85dbb2 | 992 | ) { // 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 | 993 | // if it has, fix position and reflect x velocity |
| jamesheavey | 32:4dba7a85dbb2 | 994 | laser1_pos.x = -10; |
| jamesheavey | 32:4dba7a85dbb2 | 995 | // audio feedback |
| jamesheavey | 32:4dba7a85dbb2 | 996 | pad.tone(1000.0,0.1); |
| jamesheavey | 33:e47f6fa1d9ce | 997 | //if(_brick25.hit() == true) { |
| jamesheavey | 32:4dba7a85dbb2 | 998 | _brick25_pos.x = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 999 | _brick25_pos.y = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 1000 | _brick25.set_pos(_brick11_pos); |
| jamesheavey | 32:4dba7a85dbb2 | 1001 | one_less(); |
| jamesheavey | 33:e47f6fa1d9ce | 1002 | //} |
| jamesheavey | 32:4dba7a85dbb2 | 1003 | } |
| jamesheavey | 32:4dba7a85dbb2 | 1004 | // check p1 first |
| jamesheavey | 32:4dba7a85dbb2 | 1005 | Vector2D _brick26_pos = _brick26.get_pos(); |
| jamesheavey | 32:4dba7a85dbb2 | 1006 | |
| jamesheavey | 32:4dba7a85dbb2 | 1007 | // see if ball has hit the paddle by checking for overlaps |
| jamesheavey | 32:4dba7a85dbb2 | 1008 | if ( |
| jamesheavey | 32:4dba7a85dbb2 | 1009 | (laser1_pos.x >= _brick26_pos.x) && //left |
| jamesheavey | 32:4dba7a85dbb2 | 1010 | (laser1_pos.x <= _brick26_pos.x + BRICK_WIDTH) && //right |
| jamesheavey | 32:4dba7a85dbb2 | 1011 | (laser1_pos.y >= _brick26_pos.y) && //bottom |
| jamesheavey | 32:4dba7a85dbb2 | 1012 | (laser1_pos.y <= _brick26_pos.y + BRICK_HEIGHT) //top |
| jamesheavey | 32:4dba7a85dbb2 | 1013 | ) { // 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 | 1014 | // if it has, fix position and reflect x velocity |
| jamesheavey | 32:4dba7a85dbb2 | 1015 | laser1_pos.x = -10; |
| jamesheavey | 32:4dba7a85dbb2 | 1016 | // audio feedback |
| jamesheavey | 32:4dba7a85dbb2 | 1017 | pad.tone(1000.0,0.1); |
| jamesheavey | 33:e47f6fa1d9ce | 1018 | //if(_brick26.hit() == true) { |
| jamesheavey | 32:4dba7a85dbb2 | 1019 | _brick26_pos.x = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 1020 | _brick26_pos.y = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 1021 | _brick26.set_pos(_brick11_pos); |
| jamesheavey | 32:4dba7a85dbb2 | 1022 | one_less(); |
| jamesheavey | 33:e47f6fa1d9ce | 1023 | //} |
| jamesheavey | 32:4dba7a85dbb2 | 1024 | } |
| jamesheavey | 32:4dba7a85dbb2 | 1025 | // check p1 first |
| jamesheavey | 32:4dba7a85dbb2 | 1026 | Vector2D _brick31_pos = _brick31.get_pos(); |
| jamesheavey | 32:4dba7a85dbb2 | 1027 | |
| jamesheavey | 32:4dba7a85dbb2 | 1028 | // see if ball has hit the paddle by checking for overlaps |
| jamesheavey | 32:4dba7a85dbb2 | 1029 | if ( |
| jamesheavey | 32:4dba7a85dbb2 | 1030 | (laser1_pos.x >= _brick31_pos.x) && //left |
| jamesheavey | 32:4dba7a85dbb2 | 1031 | (laser1_pos.x <= _brick31_pos.x + BRICK_WIDTH) && //right |
| jamesheavey | 32:4dba7a85dbb2 | 1032 | (laser1_pos.y >= _brick31_pos.y) && //bottom |
| jamesheavey | 32:4dba7a85dbb2 | 1033 | (laser1_pos.y <= _brick31_pos.y + BRICK_HEIGHT) //top |
| jamesheavey | 32:4dba7a85dbb2 | 1034 | ) { // 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 | 1035 | // if it has, fix position and reflect x velocity |
| jamesheavey | 32:4dba7a85dbb2 | 1036 | laser1_pos.x = -10; |
| jamesheavey | 32:4dba7a85dbb2 | 1037 | // audio feedback |
| jamesheavey | 32:4dba7a85dbb2 | 1038 | pad.tone(1000.0,0.1); |
| jamesheavey | 33:e47f6fa1d9ce | 1039 | //if(_brick31.hit() == true) { |
| jamesheavey | 32:4dba7a85dbb2 | 1040 | _brick31_pos.x = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 1041 | _brick31_pos.y = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 1042 | _brick31.set_pos(_brick11_pos); |
| jamesheavey | 32:4dba7a85dbb2 | 1043 | one_less(); |
| jamesheavey | 33:e47f6fa1d9ce | 1044 | //} |
| jamesheavey | 32:4dba7a85dbb2 | 1045 | } |
| jamesheavey | 32:4dba7a85dbb2 | 1046 | // check p1 first |
| jamesheavey | 32:4dba7a85dbb2 | 1047 | Vector2D _brick32_pos = _brick32.get_pos(); |
| jamesheavey | 32:4dba7a85dbb2 | 1048 | |
| jamesheavey | 32:4dba7a85dbb2 | 1049 | // see if ball has hit the paddle by checking for overlaps |
| jamesheavey | 32:4dba7a85dbb2 | 1050 | if ( |
| jamesheavey | 32:4dba7a85dbb2 | 1051 | (laser1_pos.x >= _brick32_pos.x) && //left |
| jamesheavey | 32:4dba7a85dbb2 | 1052 | (laser1_pos.x <= _brick32_pos.x + BRICK_WIDTH) && //right |
| jamesheavey | 32:4dba7a85dbb2 | 1053 | (laser1_pos.y >= _brick32_pos.y) && //bottom |
| jamesheavey | 32:4dba7a85dbb2 | 1054 | (laser1_pos.y <= _brick32_pos.y + BRICK_HEIGHT) //top |
| jamesheavey | 32:4dba7a85dbb2 | 1055 | ) { // 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 | 1056 | // if it has, fix position and reflect x velocity |
| jamesheavey | 32:4dba7a85dbb2 | 1057 | laser1_pos.x = -10; |
| jamesheavey | 32:4dba7a85dbb2 | 1058 | // audio feedback |
| jamesheavey | 32:4dba7a85dbb2 | 1059 | pad.tone(1000.0,0.1); |
| jamesheavey | 33:e47f6fa1d9ce | 1060 | //if(_brick32.hit() == true) { |
| jamesheavey | 32:4dba7a85dbb2 | 1061 | _brick32_pos.x = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 1062 | _brick32_pos.y = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 1063 | _brick32.set_pos(_brick11_pos); |
| jamesheavey | 32:4dba7a85dbb2 | 1064 | one_less(); |
| jamesheavey | 33:e47f6fa1d9ce | 1065 | //} |
| jamesheavey | 32:4dba7a85dbb2 | 1066 | } |
| jamesheavey | 32:4dba7a85dbb2 | 1067 | // check p1 first |
| jamesheavey | 32:4dba7a85dbb2 | 1068 | Vector2D _brick33_pos = _brick33.get_pos(); |
| jamesheavey | 32:4dba7a85dbb2 | 1069 | |
| jamesheavey | 32:4dba7a85dbb2 | 1070 | // see if ball has hit the paddle by checking for overlaps |
| jamesheavey | 32:4dba7a85dbb2 | 1071 | if ( |
| jamesheavey | 32:4dba7a85dbb2 | 1072 | (laser1_pos.x >= _brick33_pos.x) && //left |
| jamesheavey | 32:4dba7a85dbb2 | 1073 | (laser1_pos.x <= _brick33_pos.x + BRICK_WIDTH) && //right |
| jamesheavey | 32:4dba7a85dbb2 | 1074 | (laser1_pos.y >= _brick33_pos.y) && //bottom |
| jamesheavey | 32:4dba7a85dbb2 | 1075 | (laser1_pos.y <= _brick33_pos.y + BRICK_HEIGHT) //top |
| jamesheavey | 32:4dba7a85dbb2 | 1076 | ) { // 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 | 1077 | // if it has, fix position and reflect x velocity |
| jamesheavey | 32:4dba7a85dbb2 | 1078 | laser1_pos.x = -10; |
| jamesheavey | 32:4dba7a85dbb2 | 1079 | // audio feedback |
| jamesheavey | 32:4dba7a85dbb2 | 1080 | pad.tone(1000.0,0.1); |
| jamesheavey | 33:e47f6fa1d9ce | 1081 | //if(_brick33.hit() == true) { |
| jamesheavey | 32:4dba7a85dbb2 | 1082 | _brick33_pos.x = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 1083 | _brick33_pos.y = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 1084 | _brick33.set_pos(_brick11_pos); |
| jamesheavey | 32:4dba7a85dbb2 | 1085 | one_less(); |
| jamesheavey | 33:e47f6fa1d9ce | 1086 | //} |
| jamesheavey | 32:4dba7a85dbb2 | 1087 | } |
| jamesheavey | 32:4dba7a85dbb2 | 1088 | // check p1 first |
| jamesheavey | 32:4dba7a85dbb2 | 1089 | Vector2D _brick34_pos = _brick34.get_pos(); |
| jamesheavey | 32:4dba7a85dbb2 | 1090 | |
| jamesheavey | 32:4dba7a85dbb2 | 1091 | // see if ball has hit the paddle by checking for overlaps |
| jamesheavey | 32:4dba7a85dbb2 | 1092 | if ( |
| jamesheavey | 32:4dba7a85dbb2 | 1093 | (laser1_pos.x >= _brick34_pos.x) && //left |
| jamesheavey | 32:4dba7a85dbb2 | 1094 | (laser1_pos.x <= _brick34_pos.x + BRICK_WIDTH) && //right |
| jamesheavey | 32:4dba7a85dbb2 | 1095 | (laser1_pos.y >= _brick34_pos.y) && //bottom |
| jamesheavey | 32:4dba7a85dbb2 | 1096 | (laser1_pos.y <= _brick34_pos.y + BRICK_HEIGHT) //top |
| jamesheavey | 32:4dba7a85dbb2 | 1097 | ) { // 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 | 1098 | // if it has, fix position and reflect x velocity |
| jamesheavey | 32:4dba7a85dbb2 | 1099 | laser1_pos.x = -10; |
| jamesheavey | 32:4dba7a85dbb2 | 1100 | // audio feedback |
| jamesheavey | 32:4dba7a85dbb2 | 1101 | pad.tone(1000.0,0.1); |
| jamesheavey | 33:e47f6fa1d9ce | 1102 | //if(_brick34.hit() == true) { |
| jamesheavey | 32:4dba7a85dbb2 | 1103 | _brick34_pos.x = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 1104 | _brick34_pos.y = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 1105 | _brick34.set_pos(_brick11_pos); |
| jamesheavey | 32:4dba7a85dbb2 | 1106 | one_less(); |
| jamesheavey | 33:e47f6fa1d9ce | 1107 | //} |
| jamesheavey | 32:4dba7a85dbb2 | 1108 | } |
| jamesheavey | 32:4dba7a85dbb2 | 1109 | // check p1 first |
| jamesheavey | 32:4dba7a85dbb2 | 1110 | Vector2D _brick35_pos = _brick35.get_pos(); |
| jamesheavey | 32:4dba7a85dbb2 | 1111 | |
| jamesheavey | 32:4dba7a85dbb2 | 1112 | // see if ball has hit the paddle by checking for overlaps |
| jamesheavey | 32:4dba7a85dbb2 | 1113 | if ( |
| jamesheavey | 32:4dba7a85dbb2 | 1114 | (laser1_pos.x >= _brick35_pos.x) && //left |
| jamesheavey | 32:4dba7a85dbb2 | 1115 | (laser1_pos.x <= _brick35_pos.x + BRICK_WIDTH) && //right |
| jamesheavey | 32:4dba7a85dbb2 | 1116 | (laser1_pos.y >= _brick35_pos.y) && //bottom |
| jamesheavey | 32:4dba7a85dbb2 | 1117 | (laser1_pos.y <= _brick35_pos.y + BRICK_HEIGHT) //top |
| jamesheavey | 32:4dba7a85dbb2 | 1118 | ) { // 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 | 1119 | // if it has, fix position and reflect x velocity |
| jamesheavey | 32:4dba7a85dbb2 | 1120 | laser1_pos.x = -10; |
| jamesheavey | 32:4dba7a85dbb2 | 1121 | // audio feedback |
| jamesheavey | 32:4dba7a85dbb2 | 1122 | pad.tone(1000.0,0.1); |
| jamesheavey | 33:e47f6fa1d9ce | 1123 | //if(_brick35.hit() == true) { |
| jamesheavey | 32:4dba7a85dbb2 | 1124 | _brick35_pos.x = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 1125 | _brick35_pos.y = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 1126 | _brick35.set_pos(_brick11_pos); |
| jamesheavey | 32:4dba7a85dbb2 | 1127 | one_less(); |
| jamesheavey | 33:e47f6fa1d9ce | 1128 | //} |
| jamesheavey | 32:4dba7a85dbb2 | 1129 | } |
| jamesheavey | 32:4dba7a85dbb2 | 1130 | // check p1 first |
| jamesheavey | 32:4dba7a85dbb2 | 1131 | Vector2D _brick36_pos = _brick36.get_pos(); |
| jamesheavey | 32:4dba7a85dbb2 | 1132 | |
| jamesheavey | 32:4dba7a85dbb2 | 1133 | // see if ball has hit the paddle by checking for overlaps |
| jamesheavey | 32:4dba7a85dbb2 | 1134 | if ( |
| jamesheavey | 32:4dba7a85dbb2 | 1135 | (laser1_pos.x >= _brick36_pos.x) && //left |
| jamesheavey | 32:4dba7a85dbb2 | 1136 | (laser1_pos.x <= _brick36_pos.x + BRICK_WIDTH) && //right |
| jamesheavey | 32:4dba7a85dbb2 | 1137 | (laser1_pos.y >= _brick36_pos.y) && //bottom |
| jamesheavey | 32:4dba7a85dbb2 | 1138 | (laser1_pos.y <= _brick36_pos.y + BRICK_HEIGHT) //top |
| jamesheavey | 32:4dba7a85dbb2 | 1139 | ) { // 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 | 1140 | // if it has, fix position and reflect x velocity |
| jamesheavey | 32:4dba7a85dbb2 | 1141 | laser1_pos.x = -10; |
| jamesheavey | 32:4dba7a85dbb2 | 1142 | // audio feedback |
| jamesheavey | 32:4dba7a85dbb2 | 1143 | pad.tone(1000.0,0.1); |
| jamesheavey | 33:e47f6fa1d9ce | 1144 | //if(_brick36.hit() == true) { |
| jamesheavey | 32:4dba7a85dbb2 | 1145 | _brick36_pos.x = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 1146 | _brick36_pos.y = -100; |
| jamesheavey | 32:4dba7a85dbb2 | 1147 | _brick36.set_pos(_brick11_pos); |
| jamesheavey | 32:4dba7a85dbb2 | 1148 | one_less(); |
| jamesheavey | 33:e47f6fa1d9ce | 1149 | //} |
| jamesheavey | 32:4dba7a85dbb2 | 1150 | } |
| jamesheavey | 32:4dba7a85dbb2 | 1151 | |
| jamesheavey | 32:4dba7a85dbb2 | 1152 | // write new attributes |
| jamesheavey | 32:4dba7a85dbb2 | 1153 | _laser1.set_pos(laser1_pos); |
| jamesheavey | 32:4dba7a85dbb2 | 1154 | } |
| jamesheavey | 33:e47f6fa1d9ce | 1155 | |
| jamesheavey | 27:1b5038b0a7a2 | 1156 | bool BreakoutEngine::check_goal(Gamepad &pad) |
| jamesheavey | 27:1b5038b0a7a2 | 1157 | { |
| jamesheavey | 27:1b5038b0a7a2 | 1158 | Vector2D ball_pos = _ball.get_pos(); |
| jamesheavey | 27:1b5038b0a7a2 | 1159 | // P1 has scored |
| jamesheavey | 27:1b5038b0a7a2 | 1160 | if (ball_pos.y > HEIGHT) { |
| jamesheavey | 27:1b5038b0a7a2 | 1161 | _p1.lose_life(); |
| jamesheavey | 27:1b5038b0a7a2 | 1162 | //lose_screen(); // go to loss screen then initialise again |
| jamesheavey | 27:1b5038b0a7a2 | 1163 | |
| jamesheavey | 27:1b5038b0a7a2 | 1164 | _ball.init(_ball_size,_speed); |
| jamesheavey | 27:1b5038b0a7a2 | 1165 | pad.tone(1500.0,0.5); |
| jamesheavey | 27:1b5038b0a7a2 | 1166 | return true; |
| jamesheavey | 27:1b5038b0a7a2 | 1167 | } |
| jamesheavey | 27:1b5038b0a7a2 | 1168 | else { |
| jamesheavey | 27:1b5038b0a7a2 | 1169 | return false; |
| jamesheavey | 27:1b5038b0a7a2 | 1170 | } |
| jamesheavey | 27:1b5038b0a7a2 | 1171 | } |
| jamesheavey | 27:1b5038b0a7a2 | 1172 | |
| jamesheavey | 27:1b5038b0a7a2 | 1173 | //void flash_backlight (N5110 &lcd) { |
| jamesheavey | 27:1b5038b0a7a2 | 1174 | // lcd.setBrightness(0); |
| jamesheavey | 27:1b5038b0a7a2 | 1175 | // wait(0.1); |
| jamesheavey | 27:1b5038b0a7a2 | 1176 | // lcd.setBrightness(1); |
| jamesheavey | 27:1b5038b0a7a2 | 1177 | // wait(0.1); |
| jamesheavey | 27:1b5038b0a7a2 | 1178 | // lcd.setBrightness(0); |
| jamesheavey | 27:1b5038b0a7a2 | 1179 | // wait(0.1); |
| jamesheavey | 27:1b5038b0a7a2 | 1180 | // lcd.setBrightness(1); |
| jamesheavey | 27:1b5038b0a7a2 | 1181 | // wait(0.1); |
| jamesheavey | 27:1b5038b0a7a2 | 1182 | // lcd.setBrightness(0); |
| jamesheavey | 27:1b5038b0a7a2 | 1183 | // wait(0.1); |
| jamesheavey | 27:1b5038b0a7a2 | 1184 | // lcd.setBrightness(1); |
| jamesheavey | 27:1b5038b0a7a2 | 1185 | // wait(0.1); |
| jamesheavey | 27:1b5038b0a7a2 | 1186 | // lcd.setBrightness(0); |
| jamesheavey | 27:1b5038b0a7a2 | 1187 | // wait(0.1); |
| jamesheavey | 27:1b5038b0a7a2 | 1188 | // lcd.setBrightness(1); |
| jamesheavey | 27:1b5038b0a7a2 | 1189 | //} |
| jamesheavey | 27:1b5038b0a7a2 | 1190 | |
| jamesheavey | 27:1b5038b0a7a2 | 1191 | |
| jamesheavey | 32:4dba7a85dbb2 | 1192 | |
| jamesheavey | 27:1b5038b0a7a2 | 1193 | void BreakoutEngine::print_scores(N5110 &lcd) |
| jamesheavey | 27:1b5038b0a7a2 | 1194 | { |
| jamesheavey | 27:1b5038b0a7a2 | 1195 | // get scores from paddles |
| jamesheavey | 27:1b5038b0a7a2 | 1196 | int p1_score = _p1.get_lives(); |
| jamesheavey | 27:1b5038b0a7a2 | 1197 | |
| jamesheavey | 27:1b5038b0a7a2 | 1198 | // print to LCD i |
| jamesheavey | 27:1b5038b0a7a2 | 1199 | char buffer1[14]; |
| jamesheavey | 27:1b5038b0a7a2 | 1200 | sprintf(buffer1,"%2d",p1_score); |
| jamesheavey | 27:1b5038b0a7a2 | 1201 | lcd.printString(buffer1,WIDTH/2 -8,4); // font is 8 wide, so leave 4 pixel gape from middle assuming two digits |
| jamesheavey | 27:1b5038b0a7a2 | 1202 | } |
| jamesheavey | 27:1b5038b0a7a2 | 1203 | |
| jamesheavey | 27:1b5038b0a7a2 | 1204 | int BreakoutEngine::get_num_left(){ |
| jamesheavey | 27:1b5038b0a7a2 | 1205 | return _number_left; |
| jamesheavey | 27:1b5038b0a7a2 | 1206 | } |
| jamesheavey | 27:1b5038b0a7a2 | 1207 | void BreakoutEngine::one_less() { |
| jamesheavey | 27:1b5038b0a7a2 | 1208 | _number_left -= 1; |
| jamesheavey | 27:1b5038b0a7a2 | 1209 | } |