Browse Source

Pygame

pull/152/head
Jure Šorn 1 year ago
parent
commit
09cb5b71c4
2 changed files with 4 additions and 2 deletions
  1. 3
      README.md
  2. 3
      index.html

3
README.md

@ -2973,7 +2973,8 @@ rect = pg.Rect(240, 240, 20, 20)
while not pg.event.get(pg.QUIT):
deltas = {pg.K_UP: (0, -20), pg.K_RIGHT: (20, 0), pg.K_DOWN: (0, 20), pg.K_LEFT: (-20, 0)}
for event in pg.event.get(pg.KEYDOWN):
rect.move_ip(deltas.get(event.key, (0, 0)))
dx, dy = deltas.get(event.key, (0, 0))
rect.move_ip((dx, dy))
screen.fill((0, 0, 0))
pg.draw.rect(screen, (255, 255, 255), rect)
pg.display.flip()

3
index.html

@ -2428,7 +2428,8 @@ rect = pg.Rect(<span class="hljs-number">240</span>, <span class="hljs-number">2
<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>)))
dx, dy = deltas.get(event.key, (<span class="hljs-number">0</span>, <span class="hljs-number">0</span>))
rect.move_ip((dx, dy))
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()

Loading…
Cancel
Save