From 741ea4081fac5beda3ab3464df73c687936e0425 Mon Sep 17 00:00:00 2001 From: themixray <35273590+themixray@users.noreply.github.com> Date: Mon, 13 Dec 2021 21:52:18 +0300 Subject: [PATCH] Add files via upload --- examples/game.py | 8 ++++---- examples/template.py | 12 ++++++++++++ examples/window-move.py | 27 +++++++++++++-------------- 3 files changed, 29 insertions(+), 18 deletions(-) create mode 100644 examples/template.py diff --git a/examples/game.py b/examples/game.py index 4420654..31679ad 100644 --- a/examples/game.py +++ b/examples/game.py @@ -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 diff --git a/examples/template.py b/examples/template.py new file mode 100644 index 0000000..c75cb47 --- /dev/null +++ b/examples/template.py @@ -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() diff --git a/examples/window-move.py b/examples/window-move.py index 2a447cf..b15c88c 100644 --- a/examples/window-move.py +++ b/examples/window-move.py @@ -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