MCPcopy Index your code
hub / github.com/fogleman/Minecraft / _update

Method _update

main.py:583–610  ·  view source on GitHub ↗

Private implementation of the `update()` method. This is where most of the motion logic lives, along with gravity and collision detection. Parameters ---------- dt : float The change in time since the last call.

(self, dt)

Source from the content-addressed store, hash-verified

581 self._update(dt / m)
582
583 def _update(self, dt):
584 """ Private implementation of the `update()` method. This is where most
585 of the motion logic lives, along with gravity and collision detection.
586
587 Parameters
588 ----------
589 dt : float
590 The change in time since the last call.
591
592 """
593 # walking
594 speed = FLYING_SPEED if self.flying else WALKING_SPEED
595 d = dt * speed # distance covered this tick.
596 dx, dy, dz = self.get_motion_vector()
597 # New position in space, before accounting for gravity.
598 dx, dy, dz = dx * d, dy * d, dz * d
599 # gravity
600 if not self.flying:
601 # Update your vertical speed: if you are falling, speed up until you
602 # hit terminal velocity; if you are jumping, slow down until you
603 # start falling.
604 self.dy -= dt * GRAVITY
605 self.dy = max(self.dy, -TERMINAL_VELOCITY)
606 dy += self.dy * dt
607 # collisions
608 x, y, z = self.position
609 x, y, z = self.collide((x + dx, y + dy, z + dz), PLAYER_HEIGHT)
610 self.position = (x, y, z)
611
612 def collide(self, position, height):
613 """ Checks to see if the player at the given `position` and `height`

Callers 1

updateMethod · 0.95

Calls 2

get_motion_vectorMethod · 0.95
collideMethod · 0.95

Tested by

no test coverage detected