| | @@ -3,7 +3,7 @@ |
| 3 | 3 | #include "player.hh" |
| 4 | 4 | #include "brick.hh" |
| 5 | 5 | |
| 6 | | -#define PI 3.14 |
| 6 | +#define DEBUG false |
| 7 | 7 | |
| 8 | 8 | void Render::gameOver(Player &p, Brick &br, bool winner) { |
| 9 | 9 | if (winner) { |
| | @@ -41,10 +41,16 @@ |
| 41 | 41 | if (SDL_HasIntersection(&bl.ball, &p.player)) { |
| 42 | 42 | double rel = (p.player.x + ((float)p.player.w/2)) - ((float)bl.ball.x + ((float)bl.size/2)); |
| 43 | 43 | double norm = rel / ((float)p.player.w/2); |
| 44 | | - double bounce = norm * (5*PI/12); |
| 44 | + double bounce = norm * (5 * M_PI / 12); |
| 45 | + if (fabs(bounce - bounceSave) <= .04) bounce += .4; |
| 45 | 46 | |
| 46 | 47 | bl.yvelocity = -bl.ballspeed * cos(bounce); |
| 47 | 48 | bl.xvelocity = bl.ballspeed * -sin(bounce); |
| 49 | + |
| 50 | + if (bl.yvelocity == bl.yvelSave || -bl.yvelocity == bl.yvelSave) bl.xvelocity += .4f; |
| 51 | + bl.yvelSave = bl.yvelocity; |
| 52 | + |
| 53 | + bounceSave = bounce; |
| 48 | 54 | p.scoreMultiplier = 1; |
| 49 | 55 | } |
| 50 | 56 | |
| | @@ -58,9 +64,12 @@ |
| 58 | 64 | } |
| 59 | 65 | if (bl.ball.x <= 0 || bl.ball.x + bl.size >= Render::width) { |
| 60 | 66 | bl.xvelocity = -bl.xvelocity; |
| 67 | + if (bl.xvelocity == bl.xvelSave || -bl.xvelocity == bl.xvelSave) bl.yvelocity += .4f; |
| 68 | + bl.xvelSave = bl.xvelocity; |
| 61 | 69 | } |
| 62 | 70 | bl.ball.x += bl.xvelocity; |
| 63 | 71 | bl.ball.y += bl.yvelocity; |
| 72 | + |
| 64 | 73 | if (p.player.x < 0) { |
| 65 | 74 | p.player.x = 0; |
| 66 | 75 | } |
| | @@ -112,7 +121,7 @@ |
| 112 | 121 | } |
| 113 | 122 | } |
| 114 | 123 | |
| 115 | | -void Render::input(Player &p) { |
| 124 | +void Render::input(Render &r, Player &p, Ball &bl, Brick &br) { |
| 116 | 125 | SDL_Event e; |
| 117 | 126 | const Uint8 *keystates = SDL_GetKeyboardState(NULL); |
| 118 | 127 | |
| | @@ -123,6 +132,56 @@ |
| 123 | 132 | } |
| 124 | 133 | |
| 125 | 134 | if (keystates[SDL_SCANCODE_Q]) Render::running = false; |
| 135 | +#if DEBUG |
| 136 | + if (keystates[SDL_SCANCODE_E]) p.livesCount = 3; |
| 137 | + if (keystates[SDL_SCANCODE_R]) { |
| 138 | + if (level <= 7) { |
| 139 | + br.resetBricks(r, p, bl); |
| 140 | + bl.resetBall(r, p); |
| 141 | + gameover = false; |
| 142 | + } |
| 143 | + } |
| 144 | + if (keystates[SDL_SCANCODE_O]) { |
| 145 | + bl.ball.x = 250.f; |
| 146 | + bl.ball.y = 400.f; |
| 147 | + bl.xvelocity = 0.f; |
| 148 | + bl.yvelocity = 8.f; |
| 149 | + } |
| 150 | + if (keystates[SDL_SCANCODE_P]) { |
| 151 | + bl.ball.x = 250.f; |
| 152 | + bl.ball.y = 400.f; |
| 153 | + bl.xvelocity = 8.f; |
| 154 | + bl.yvelocity = 0.f; |
| 155 | + } |
| 156 | + if (keystates[SDL_SCANCODE_1]) { |
| 157 | + Render::level = 1; |
| 158 | + br.resetBricks(r, p, bl); |
| 159 | + } |
| 160 | + if (keystates[SDL_SCANCODE_2]) { |
| 161 | + Render::level = 2; |
| 162 | + br.resetBricks(r, p, bl); |
| 163 | + } |
| 164 | + if (keystates[SDL_SCANCODE_3]) { |
| 165 | + Render::level = 3; |
| 166 | + br.resetBricks(r, p, bl); |
| 167 | + } |
| 168 | + if (keystates[SDL_SCANCODE_4]) { |
| 169 | + Render::level = 4; |
| 170 | + br.resetBricks(r, p, bl); |
| 171 | + } |
| 172 | + if (keystates[SDL_SCANCODE_5]) { |
| 173 | + Render::level = 5; |
| 174 | + br.resetBricks(r, p, bl); |
| 175 | + } |
| 176 | + if (keystates[SDL_SCANCODE_6]) { |
| 177 | + Render::level = 6; |
| 178 | + br.resetBricks(r, p, bl); |
| 179 | + } |
| 180 | + if (keystates[SDL_SCANCODE_7]) { |
| 181 | + Render::level = 7; |
| 182 | + br.resetBricks(r, p, bl); |
| 183 | + } |
| 184 | +#endif |
| 126 | 185 | if (!Render::gameover) { |
| 127 | 186 | if (keystates[SDL_SCANCODE_LEFT]) p.player.x -= Render::xpos; |
| 128 | 187 | if (keystates[SDL_SCANCODE_RIGHT]) p.player.x += Render::xpos; |