edited comments in examples
This commit is contained in:
parent
30719ab6d8
commit
af2e74ce1b
4 changed files with 89 additions and 89 deletions
|
@ -2,8 +2,8 @@ import pygwin
|
|||
import random
|
||||
|
||||
win = pygwin.create('A Simple Game', (500,500))
|
||||
win.denyDrag() # Prohibit dragging the window
|
||||
start_pos = win.position # Start window pos
|
||||
win.denyDrag() # Prohibit dragging the window
|
||||
start_pos = win.position # Start window pos
|
||||
|
||||
player = [250,250]
|
||||
apple = pygwin.rect(random.randint(0,490),
|
||||
|
@ -22,26 +22,26 @@ while run:
|
|||
set_position = list(win.position)
|
||||
if pygwin.keyboard.isPressed('w'):
|
||||
player[1] -= 5
|
||||
set_position[1] -= 5 # Move window up
|
||||
set_position[1] -= 5 # Move window up
|
||||
if pygwin.keyboard.isPressed('s'):
|
||||
player[1] += 5
|
||||
set_position[1] += 5 # Move window down
|
||||
set_position[1] += 5 # Move window down
|
||||
if pygwin.keyboard.isPressed('d'):
|
||||
player[0] += 5
|
||||
set_position[0] += 5 # Move window right
|
||||
set_position[0] += 5 # Move window right
|
||||
if pygwin.keyboard.isPressed('a'):
|
||||
player[0] -= 5
|
||||
set_position[0] -= 5 # Move window left
|
||||
win.move(*set_position) # Set position
|
||||
set_position[0] -= 5 # Move window left
|
||||
win.move(*set_position) # Set position
|
||||
|
||||
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
|
||||
|
||||
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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue