#include "testApp.h"

//--------------------------------------------------------------
void testApp::setup(){   
   ofBackground(0, 0, 0);
      
   ofSetFrameRate(30);   
   ofSetWindowTitle("simple bouncing ball");
      
   ofEnableSmoothing();
   ofNoFill();
   ofSetColor(0x00AEEF);
   
   speedX = ofRandom(-5, 5);
   speedY = ofRandom(-5, 5);
   
   x = ofGetWidth()/2;
   y = ofGetHeight()/2;
   
   ballA = new ofBall();
}

//--------------------------------------------------------------
void testApp::update(){
   x += speedX;
   y += speedY;
   
   if(x < 0 ){
      x = 0;
      speedX *= -1;
   }else if( x > ofGetWidth() ){
      x = ofGetWidth();
      speedX *= -1;
   }
   
   if(y < 0 ){
      y = 0;
      speedY *= -1;
   }else if( y > ofGetHeight() ){
      y = ofGetHeight();
      speedY *= -1;
   }

   ballA->update();
   
}

//--------------------------------------------------------------
void testApp::draw(){
   ofCircle(x, y, 20);
   string pos = ofToString(x, 0) + ", " + ofToString(y, 0) ;
   ofDrawBitmapString(pos, x-30,y+40);
   ballA->draw();
}
