Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: 4DGL-uLCD-SE mbed wave_player
Fork of MazeRunner_Fall2017-shell by
Diff: wall.cpp
- Revision:
- 1:2c6ae0fe9a2a
- Parent:
- 0:cf4396614a79
diff -r cf4396614a79 -r 2c6ae0fe9a2a wall.cpp --- a/wall.cpp Fri Nov 03 18:48:48 2017 +0000 +++ b/wall.cpp Fri Dec 29 15:32:31 2017 +0000 @@ -5,6 +5,8 @@ #include "game.h" #include "math_extra.h" +#include <math.h> + Wall* create_wall(int direction, int x, int y, int length, float bounce) { // Alocate memory for wall @@ -25,11 +27,11 @@ return wall; } -void do_wall(Physics* next, const Physics* curr, Wall* wall, float delta) +int do_wall(Physics* next, const Physics* curr, Wall* wall, float delta) { // Debug info // pc.printf("wall: %d %d %d %d\r\n", wall->direction, wall->x, wall->y, wall->length); - + int hit = 0; float adj, percent, contact; if (wall->direction == VERTICAL) @@ -56,6 +58,8 @@ // This dampens the integration based on how far the ball had // to travel before reflecting. next->px = adj - percent*next->vx*delta; + if (fabs(curr->vx) > 5) + hit = 1; } // Draw the wall if we're close by wall->should_draw = 1; @@ -81,9 +85,13 @@ { next->vy = -wall->bounce*curr->vy; next->py = adj - percent*next->vy*delta; + if (fabs(curr->vy) > 5) + hit = 1; + } // Draw the wall if we bounce wall->should_draw = 1; + } if (in_range((int)curr->py, wall->y - (radius+1), wall->y + (radius+1)) && in_range((int)curr->px, wall->x, wall->x + wall->length)) @@ -92,6 +100,7 @@ wall->should_draw = 1; } } + return hit; } void draw_wall(Wall* wall)