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

@ -15,10 +15,6 @@ while run: # Creating loop
run = False # Break loop
win.fill((255,255,255)) # Fill window with color
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
win.blit(score,(0,0)) # Writing player score
if pygwin.keyboard.isPressed('w'): # If keyboard key w pressed
@ -39,6 +35,10 @@ while run: # Creating loop
if player[1] > 510: # If player out of the screen (down)
player[1] = -10 # Set player position in up
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): # If player rect collide apple rect
apple = pygwin.rect(random.randint(0,490),
random.randint(0,490),20,20) # Change apple rect

12
examples/template.py Normal file
View file

@ -0,0 +1,12 @@
import pygwin
win = pygwin.create('Title',(500,500))
run = True
while run:
for event in pygwin.getEvents():
if event.type == pygwin.QUIT:
run = False
win.update()
pygwin.close()

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