aboutsummaryrefslogtreecommitdiff
path: root/src/Person.cpp
diff options
context:
space:
mode:
authorNguyễn Gia Phong <mcsinyx@disroot.org>2021-10-28 23:45:34 +0700
committerNguyễn Gia Phong <mcsinyx@disroot.org>2021-10-28 23:45:34 +0700
commitbd8985065f2377a62f0ee9f4236d5cd9ad99dfe4 (patch)
treecee76279026bbba88fededfc9474c8eba67d5c2d /src/Person.cpp
parent036ab1d1051b54e71f80fbb791bf69bd7c236f62 (diff)
downloadblackshades-bd8985065f2377a62f0ee9f4236d5cd9ad99dfe4.tar.gz
Reorganize key mappings
Diffstat (limited to 'src/Person.cpp')
-rw-r--r--src/Person.cpp207
1 files changed, 83 insertions, 124 deletions
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&&currentanimation!=crouchanim){
- if(playerrotation>playerlowrotation+50){playerlowrotation=playerrotation-50; targetanimation=walkanim; targetframe=0; target=0;}
- if(playerrotation<playerlowrotation-50){playerlowrotation=playerrotation+50; targetanimation=walkanim; targetframe=0; target=0;}
+ if (keyPress(GLFW_KEY_LEFT_CONTROL)
+ && currentanimation == idleanim
+ && targetanimation == idleanim) {
+ targetanimation = crouchanim;
+ target = 0;
}
- if(targetanimation==crouchanim||currentanimation==crouchanim){
- if(playerrotation>playerlowrotation+70){playerrotation=playerlowrotation+70;}
- if(playerrotation<playerlowrotation-70){playerrotation=playerlowrotation-70;}
+ if (!keyPress(GLFW_KEY_LEFT_CONTROL)
+ && currentanimation == crouchanim
+ && targetanimation == crouchanim) {
+ targetanimation = idleanim;
+ target = 0;
}
- 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;
+ auto forwards = keyPress(keymap.forwards) - keyPress(keymap.backwards);
+ auto right = keyPress(keymap.right) - keyPress(keymap.left);
+ if ((onground || visions) && currentanimation != crouchanim) {
+ playerlowrotation -= right * (forwards ? forwards * 45 : 90);
+ backwardsanim = forwards < 0;
+ auto moveanim = (keyPress(GLFW_KEY_LEFT_SHIFT) || visions)
+ ? joganim : walkanim; // Should jog be the default?
+ if (forwards || right) {
+ if (targetanimation != moveanim) {
+ targetanimation = moveanim;
+ targetframe = 0;
+ }
+ } else {
+ if (targetanimation == joganim
+ || (targetanimation == walkanim
+ && targetframe != 0 && targetframe != 2)) {
+ targetanimation = idleanim;
+ targetframe = 0;
+ target = 0;
+ }
+ }
}
- //Do controls
- if(who==0&&targetanimation!=diveanim&&targetanimation!=throwanim&&targetanimation!=thrownanim&&currentanimation!=diveanim&&currentanimation!=getupfrontanim){
- backwardsanim=0;
- if(visions==1)speed=40;
- if(visions==0&&targetanimation==joganim)speed=2.2;
- if(visions==0&&targetanimation!=joganim)speed=1.3;
- if(visions==0&&targetanimation==walkanim)speed=2.5;
+ // Air? What does this even do?
+ if (!onground && (forwards || right)) {
+ auto rotation = playerrotation
+ - right * (forwards ? forwards * 45 : 90);
+ facing = DoRotation({0, 0, 1}, 0, rotation, 0);
+ velocity += facing * multiplier * 4;
+ }
+}
- if (IsKeyDown(GLFW_KEY_LEFT_SHIFT) || visions == 1)
- moveanim = joganim;
- else
- moveanim=walkanim;
- if (IsKeyDown(GLFW_KEY_LEFT_CONTROL)
- && currentanimation == idleanim
- && targetanimation == idleanim) {
- targetanimation = crouchanim;
+void Person::DoStuff(int who)
+{
+ if (targetanimation != idleanim && targetanimation != crouchanim || visions)
+ playerlowrotation = playerrotation;
+ if (targetanimation != crouchanim && currentanimation != crouchanim) {
+ 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))&&currentanimation!=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;