#ifndef IGNORE_DEPEND #include #include #endif #include "world.h" void World::ResetPlayer(int i, bool init, int gamemode){ players[i].loc.set(0,0,0); players[i].theta=0; players[i].phi= 0; players[i].speed = 0.14;//0.1; players[i].angle = 1; players[i].glowing=BASE_GLOW; players[i].hp=BASE_HP; if(npc.numModels>i) players[i].model = i; else players[i].model = -1; players[i].frame = 0; //if this is a real player or just reseting player pos if (!init || i<=gamemode) course.SetStartLocation(&(players[i]),i, init); } void World::ResetCamera(int i){ cameras[i].at.set(0,0,0); cameras[i].eye.set(0,0,0); cameras[i].up.set(0,0,1); cameras[i].dir.set(-3,0,0); cameras[i].mode = ATTACHED_CAMERA; } bool World::Init(int gamemode, char *skyboxPath, char*courseFilename, char* npcFilename, char *eventFilename) { bool bError = false; levelover1=false; levelover2=false; goaltype=0; goalx=0; goaly=0; goaldistance=2.0; // initalize skybox data //if (!skybox.Init(skyboxPath)) { // cerr << "World: ERROR initializing skybox" << endl; // bError = true; //} // initalize course data if (!course.Init(courseFilename)) { cerr << "World: ERROR initializing course" << endl; bError = true; } if (!npc.Init(npcFilename, &chats, &course)){ cerr <<"World: ERROR initializing npc"< 1){ players[ID].frame += delta%(totalFrames-1); if(players[ID].frame < 0) //-1 becomes 30 players[ID].frame += totalFrames; else if(players[ID].frame > totalFrames-1) //31 becomes 1 players[ID].frame -= totalFrames-1; else if(players[ID].frame == 0) //0 becomes 1 or 30 players[ID].frame = (delta > 0)?1:totalFrames-1; }else players[ID].frame = 0; } } void World::RenderPlayer(int ID){ glPushMatrix(); glColor3f(1,1,1); glTranslatef(V3COMP(players[ID].loc)); glRotatef(players[ID].theta, 0,0,1); //glRotatef(players[ID].phi, 0,1,0); if (players[ID].glowing>=0) { GLfloat globalambient[]={0.4,0.4,0.2,1.0}; glLightModelfv(GL_LIGHT_MODEL_AMBIENT, globalambient); } npc.RenderModel(players[ID].model, players[ID].frame); GLfloat globalambientdefault[]={0.2,0.2,0.2,1.0}; glLightModelfv(GL_LIGHT_MODEL_AMBIENT, globalambientdefault); glPopMatrix(); } void World::Render(int numplayers, int playerID){ //if (!skybox.Render()) //cerr << "World: ERROR rendering skybox" << endl; if (!course.Render()) cerr << "World: ERROR rendering course" << endl; if (!npc.RenderAll(&cameras[playerID])) cerr << "World: ERROR rendering npc" <1) RenderPlayer(1); glPopMatrix(); npc.SetDefaultMaterial(); /* //draw a marker at the goal glPushMatrix(); glColor3f(1,0.7,0); glTranslatef(goalx,goaly,3); glDisable(GL_LIGHTING); glutSolidTeapot(0.3); glPopMatrix(); */ } void World::StartGlowing(int player) { if (players[player].glowing<=BASE_GLOW) { players[player].glowing=FULL_GLOW; if ( (players[0].loc.x-players[1].loc.x)*(players[0].loc.x-players[1].loc.x) + (players[0].loc.x-players[1].loc.y)*(players[0].loc.x-players[1].loc.y) < GLOWDISTANCE*GLOWDISTANCE) { //in range, so whack the other player if (player==0) players[1].hp-=GLOW_DAMAGE; if (player==1) players[0].hp-=GLOW_DAMAGE; } } } void World::UpdateState() { //cout<<"World updates state"<=0) players[1].hp-=GLOW_AREA_DAMAGE; if (players[1].glowing>=0) players[0].hp-=GLOW_AREA_DAMAGE; //cout<<"glow damage from area"<="<BASE_GLOW) players[x].glowing--; if (players[x].hpMAXPLAYERS) { cerr<<"WARNING GetPlayer called on a player ("<=course.coursewidth)||(targetybase>=course.courseheight))) { if ( ((course.coursemap[targetybase*(course.coursewidth)+targetxbase]).contents>-1)&& (course.coursemap[targetybase*(course.coursewidth)+targetxbase]).contents<10000) { //attempt to converse with the object in that square, which is not a player cout<<"value at targetx,targety, times width "<=course.coursewidth)||(targety>=course.courseheight)) continue; if ( ((course.coursemap[targety*(course.coursewidth)+targetx]).contents>-1)&& (course.coursemap[targety*(course.coursewidth)+targetx]).contents<10000) { //attempt to converse with the object in that square, which is not a player cout<<"value at targetx,targety, times width "<