bouncing_ball backend
Fork of bouncing_ball by
bouncing_ball.h@1:0aa572c0f2b1, 2017-10-24 (annotated)
- Committer:
- slicht
- Date:
- Tue Oct 24 12:33:39 2017 +0000
- Revision:
- 1:0aa572c0f2b1
- Parent:
- 0:aff81f4c72f3
- Child:
- 2:ba1844b0eb9f
Compiles and runs with physics moved entirely to bouncing_ball object. Creates large, unmoving ball in center.
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 | |
slicht | 0:aff81f4c72f3 | 5 | #include "mbed.h" |
slicht | 0:aff81f4c72f3 | 6 | |
slicht | 0:aff81f4c72f3 | 7 | #ifndef bouncing_ball_H |
slicht | 1:0aa572c0f2b1 | 8 | #define bouncing_ball_H //in case any other library wishes to check for presence of this library (see example below) |
slicht | 1:0aa572c0f2b1 | 9 | #include "MMA8452Q.h" //includes our new accelerometer library definitions |
slicht | 0:aff81f4c72f3 | 10 | |
slicht | 1:0aa572c0f2b1 | 11 | #define DEFAULT_WIDTH 126 |
slicht | 1:0aa572c0f2b1 | 12 | #define DEFAULT_HEIGHT 126 |
slicht | 1:0aa572c0f2b1 | 13 | #define DEFAULT_SPEEDX 0 |
slicht | 1:0aa572c0f2b1 | 14 | #define DEFAULT_SPEEDY 0 |
slicht | 1:0aa572c0f2b1 | 15 | #define DEFAULT_POSX 64 |
slicht | 1:0aa572c0f2b1 | 16 | #define DEFAULT_POSY 64 |
slicht | 1:0aa572c0f2b1 | 17 | #define DEFAULT_COLOR 0 |
slicht | 1:0aa572c0f2b1 | 18 | #define DEFAULT_RADIUS 10 |
slicht | 0:aff81f4c72f3 | 19 | |
slicht | 0:aff81f4c72f3 | 20 | // Class declaration |
slicht | 0:aff81f4c72f3 | 21 | class physics_ball |
slicht | 0:aff81f4c72f3 | 22 | { |
slicht | 0:aff81f4c72f3 | 23 | public: |
slicht | 0:aff81f4c72f3 | 24 | physics_ball(int color, int radius); |
slicht | 0:aff81f4c72f3 | 25 | ~physics_ball(); |
slicht | 0:aff81f4c72f3 | 26 | |
slicht | 0:aff81f4c72f3 | 27 | float speedx; |
slicht | 0:aff81f4c72f3 | 28 | float speedy; |
slicht | 0:aff81f4c72f3 | 29 | int posx; |
slicht | 0:aff81f4c72f3 | 30 | int posy; |
slicht | 1:0aa572c0f2b1 | 31 | int color; |
slicht | 1:0aa572c0f2b1 | 32 | int radius; |
slicht | 1:0aa572c0f2b1 | 33 | |
slicht | 0:aff81f4c72f3 | 34 | void update(float time_step, MMA8452Q accelerometer); |
slicht | 0:aff81f4c72f3 | 35 | void define_space(int width, int height); |
slicht | 0:aff81f4c72f3 | 36 | void set_param(int radius, int color); |
slicht | 0:aff81f4c72f3 | 37 | void set_state(int x, int y, float vx, float vy); |
slicht | 0:aff81f4c72f3 | 38 | |
slicht | 0:aff81f4c72f3 | 39 | private: |
slicht | 0:aff81f4c72f3 | 40 | |
slicht | 1:0aa572c0f2b1 | 41 | int space_width; |
slicht | 1:0aa572c0f2b1 | 42 | int space_height; |
slicht | 0:aff81f4c72f3 | 43 | }; |
slicht | 0:aff81f4c72f3 | 44 | |
slicht | 1:0aa572c0f2b1 | 45 | #endif //bouncing_ball_H |
slicht | 0:aff81f4c72f3 | 46 | |
slicht | 0:aff81f4c72f3 | 47 |