Add files via upload

This commit is contained in:
themixray 2021-12-08 11:22:41 +03:00 committed by GitHub
parent d63a3ebd54
commit edd3f86508
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 228 additions and 87 deletions

View file

@ -1,42 +1,48 @@
from random import randint
import pygwin as pgw
import pygwin # Importing pygwin
import random # Importing random
win = pgw.create('Game Example', (500,500))
win = pygwin.create('A Simple Game', (500,500)) # Creating window
player = [250,250]
apple = pgw.rect(randint(0,490),randint(0,490),20,20)
count = 0
player = [250,250] # Player position
apple = pygwin.rect(random.randint(0,490),
random.randint(0,490),20,20) # Apple rect
score = 0 # Player score
run = True
while run:
for event in pgw.getEvents():
if event.type == pgw.QUIT:
run = False
win.fill((255,255,255))
playerRect = pgw.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 pgw.keyboard.isPressed('w'):
player[1] -= 5
if pgw.keyboard.isPressed('s'):
player[1] += 5
if pgw.keyboard.isPressed('d'):
player[0] += 5
if pgw.keyboard.isPressed('a'):
player[0] -= 5
run = True # Is loop running
while run: # Creating loop
for event in pygwin.getEvents(): # Events loop
if event.type == pygwin.QUIT: # If window quit
run = False # Break loop
win.fill((255,255,255)) # Fill window with color
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
playerRect = pygwin.rect(player[0]-10,player[1]-10,20,20) # Player rect
win.draw.rect((0,0,0),playerRect) # Drawing player rect
win.draw.rect((200,50,50),apple) # Drawing apple rect
if playerRect.collide(apple):
apple = pgw.rect(randint(0,490),randint(0,490),20,20)
count += 1
win.update(60)
pgw.close()
win.blit(score,(0,0)) # Writing player score
if pygwin.keyboard.isPressed('w'): # If keyboard key w pressed
player[1] -= 5 # Player position up
if pygwin.keyboard.isPressed('s'): # If keyboard key s pressed
player[1] += 5 # Player position down
if pygwin.keyboard.isPressed('d'): # If keyboard key d pressed
player[0] += 5 # Player position right
if pygwin.keyboard.isPressed('a'): # If keyboard key a pressed
player[0] -= 5 # Player position left
if player[0] <= -10: # If player out of the screen (left)
player[0] = 510 # Set player position in right
if player[1] <= -10: # If player out of the screen (up)
player[1] = 510 # Set player position in down
if player[0] > 510: # If player out of the screen (right)
player[0] = -10 # Set player position in left
if player[1] > 510: # If player out of the screen (down)
player[1] = -10 # Set player position in up
if playerRect.collide(apple): # If player rect collide apple rect
apple = pygwin.rect(random.randint(0,490),
random.randint(0,490),20,20) # Change apple rect
score += 1 # Update player score
win.update(60) # Update window
pygwin.close() # Close pygwin