Skip to content
Open
Changes from 1 commit
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
16 changes: 15 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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you use spaces instead of tabs?

# 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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment

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,9 @@ 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
print "Sprinting"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this line (or use print("Sprinting") to work on Python 3)

elif symbol in self.num_keys:
index = (symbol - self.num_keys[0]) % len(self.inventory)
self.block = self.inventory[index]
Expand All @@ -757,6 +769,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