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.
Dependents: Barros_Assignment4
physics_ball.cpp@0:9591bae8d04c, 2017-10-31 (annotated)
- Committer:
- Kaitlyn_Barros
- Date:
- Tue Oct 31 12:59:49 2017 +0000
- Revision:
- 0:9591bae8d04c
- Child:
- 1:a2dda7baafaa
OCE 360 Assignment #4
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Kaitlyn_Barros | 0:9591bae8d04c | 1 | #include "physics_ball.h" |
| Kaitlyn_Barros | 0:9591bae8d04c | 2 | |
| Kaitlyn_Barros | 0:9591bae8d04c | 3 | //Constructor |
| Kaitlyn_Barros | 0:9591bae8d04c | 4 | physics_ball::physics_ball(){ |
| Kaitlyn_Barros | 0:9591bae8d04c | 5 | posx = 0; |
| Kaitlyn_Barros | 0:9591bae8d04c | 6 | posy = 0; |
| Kaitlyn_Barros | 0:9591bae8d04c | 7 | |
| Kaitlyn_Barros | 0:9591bae8d04c | 8 | speedx = 25; |
| Kaitlyn_Barros | 0:9591bae8d04c | 9 | speedy = 25; |
| Kaitlyn_Barros | 0:9591bae8d04c | 10 | |
| Kaitlyn_Barros | 0:9591bae8d04c | 11 | radius = 10; |
| Kaitlyn_Barros | 0:9591bae8d04c | 12 | color = 1; |
| Kaitlyn_Barros | 0:9591bae8d04c | 13 | |
| Kaitlyn_Barros | 0:9591bae8d04c | 14 | width = 128; |
| Kaitlyn_Barros | 0:9591bae8d04c | 15 | height = 128; |
| Kaitlyn_Barros | 0:9591bae8d04c | 16 | } |
| Kaitlyn_Barros | 0:9591bae8d04c | 17 | |
| Kaitlyn_Barros | 0:9591bae8d04c | 18 | void physics_ball::set_param(int radius_in, int color_in) |
| Kaitlyn_Barros | 0:9591bae8d04c | 19 | { |
| Kaitlyn_Barros | 0:9591bae8d04c | 20 | radius = radius_in; |
| Kaitlyn_Barros | 0:9591bae8d04c | 21 | color = color_in; |
| Kaitlyn_Barros | 0:9591bae8d04c | 22 | } |
| Kaitlyn_Barros | 0:9591bae8d04c | 23 | |
| Kaitlyn_Barros | 0:9591bae8d04c | 24 | void physics_ball::define_space( int width_in, int height_in) |
| Kaitlyn_Barros | 0:9591bae8d04c | 25 | { |
| Kaitlyn_Barros | 0:9591bae8d04c | 26 | width = width_in; |
| Kaitlyn_Barros | 0:9591bae8d04c | 27 | height = height_in; |
| Kaitlyn_Barros | 0:9591bae8d04c | 28 | } |
| Kaitlyn_Barros | 0:9591bae8d04c | 29 | |
| Kaitlyn_Barros | 0:9591bae8d04c | 30 | void physics_ball::set_state(int x_in, int y_in, float speedx_in, float speedy_in) |
| Kaitlyn_Barros | 0:9591bae8d04c | 31 | { |
| Kaitlyn_Barros | 0:9591bae8d04c | 32 | posx = x_in; |
| Kaitlyn_Barros | 0:9591bae8d04c | 33 | posy = y_in; |
| Kaitlyn_Barros | 0:9591bae8d04c | 34 | |
| Kaitlyn_Barros | 0:9591bae8d04c | 35 | speedx = speedx_in; |
| Kaitlyn_Barros | 0:9591bae8d04c | 36 | speedy = speedy_in; |
| Kaitlyn_Barros | 0:9591bae8d04c | 37 | } |
| Kaitlyn_Barros | 0:9591bae8d04c | 38 | |
| Kaitlyn_Barros | 0:9591bae8d04c | 39 | void physics_ball::update( float time_step_in , int posx, int posy, int speedx, int speedy, MMA8452Q & accel) |
| Kaitlyn_Barros | 0:9591bae8d04c | 40 | { |
| Kaitlyn_Barros | 0:9591bae8d04c | 41 | time_step = time_step_in; |
| Kaitlyn_Barros | 0:9591bae8d04c | 42 | |
| Kaitlyn_Barros | 0:9591bae8d04c | 43 | posx = posx - (speedx * accel.readY()); |
| Kaitlyn_Barros | 0:9591bae8d04c | 44 | posy = posy - (speedy * accel.readX()); |
| Kaitlyn_Barros | 0:9591bae8d04c | 45 | |
| Kaitlyn_Barros | 0:9591bae8d04c | 46 | //Ball 1 Physics |
| Kaitlyn_Barros | 0:9591bae8d04c | 47 | if ((posx <= radius) || (posx >= 128-radius)){ |
| Kaitlyn_Barros | 0:9591bae8d04c | 48 | speedx = -1 * speedx; |
| Kaitlyn_Barros | 0:9591bae8d04c | 49 | } |
| Kaitlyn_Barros | 0:9591bae8d04c | 50 | if ((radius < posx) && (posx < 128- radius)){ |
| Kaitlyn_Barros | 0:9591bae8d04c | 51 | speedx = speedx; |
| Kaitlyn_Barros | 0:9591bae8d04c | 52 | } |
| Kaitlyn_Barros | 0:9591bae8d04c | 53 | if ((posy <= radius) || (posy >= 128-radius)) { |
| Kaitlyn_Barros | 0:9591bae8d04c | 54 | speedy = -1 * speedy; |
| Kaitlyn_Barros | 0:9591bae8d04c | 55 | } |
| Kaitlyn_Barros | 0:9591bae8d04c | 56 | } |
| Kaitlyn_Barros | 0:9591bae8d04c | 57 | |
| Kaitlyn_Barros | 0:9591bae8d04c | 58 |
