Advertisement
Guest User

Untitled

a guest
Mar 31st, 2014
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1. testApp.h:
  2.  
  3. #ifndef _TEST_APP
  4. #define _TEST_APP
  5.  
  6. #include "ofMain.h"
  7. #include "ofBall.h"
  8.  
  9. class testApp : public ofBaseApp{
  10.  
  11. public:
  12.  
  13. void setup();
  14. void update();
  15. void draw();
  16.  
  17.  
  18.  
  19. private:
  20.  
  21. ofBall** myBall;
  22. int nBalls;
  23.  
  24.  
  25. };
  26.  
  27. #endif
  28.  
  29.  
  30.  
  31. testApp.cpp
  32.  
  33.  
  34. #include "testApp.h"
  35.  
  36.  
  37.  
  38. //--------------------------------------------------------------
  39. void testApp::setup(){
  40.  
  41. ofBackground(255);
  42. ofSetFrameRate(30);
  43. ofSetWindowTitle("balls - class example_4");
  44.  
  45. ofEnableSmoothing();
  46. ofNoFill();
  47.  
  48. nBalls = 1;
  49. myBall = new ofBall*[nBalls];
  50. for (int i = 0; i < nBalls; i++){
  51. float x = 20+(100*i);
  52. float y = 20+(100*i);
  53. int dim = 10+(i*10);
  54. ofLog() << "posx " << x;
  55. myBall[i] = new ofBall(x,y, dim);
  56.  
  57. }
  58.  
  59. }
  60.  
  61. //--------------------------------------------------------------
  62. void testApp::update(){
  63.  
  64. for (int i = 0; i < nBalls; i++){
  65. myBall[i]->update();
  66. }
  67.  
  68.  
  69. }
  70.  
  71. //--------------------------------------------------------------
  72. void testApp::draw(){
  73.  
  74. for (int i = 0; i < nBalls; i++){
  75. myBall[i]->draw();
  76. }
  77.  
  78.  
  79. }
  80.  
  81.  
  82. ofBall.h:
  83.  
  84.  
  85.  
  86. #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
  87. #define _OF_BALL //if the class has NOT been defined then define it
  88.  
  89.  
  90. #include "ofMain.h"
  91.  
  92.  
  93. class ofBall {
  94.  
  95.  
  96.  
  97. public:
  98.  
  99. // methods
  100. void update();
  101. void draw();
  102.  
  103. //constructor
  104. ofBall(float x, float y, int dim);
  105.  
  106. // variables
  107. ofRectangle blackSnap;
  108. float x;
  109. float y;
  110. int dim;
  111.  
  112.  
  113. private:
  114.  
  115.  
  116. }; //don't forget the semicolon in the end of the class definition
  117.  
  118. #endif
  119.  
  120.  
  121. ofBall.cpp:
  122.  
  123.  
  124. #include "ofBall.h"
  125.  
  126.  
  127. ofBall::ofBall(float _x, float _y, int _dim)
  128. {
  129. x = _x;
  130. y = _y;
  131. dim = _dim;
  132.  
  133.  
  134. }
  135.  
  136.  
  137. void ofBall::update(){
  138. x++;
  139. y++;
  140.  
  141. }
  142.  
  143.  
  144. void ofBall::draw(){
  145.  
  146. ofSetColor(120,120,120);
  147. ofCircle(x, y, dim);
  148. ofRect(x,y,100,200);
  149. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement