Skip to content

Instantly share code, notes, and snippets.

@companje
Created December 6, 2011 12:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save companje/1437977 to your computer and use it in GitHub Desktop.
Save companje/1437977 to your computer and use it in GitHub Desktop.
//////////// testApp.h
#pragma once
#include "ofMain.h"
class Ball {
public:
ofPoint pos; //it's better to use ofVec3f instead of ofPoint
ofPoint vel;
ofColor color;
int size;
};
class testApp : public ofBaseApp{
public:
void setup();
void update();
void draw();
void keyPressed (int key);
void keyReleased(int key);
void mouseMoved(int x, int y );
void mouseDragged(int x, int y, int button);
void mousePressed(int x, int y, int button);
void mouseReleased(int x, int y, int button);
void windowResized(int w, int h);
void dragEvent(ofDragInfo dragInfo);
void gotMessage(ofMessage msg);
Ball ball;
};
//--------------------------------------------------------------
//--------------------------------------------------------------
//--------------------------------------------------------------
//--------------------------------------------------------------
//--------------------------------------------------------------
//--------------------------------------------------------------
//--------------------------------------------------------------
//--------------------------------------------------------------
//--------------------------------------------------------------
//////////// testApp.cpp
//--------------------------------------------------------------
#include "testApp.h"
//--------------------------------------------------------------
void testApp::setup(){
ofSetFrameRate(60); //limit framerate to 60
ofSetBackgroundAuto(false); //turn off automatic background clearing
ofEnableAlphaBlending(); //enable transparency
ofBackground(0); //set background to black
ball.pos.set(100,200);
ball.vel.set(5,5);
}
//--------------------------------------------------------------
void testApp::update(){
//ball.pos = ball.pos + ball.vel; //this is for dummies
ball.pos += ball.vel; //this is for smart people
//check if ball hits the sides of the screen, if so then bounce back
if (ball.pos.x > ofGetWidth()) ball.vel.x *= -1;
if (ball.pos.y > ofGetHeight()) ball.vel.y *= -1;
if (ball.pos.x < 0) ball.vel.x *= -1;
if (ball.pos.y < 0) ball.vel.y *= -1;
}
//--------------------------------------------------------------
void testApp::draw(){
//draw a semi transparent black rectangle
ofSetColor(0,20);
ofRect(0,0,ofGetWidth(),ofGetHeight());
//draw a white circle
ofSetColor(255);
ofCircle(ball.pos.x, ball.pos.y, 50);
}
//--------------------------------------------------------------
void testApp::keyPressed(int key){
}
//--------------------------------------------------------------
void testApp::keyReleased(int key){
}
//--------------------------------------------------------------
void testApp::mouseMoved(int x, int y ){
}
//--------------------------------------------------------------
void testApp::mouseDragged(int x, int y, int button){
}
//--------------------------------------------------------------
void testApp::mousePressed(int x, int y, int button){
}
//--------------------------------------------------------------
void testApp::mouseReleased(int x, int y, int button){
}
//--------------------------------------------------------------
void testApp::windowResized(int w, int h){
}
//--------------------------------------------------------------
void testApp::gotMessage(ofMessage msg){
}
//--------------------------------------------------------------
void testApp::dragEvent(ofDragInfo dragInfo){
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment