Skip to content

Use left shift to run and if is not pressed then walk. #89

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ See the [wiki](https://github.com/fogleman/Minecraft/wiki) for this project to i
- Mouse: look around
- Space: jump
- Tab: toggle flying mode
- Left Shift: run

### Building

Expand Down
12 changes: 10 additions & 2 deletions main.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
# Size of sectors used to ease block loading.
SECTOR_SIZE = 16

WALKING_SPEED = 5
WALKING_SPEED = 2
RUNNING_SPEED = 5
FLYING_SPEED = 15

GRAVITY = 20.0
Expand Down Expand Up @@ -442,6 +443,9 @@ def __init__(self, *args, **kwargs):
# When flying gravity has no effect and speed is increased.
self.flying = False

# Determine if player is running. If false, then player is walking.
self.running = False

# Strafing is moving lateral to the direction you are facing,
# e.g. moving to the left or right while continuing to face forward.
#
Expand Down Expand Up @@ -591,7 +595,7 @@ def _update(self, dt):

"""
# walking
speed = FLYING_SPEED if self.flying else WALKING_SPEED
speed = FLYING_SPEED if self.flying else RUNNING_SPEED if self.running else WALKING_SPEED
d = dt * speed # distance covered this tick.
dx, dy, dz = self.get_motion_vector()
# New position in space, before accounting for gravity.
Expand Down Expand Up @@ -733,6 +737,8 @@ def on_key_press(self, symbol, modifiers):
self.set_exclusive_mouse(False)
elif symbol == key.TAB:
self.flying = not self.flying
elif symbol == key.LSHIFT:
self.running = True
elif symbol in self.num_keys:
index = (symbol - self.num_keys[0]) % len(self.inventory)
self.block = self.inventory[index]
Expand All @@ -757,6 +763,8 @@ def on_key_release(self, symbol, modifiers):
self.strafe[1] += 1
elif symbol == key.D:
self.strafe[1] -= 1
elif symbol == key.LSHIFT:
self.running = False

def on_resize(self, width, height):
""" Called when the window is resized to a new `width` and `height`.
Expand Down