summaryrefslogtreecommitdiff
path: root/gaunt01
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
parent5606e9f56d1333c32fd711a74f372669948bae8d (diff)
usable version
Diffstat (limited to 'gaunt01')
-rw-r--r--gaunt01/bin/data/settings.xml24
-rw-r--r--gaunt01/src/bird.cpp97
-rw-r--r--gaunt01/src/bird.h8
-rw-r--r--gaunt01/src/testApp.cpp12
4 files changed, 71 insertions, 70 deletions
diff --git a/gaunt01/bin/data/settings.xml b/gaunt01/bin/data/settings.xml
index bf69a57..925e199 100644
--- a/gaunt01/bin/data/settings.xml
+++ b/gaunt01/bin/data/settings.xml
@@ -1,18 +1,12 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<gauntlet cam_angle="-55" threshold="30" keyChannel="6" learningRate="0.001"/>
+<gauntlet cam_angle="-55" threshold="30" keyChannel="6" learningRate="0.001" />
<bounds>
- <vertex x="362.884" y="864.936"></vertex>
- <vertex x="661.116" y="864.936"></vertex>
- <vertex x="831.377" y="434.039"></vertex>
- <vertex x="765.19" y="385.303"></vertex>
- <vertex x="709.003" y="352.921"></vertex>
- <vertex x="654.185" y="321.916"></vertex>
- <vertex x="570.816" y="288.97"></vertex>
- <vertex x="395.481" y="202.178"></vertex>
- <vertex x="298.262" y="162.836"></vertex>
- <vertex x="257.18" y="123.481"></vertex>
- <vertex x="223.451" y="135.92"></vertex>
- <vertex x="230.915" y="311.189"></vertex>
- <vertex x="199.103" y="387.095"></vertex>
- <vertex x="199.112" y="448.572"></vertex>
+ <vertex x="664.309" y="866.4"></vertex>
+ <vertex x="844.015" y="425.757"></vertex>
+ <vertex x="681.121" y="202.178"></vertex>
+ <vertex x="529.622" y="248.805"></vertex>
+ <vertex x="390.791" y="330.375"></vertex>
+ <vertex x="262.333" y="392.649"></vertex>
+ <vertex x="202.303" y="451.838"></vertex>
+ <vertex x="357.206" y="864.222"></vertex>
</bounds>
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);
}
diff --git a/gaunt01/src/bird.h b/gaunt01/src/bird.h
index fdaf915..ba8f2cd 100644
--- a/gaunt01/src/bird.h
+++ b/gaunt01/src/bird.h
@@ -70,9 +70,10 @@ class bird
int state;
morphmesh model;
+ ofPlane* bounds;
+ ofVec2f centre;
ofRay pointer;
ofVec3f position;
- ofVec2f centrePoint; //2d coords of centre of screen
ofVec3f edgepoint; //point where the bird will hit the edge of the screen
float edgelength,edgeangle;
@@ -83,9 +84,6 @@ class bird
vector<float> playdist;
vector<ofVec3f> playpos;
- ofPlane* bounds;
- ofVec2f centre;
-
bool leaving;
float centrehead;
@@ -109,7 +107,7 @@ class bird
float lastTime;
ofSoundPlayer* aggressives;
- ofSoundPlayer* chirps;
+ ofSoundPlayer* whistles;
ofSoundPlayer* rattles;
ofImage texture;
diff --git a/gaunt01/src/testApp.cpp b/gaunt01/src/testApp.cpp
index 6af06ad..6522f91 100644
--- a/gaunt01/src/testApp.cpp
+++ b/gaunt01/src/testApp.cpp
@@ -712,7 +712,7 @@ void testApp::update(){
}
}
- if (gameState==PLAYING) Bird.update(players,cam_angle);
+ if (gameState>EXPLAIN) Bird.update(players,cam_angle);
}
@@ -833,19 +833,19 @@ void testApp::draw(){
switch(gameState) {
case TITLES:
billboards[0].draw(windowWidth/6
- ,scaleFactor.y*((-billboards[0].height/2)+(billboards[0].height*pow(sin(segElapsed*PI),0.5)))
+ ,scaleFactor.y*((-billboards[0].height/2)+(billboards[0].height*pow(sin(segElapsed*PI),0.4)))
,billboards[0].width*scaleFactor.x
,billboards[0].height*scaleFactor.y);
break;
case CREDIT:
billboards[1].draw(windowWidth/6
- ,windowHeight+(scaleFactor.y*((billboards[1].height/2)-(billboards[1].height*pow(sin(segElapsed*PI),0.5))))
+ ,windowHeight+(scaleFactor.y*((billboards[1].height/2)-(billboards[1].height*pow(sin(segElapsed*PI),0.4))))
,billboards[1].width*scaleFactor.x
,billboards[1].height*scaleFactor.y);
break;
case EXPLAIN:
billboards[2].draw(windowWidth/2
- ,scaleFactor.y*((-billboards[2].height/2)+(billboards[2].height*pow(sin(segElapsed*PI),0.5)))
+ ,scaleFactor.y*((-billboards[2].height/2)+(billboards[2].height*pow(sin(segElapsed*PI),0.4)))
,billboards[2].width*scaleFactor.x
,billboards[2].height*scaleFactor.y);
break;
@@ -853,7 +853,7 @@ void testApp::draw(){
break;
case GOTCHA:
billboards[3].draw(windowWidth/2
- ,scaleFactor.y*((-billboards[2].height/2)+(billboards[3].height*pow(sin(segElapsed*PI),0.5)))
+ ,scaleFactor.y*((-billboards[2].height/2)+(billboards[3].height*pow(sin(segElapsed*PI),0.4)))
,billboards[3].width*scaleFactor.x
,billboards[3].height*scaleFactor.y);
break;
@@ -928,7 +928,7 @@ void testApp::draw(){
ofPopMatrix();
char numStr[10];
- sprintf(numStr, "%4.1f", Bird.playhead[i]);
+ sprintf(numStr, "%4.1f", Bird.playdist[i]);
ofVec3f sc=cam.worldToScreen(ofVec3f((Bird.position.x+Bird.playpos[i].x)/2,(Bird.position.y+Bird.playpos[i].y)/2,(Bird.position.z+Bird.playpos[i].z)/2).rotated(cam_angle,ofVec3f(1,0,0)));
ofDrawBitmapString(numStr, sc.x, sc.y);
}