From 3f53ad093ba5d7c5b14a2eb89dce40b776d3a966 Mon Sep 17 00:00:00 2001 From: kk6axq Date: Wed, 8 Nov 2017 19:53:35 -0700 Subject: [PATCH 1/2] Add Sprint Functionality --- main.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 84fc069d..08b5f683 100644 --- a/main.py +++ b/main.py @@ -17,6 +17,7 @@ SECTOR_SIZE = 16 WALKING_SPEED = 5 +SPRINTING_SPEED = 10 FLYING_SPEED = 15 GRAVITY = 20.0 @@ -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) @@ -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. @@ -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" elif symbol in self.num_keys: index = (symbol - self.num_keys[0]) % len(self.inventory) self.block = self.inventory[index] @@ -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`. From 98a323a494d1cba15d79c336baf7b63ad96baf9f Mon Sep 17 00:00:00 2001 From: kk6axq Date: Tue, 14 Nov 2017 18:53:13 -0700 Subject: [PATCH 2/2] Remove print and fix indenting --- main.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index 08b5f683..1efbb562 100644 --- a/main.py +++ b/main.py @@ -451,8 +451,8 @@ def __init__(self, *args, **kwargs): # right, and 0 otherwise. self.strafe = [0, 0] - #True if sprinting - self.sprinting = False + #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. @@ -596,11 +596,11 @@ def _update(self, dt): """ # walking if self.flying: - speed = FLYING_SPEED + speed = FLYING_SPEED elif self.sprinting: - speed = SPRINTING_SPEED + speed = SPRINTING_SPEED else: - speed = WALKING_SPEED + 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. @@ -744,7 +744,6 @@ def on_key_press(self, symbol, modifiers): self.flying = not self.flying elif symbol == key.LSHIFT: self.sprinting = True - print "Sprinting" elif symbol in self.num_keys: index = (symbol - self.num_keys[0]) % len(self.inventory) self.block = self.inventory[index]