summaryrefslogtreecommitdiff
path: root/gaunt01/src/bird.cpp
diff options
context:
space:
mode:
authorTim Redfern <tim@eclectronics.org>2012-06-22 17:10:17 +0100
committerTim Redfern <tim@eclectronics.org>2012-06-22 17:10:17 +0100
commit8e22cdc4203dc04e7fdfdd607f27c6b2a61f458b (patch)
treec9c22ec106d20c6b13d2d184f141a2a3774c9ca1 /gaunt01/src/bird.cpp
parent5606e9f56d1333c32fd711a74f372669948bae8d (diff)
usable version
Diffstat (limited to 'gaunt01/src/bird.cpp')
-rw-r--r--gaunt01/src/bird.cpp97
1 files changed, 53 insertions, 44 deletions
diff --git a/gaunt01/src/bird.cpp b/gaunt01/src/bird.cpp
index fadfcab..fe6bf17 100644
--- a/gaunt01/src/bird.cpp
+++ b/gaunt01/src/bird.cpp
@@ -25,9 +25,9 @@ bird::bird()
aggressives=new ofSoundPlayer[2];
aggressives[0].loadSound("aggressive1.wav");
aggressives[1].loadSound("aggressive2.wav");
- chirps=new ofSoundPlayer[2];
- chirps[0].loadSound("chirp1.wav");
- chirps[1].loadSound("chirp2.wav");
+ whistles=new ofSoundPlayer[2];
+ whistles[0].loadSound("whistle1.wav");
+ whistles[1].loadSound("whistle2.wav");
rattles=new ofSoundPlayer[3];
rattles[0].loadSound("rattle1.wav");
rattles[1].loadSound("rattle2.wav");
@@ -43,7 +43,7 @@ bird::bird()
position=ofVec3f(ofRandom(ofGetWidth()/4,(3*ofGetWidth())/4),ofRandom(ofGetHeight()/4,(3*ofGetHeight())/4),-ofGetHeight()/10);
heading=-90;
direction=ofVec3f(0,-1,0); //director for a heading of 0, level
- velocity=1.0f/20;
+ velocity=1.0f/10;
turnRate=20;
diveRate=0;
@@ -52,7 +52,6 @@ bird::bird()
lastTime=ofGetElapsedTimef();
- centrePoint=ofVec2f(ofGetWidth()/2,600); //quick and dirty
}
void bird::setBounds(ofPlane* _bounds) {
bounds=_bounds;
@@ -61,6 +60,8 @@ void bird::setBounds(ofPlane* _bounds) {
void bird::setCentre(ofVec2f _centre) {
//in 2D on plane
centre=_centre;
+ position=ofVec3f(centre.x,centre.y,-ofGetHeight()/10);
+ printf("bird init: %4.2f,%4.2f,%4.2f\n",position.x,position.y,position.z);
}
bird::~bird()
{
@@ -75,28 +76,8 @@ void bird::update(map<int,player>& players, float angle){
float timeSeg=time-lastTime;
lastTime=time;
+ //this is causing the bird to go off the screen at the start.. maybe not a problem..
- //tending to straighten unless avoiding an edge
- //turnRate *= 0.995;
-
- //create, -->draw a line representing the birds heading
-
- //absolute ray pointer
- //put on ground
- //do intersection with outline?
- //ray: can intersect with another ray
- //so: make a ray for each segment of polygon and intersect, find the nearest?
- //ray:: intersect returns a ray- shortest line between lines
- //or: project bird & heading onto ground
- //get intersection with each line of poly bounds
- //or maybe just use screen edges- quicker
- //find the shortest
- //depending on the angle it makes, decide whether to turn left or right to avoid boundary or get back within it
-
- //similar for people - use similar 2d algorithm
- //deal with elevation seperately
-
- //bounds is already an array of 4 planes representing edges of screen- does this work?
pointer=ofRay(position.rotated(angle,ofVec3f(1,0,0)),-direction.rotated(heading,ofVec3f(0,0,-1)).rotated(angle,ofVec3f(1,0,0))*1000.0f,false);
//intersect with bounds and find shortest distance to edge of world
@@ -172,11 +153,11 @@ void bird::update(map<int,player>& players, float angle){
map<int,player>::iterator it;
for (it=players.begin();it!=players.end();it++) {
- if (it->second.active) {
+ if (it->second.active&& !it->second.isCaught) {
float headif=(atan2(it->second.getWorldPosition().x-position.x,it->second.getWorldPosition().y-position.y)*RAD_TO_DEG)-heading;
while (headif>180) headif=headif-360;
while (headif <-180) headif=headif+360;
- if (abs(headif) < 30) { //this could be based on height
+ if (abs(headif) < 120) { //was 30
playhead.push_back(headif);
ofVec3f p=it->second.getWorldPosition()-position;
playang.push_back(p.angle(-direction.rotated(heading,ofVec3f(0,0,-1))));
@@ -197,7 +178,7 @@ void bird::update(map<int,player>& players, float angle){
//influence direction
turnRate+=playhead[nearnum]*.1;
//check if relatively high
- if (position.z<-ofGetHeight()/20) {
+ if (position.z<-ofGetHeight()/15) {
if (diveRate<2.0f) {
//increase dive rate
diveRate+=0.1f;
@@ -211,7 +192,7 @@ void bird::update(map<int,player>& players, float angle){
}
}
else {
- if (position.z>-ofGetHeight()/10) {
+ if (position.z>-ofGetHeight()/5) {
//below ceiling
if (diveRate>-0.5f) {
//increase climb rate
@@ -221,26 +202,55 @@ void bird::update(map<int,player>& players, float angle){
else diveRate*=0.9f;
}
+ float neardist=ofGetWidth()/12.0f;
+
+ if ((state==SCANNING||state==SWOOPING)&&nearnum>-1) {
+ if (playdist[nearnum]<neardist) {
+ model.sequences["flap"].fadeout(0.5);
+ model.sequences["swoop"].fadeout(0.5); //no need to check which one is active
+ model.sequences["attack"].start();
+ state=ATTACKING;
+ int whichsound=(int)ofRandom(1.9999999);
+ aggressives[whichsound].play();
+ }
+ }
+
+ velocity *=(1.0f+(diveRate*.01));
+ //leave mode switch
switch (state) {
case SCANNING:
+ if (velocity<0.05f) velocity *=1.1;
+ if (velocity>0.1f) velocity /=1.01;
if (diveRate>0.5f) {
model.sequences["flap"].fadeout(0.5);
model.sequences["swoop"].start();
state=SWOOPING;
- int whichsound=(int)ofRandom(1.9999999);
- chirps[whichsound].play();
+ int whichsound=(int)ofRandom(2.9999999);
+ rattles[whichsound].play();
}
break;
case SWOOPING:
+ if (velocity<0.1f) velocity *=1.1;
+ if (velocity>0.25f) velocity /=1.02;
if (diveRate<0.5f) {
model.sequences["swoop"].fadeout(0.5);
model.sequences["flap"].start();
state=SCANNING;
- int whichsound=(int)ofRandom(2.9999999);
- rattles[whichsound].play();
+ int whichsound=(int)ofRandom(1.9999999);
+ whistles[whichsound].play();
}
break;
case ATTACKING:
+ if (nearnum==-1||playdist[nearnum]>neardist) { //player escaped
+ model.sequences["attack"].fadeout(0.5);
+ model.sequences["flap"].start();
+ state=SCANNING;
+ int whichsound=(int)ofRandom(1.9999999);
+ whistles[whichsound].play();
+ }
+ if (nearnum>-1) {
+ velocity*=(19+(playdist[nearnum]/neardist))*.05; //slow down
+ }
break;
}
@@ -262,14 +272,13 @@ void bird::update(map<int,player>& players, float angle){
//flap faster while climbing + swoop
//bird noises
- //where does it start
- //whistles rather than chirps
+ //increase angle of view and allow more extreme turn angles
heading=heading+(turnRate*timeSeg);
while (heading>180) heading=heading-360;
while (heading <-180) heading=heading+360;
- position-=direction.rotated(heading,ofVec3f(0,0,-1))*(velocity*ofGetHeight()*(1.0f+diveRate))*timeSeg; //.rotate(heading,ofVec3f(0,1,0))
+ position-=direction.rotated(heading,ofVec3f(0,0,-1))*(velocity*ofGetHeight())*timeSeg; //.rotate(heading,ofVec3f(0,1,0))
position +=ofVec3f(0,0,5)*diveRate*timeSeg;
}
void bird::draw(){
@@ -288,15 +297,15 @@ void bird::draw(){
glDisable(GL_DEPTH_TEST);
}
void bird::drawShadow(){
- ofPushMatrix();
- ofTranslate(position);
+ ofPushMatrix();
+ ofTranslate(ofVec3f(position.x,position.y,0));
ofRotate(90,0,0,1);
ofRotate(90,-1,0,0);
ofRotate(heading+90,0,1,0);
- ofSetHexColor(0x303030);
- ofTranslate(0,(-ofGetHeight()/4)+5,0);
- ofScale(.15,0,.15);
- model.drawAnimated();
+ ofSetHexColor(0x303030);
+ //ofTranslate(0,(-ofGetHeight()/4)+5,0);
+ ofScale(.15,0,.15);
+ model.drawAnimated();
ofPopMatrix();
}
void bird::drawDebug(){
@@ -310,7 +319,7 @@ void bird::drawDebug(){
if (DEBUG) {
ofSetHexColor(0xff00ff);
char numStr[100];
- sprintf(numStr, "dive: %4.2f\nheight: %4.2f\n%s", diveRate,position.z,state==1?"SCANNING":state==2?"SWOOPING":"ATTACKING");
+ sprintf(numStr, "dive: %4.2f\nheight: %4.2f\n%s\n%4.2f,%4.2f,%4.2f", diveRate,position.z,state==1?"SCANNING":state==2?"SWOOPING":"ATTACKING",position.x,position.y,position.z);
ofDrawBitmapString(numStr,10,10);
}