diff options
Diffstat (limited to 'gaunt01/src/bird.cpp')
| -rw-r--r-- | gaunt01/src/bird.cpp | 41 |
1 files changed, 29 insertions, 12 deletions
diff --git a/gaunt01/src/bird.cpp b/gaunt01/src/bird.cpp index 35d9020..a6dfcf8 100644 --- a/gaunt01/src/bird.cpp +++ b/gaunt01/src/bird.cpp @@ -34,6 +34,8 @@ bird::bird() fieldofview=60; lastTime=ofGetElapsedTimef(); + + centrePoint=ofVec2f(ofGetWidth()/2,600); //quick and dirty } bird::~bird() @@ -41,7 +43,7 @@ bird::~bird() //dtor } -void bird::update(map<int,player>& players, float angle){ +void bird::update(map<int,player>& players, float angle,vector<ofPoint> border){ float time=ofGetElapsedTimef(); float timeSeg=time-lastTime; lastTime=time; @@ -75,16 +77,30 @@ void bird::update(map<int,player>& players, float angle){ playhead.push_back(headif); } } - //fly towards nearest visible player - int nearest=-1; - float distance=9999; - for(int i=0;i<playhead.size();i++) { - if ((abs(playhead[i])<(fieldofview/2))&&playdist[i]<distance) { - nearest=i; - distance=playdist[i]; + //check if flying out of play + ofVec3f futurepos=position-direction.rotated(heading,ofVec3f(0,0,-1))*velocity*2.0; + ofPoint futurepoint=ofPoint(futurepos.x,futurepos.y); + centrehead=atan2(position.x-centrePoint.x,position.y-centrePoint.y)*RAD_TO_DEG; + while (centrehead>180) centrehead=centrehead-360; + while (centrehead <-180) centrehead=centrehead+360; + if (OutsidePolygon(border,futurepoint)) { + //if (ofVec + leaving=true; + turnRate=centrehead/5; + } + else { + leaving=false; + //fly towards nearest visible player + int nearest=-1; + float distance=9999; + for(int i=0;i<playhead.size();i++) { + if ((abs(playhead[i])<(fieldofview/2))&&playdist[i]<distance) { + nearest=i; + distance=playdist[i]; + } } + if (nearest>-1) turnRate=-playhead[nearest]; } - if (nearest>-1) turnRate=playhead[nearest]; } void bird::draw(){ @@ -95,7 +111,7 @@ void bird::draw(){ ofRotate(90,-1,0,0); ofRotate(heading+90,0,1,0); ofSetHexColor(0xffffff); - ofScale(.15,.15,.15); + ofScale(.25,.25,.25); bindTexture(texture); model.drawAnimated(); unbindTexture(texture); @@ -114,8 +130,9 @@ void bird::drawShadow(){ model.drawAnimated(); ofPopMatrix(); } -void bird::drawDebug(){ - ofSetHexColor(0xff00ff); +void bird::drawDebug(){ + if (leaving) ofSetHexColor(0xff0000); + else ofSetHexColor(0xff00ff); ofLine(pointer.s,pointer.s+1000*pointer.t); } |
