void drawPlayer(player_s* p) { if(!p)return; gsPushMatrix(); camera_s* c=&p->camera; gsTranslate(p->object.position.x,p->object.position.y-4.0f,p->object.position.z); float m[9]; vect3Df_s v1 = moveCameraVector(c, vect3Df(1.0f, 0.0f, 0.0f), false); vect3Df_s v2 = moveCameraVector(c, vect3Df(0.0f, 0.0f, 1.0f), false); m[0]=v1.x;m[3]=v1.y;m[6]=v1.z; m[1]=0.0f;m[4]=1.0f;m[7]=0.0f; m[2]=v2.x;m[5]=v2.y;m[8]=v2.z; gsMultMatrix3(m); gsScale(1.2f,1.2f,1.2f); gsRotateY(M_PI); md2InstanceDraw(&p->ratmanInstance); gsPopMatrix(); }
void movePlayer(player_s* p, vect3Df_s v) { if(!p)return; if(p->object.contact) { if(fabs(v.z)>0.0f && fabs(v.z)>fabs(v.x))md2InstanceChangeAnimation(&p->ratmanInstance, 3, false); else if((v.x)<0.0f)md2InstanceChangeAnimation(&p->ratmanInstance, 4, false); else if((v.x)>0.0f)md2InstanceChangeAnimation(&p->ratmanInstance, 5, false); } p->object.speed = vaddf(p->object.speed, moveCameraVector(&p->camera, v, p->flying)); }
void updateControls(player_s* p) { circlePosition cpad; circlePosition cstick; hidCircleRead(&cpad); irrstCstickRead(&cstick); rotatePlayer(p, vect3Df((abs(cstick.dy)<5)?0:(-cstick.dy*0.001f), (abs(cstick.dx)<5)?0:(cstick.dx*0.001f), 0.0f)); if(abs(cpad.dx) > 15 || abs(cpad.dy) > 15) //dead zone { float factor = 0.0015f; if(p->flying)factor*=2; else if(!p->object.contact)factor*=0.06f; else updatePlayerWalk(p, cpad.dy*factor*2, cpad.dx*factor); movePlayer(p, vect3Df(cpad.dx*factor, 0.0f, -cpad.dy*factor)); } if(keysDown()&KEY_ZL) { // "USE" key vect3Df_s u = moveCameraVector(&p->camera, vect3Df(0.0f, 0.0f, -1.0f), true); timedButton_s* tb = collideRayTimedButtons(p->object.position, u, TILESIZE_FLOAT*2); if(tb) { activateTimedButton(tb); }else{ OBB_s* o = collideRayBoxes(p->object.position, u, TILESIZE_FLOAT*4); if(o) { gravityGunObject = o; } } } if(keysDown()&KEY_ZR) { // JUMP key if(p->object.contact) { p->object.speed.y += 0.6f; } } if(gravityGunObject) { if(!(keysHeld()&KEY_ZL)) { gravityGunObject = NULL; md2InstanceChangeAnimation(&p->gunInstance, 0, false); md2InstanceChangeAnimation(&p->gunInstance, 1, true); }else{ const vect3Df_s u = moveCameraVector(&p->camera, vect3Df(0.0f, 0.0f, -5.0f), true); const vect3Df_s t = vaddf(u, p->object.position); const vect3Df_s v = vmulf(vsubf(t, gravityGunObject->position), 1.75f); setObbVelocity(gravityGunObject, v); md2InstanceChangeAnimation(&p->gunInstance, 2, false); } }else if(p->gunInstance.currentAnim == 2){ md2InstanceChangeAnimation(&p->gunInstance, 0, false); md2InstanceChangeAnimation(&p->gunInstance, 1, true); } }