From 1f5814c62256ea6a2a01c289e54805f73b9bdc95 Mon Sep 17 00:00:00 2001 From: themixray <35273590+themixray@users.noreply.github.com> Date: Tue, 2 Nov 2021 13:52:12 +0300 Subject: [PATCH] Update README.md --- README.md | 44 ++++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 0c25a93..2cb2d59 100644 --- a/README.md +++ b/README.md @@ -7,11 +7,14 @@ A library for creating Python applications. A simple game. ```python import pygwin +import random win = pygwin.create('A Simple Game', (500,500)) -x = 250 -y = 250 +player = [250,250] +apple = pygwin.rect(random.randint(0,490), + random.randint(0,490),20,20) +count = 0 run = True while run: @@ -20,27 +23,36 @@ while run: run = False win.fill((255,255,255)) - win.blit(win.fps,(0,0)) - win.draw.rect((0,0,0),pygwin.rect(x-10,y-10,20,20)) + playerRect = pygwin.rect(player[0]-10,player[1]-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'): - y -= 5 + player[1] -= 5 if pygwin.keyboard.isPressed('s'): - y += 5 + player[1] += 5 if pygwin.keyboard.isPressed('d'): - x += 5 + player[0] += 5 if pygwin.keyboard.isPressed('a'): - x -= 5 + player[0] -= 5 - if x <= -10: - x = 510 - if y <= -10: - y = 510 - if x > 510: - x = -10 - if y > 510: - y = -10 + if player[0] <= -10: + player[0] = 510 + if player[1] <= -10: + player[1] = 510 + if player[0] > 510: + player[0] = -10 + if player[1] > 510: + 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) pygwin.close() + ```