Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- testApp.h:
- #ifndef _TEST_APP
- #define _TEST_APP
- #include "ofMain.h"
- #include "ofBall.h"
- class testApp : public ofBaseApp{
- public:
- void setup();
- void update();
- void draw();
- private:
- ofBall** myBall;
- int nBalls;
- };
- #endif
- testApp.cpp
- #include "testApp.h"
- //--------------------------------------------------------------
- void testApp::setup(){
- ofBackground(255);
- ofSetFrameRate(30);
- ofSetWindowTitle("balls - class example_4");
- ofEnableSmoothing();
- ofNoFill();
- nBalls = 1;
- myBall = new ofBall*[nBalls];
- for (int i = 0; i < nBalls; i++){
- float x = 20+(100*i);
- float y = 20+(100*i);
- int dim = 10+(i*10);
- ofLog() << "posx " << x;
- myBall[i] = new ofBall(x,y, dim);
- }
- }
- //--------------------------------------------------------------
- void testApp::update(){
- for (int i = 0; i < nBalls; i++){
- myBall[i]->update();
- }
- }
- //--------------------------------------------------------------
- void testApp::draw(){
- for (int i = 0; i < nBalls; i++){
- myBall[i]->draw();
- }
- }
- ofBall.h:
- #ifndef _OF_BALL // by using this if statement you prevent the class to be called more than once - in other words what we're saying here is
- #define _OF_BALL //if the class has NOT been defined then define it
- #include "ofMain.h"
- class ofBall {
- public:
- // methods
- void update();
- void draw();
- //constructor
- ofBall(float x, float y, int dim);
- // variables
- ofRectangle blackSnap;
- float x;
- float y;
- int dim;
- private:
- }; //don't forget the semicolon in the end of the class definition
- #endif
- ofBall.cpp:
- #include "ofBall.h"
- ofBall::ofBall(float _x, float _y, int _dim)
- {
- x = _x;
- y = _y;
- dim = _dim;
- }
- void ofBall::update(){
- x++;
- y++;
- }
- void ofBall::draw(){
- ofSetColor(120,120,120);
- ofCircle(x, y, dim);
- ofRect(x,y,100,200);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement