@ -2424,10 +2424,10 @@ simpleaudio.play_buffer(samples_b, <span class="hljs-number">1</span>, <span cla
pg.init()
screen = pg.display.set_mode((< span class = "hljs-number" > 500< / span > , < span class = "hljs-number" > 500< / span > ))
rect = pg.Rect(< span class = "hljs-number" > 240< / span > , < span class = "hljs-number" > 240< / span > , < span class = "hljs-number" > 20< / span > , < span class = "hljs-number" > 20< / span > )
< span class = "hljs-keyword" > while< / span > all(event.type != pg.QUIT < span class = "hljs-keyword" > for< / span > event < span class = "hljs-keyword" > in< / span > pg.event.get() ):
deltas = {pg.K_UP: (< span class = "hljs-number" > 0< / span > , < span class = "hljs-number" > -1 < / span > ), pg.K_RIGHT: (< span class = "hljs-number" > 1 < / span > , < span class = "hljs-number" > 0< / span > ), pg.K_DOWN: (< span class = "hljs-number" > 0< / span > , < span class = "hljs-number" > 1 < / span > ), pg.K_LEFT: (< span class = "hljs-number" > -1 < / span > , < span class = "hljs-number" > 0< / span > )}
< span class = "hljs-keyword" > for< / span > ch, is_pressed < span class = "hljs-keyword" > in< / span > enumerate(pg.key.get_pressed() ):
rect = rect.move(deltas[ch]) < span class = "hljs-keyword" > if< / span > ch < span class = "hljs-keyword" > in < / span > deltas < span class = "hljs-keyword" > and< / span > is_pressed < span class = "hljs-keyword" > else < / span > rect
< span class = "hljs-keyword" > while< / span > < span class = "hljs-keyword" > not< / span > pg.event.get(pg.QUIT ):
deltas = {pg.K_UP: (< span class = "hljs-number" > 0< / span > , < span class = "hljs-number" > -20 < / span > ), pg.K_RIGHT: (< span class = "hljs-number" > 20 < / span > , < span class = "hljs-number" > 0< / span > ), pg.K_DOWN: (< span class = "hljs-number" > 0< / span > , < span class = "hljs-number" > 20 < / span > ), pg.K_LEFT: (< span class = "hljs-number" > -20 < / span > , < span class = "hljs-number" > 0< / span > )}
< span class = "hljs-keyword" > for< / span > event < span class = "hljs-keyword" > in< / span > pg.event.get(pg.KEYDOWN ):
rect.move_ip(deltas.get(event.key, ( < span class = "hljs-number" > 0 < / span > , < span class = "hljs-number" > 0 < / span > ))
screen.fill((< span class = "hljs-number" > 0< / span > , < span class = "hljs-number" > 0< / span > , < span class = "hljs-number" > 0< / span > ))
pg.draw.rect(screen, (< span class = "hljs-number" > 255< / span > , < span class = "hljs-number" > 255< / span > , < span class = "hljs-number" > 255< / span > ), rect)
pg.display.flip()
@ -2502,14 +2502,14 @@ 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 = pg.time.Clock()
< span class = "hljs-keyword" > while< / span > all(event.type != pg.QUIT < span class = "hljs-keyword" > for < / span > event < span class = "hljs-keyword" > in < / span > pg.event.get() ):
clock, pressed = pg.time.Clock(), 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(ch) < span class = "hljs-keyword" > for< / span > ch, is_prsd < span class = "hljs-keyword" > in< / span > enumerate(pg.key.get_pressed()) < span class = "hljs-keyword" > if< / span > is_prsd}
pressed |= {keys.get(event.key) < span class = "hljs-keyword" > for< / span > event < span class = "hljs-keyword" > in< / span > pg.event.get(pg.KEYDOWN)}
pressed -= {keys.get(event.key) < span class = "hljs-keyword" > for< / span > event < span class = "hljs-keyword" > in< / span > pg.event.get(pg.KEYUP)}
update_speed(mario, tiles, pressed)
update_position(mario, tiles)
draw(screen, images, mario, tiles, pressed)
clock.tick(< span class = "hljs-number" > 28< / span > )
< span class = "hljs-function" > < span class = "hljs-keyword" > def< / span > < span class = "hljs-title" > update_speed< / span > < span class = "hljs-params" > (mario, tiles, pressed)< / span > :< / span >
x, y = mario.spd