/** ** SURVIVAL OF THE RECTANGLES: ** Rectangles that love to hate on circles ** **/ #include "testApp.h" #include "ofMain.h" //-------------------------------------------------------------- void testApp::setup(){ ofSetVerticalSync(true); ofSetFrameRate(60); ofBackground(0, 20, 52); bgAlpha = 0; unsigned char margin = 50; // daily, we always deal with haters in life numWhoHate = 15; thoseWhoHate = new creature[numWhoHate]; for (int i = 0; i < numWhoHate; i++) { thoseWhoHate[i].pos.x = ofRandom(margin, ofGetWidth()-margin); thoseWhoHate[i].pos.y = ofRandom(margin, ofGetHeight()-margin); } } //-------------------------------------------------------------- void testApp::update(){ theFood.update(); // tell the haters where the food is foodCheck(); // the food's under attack beefCheck(); for (int i = 0; i < numWhoHate; i++) { thoseWhoHate[i].update(); } } //-------------------------------------------------------------- void testApp::draw(){ if (10 < (bgAlpha += 5.2f)) bgAlpha = 0; theFood.draw(); for (int i = 0; i < numWhoHate; i++) { thoseWhoHate[i].draw(); } ofSetColor(0, 222, 255, 100); //ofDrawBitmapString(ofToString(theFood.danger), 20, 20); // key ofDrawBitmapString( "[q] hater info / [w] hater awareness / [z] give full gas", 20, ofGetHeight()-20 ); } //-------------------------------------------------------------- void testApp::foodCheck (){ // the haters always find the food somehow for (int i = 0; i < numWhoHate; i++) { thoseWhoHate[i].eatTarget(theFood.pos.x, theFood.pos.y, theFood.radius); } } //-------------------------------------------------------------- void testApp::beefCheck (){ bool attacked = false; // if hater is engaged, the food's gotta know for (int i = 0; i < numWhoHate; i++) { if (thoseWhoHate[i].bEngage) { theFood.danger += 0.005f; attacked = true; } } if (attacked) { theFood.bUnderAttack = true; } else { theFood.bUnderAttack = false; } } //-------------------------------------------------------------- void testApp::keyPressed (int key){ switch (key){ // info case 'q': for (int i = 0; i < numWhoHate; i++) { if (true == thoseWhoHate[i].bDebugInfo) { thoseWhoHate[i].bDebugInfo = false; } else { thoseWhoHate[i].bDebugInfo = true; } } break; // ranges case 'w': for (int i = 0; i < numWhoHate; i++) { if (true == thoseWhoHate[i].bDebugRange) { thoseWhoHate[i].bDebugRange = false; } else { thoseWhoHate[i].bDebugRange = true; } } break; // give the haters what they need case 'z': for (int i = 0; i < numWhoHate; i++) { thoseWhoHate[i].gasser.tank = 1.0f; } break; } } //-------------------------------------------------------------- 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(){ }