From bd8985065f2377a62f0ee9f4236d5cd9ad99dfe4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Gia=20Phong?= Date: Thu, 28 Oct 2021 23:45:34 +0700 Subject: Reorganize key mappings --- src/Person.cpp | 207 +++++++++++++++++++++++---------------------------------- 1 file changed, 83 insertions(+), 124 deletions(-) (limited to 'src/Person.cpp') diff --git a/src/Person.cpp b/src/Person.cpp index 3789865..d096b1d 100644 --- a/src/Person.cpp +++ b/src/Person.cpp @@ -23,6 +23,7 @@ #include "Person.h" #include "Support.h" +#include "config.h" #include "misc.h" extern float multiplier; @@ -38,13 +39,7 @@ extern Sprites sprites; extern float soundscalefactor; extern int slomo; -extern int forwardskey; -extern int backwardskey; -extern int leftkey; -extern int rightkey; -extern int aimkey; -extern int psychicaimkey; -extern int psychickey; +extern struct Key keymap; extern Model skeletonmodels[10]; extern Costume costume[10]; @@ -629,136 +624,100 @@ void Person::DoAnimationslite(int who) currentframe = targetframe; } -void Person::DoStuff(int who){ - int moveanim; +void Person::control() +{ + if (visions) + speed = 40; + else + speed = (targetanimation == joganim) ? 2.2 : 2.5; - if((targetanimation!=idleanim&&targetanimation!=crouchanim)||visions==1)playerlowrotation=playerrotation; - if(targetanimation!=crouchanim&¤tanimation!=crouchanim){ - if(playerrotation>playerlowrotation+50){playerlowrotation=playerrotation-50; targetanimation=walkanim; targetframe=0; target=0;} - if(playerrotationplayerlowrotation+70){playerrotation=playerlowrotation+70;} - if(playerrotation playerlowrotation + 50) { + playerlowrotation = playerrotation - 50; + targetanimation = walkanim; + targetframe = 0; target = 0; - } - if (!IsKeyDown(GLFW_KEY_LEFT_CONTROL) - && currentanimation == crouchanim - && targetanimation == crouchanim) { - targetanimation = idleanim; + } else if (playerrotation < playerlowrotation - 50) { + playerlowrotation = playerrotation + 50; + targetanimation = walkanim; + targetframe = 0; target = 0; } - if((onground||(who==0&&visions==1))&¤tanimation!=crouchanim){ - if (IsKeyDown(forwardskey) && !IsKeyDown(backwardskey)) { - if(targetanimation!=moveanim)targetframe=0; - targetanimation=moveanim; - } - if (IsKeyDown(rightkey) && !IsKeyDown(leftkey)) { - if(targetanimation!=moveanim)targetframe=0; - targetanimation=moveanim; - playerlowrotation-=90; - if (IsKeyDown(forwardskey)) - playerlowrotation += 45; - if (IsKeyDown(backwardskey)) - playerlowrotation -= 235; - } - if (IsKeyDown(leftkey) && !IsKeyDown(rightkey)) { - if(targetanimation!=moveanim)targetframe=0; - targetanimation=moveanim; - playerlowrotation+=90; - if (IsKeyDown(forwardskey)) - playerlowrotation -= 45; - if (IsKeyDown(backwardskey)) - playerlowrotation += 235; - } - if (IsKeyDown(backwardskey)) { - if(targetanimation!=moveanim)targetframe=0; - targetanimation=moveanim; - backwardsanim=1; - } - } - //air control - if(!onground){ - float oldplayerrotation=playerrotation; - if (IsKeyDown(forwardskey) && !IsKeyDown(backwardskey)) { - facing=0; - facing.z=1; - facing=DoRotation(facing,0,playerrotation,0); - velocity=velocity+facing*multiplier*4; - } - if (IsKeyDown(rightkey) && !IsKeyDown(leftkey)) { - playerrotation-=90; - if (IsKeyDown(forwardskey)) - playerrotation += 45; - if (IsKeyDown(backwardskey)) - playerrotation -= 45; - facing=0; - facing.z=1; - facing=DoRotation(facing,0,playerrotation,0); - velocity=velocity+facing*multiplier*4; - } - if (IsKeyDown(leftkey) && !IsKeyDown(rightkey)) { - playerrotation+=90; - if (IsKeyDown(forwardskey)) - playerrotation -= 45; - if (IsKeyDown(backwardskey)) - playerrotation += 45; - facing=0; - facing.z=1; - facing=DoRotation(facing,0,playerrotation,0); - velocity=velocity+facing*multiplier*4; - } - if (IsKeyDown(backwardskey) && !IsKeyDown(forwardskey) - && !IsKeyDown(leftkey) && !IsKeyDown(rightkey)) { - playerrotation+=180; - facing=0; - facing.z=1; - facing=DoRotation(facing,0,playerrotation,0); - velocity=velocity+facing*multiplier*4; - } - playerrotation=oldplayerrotation; - } - if (!IsKeyDown(forwardskey) && !IsKeyDown(leftkey) - && !IsKeyDown(rightkey) && !IsKeyDown(backwardskey) - && (targetanimation==joganim||targetanimation==walkanim)) { - if(!(targetanimation==walkanim&&(targetframe==0||targetframe==2))){ - targetanimation=idleanim; - targetframe=0; - target=0; - } - } + } else if (playerrotation > playerlowrotation + 70) { + playerrotation = playerlowrotation + 70; + } else if (playerrotation < playerlowrotation - 70) { + playerrotation = playerlowrotation - 70; } - facing=0; - facing.z=1; + if (who == 0) + camera.rotation = 180 - playerrotation; + + if(who!=0&&visions==0){ + if(targetanimation!=walkanim&&targetanimation!=zombiewalkanim)speed=1.0*speedmult; + if(targetanimation==walkanim||targetanimation==zombiewalkanim)speed=1.8*speedmult; + playerlowrotation=playerrotation; + } - facing=DoRotation(facing,0,playerlowrotation,0); - if(backwardsanim)facing*=-1; + // Do controls + if (who == 0 && targetanimation != diveanim + && targetanimation != throwanim + && targetanimation != thrownanim + && currentanimation != diveanim + && currentanimation != getupfrontanim) + control(); + + facing = DoRotation({0, 0, 1}, 0, playerlowrotation, 0); + if (backwardsanim) + facing *= -1; if(onground){ velocity=0; -- cgit v1.2.3