Skip to content

Add Sprint Functionality #86

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 2 commits into
base: master
Choose a base branch
from
Open
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
15 changes: 14 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
SECTOR_SIZE = 16

WALKING_SPEED = 5
SPRINTING_SPEED = 10
FLYING_SPEED = 15

GRAVITY = 20.0
Expand Down Expand Up @@ -450,6 +451,9 @@ def __init__(self, *args, **kwargs):
# right, and 0 otherwise.
self.strafe = [0, 0]

#True if sprinting
self.sprinting = False

# Current (x, y, z) position in the world, specified with floats. Note
# that, perhaps unlike in math class, the y-axis is the vertical axis.
self.position = (0, 0, 0)
Expand Down Expand Up @@ -591,7 +595,12 @@ def _update(self, dt):

"""
# walking
speed = FLYING_SPEED if self.flying else WALKING_SPEED
if self.flying:
speed = FLYING_SPEED
elif self.sprinting:
speed = SPRINTING_SPEED
else:
speed = 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 +742,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.sprinting = 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 +768,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.sprinting = False

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