#include "coursecity.h" coursecity::coursecity() { //cout<<"creating coursecity"<>coursewidth; is>>courseheight; is>>numtexturestoread; //load the textures cout<<"loading course textures"<>nexttexture; cout<<"going to load texture: "<>start1x>>start1y>>start1z>>start1theta>>start2x>>start2y>>start2z>>start2theta; cout<<"read the starts as "<>clearline; is>>numtypes; is>>clearline; tiletypes=new tileinfo[256];//can potentially use any char, not just the usual ones for (int x=0; x<256; x++) tiletypes[x].id=0; int heightint=0; int idindex=0; char inchar; for (int x=0; x>inchar; idindex=(int)inchar; tiletypes[idindex].id=inchar; is>>tiletypes[idindex].solid>>heightint>>tiletypes[idindex].modelid>>tiletypes[idindex].xsize>>tiletypes[idindex].ysize; tiletypes[idindex].height=((float)heightint)/10.0; } cout<<"tiletypes read as:"<>clearline; cout<>coursemap[(courseheight-1-y)*coursewidth+x].type; //coursemap[x].rendered=false; coursemap[(courseheight-1-y)*coursewidth+x].contents=-1; } for (int x=0; x=z-zthreshold)) return true; / * if (coursemap[(int)(y+radius)*coursewidth+(int)(x+radius)].height>=z-zthreshold) return true; if (coursemap[(int)(y-radius)*coursewidth+(int)(x-radius)].height>=z-zthreshold) return true; if (coursemap[(int)(y+radius)*coursewidth+(int)(x+radius)].height>=z-zthreshold) return true; if (coursemap[(int)(y-radius)*coursewidth+(int)(x-radius)].height>=z-zthreshold) return true; * / return false; } */ //when testing a single square, not a path, it ignores occupants of the tile bool coursecity::CheckCollision(float foldx, float foldy, float oldz, float fnewx, float fnewy, float newz, int thisguy) { int oldx=(int)foldx; int oldy=(int)foldy; int newx=(int)fnewx; int newy=(int)fnewy; if ((oldx<0)||(oldy<0)||(newx<0)||(newy<0)) return true;//off course if ((oldx>=coursewidth)||(newx>=coursewidth)||(oldy>=courseheight)||(newy>=courseheight)) { //cout<<"collision by off course"<=coursewidth)||(y<0)||(y>=courseheight)) { //cout<<"collision by edge of course"<=newz-1.0) { return true;//tile is solid, youre not above the block } if (coursemap[y*coursewidth+x].contents!=-1) if (coursemap[y*coursewidth+x].contents!=thisguy) { //if (distance between the two is <1.01) { no need to take the sqrt, since if it's <=1 itll get smaller, if >1 bigger, about 1 is our cutoff if ( ((thenpcs->chars[coursemap[y*coursewidth+x].contents].loc.x-fnewx)*(thenpcs->chars[coursemap[y*coursewidth+x].contents].loc.x-fnewx) + (thenpcs->chars[coursemap[y*coursewidth+x].contents].loc.y-fnewy)*(thenpcs->chars[coursemap[y*coursewidth+x].contents].loc.y-fnewy))<1.01 ) { //cout<<"collision by too close to object "<=courseheight) return coursewidth; else return courseheight; } void coursecity::SetStartLocation(PlayerState *theplayer,int which, bool init) { playerlist[which]=theplayer; if (which%2==0) { (*theplayer).loc.x=(float)start1x+0.05;//add this to prevent rounding error //floats at x.00 vs. x.99 could get confused, and the course could lose track of where the object is. the same thing is done for npc's (*theplayer).loc.y=(float)start1y+0.05; (*theplayer).loc.z=start1z; (*theplayer).theta=start1theta; (*theplayer).phi=90; if(init) AddDynamicObject((int)start1x,(int)start1y,10000); } else { (*theplayer).loc.x=(float)start2x+0.05; (*theplayer).loc.y=(float)start2y+0.05; (*theplayer).loc.z=start2z; (*theplayer).theta=start2theta; (*theplayer).phi=90; if(init) AddDynamicObject((int)start2x,(int)start2y,10001); } } void coursecity::Skybox(int hour, int minute) { glEnable(GL_TEXTURE_2D); glDisable(GL_DEPTH_TEST); glDepthMask(GL_FALSE); glMatrixMode(GL_MODELVIEW); // load camera transformation matrix GLfloat modelview[16]; glPushMatrix(); glGetFloatv(GL_MODELVIEW_MATRIX, modelview); // zero the translation part modelview[12] = 0.0; modelview[13] = 0.0; modelview[14] = 0.0; glLoadMatrixf(modelview); glClearColor(1,1,1,1); //glLoadIdentity(); glColor3f(0,1,0);//debug color-shouldnt actually show up //adjust colors depending on the time of day if ((hour>7)&&(hour<17)) {//day glColor3f(1,1,1); } else if ((hour<4)||(hour>20)) {//night glColor3f(0.1,0.05,0.2); } else {//transition if (hour==4) { glColor3f(0.2+((float)minute/60.0)/5.0,0.1,0.4); } else if (hour==5) { glColor3f(0.4+((float)minute/60.0)/2.5,0.1+((float)minute/60.0)/3.333,0.4); } else if (hour==6) { glColor3f(0.8+((float)minute/60.0)/5.0,0.4+((float)minute/60.0)/2.5,0.4+((float)minute/60.0)/5.0); } else if (hour==7) { glColor3f(1.0,0.8+((float)minute/60.0)/5.0,0.6+((float)minute/60.0)/2.5); } else if (hour==20) { glColor3f(0.4-((float)minute/60.0)/5.0,0.1,0.4); } else if (hour==19) { glColor3f(0.8-((float)minute/60.0)/2.5,0.4-((float)minute/60.0)/3.333,0.4); } else if (hour==18) { glColor3f(1.0-((float)minute/60.0)/5.0,0.8-((float)minute/60.0)/2.5,0.6-((float)minute/60.0)/5.0); } else if (hour==17) { glColor3f(1.0,1.0-((float)minute/60.0)/5.0,1.0-((float)minute/60.0)/2.5); } } //cout<<"up texture name: "<glowing>=0) { glEnable(GL_LIGHT2); //GLfloat position2[]={0,1,0,1}; GLfloat position2[]={playerlist[0]->loc.x,playerlist[0]->loc.y,playerlist[0]->loc.z}; GLfloat ambient2[]={1,1,0,1.0}; GLfloat diffuse2[]={1,1,0.1,1.0}; GLfloat specular2[]={1,1,0.1,1.0}; glLightf(GL_LIGHT2,GL_QUADRATIC_ATTENUATION,0.08); glPushMatrix(); //glLoadIdentity(); glLightfv(GL_LIGHT2,GL_POSITION,position2); glLightfv(GL_LIGHT2,GL_AMBIENT,ambient2); //was disabled glLightfv(GL_LIGHT2,GL_DIFFUSE,diffuse2); glLightfv(GL_LIGHT2,GL_DIFFUSE,specular2); glPopMatrix(); } if (playerlist[1]!=NULL) if (playerlist[1]->glowing>=0) { glEnable(GL_LIGHT3); //GLfloat position3[]={0,1,0,1}; GLfloat position3[]={playerlist[1]->loc.x,playerlist[1]->loc.y,playerlist[1]->loc.z}; GLfloat ambient3[]={1,1,0,1.0}; GLfloat diffuse3[]={1,1,0.1,1.0}; GLfloat specular3[]={1,1,0.1,1.0}; glLightf(GL_LIGHT3,GL_QUADRATIC_ATTENUATION,0.08); glPushMatrix(); //glLoadIdentity(); glLightfv(GL_LIGHT3,GL_POSITION,position3); glLightfv(GL_LIGHT3,GL_AMBIENT,ambient3); //was disabled glLightfv(GL_LIGHT3,GL_DIFFUSE,diffuse3); glLightfv(GL_LIGHT2,GL_DIFFUSE,specular3); glPopMatrix(); } } else { glDisable(GL_LIGHT2); glDisable(GL_LIGHT3); glDisable(GL_LIGHTING); } }