//Dave Seneker and Luisa Lu //implementation of the event manager #include "events.h" eventthing::~eventthing() { if (theevents!=NULL) delete[] theevents; if (defaultmessagetex!=NULL) delete[] defaultmessagetex; } bool eventthing::Init(char *eventfile, coursecity *coursepointer) { //now read in and set up the events cout<<"event init"<>clearline; cout<<"clearline: "<>texturefile; TextureMap &texd1=defaultmessagetex[0]; if (texd1.LoadTIFF(texturefile)) { // set up params and bind name glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); texd1.InitTextureParams(false);//or after the clamps? glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); } else cerr<<"Error loading event message background"<>clearline; is>>texturefile; TextureMap &texd2=defaultmessagetex[1]; if (texd2.LoadTIFF(texturefile)) { // set up params and bind name glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); texd2.InitTextureParams(false);//or after the clamps? glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); } else cerr<<"Error loading event message background"<>clearline; is>>texturefile; TextureMap &texd3=defaultmessagetex[2]; if (texd3.LoadTIFF(texturefile)) { // set up params and bind name glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); texd3.InitTextureParams(false);//or after the clamps? glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); } else cerr<<"Error loading event message background"<>clearline; is>>numevents; /* is>>clearline; is>>texturefile; TextureMap &texc=messagechar; if (texc.LoadTIFF(texturefile)) { // set up params and bind name glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); texc.InitTextureParams(false);//or after the clamps? glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); } else cerr<<"Error loading message char texture"<>clearline; is>>texturefile; texc=windowback; if (texc.LoadTIFF(texturefile)) { // set up params and bind name glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); texc.InitTextureParams(false);//or after the clamps? glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); } else cerr<<"Error loading message char texture"<>clearline; //get type: message or cut scene is>>theevents[x].type; //get area is>>clearline; is>>theevents[x].xstart>>theevents[x].ystart>>theevents[x].xend>>theevents[x].yend; is>>clearline; is>>theevents[x].duration; cout<<"a"<>clearline; is>>texturefile; cout<<"0d"<>clearline; is>>texturefile; if (tex2.LoadTIFF(texturefile)) { // set up params and bind name glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); tex2.InitTextureParams(false);//or after the clamps? glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); } else cerr<<"Error loading event message background"<>clearline; is>>texturefile; if (tex3.LoadTIFF(texturefile)) { // set up params and bind name glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); tex3.InitTextureParams(false);//or after the clamps? glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); } else cerr<<"Error loading event message background"<>clearline; theevents[x].message=new char[1024]; char clearchar; is>>clearchar; //is>>theevents[x].message; is.getline(theevents[x].message,1024,'\n'); cout<<"message read as: "<>clearline; is>>theevents[x].frameduration; is>>clearline; is>>theevents[x].playerx; is>>clearline; is>>theevents[x].playery; is>>clearline; is>>theevents[x].playertheta; is>>clearline; is>>theevents[x].numtextures; is>>clearline; theevents[x].textures=new TextureMap[theevents[x].numtextures]; for (int y=0; y>texturefile; TextureMap &tex=theevents[x].textures[y]; if (tex.LoadTIFF(texturefile)) { // set up params and bind name glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); tex.InitTextureParams(false);//or after the clamps? glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); } else cerr<<"Error loading event message background"<coursemap[yy*thecourse->coursewidth+xx].event=x; } } cout<<"f"<=theevents[a].xstart)&&(x<=theevents[a].xend)&&(y>=theevents[a].ystart)&&(y<=theevents[a].yend)) { //begin the event if (playerid==0) { player1event=a; p1start=(unsigned int)glutGet(GLUT_ELAPSED_TIME);//****************************set to current time here theevents[a].player1done=true; cout<<"beginning event for player 1: "<p1start+manualevents[0].duration) { cout<<"ending manual event for player 1: "<p1start+theevents[player1event].duration) { cout<<"ending event for player 1: "<p2start+manualevents[1].duration) { cout<<"ending manual event for player 2: "<p2start+theevents[player2event].duration) { if (theevents[player2event].type==1) repositionevent(1,player2event); player2event=-1; } } } void eventthing::repositionevent(int player, int eventid) { //cout<<"repositionevent with player "<=0) { int oldx=(int)((*(thecourse->playerlist[player])).loc.x); int oldy=(int)((*(thecourse->playerlist[player])).loc.y); if (thecourse->MoveDynamicObject(oldx,oldy,(int)((float)(theevents[eventid].playerx)+0.05),(int)((float)(theevents[eventid].playery)+0.05)) ) { } else { cerr<<"moving player "<playerlist[player])).loc.x=(float)(theevents[eventid].playerx)+0.05; (*(thecourse->playerlist[player])).loc.y=(float)(theevents[eventid].playery)+0.05; } if (theevents[eventid].playertheta>0) { (*(thecourse->playerlist[player])).theta=theevents[eventid].playertheta; } //now update it in the course square tracking stuff } bool eventthing::manualmessage(int player, int duration, char *message) { if (player==0) { player1event=-2; p1start=(unsigned int)glutGet(GLUT_ELAPSED_TIME); } else if (player==1) { player2event=-2; p2start=(unsigned int)glutGet(GLUT_ELAPSED_TIME); } else return false; manualevents[player].type=0; manualevents[player].duration=duration; if (manualevents[player].message!=NULL) delete[] manualevents[player].message; manualevents[player].message=new char[1024]; manualevents[player].numtextures=1;//value doesnt matter? manualevents[player].textures=defaultmessagetex; strcpy(manualevents[player].message,message); return true; } void eventthing::drawmessages(int player, int numplayers, int width, int height) { //draw the things for any message type events that are running for that player eventinfo thisevent; if (player==0) { if (player1event==-1) return; if (player1event==-2) thisevent=manualevents[0]; else thisevent=theevents[player1event]; if (thisevent.type!=0) return; } else if (player==1) { if (player2event==-1) return; if (player2event==-2) thisevent=manualevents[1]; else thisevent=theevents[player2event]; if (thisevent.type!=0) return; } else return; //if we get here, its a real event, set up ortho mode //go to ortho mode-see intro glDisable(GL_DEPTH_TEST); glPushMatrix(); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); //glOrtho(-250,640+200,-250,480+250,0,100);//aspect 1 glOrtho(-120,640+120,-190,480+220,0,100); //glOrtho(0,width,0,height,0,100); glEnable(GL_TEXTURE_2D); glDisable(GL_LIGHTING); glColor4f(1,1,1,1); //set up the parameters. make these passed in like conversations int textcols=38;// 40 //how many columns of text display in one box int textrows=2;// 4 //how many rows of text display in one box int boxx=130;// 0 //x coordinate of lower left corner int boxy=395;// 0 //y coordinate of the lower left corner int boxwidth=480;// 400//width of the box int boxheight=100;// 100//height of the box int borderthickness=5; int charboxx=15;//(int)(15*(float)width/640.0); int charboxy=395;//(int)(395*(float)height/480.0); int charboxsize=100;//(int)(100*(float)width/640.0); //first draw sumomo //add a mask to this glDisable(GL_DEPTH_TEST); glEnable(GL_BLEND); glBlendFunc(GL_DST_COLOR,GL_ZERO); glBindTexture(GL_TEXTURE_2D, thisevent.textures[1].GetName()); glBegin(GL_QUADS); glTexCoord2i(0,0); glVertex2f(charboxx,charboxy); glTexCoord2i(1,0); glVertex2f(charboxx+charboxsize,charboxy); glTexCoord2i(1,1); glVertex2f(charboxx+charboxsize, charboxy+charboxsize); glTexCoord2i(0,1); glVertex2f(charboxx,charboxy+charboxsize); glEnd(); glBlendFunc(GL_ONE,GL_ONE); glBindTexture(GL_TEXTURE_2D, thisevent.textures[0].GetName()); glBegin(GL_QUADS); glTexCoord2i(0,0); glVertex2f(charboxx,charboxy); glTexCoord2i(1,0); glVertex2f(charboxx+charboxsize,charboxy); glTexCoord2i(1,1); glVertex2f(charboxx+charboxsize, charboxy+charboxsize); glTexCoord2i(0,1); glVertex2f(charboxx,charboxy+charboxsize); glEnd(); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDisable(GL_BLEND); //then draw the message glBindTexture(GL_TEXTURE_2D, thisevent.textures[2].GetName()); glColor3f(1,1,1); //draw the background //left quad, includes corners //glBindTexture(GL_TEXTURE_2D, BackgroundTexture.GetName()); glBegin(GL_QUADS); glTexCoord2i(0,0); glVertex2f(boxx,borderthickness+boxy); glTexCoord2i(0,1); glVertex2f(boxx,boxheight-borderthickness+boxy); glTexCoord2i(1,1); glVertex2f(borderthickness+boxx,boxheight+boxy); glTexCoord2i(1,0); glVertex2f(borderthickness+boxx,boxy); glEnd(); //top quad glBegin(GL_QUADS); glTexCoord2i(0,0); glVertex2f(borderthickness+boxx,boxheight-borderthickness+boxy); glTexCoord2i(0,1); glVertex2f(borderthickness+boxx,boxheight+boxy); glTexCoord2i(1,1); glVertex2f(boxwidth-borderthickness+boxx,boxheight+boxy); glTexCoord2i(1,0); glVertex2f(boxwidth-borderthickness+boxx,boxheight-borderthickness+boxy); glEnd(); //right quad, includes corners glBegin(GL_QUADS); glTexCoord2i(0,0); glVertex2f(boxwidth-borderthickness+boxx,0+boxy); glTexCoord2i(0,1); glVertex2f(boxwidth-borderthickness+boxx,boxheight+boxy); glTexCoord2i(1,1); glVertex2f(boxwidth+boxx,boxheight-borderthickness+boxy); glTexCoord2i(1,0); glVertex2f(boxwidth+boxx,borderthickness+boxy); glEnd(); //bottom quad glBegin(GL_QUADS); glTexCoord2i(0,0); glVertex2f(borderthickness+boxx,0+boxy); glTexCoord2i(0,1); glVertex2f(borderthickness+boxx,borderthickness+boxy); glTexCoord2i(1,1); glVertex2f(boxwidth-borderthickness+boxx,borderthickness+boxy); glTexCoord2i(1,0); glVertex2f(boxwidth-borderthickness+boxx,0+boxy); glEnd(); //bind internal texture glColor3f(0,0,1); glColor3f(.9,0,0.3); //internal quad (repeating texture) //glBindTexture(GL_TEXTURE_2D, BackgroundTexture.GetName()); glBegin(GL_QUADS); glTexCoord2i(0,0); glVertex2f(borderthickness+boxx,borderthickness+boxy); glTexCoord2i(0,1); glVertex2f(borderthickness+boxx,boxheight-borderthickness+boxy); glTexCoord2i(1,1); glVertex2f(boxwidth-borderthickness+boxx,boxheight-borderthickness+boxy); glTexCoord2i(1,0); glVertex2f(boxwidth-borderthickness+boxx,borderthickness+boxy); glEnd(); //now draw the letters glColor3f(1,1,1); unsigned int progress=0; //draw the text //la la, text drawing here //from message[progress] //draw a > at the bottom right corner if there's more text after this glRasterPos2f(150,boxy+boxheight-40); if (numplayers>2) { glTranslatef(borderthickness+30,boxy+boxheight-borderthickness-50,0); glScalef(0.16,0.16,0.16); glDisable(GL_DEPTH_TEST); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glLineWidth(1.0); glEnable(GL_LINE_SMOOTH); } //glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,'A'); //glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,'a'); if ((progress>=0)&&(thisevent.message!=NULL)) { int startprogress=progress; while ((int)progress<(int)strlen(thisevent.message) && ((int)progress-(int)startprogress<(int)textcols*4)) { if (numplayers==1) glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,thisevent.message[progress]); else if (numplayers==2) glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10,thisevent.message[progress]); else {//many players glEnable(GL_BLEND); glutStrokeCharacter(GLUT_STROKE_ROMAN,thisevent.message[progress]); glDisable(GL_BLEND); } progress++; if ((progress-startprogress)%textcols==0) { //60,150 if (numplayers<=2) glRasterPos2f(boxx+40,(boxy+boxheight-50-((progress-startprogress)/textcols)*colheight)); else glTranslatef(-3300,-170,0); } } if (progress'); //} else { // glutStrokeCharacter(GLUT_STROKE_MONO_ROMAN,' '); // glutStrokeCharacter(GLUT_STROKE_MONO_ROMAN,'>'); //} } progress=startprogress;//only continue function will update it } glPopMatrix(); glEnable(GL_DEPTH_TEST); } //cut scene bool eventthing::incutscene(int player) { if (player==0) { if (player1event==-1) return false; if (theevents[player1event].type!=1) return false; } else if (player==1) { if (player2event==-1) return false; if (theevents[player2event].type!=1) return false; } return true; } void eventthing::continuecut(int player, int iWindowWidth, int iWindowHeight) { //check time, pick a frame //draw the frame //p1/p2start, duration int starttime; int duration; int index; int whichframe; if (player==0) { starttime=p1start; index=player1event; duration=theevents[player1event].duration; } else if (player==1) { starttime=p2start; index=player2event; duration=theevents[player2event].duration; } whichframe= (glutGet(GLUT_ELAPSED_TIME)-starttime)/theevents[index].frameduration; if (whichframe