Update README.md

This commit is contained in:
themixray 2021-11-02 13:52:12 +03:00 committed by GitHub
parent 1170f1521c
commit 1f5814c622
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -7,11 +7,14 @@ A library for creating Python applications.
A simple game. A simple game.
```python ```python
import pygwin import pygwin
import random
win = pygwin.create('A Simple Game', (500,500)) win = pygwin.create('A Simple Game', (500,500))
x = 250 player = [250,250]
y = 250 apple = pygwin.rect(random.randint(0,490),
random.randint(0,490),20,20)
count = 0
run = True run = True
while run: while run:
@ -20,27 +23,36 @@ while run:
run = False run = False
win.fill((255,255,255)) win.fill((255,255,255))
win.blit(win.fps,(0,0)) playerRect = pygwin.rect(player[0]-10,player[1]-10,20,20)
win.draw.rect((0,0,0),pygwin.rect(x-10,y-10,20,20)) win.draw.rect((0,0,0),playerRect)
win.draw.rect((200,50,50),apple)
win.blit(count,(0,0))
if pygwin.keyboard.isPressed('w'): if pygwin.keyboard.isPressed('w'):
y -= 5 player[1] -= 5
if pygwin.keyboard.isPressed('s'): if pygwin.keyboard.isPressed('s'):
y += 5 player[1] += 5
if pygwin.keyboard.isPressed('d'): if pygwin.keyboard.isPressed('d'):
x += 5 player[0] += 5
if pygwin.keyboard.isPressed('a'): if pygwin.keyboard.isPressed('a'):
x -= 5 player[0] -= 5
if x <= -10: if player[0] <= -10:
x = 510 player[0] = 510
if y <= -10: if player[1] <= -10:
y = 510 player[1] = 510
if x > 510: if player[0] > 510:
x = -10 player[0] = -10
if y > 510: if player[1] > 510:
y = -10 player[1] = -10
if playerRect.collide(apple):
apple = pygwin.rect(random.randint(0,490),
random.randint(0,490),20,20)
count += 1
win.update(60) win.update(60)
pygwin.close() pygwin.close()
``` ```