bouncing_ball backend
Fork of bouncing_ball by
bouncing_ball.h@6:68a764001a73, 2017-11-09 (annotated)
- Committer:
- Eric_Rupert
- Date:
- Thu Nov 09 14:37:44 2017 +0000
- Revision:
- 6:68a764001a73
- Parent:
- 5:17aa521aaa2f
Added header comment. Includes bug fixes (moves ball off wall after bounce and reset_upside_down is public)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
slicht | 1:0aa572c0f2b1 | 1 | // Bouncing ball is a library adding physics based ball bouncing to the Sparkfun Experiment 3/4 rolling ball demo. |
slicht | 1:0aa572c0f2b1 | 2 | // Example Code |
slicht | 1:0aa572c0f2b1 | 3 | // 10/19/2017 Stephen Licht |
slicht | 0:aff81f4c72f3 | 4 | |
Eric_Rupert | 5:17aa521aaa2f | 5 | /* |
Eric_Rupert | 5:17aa521aaa2f | 6 | Modified by Eric Rupert, 11/7/2017-11/9/2017 |
Eric_Rupert | 6:68a764001a73 | 7 | |
Eric_Rupert | 5:17aa521aaa2f | 8 | */ |
Eric_Rupert | 5:17aa521aaa2f | 9 | |
slicht | 0:aff81f4c72f3 | 10 | #include "mbed.h" |
slicht | 0:aff81f4c72f3 | 11 | |
slicht | 0:aff81f4c72f3 | 12 | #ifndef bouncing_ball_H |
slicht | 1:0aa572c0f2b1 | 13 | #define bouncing_ball_H //in case any other library wishes to check for presence of this library (see example below) |
slicht | 1:0aa572c0f2b1 | 14 | #include "MMA8452Q.h" //includes our new accelerometer library definitions |
slicht | 0:aff81f4c72f3 | 15 | |
slicht | 2:ba1844b0eb9f | 16 | #define DEFAULT_WIDTH 128 |
slicht | 2:ba1844b0eb9f | 17 | #define DEFAULT_HEIGHT 128 |
slicht | 1:0aa572c0f2b1 | 18 | #define DEFAULT_SPEEDX 0 |
slicht | 1:0aa572c0f2b1 | 19 | #define DEFAULT_SPEEDY 0 |
slicht | 1:0aa572c0f2b1 | 20 | #define DEFAULT_POSX 64 |
slicht | 1:0aa572c0f2b1 | 21 | #define DEFAULT_POSY 64 |
slicht | 1:0aa572c0f2b1 | 22 | #define DEFAULT_COLOR 0 |
slicht | 1:0aa572c0f2b1 | 23 | #define DEFAULT_RADIUS 10 |
slicht | 2:ba1844b0eb9f | 24 | #define GRAVITY 9.8 |
slicht | 0:aff81f4c72f3 | 25 | |
slicht | 0:aff81f4c72f3 | 26 | // Class declaration |
slicht | 0:aff81f4c72f3 | 27 | class physics_ball |
slicht | 0:aff81f4c72f3 | 28 | { |
slicht | 0:aff81f4c72f3 | 29 | public: |
slicht | 2:ba1844b0eb9f | 30 | physics_ball(); |
slicht | 0:aff81f4c72f3 | 31 | ~physics_ball(); |
slicht | 0:aff81f4c72f3 | 32 | |
slicht | 0:aff81f4c72f3 | 33 | float speedx; |
slicht | 0:aff81f4c72f3 | 34 | float speedy; |
slicht | 0:aff81f4c72f3 | 35 | int posx; |
slicht | 0:aff81f4c72f3 | 36 | int posy; |
slicht | 1:0aa572c0f2b1 | 37 | int color; |
slicht | 1:0aa572c0f2b1 | 38 | int radius; |
slicht | 1:0aa572c0f2b1 | 39 | |
slicht | 2:ba1844b0eb9f | 40 | void update(float time_step, MMA8452Q &accelerometer); |
slicht | 2:ba1844b0eb9f | 41 | void define_space(int desired_width, int desired_height); |
slicht | 2:ba1844b0eb9f | 42 | void set_param(int desired_radius, int desired_color); |
slicht | 2:ba1844b0eb9f | 43 | void set_state(int desired_x, int desired_y, float desired_vx, float desired_vy); |
Eric_Rupert | 4:73a00b0667fc | 44 | void reset_upside_down(); |
slicht | 0:aff81f4c72f3 | 45 | |
slicht | 0:aff81f4c72f3 | 46 | private: |
slicht | 0:aff81f4c72f3 | 47 | |
slicht | 2:ba1844b0eb9f | 48 | int _width; |
slicht | 2:ba1844b0eb9f | 49 | int _height; |
slicht | 2:ba1844b0eb9f | 50 | int _upside_down_status; |
slicht | 2:ba1844b0eb9f | 51 | float _posx_f; |
slicht | 2:ba1844b0eb9f | 52 | float _posy_f; |
slicht | 2:ba1844b0eb9f | 53 | |
Eric_Rupert | 4:73a00b0667fc | 54 | |
slicht | 0:aff81f4c72f3 | 55 | }; |
slicht | 0:aff81f4c72f3 | 56 | |
slicht | 1:0aa572c0f2b1 | 57 | #endif //bouncing_ball_H |
slicht | 0:aff81f4c72f3 | 58 | |
slicht | 0:aff81f4c72f3 | 59 |