- commit
- 73f83268f438fec410c1e24fcf5489b7814c611d
- parent
- b45afe5f27eaa29ca1a6dc897d3461b124c1911b
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2021-05-09 07:24
adjustjump constants to map
Diffstat
| M | tighogg.py | 28 | +++++++++++++++++++++------- |
1 files changed, 21 insertions, 7 deletions
diff --git a/tighogg.py b/tighogg.py
@@ -10,14 +10,27 @@ RIGHT = 1 10 10 YELLOW = 10 11 11 GREEN = 11 12 12 -1 13 BLOCK_HEIGHT = 5 -1 14 BLOCK_WIDTH = 15 -1 15 RUN_VELOCITY = 1 -1 16 GRAVITY = 0.1 -1 17 -1 18 # x(t) = t * RUN_VELOCITY -1 19 # y(t) = t**2 * GRAVITY / 2 - t * JUMP_VELOCITY -1 20 # A single jump should cover BLOCK_WIDTH and BLOCK_HEIGHT -1 21 JUMP_VELOCITY = ((BLOCK_WIDTH / RUN_VELOCITY) ** 2 * GRAVITY / 2 + BLOCK_HEIGHT) / (BLOCK_WIDTH / RUN_VELOCITY) # noqa -1 22 13 23 14 24 class Map:15 -1 def __init__(self, size=1000, s='------__ _ _-- ____---- --'):16 -1 self.size = size-1 25 def __init__(self, s='------__ _ _-- ____---- --'): 17 26 self.s = s 18 27 -1 28 @property -1 29 def size(self): -1 30 return len(self.s) * BLOCK_WIDTH * 2 -1 31 19 32 def get_floor(self, x):20 -1 k = int(abs((x / self.size * 2 - 1) * len(self.s)))-1 33 k = abs(round(x / BLOCK_WIDTH) - len(self.s)) 21 34 try: 22 35 if self.s[k] == '-': 23 36 return 12 @@ -61,13 +74,14 @@ class Player: 61 74 def step(self): 62 75 if self.running: 63 76 if self.direction == RIGHT:64 -1 self.x += 1-1 77 self.x += RUN_VELOCITY 65 78 else:66 -1 self.x -= 1-1 79 self.x -= RUN_VELOCITY 67 80 68 81 if self.floor > self.y:69 -1 self.dy += 0.1-1 82 self.dy += GRAVITY 70 83 self.y += self.dy -1 84 # FIXME: auto climb 71 85 if self.floor < self.y: 72 86 self.dy = 0 73 87 self.y = self.floor @@ -82,7 +96,7 @@ class Player: 82 96 83 97 def jump(self): 84 98 if self.floor == self.y:85 -1 self.dy = -1-1 99 self.dy = -JUMP_VELOCITY 86 100 87 101 def _render(self): 88 102 if self.running: