bouncing_ball backend

Fork of bouncing_ball by Stephen Licht

Committer:
Eric_Rupert
Date:
Thu Nov 09 14:26:55 2017 +0000
Revision:
4:73a00b0667fc
Parent:
2:ba1844b0eb9f
Child:
5:17aa521aaa2f
1) _reset_upside_down (private)->reset_upside_down(public) (no longer called from within bouncing_ball) 2) move ball off wall due to bounce. 1 solves color problem and 2 solves disappearing and stuck ball.

Who changed what in which revision?

UserRevisionLine numberNew 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 2:ba1844b0eb9f 11 #define DEFAULT_WIDTH 128
slicht 2:ba1844b0eb9f 12 #define DEFAULT_HEIGHT 128
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 2:ba1844b0eb9f 19 #define GRAVITY 9.8
slicht 0:aff81f4c72f3 20
slicht 0:aff81f4c72f3 21 // Class declaration
slicht 0:aff81f4c72f3 22 class physics_ball
slicht 0:aff81f4c72f3 23 {
slicht 0:aff81f4c72f3 24 public:
slicht 2:ba1844b0eb9f 25 physics_ball();
slicht 0:aff81f4c72f3 26 ~physics_ball();
slicht 0:aff81f4c72f3 27
slicht 0:aff81f4c72f3 28 float speedx;
slicht 0:aff81f4c72f3 29 float speedy;
slicht 0:aff81f4c72f3 30 int posx;
slicht 0:aff81f4c72f3 31 int posy;
slicht 1:0aa572c0f2b1 32 int color;
slicht 1:0aa572c0f2b1 33 int radius;
slicht 1:0aa572c0f2b1 34
slicht 2:ba1844b0eb9f 35 void update(float time_step, MMA8452Q &accelerometer);
slicht 2:ba1844b0eb9f 36 void define_space(int desired_width, int desired_height);
slicht 2:ba1844b0eb9f 37 void set_param(int desired_radius, int desired_color);
slicht 2:ba1844b0eb9f 38 void set_state(int desired_x, int desired_y, float desired_vx, float desired_vy);
Eric_Rupert 4:73a00b0667fc 39 void reset_upside_down();
slicht 0:aff81f4c72f3 40
slicht 0:aff81f4c72f3 41 private:
slicht 0:aff81f4c72f3 42
slicht 2:ba1844b0eb9f 43 int _width;
slicht 2:ba1844b0eb9f 44 int _height;
slicht 2:ba1844b0eb9f 45 int _upside_down_status;
slicht 2:ba1844b0eb9f 46 float _posx_f;
slicht 2:ba1844b0eb9f 47 float _posy_f;
slicht 2:ba1844b0eb9f 48
Eric_Rupert 4:73a00b0667fc 49
slicht 0:aff81f4c72f3 50 };
slicht 0:aff81f4c72f3 51
slicht 1:0aa572c0f2b1 52 #endif //bouncing_ball_H
slicht 0:aff81f4c72f3 53
slicht 0:aff81f4c72f3 54