void plCorrectPosition(Player* P, Vec2 Pos) { if(P->Shape != NULL) { vxSetPosition(P->VxUL, vec2Add(vxGetPosition(P->VxUL), Pos)); vxSetPosition(P->VxUR, vec2Add(vxGetPosition(P->VxUR), Pos)); vxSetPosition(P->VxDL, vec2Add(vxGetPosition(P->VxDL), Pos)); vxSetPosition(P->VxDR, vec2Add(vxGetPosition(P->VxDR), Pos)); } Vec2 v = vec2Sub(vxGetPosition(P->VxUL), vxGetPosition(P->VxDL)); P->PrevCenter = P->Center; P->Center = polyComputeCenter(P->Shape); v = vec2Normalized(v); vxSetPosition(P->vxBodyParts[bpBase], vec2Add(P->Center, vec2Prod(v, -15.f))); aniUpdateForCurrentState(P->aniStand, P); aniUpdate(P->aniStand, P, 1.f); }
void CBaseChar::update() { //중력 계산 colliderUpdate(); //보는것 계산 lookUpdate(); //애니움직임 aniUpdate(); //스테이트로 움직임 stateUpdate(); //최종 벡터 연산 moveUpdate(); //무기 발사 weaponUpdate(); attackUpdate(); }
void plUpdate(Player* P, s_SharedResources* SR) { P->GroundVec = vec2Ortho(P->Normal); // Mise à jour quelques States Vec2 RdBottom = vec2Normalized(vec2Sub(vxGetPosition(P->VxDR), vxGetPosition(P->VxDL))); if(RdBottom.x < 0.f) { P->State = P->State | PL_UPSIDEDOWN; P->State = P->State | PL_FALLING; } else { if(RdBottom.y < -0.5f) { P->State = P->State | PL_FALLING; P->State = P->State | PL_FALLING_L; } else if(RdBottom.y > 0.5f) { P->State = P->State | PL_FALLING; P->State = P->State | PL_FALLING_R; } } if(P->GrabL != NULL) P->State = P->State | PL_GRABL; if(P->GrabR != NULL) P->State = P->State | PL_GRABR; Vec2 v = vec2Sub(vxGetPosition(P->VxUL), vxGetPosition(P->VxDL)); P->PrevCenter = P->Center; P->Center = polyComputeCenter(P->Shape); v = vec2Normalized(v); vxSetPosition(P->vxBodyParts[bpBase], vec2Add(P->Center, vec2Prod(v, -15.f))); Vec2 speed = vec2Sub(P->Center, P->PrevCenter); //printf("speed:%f,%f\n",speed.x, speed.y); if (!(P->State & PL_ON_GROUND) && ABS(speed.y) > 0.1f) { if (speed.y<2.f) P->CurrentAnim = P->aniJump; else P->CurrentAnim = P->aniFall; P->timer.restart(); } else { if (ABS(speed.x) > 1.f) P->CurrentAnim = P->aniRun, P->timer.restart(); else if (P->timer.getElapsedTime().asSeconds() < 5.f) P->CurrentAnim = P->aniStand; else P->CurrentAnim = P->aniHello; } if (P->timer.getElapsedTime().asSeconds() > 20.f) P->timer.restart(); unsigned int LastState; if (aniGetType(P->CurrentAnim) == ANIM_POSITIONS) LastState = P->Positions.CurrentState; else LastState = P->Angles.CurrentState; if (ABS(speed.x) > 1.f && P->CurrentAnim == P->aniRun) { float spp = vec2Length(speed); aniUpdate(P->CurrentAnim, P, MAX(0.25f, spp/10.f)); } else aniUpdate(P->CurrentAnim, P, 1.f); if (aniGetType(P->CurrentAnim) == ANIM_POSITIONS) { if (P->CurrentAnim == P->aniRun && LastState != P->Positions.CurrentState) sndmPlay(shSoundManager(SR), P->SndFoot[LastState]); } else { if (P->CurrentAnim == P->aniRun && LastState != P->Angles.CurrentState) sndmPlay(shSoundManager(SR), P->SndFoot[LastState]); } }
void plInit(Player* P, World *W) { P->ULPos = vec2(-20.f, -70.f); P->URPos = vec2(20.f, -70.f); P->DLPos = vec2(-35.f, 70.f); P->DRPos = vec2(35.f, 70.f); strcpy(P->SndFoot[0], "snd_step1"); strcpy(P->SndFoot[1], "snd_step2"); P->timer.restart(); P->VxUL = newVertex(); vxSetPosition(P->VxUL, P->ULPos); P->VxUR = newVertex(); vxSetPosition(P->VxUR, P->URPos); P->VxDR = newVertex(); vxSetPosition(P->VxDR, P->DRPos); P->VxDL = newVertex(); vxSetPosition(P->VxDL, P->DLPos); vxSetMass(P->VxUL, 0.01f); vxSetMass(P->VxUR, 0.01f); vxSetMass(P->VxDL, 1.5f); vxSetMass(P->VxDR, 1.5f); P->Shape = polyRectangle(P->VxUL, P->VxUR, P->VxDR, P->VxDL); wdAddVxFromPoly(W, P->Shape); P->GroundAngle = M_PI_2; P->Dir = DIR_RIGHT; animAnglesStatesInit(&P->Angles); animPositionsStatesInit(&P->Positions); P->aniRun = newAnimation(ANIM_ANGLES, ANIM_ALL_TRIGGERS, TRUE); aniLoadFromFile(P->aniRun, (ResourcePath()+"data/anims/animRun.ani").c_str()); //aniSetForce(P->aniRun, 0.65f); P->aniJump = newAnimation(ANIM_ANGLES, ANIM_ALL_TRIGGERS, TRUE); aniLoadFromFile(P->aniJump, (ResourcePath()+"data/anims/animJump.ani").c_str()); aniSetForce(P->aniJump, 0.65f); P->aniFall = newAnimation(ANIM_ANGLES, ANIM_ALL_TRIGGERS, TRUE); aniLoadFromFile(P->aniFall, (ResourcePath()+"data/anims/animFall.ani").c_str()); P->aniHello = newAnimation(ANIM_ANGLES, ANIM_ALL_TRIGGERS, TRUE); aniLoadFromFile(P->aniHello, (ResourcePath()+"data/anims/animHello.ani").c_str()); P->aniStand = newAnimation(ANIM_ANGLES, ANIM_ALL_TRIGGERS, TRUE); aniLoadFromFile(P->aniStand, (ResourcePath()+"data/anims/animStand.ani").c_str()); unsigned int i=0; for (i=0; i<polyGetVxCount(P->Shape); i++) vxSetFixed(polyGetVertex(P->Shape, i), FALSE); P->GrabR = NULL; P->GrabL = NULL; P->VxULStatus = P->VxURStatus = P->VxDRStatus = P->VxDLStatus = P->RdUStatus = P->RdRStatus = P->RdDStatus = P->RdLStatus = nullCollisionInfo(); P->State = PL_NOSTATE; plResetJump(P); /* On crée les vertices du personnage, pour l'animation et quand il meurt */ for (int i=0; i<12; i++) P->vxBodyParts[i] = newVertex(); vxSetPosition(P->vxBodyParts[bpBase], vec2(0.f, 100.f)); Vec2 B = vxGetPosition(P->vxBodyParts[bpBase]); vxSetPosition(P->vxBodyParts[bpNeck], vec2(B.x, B.y - 60.f)); vxSetPosition(P->vxBodyParts[bpHeadLeft], vec2Add(vxGetPosition(P->vxBodyParts[bpNeck]), vec2(-20.f, -20.f))); vxSetPosition(P->vxBodyParts[bpHeadRight], vec2Add(vxGetPosition(P->vxBodyParts[bpNeck]), vec2(20.f, -20.f))); vxSetPosition(P->vxBodyParts[bpLeftArm1], vec2Add(vxGetPosition(P->vxBodyParts[bpNeck]), vec2(0.f, 25.f))); vxSetPosition(P->vxBodyParts[bpLeftArm2], vec2Add(vxGetPosition(P->vxBodyParts[bpNeck]), vec2(0.f, 50.f))); vxSetPosition(P->vxBodyParts[bpRightArm1], vec2Add(vxGetPosition(P->vxBodyParts[bpNeck]), vec2(0.f, 25.f))); vxSetPosition(P->vxBodyParts[bpRightArm2], vec2Add(vxGetPosition(P->vxBodyParts[bpNeck]), vec2(0.f, 50.f))); vxSetPosition(P->vxBodyParts[bpLeftLeg1], vec2Add(vxGetPosition(P->vxBodyParts[bpBase]), vec2(0.f, 30.f))); vxSetPosition(P->vxBodyParts[bpLeftLeg2], vec2Add(vxGetPosition(P->vxBodyParts[bpBase]), vec2(0.f, 60.f))); vxSetPosition(P->vxBodyParts[bpRightLeg1], vec2Add(vxGetPosition(P->vxBodyParts[bpBase]), vec2(0.f, 30.f))); vxSetPosition(P->vxBodyParts[bpRightLeg2], vec2Add(vxGetPosition(P->vxBodyParts[bpBase]), vec2(0.f, 60.f))); for (int i=0; i<12; i++) { switch (i) { case bpNeck: case bpLeftLeg1: case bpRightLeg1: P->BodyRigids[i] = newRigid(P->vxBodyParts[i], P->vxBodyParts[bpBase], -1.f); break; case bpLeftArm1: case bpRightArm1: case bpHeadLeft: case bpHeadRight: P->BodyRigids[i] = newRigid(P->vxBodyParts[i], P->vxBodyParts[bpNeck], -1.f); break; case bpLeftArm2: case bpRightArm2: case bpLeftLeg2: case bpRightLeg2: P->BodyRigids[i] = newRigid(P->vxBodyParts[i], P->vxBodyParts[i-1], -1.f); break; case bpBase: P->BodyRigids[i] = newRigid(P->vxBodyParts[bpHeadLeft], P->vxBodyParts[bpHeadRight], -1.f); break; default: break; } } P->CurrentAnim = P->aniStand; aniUpdateForCurrentState(P->CurrentAnim, P); aniUpdate(P->CurrentAnim, P, 1.f); }