[C++]
How to make left mouse button move you forward (and do your mining reclined in a couch)
Having to keep a hand on the keyboard for moving can sometimes be way to strenous,
especially when doing brain-dead dig-everywhere mining.
This hack makes you move forward when clicking the mouse at air, allowing you to dig until
there's nothing there, then move forward so you can reach more stuff to dig.
The functions that determine player input are located in the main loop in the source file
src/game.cpp.
The main doings in
game.cpp is performed inside the
the_game function, stretching from line 854 to the end of the
game.cpp file (row 2921)
Inside
the_game is an infinite loop starting with
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
This loop is called "Main loop" in the comment lines.
It stretching from lines 1274 to 2879 (almost to the end of the file)
Direct handling of user input start of line 1483:
The movement keys on the keyboard are checked at line 1874,
called Player speed control in a comment line
which checks for pressed keyboard keys and and sends keypress info using a
PlayerControl object, which it sends somewhere using
client.setPlayerControl (probably to some method for sending info to the server).
The info packed intothe PlayerControl object are a bunch of true/false variables in the order (forward, back, left,rigtht + some other info).
You can check the behaviour of this by changing forward to always being true, to get a game in which you are constantly moving forward:
on line 1886 to 1896 of game.cpp, change
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
PlayerControl control(
input->isKeyDown(getKeySetting("keymap_forward")),
input->isKeyDown(getKeySetting("keymap_backward")),
input->isKeyDown(getKeySetting("keymap_left")),
input->isKeyDown(getKeySetting("keymap_right")),
input->isKeyDown(getKeySetting("keymap_jump")),
input->isKeyDown(getKeySetting("keymap_special1")),
input->isKeyDown(getKeySetting("keymap_sneak")),
camera_pitch,
camera_yaw
);
to
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
PlayerControl control(
//input->isKeyDown(getKeySetting("keymap_forward")),
true,
input->isKeyDown(getKeySetting("keymap_backward")),
input->isKeyDown(getKeySetting("keymap_left")),
input->isKeyDown(getKeySetting("keymap_right")),
input->isKeyDown(getKeySetting("keymap_jump")),
input->isKeyDown(getKeySetting("keymap_special1")),
input->isKeyDown(getKeySetting("keymap_sneak")),
camera_pitch,
camera_yaw
);
Detecting when you should move forward instead of doing "left-mouse button":There is conveniently already a function for telling wether you "hit the air", but its down on line 2384, after a bunch of other calculations for mouse button input.
It looks like this
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
else if(input->getLeftState())
{
// When button is held down in air, show continuous animation
left_punch = true;
}
, and sets a variable
left_punch to tell wether you "hit air" or not.
I can't see a reason for sending the movement info to
client.setPlayerControl that early in the code way up on line 1896. Its located before all mouse actions have been calculated but we need the
left_punch calculation performed there.
I'm moving the "Player speed control" section of the program down to line 2389, which is AFTER the loop has investigated if we're hitting air or not:
(NOTE that I don't know what the hell I'm doing, there may be a perfectly good reason for having the code where it is).
Cut this (line 1873 to 1898) :
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
/*
Player speed control
*/
{
/*bool a_up,
bool a_down,
bool a_left,
bool a_right,
bool a_jump,
bool a_superspeed,
bool a_sneak,
float a_pitch,
float a_yaw*/
PlayerControl control(
input->isKeyDown(getKeySetting("keymap_forward")),
input->isKeyDown(getKeySetting("keymap_backward")),
input->isKeyDown(getKeySetting("keymap_left")),
input->isKeyDown(getKeySetting("keymap_right")),
input->isKeyDown(getKeySetting("keymap_jump")),
input->isKeyDown(getKeySetting("keymap_special1")),
input->isKeyDown(getKeySetting("keymap_sneak")),
camera_pitch,
camera_yaw
);
client.setPlayerControl(control);
}
and paste it just underneath this:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
else if(input->getLeftState())
{
// When button is held down in air, show continuous animation
left_punch = true;
}
on line 2389.
All we have done so far is changing the order of some commands. If you compile and run the game now, where will be no differences.
[Anticlimax - continued in post below]