summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--data/config.ini7
-rw-r--r--src/GameLoop.cpp12
-rw-r--r--src/Person.cpp9
-rw-r--r--src/config.h3
-rw-r--r--src/config.zig15
5 files changed, 30 insertions, 16 deletions
diff --git a/data/config.ini b/data/config.ini
index 3197751..5781505 100644
--- a/data/config.ini
+++ b/data/config.ini
@@ -10,14 +10,19 @@ music = true
 
 [input]
 mouse sensitivity = 1.0
+; Key names: https://www.glfw.org/docs/latest/group__keys.html
 forwards key = W
 backwards key = S
 left key = A
 right key = D
+crouch key = LEFT_CONTROL
+accelerate key = LEFT_SHIFT
+dive key = SPACE
+reload key = R
 aim key = E
 psychic aim key = Q
 psychic key = Z
+laser sight key = L
 
 [misc]
 custom levels = 0
-debug = false
diff --git a/src/GameLoop.cpp b/src/GameLoop.cpp
index 8a1af59..cc383c8 100644
--- a/src/GameLoop.cpp
+++ b/src/GameLoop.cpp
@@ -38,12 +38,6 @@ void handleKey(Game* game, int key, int action, int mods)
 {
 	if (action != GLFW_PRESS)
 		return;
-	if (game->menu) {
-		if (key == GLFW_KEY_SPACE)
-			setMenu(game, false);
-		return;
-	}
-
 	auto& player = game->person[0];
 	if (key == GLFW_KEY_ESCAPE) {
 		alSourcePause(gSourceID[rainsound]);
@@ -63,9 +57,9 @@ void handleKey(Game* game, int key, int action, int mods)
 		alSourcef(gSourceID[mainmenusong], AL_MIN_GAIN, 0);
 		alSourcePlay(gSourceID[game->whichsong]);
 		alSourcef(gSourceID[game->whichsong], AL_MIN_GAIN, 1);
-	} else if (key == GLFW_KEY_L) {
+	} else if (key == keymap.laser_sight) {
 		game->lasersight ^= 1;
-	} else if (key == GLFW_KEY_SPACE) {
+	} else if (key == keymap.dive) {
 		if (player.playerrotation == player.playerlowrotation
 		    && player.targetanimation == joganim
 		    && player.currentanimation == joganim
@@ -74,7 +68,7 @@ void handleKey(Game* game, int key, int action, int mods)
 			player.targetframe = player.target = 0;
 			player.aimamount = 0;
 		}
-	} else if (key == GLFW_KEY_R) {
+	} else if (key == keymap.reload) {
 		if (player.whichgun != grenade
 		    && player.reloads[player.whichgun] > 0
 		    && player.reloading <= 0)
diff --git a/src/Person.cpp b/src/Person.cpp
index d096b1d..fb05907 100644
--- a/src/Person.cpp
+++ b/src/Person.cpp
@@ -631,14 +631,13 @@ void Person::control()
 	else
 		speed = (targetanimation == joganim) ? 2.2 : 2.5;
 
-	if (keyPress(GLFW_KEY_LEFT_CONTROL)
-	    && currentanimation == idleanim
+	auto crouch = keyPress(keymap.crouch);
+	if (crouch && currentanimation == idleanim
 	    && targetanimation == idleanim) {
 		targetanimation = crouchanim;
 		target = 0;
 	}
-	if (!keyPress(GLFW_KEY_LEFT_CONTROL)
-	    && currentanimation == crouchanim
+	if (!crouch && currentanimation == crouchanim
 	    && targetanimation == crouchanim) {
 		targetanimation = idleanim;
 		target = 0;
@@ -649,7 +648,7 @@ void Person::control()
 	if ((onground || visions) && currentanimation != crouchanim) {
 		playerlowrotation -= right * (forwards ? forwards * 45 : 90);
 		backwardsanim = forwards < 0;
-		auto moveanim = (keyPress(GLFW_KEY_LEFT_SHIFT) || visions)
+		auto moveanim = (keyPress(keymap.accelerate) || visions)
 			? joganim : walkanim; // Should jog be the default?
 		if (forwards || right) {
 			if (targetanimation != moveanim) {
diff --git a/src/config.h b/src/config.h
index 486a4f6..a58c2f3 100644
--- a/src/config.h
+++ b/src/config.h
@@ -16,7 +16,8 @@ struct Level {
 
 struct Key {
 	int forwards, backwards, left, right;
-	int aim, psychic_aim, psychic;
+	int crouch, accelerate, dive;
+	int reload, aim, psychic_aim, psychic, laser_sight;
 };
 
 struct Config {
diff --git a/src/config.zig b/src/config.zig
index eec36d7..86eb6d8 100644
--- a/src/config.zig
+++ b/src/config.zig
@@ -146,9 +146,14 @@ pub const Config = extern struct {
         backwards: c_int = @enumToInt(Key.S),
         left: c_int = @enumToInt(Key.A),
         right: c_int = @enumToInt(Key.D),
+        crouch: c_int = @enumToInt(Key.LEFT_CONTROL),
+        accelerate: c_int = @enumToInt(Key.LEFT_SHIFT),
+        dive: c_int = @enumToInt(Key.SPACE),
+        reload: c_int = @enumToInt(Key.R),
         aim: c_int = @enumToInt(Key.E),
         psychic_aim: c_int = @enumToInt(Key.Q),
         psychic: c_int = @enumToInt(Key.Z),
+        laser_sight: c_int = @enumToInt(Key.L),
     } = .{},
 
     levels: extern struct { ptr: [*]Level = undefined, len: usize = 0 } = .{},
@@ -206,12 +211,22 @@ pub fn parse(base_dir: []const u8) !Config {
                     config.key.left = parseKey(kv.value)
                 else if (eql(u8, kv.key, "right key"))
                     config.key.right = parseKey(kv.value)
+                else if (eql(u8, kv.key, "crouch key"))
+                    config.key.crouch = parseKey(kv.value)
+                else if (eql(u8, kv.key, "accelerate key"))
+                    config.key.accelerate = parseKey(kv.value)
+                else if (eql(u8, kv.key, "dive key"))
+                    config.key.dive = parseKey(kv.value)
+                else if (eql(u8, kv.key, "reload key"))
+                    config.key.reload = parseKey(kv.value)
                 else if (eql(u8, kv.key, "aim key"))
                     config.key.aim = parseKey(kv.value)
                 else if (eql(u8, kv.key, "psychic aim key"))
                     config.key.psychic_aim = parseKey(kv.value)
                 else if (eql(u8, kv.key, "psychic key"))
                     config.key.psychic = parseKey(kv.value)
+                else if (eql(u8, kv.key, "laser sight key"))
+                    config.key.laser_sight = parseKey(kv.value)
                 else return error.InvalidData;
             } else if (eql(u8, section, "misc")) {
                 if (eql(u8, kv.key, "custom levels"))