Browse Source

Pygame

pull/144/head
Jure Šorn 1 year ago
parent
commit
d809d87163
3 changed files with 11 additions and 11 deletions
  1. 6
      README.md
  2. 10
      index.html
  3. 6
      parse.js

6
README.md

@ -3065,7 +3065,8 @@ def main():
run(get_screen(), get_images(), get_mario(), get_tiles())
def run(screen, images, mario, tiles):
clock, pressed = pg.time.Clock(), set()
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)}
@ -3086,8 +3087,7 @@ def update_position(mario, tiles):
n_steps = max(abs(s) for s in mario.spd)
for _ in range(n_steps):
mario.spd = stop_on_collision(mario.spd, get_boundaries(mario.rect, tiles))
x, y = x + (mario.spd.x / n_steps), y + (mario.spd.y / n_steps)
mario.rect.topleft = x, y
mario.rect.topleft = x, y = x + (mario.spd.x / n_steps), y + (mario.spd.y / n_steps)
def get_boundaries(rect, tiles):
deltas = {D.n: P(0, -1), D.e: P(1, 0), D.s: P(0, 1), D.w: P(-1, 0)}

10
index.html

@ -54,7 +54,7 @@
<body>
<header>
<aside>December 27, 2022</aside>
<aside>December 30, 2022</aside>
<a href="https://gto76.github.io" rel="author">Jure Šorn</a>
</header>
@ -2502,7 +2502,8 @@ W, H, MAX_S = <span class="hljs-number">50</span>, <span class="hljs-number">50<
run(get_screen(), get_images(), get_mario(), get_tiles())
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">run</span><span class="hljs-params">(screen, images, mario, tiles)</span>:</span>
clock, pressed = pg.time.Clock(), set()
clock = pg.time.Clock()
pressed = set()
<span class="hljs-keyword">while</span> <span class="hljs-keyword">not</span> pg.event.get(pg.QUIT) <span class="hljs-keyword">and</span> clock.tick(<span class="hljs-number">28</span>):
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) <span class="hljs-keyword">for</span> e <span class="hljs-keyword">in</span> pg.event.get(pg.KEYDOWN)}
@ -2523,8 +2524,7 @@ W, H, MAX_S = <span class="hljs-number">50</span>, <span class="hljs-number">50<
n_steps = max(abs(s) <span class="hljs-keyword">for</span> s <span class="hljs-keyword">in</span> mario.spd)
<span class="hljs-keyword">for</span> _ <span class="hljs-keyword">in</span> range(n_steps):
mario.spd = stop_on_collision(mario.spd, get_boundaries(mario.rect, tiles))
x, y = x + (mario.spd.x / n_steps), y + (mario.spd.y / n_steps)
mario.rect.topleft = x, y
mario.rect.topleft = x, y = x + (mario.spd.x / n_steps), y + (mario.spd.y / n_steps)
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">get_boundaries</span><span class="hljs-params">(rect, tiles)</span>:</span>
deltas = {D.n: P(<span class="hljs-number">0</span>, <span class="hljs-number">-1</span>), D.e: P(<span class="hljs-number">1</span>, <span class="hljs-number">0</span>), D.s: P(<span class="hljs-number">0</span>, <span class="hljs-number">1</span>), D.w: P(<span class="hljs-number">-1</span>, <span class="hljs-number">0</span>)}
@ -2919,7 +2919,7 @@ $ pyinstaller script.py --add-data '&lt;path&gt;:.' <span class="hljs-comment">
<footer>
<aside>December 27, 2022</aside>
<aside>December 30, 2022</aside>
<a href="https://gto76.github.io" rel="author">Jure Šorn</a>
</footer>

6
parse.js

@ -201,7 +201,8 @@ const MARIO =
' run(get_screen(), get_images(), get_mario(), get_tiles())\n' +
'\n' +
'<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">run</span><span class="hljs-params">(screen, images, mario, tiles)</span>:</span>\n' +
' clock, pressed = pg.time.Clock(), set()\n' +
' clock = pg.time.Clock()\n' +
' pressed = set()\n' +
' <span class="hljs-keyword">while</span> <span class="hljs-keyword">not</span> pg.event.get(pg.QUIT) <span class="hljs-keyword">and</span> clock.tick(<span class="hljs-number">28</span>):\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) <span class="hljs-keyword">for</span> e <span class="hljs-keyword">in</span> pg.event.get(pg.KEYDOWN)}\n' +
@ -222,8 +223,7 @@ const MARIO =
' n_steps = max(abs(s) <span class="hljs-keyword">for</span> s <span class="hljs-keyword">in</span> mario.spd)\n' +
' <span class="hljs-keyword">for</span> _ <span class="hljs-keyword">in</span> range(n_steps):\n' +
' mario.spd = stop_on_collision(mario.spd, get_boundaries(mario.rect, tiles))\n' +
' x, y = x + (mario.spd.x / n_steps), y + (mario.spd.y / n_steps)\n' +
' mario.rect.topleft = x, y\n' +
' mario.rect.topleft = x, y = x + (mario.spd.x / n_steps), y + (mario.spd.y / n_steps)\n' +
'\n' +
'<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">get_boundaries</span><span class="hljs-params">(rect, tiles)</span>:</span>\n' +
' deltas = {D.n: P(<span class="hljs-number">0</span>, <span class="hljs-number">-1</span>), D.e: P(<span class="hljs-number">1</span>, <span class="hljs-number">0</span>), D.s: P(<span class="hljs-number">0</span>, <span class="hljs-number">1</span>), D.w: P(<span class="hljs-number">-1</span>, <span class="hljs-number">0</span>)}\n' +

Loading…
Cancel
Save