diff --git a/README.md b/README.md index 4c441e2..879c3a0 100644 --- a/README.md +++ b/README.md @@ -3096,19 +3096,19 @@ def main(): def run(screen, images, mario, tiles): clock = pg.time.Clock() pressed = set() - while not pg.event.get(pg.QUIT) and clock.tick(28): - keys = {pg.K_UP: D.n, pg.K_RIGHT: D.e, pg.K_DOWN: D.s, pg.K_LEFT: D.w} - pressed |= {keys.get(e.key) for e in pg.event.get(pg.KEYDOWN)} - pressed -= {keys.get(e.key) for e in pg.event.get(pg.KEYUP)} + while not pg.event.get(pg.QUIT): + clock.tick(28) + pressed |= {e.key for e in pg.event.get(pg.KEYDOWN)} + pressed -= {e.key for e in pg.event.get(pg.KEYUP)} update_speed(mario, tiles, pressed) update_position(mario, tiles) draw(screen, images, mario, tiles) def update_speed(mario, tiles, pressed): x, y = mario.spd - x += 2 * ((D.e in pressed) - (D.w in pressed)) + x += 2 * ((pg.K_RIGHT in pressed) - (pg.K_LEFT in pressed)) x += (x < 0) - (x > 0) - y += 1 if D.s not in get_boundaries(mario.rect, tiles) else (D.n in pressed) * -10 + y += 1 if D.s not in get_boundaries(mario.rect, tiles) else (pg.K_UP in pressed) * -10 mario.spd = P(x=max(-MAX_S.x, min(MAX_S.x, x)), y=max(-MAX_S.y, min(MAX_S.y, y))) def update_position(mario, tiles): diff --git a/index.html b/index.html index 615f797..eaeee48 100644 --- a/index.html +++ b/index.html @@ -56,7 +56,7 @@
- +
@@ -2533,19 +2533,19 @@ W, H, MAX_S = 50, 50< def run(screen, images, mario, tiles): clock = pg.time.Clock() pressed = set() - while not pg.event.get(pg.QUIT) and clock.tick(28): - keys = {pg.K_UP: D.n, pg.K_RIGHT: D.e, pg.K_DOWN: D.s, pg.K_LEFT: D.w} - pressed |= {keys.get(e.key) for e in pg.event.get(pg.KEYDOWN)} - pressed -= {keys.get(e.key) for e in pg.event.get(pg.KEYUP)} + while not pg.event.get(pg.QUIT): + clock.tick(28) + pressed |= {e.key for e in pg.event.get(pg.KEYDOWN)} + pressed -= {e.key for e in pg.event.get(pg.KEYUP)} update_speed(mario, tiles, pressed) update_position(mario, tiles) draw(screen, images, mario, tiles) def update_speed(mario, tiles, pressed): x, y = mario.spd - x += 2 * ((D.e in pressed) - (D.w in pressed)) + x += 2 * ((pg.K_RIGHT in pressed) - (pg.K_LEFT in pressed)) x += (x < 0) - (x > 0) - y += 1 if D.s not in get_boundaries(mario.rect, tiles) else (D.n in pressed) * -10 + y += 1 if D.s not in get_boundaries(mario.rect, tiles) else (pg.K_UP in pressed) * -10 mario.spd = P(x=max(-MAX_S.x, min(MAX_S.x, x)), y=max(-MAX_S.y, min(MAX_S.y, y))) def update_position(mario, tiles): @@ -2942,7 +2942,7 @@ $ deactivate # Deactivates the active
- +
diff --git a/parse.js b/parse.js index f7895a0..ec7fa74 100755 --- a/parse.js +++ b/parse.js @@ -259,19 +259,19 @@ const MARIO = 'def run(screen, images, mario, tiles):\n' + ' clock = pg.time.Clock()\n' + ' pressed = set()\n' + - ' while not pg.event.get(pg.QUIT) and clock.tick(28):\n' + - ' keys = {pg.K_UP: D.n, pg.K_RIGHT: D.e, pg.K_DOWN: D.s, pg.K_LEFT: D.w}\n' + - ' pressed |= {keys.get(e.key) for e in pg.event.get(pg.KEYDOWN)}\n' + - ' pressed -= {keys.get(e.key) for e in pg.event.get(pg.KEYUP)}\n' + + ' while not pg.event.get(pg.QUIT):\n' + + ' clock.tick(28)\n' + + ' pressed |= {e.key for e in pg.event.get(pg.KEYDOWN)}\n' + + ' pressed -= {e.key for e in pg.event.get(pg.KEYUP)}\n' + ' update_speed(mario, tiles, pressed)\n' + ' update_position(mario, tiles)\n' + ' draw(screen, images, mario, tiles)\n' + '\n' + 'def update_speed(mario, tiles, pressed):\n' + ' x, y = mario.spd\n' + - ' x += 2 * ((D.e in pressed) - (D.w in pressed))\n' + + ' x += 2 * ((pg.K_RIGHT in pressed) - (pg.K_LEFT in pressed))\n' + ' x += (x < 0) - (x > 0)\n' + - ' y += 1 if D.s not in get_boundaries(mario.rect, tiles) else (D.n in pressed) * -10\n' + + ' y += 1 if D.s not in get_boundaries(mario.rect, tiles) else (pg.K_UP in pressed) * -10\n' + ' mario.spd = P(x=max(-MAX_S.x, min(MAX_S.x, x)), y=max(-MAX_S.y, min(MAX_S.y, y)))\n' + '\n' + 'def update_position(mario, tiles):\n' +