Kaitlyn Barros / physics_ball

Dependents:   Barros_Assignment4

physics_ball.cpp

Committer:
Kaitlyn_Barros
Date:
2017-10-31
Revision:
1:a2dda7baafaa
Parent:
0:9591bae8d04c
Child:
2:6ba843cde0bb

File content as of revision 1:a2dda7baafaa:

#include "physics_ball.h"

//Constructor
physics_ball::physics_ball(){
    posx = 0;
    posy = 0;
    
    speedx = 25;
    speedy = 25;
    
    radius = 10;
    color = 1;
    
    width = 128;
    height = 128;
    }
    
void physics_ball::set_param(int radius_in, int color_in)
 {
    radius = radius_in; 
    color = color_in;
    }   

void physics_ball::define_space( int width_in, int height_in)
{
    width = width_in;
    height = height_in;
    }

void physics_ball::set_state(int x_in, int y_in, float speedx_in, float speedy_in)
{
    posx = x_in;
    posy = y_in;
    
    speedx = speedx_in;
    speedy = speedy_in;
    }
    
void physics_ball::update( float time_step_in , MMA8452Q & accel)
{
    time_step = time_step_in;
  
        posx = posx - (speedx * accel.readY());
        posy = posy - (speedy * accel.readX());
        
        //Ball  Physics 
        if ((posx <= radius) || (posx >= 128-radius)){
        speedx = -1 * speedx;
         }
        if ((radius < posx) && (posx < 128- radius)){
             speedx = speedx;
             }
        if ((posy <= radius) || (posy >= 128-radius)) {
         speedy = -1 * speedy;
        }       
              }