Add files via upload

This commit is contained in:
themixray 2021-12-13 21:52:18 +03:00 committed by GitHub
parent d6915bc901
commit 741ea4081f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 18 deletions

View file

@ -1,11 +1,9 @@
from win32api import GetSystemMetrics # Importing monitor resolution getter
import pygwin
import random
import copy
win = pygwin.create('A Simple Game', (500,500))
win.move(*[int(GetSystemMetrics(i)/2-win.size[i]/2) for i in range(2)]) # Center window
centered_position = win.position # Get centered position of window
win.denyDrag() # Prohibit dragging the window
start_pos = win.position # Start window pos
player = [250,250]
apple = pygwin.rect(random.randint(0,490),
@ -19,15 +17,6 @@ while run:
run = False
win.fill((255,255,255))
playerRect = pygwin.rect(player[0]-10,player[1]-10,20,20)
playerRect.x += centered_position[0]-win.position[0] # Set player rect x pos relatively center of monitor
playerRect.y += centered_position[1]-win.position[1] # Set player rect y pos relatively center of monitor
win.draw.rect((0,0,0),playerRect)
atemp = copy.copy(apple) # Create copy of apple rect
atemp.x += centered_position[0]-win.position[0] # Set apple x pos relatively center of monitor
atemp.y += centered_position[1]-win.position[1] # Set apple y pos relatively center of monitor
win.draw.rect((200,50,50),atemp)
win.blit(score,(0,0))
set_position = list(win.position)
@ -45,7 +34,17 @@ while run:
set_position[0] -= 5 # Move window left
win.move(*set_position) # Set position
if playerRect.collide(apple):
playerRect = pygwin.rect(player[0]-10,player[1]-10,20,20)
playerRect.x += start_pos[0]-win.position[0] # Set player rect x pos relatively start window position
playerRect.y += start_pos[1]-win.position[1] # Set player rect y pos relatively start window position
win.draw.rect((0,0,0),playerRect)
# print(playerRect)
atemp = apple.copy() # Create copy of apple rect
atemp.x += start_pos[0]-win.position[0] # Set apple x pos relatively start window position
atemp.y += start_pos[1]-win.position[1] # Set apple y pos relatively start window position
win.draw.rect((200,50,50),atemp)
if atemp.collide(playerRect):
apple = pygwin.rect(random.randint(50,490),
random.randint(50,490),20,20)
score += 1