edited comments in examples
This commit is contained in:
parent
30719ab6d8
commit
af2e74ce1b
4 changed files with 89 additions and 89 deletions
|
@ -1,48 +1,48 @@
|
||||||
import pygwin # Importing pygwin
|
import pygwin # Importing pygwin
|
||||||
import random # Importing random
|
import random # Importing random
|
||||||
|
|
||||||
win = pygwin.create('A Simple Game', (500,500)) # Creating window
|
win = pygwin.create('A Simple Game', (500,500)) # Creating window
|
||||||
|
|
||||||
player = [250,250] # Player position
|
player = [250,250] # Player position
|
||||||
apple = pygwin.rect(random.randint(0,490),
|
apple = pygwin.rect(random.randint(0,490),
|
||||||
random.randint(0,490),20,20) # Apple rect
|
random.randint(0,490),20,20) # Apple rect
|
||||||
score = 0 # Player score
|
score = 0 # Player score
|
||||||
|
|
||||||
run = True # Is loop running
|
run = True # Is loop running
|
||||||
while run: # Creating loop
|
while run: # Creating loop
|
||||||
for event in pygwin.getEvents(): # Events loop
|
for event in pygwin.getEvents(): # Events loop
|
||||||
if event.type == pygwin.QUIT: # If window quit
|
if event.type == pygwin.QUIT: # If window quit
|
||||||
run = False # Break loop
|
run = False # Break loop
|
||||||
win.fill((255,255,255)) # Fill window with color
|
win.fill((255,255,255)) # Fill window with color
|
||||||
|
|
||||||
win.blit(score,(0,0)) # Writing player score
|
win.blit(score,(0,0)) # Writing player score
|
||||||
|
|
||||||
if pygwin.keyboard.isPressed('w'): # If keyboard key w pressed
|
if pygwin.keyboard.isPressed('w'): # If keyboard key w pressed
|
||||||
player[1] -= 5 # Player position up
|
player[1] -= 5 # Player position up
|
||||||
if pygwin.keyboard.isPressed('s'): # If keyboard key s pressed
|
if pygwin.keyboard.isPressed('s'): # If keyboard key s pressed
|
||||||
player[1] += 5 # Player position down
|
player[1] += 5 # Player position down
|
||||||
if pygwin.keyboard.isPressed('d'): # If keyboard key d pressed
|
if pygwin.keyboard.isPressed('d'): # If keyboard key d pressed
|
||||||
player[0] += 5 # Player position right
|
player[0] += 5 # Player position right
|
||||||
if pygwin.keyboard.isPressed('a'): # If keyboard key a pressed
|
if pygwin.keyboard.isPressed('a'): # If keyboard key a pressed
|
||||||
player[0] -= 5 # Player position left
|
player[0] -= 5 # Player position left
|
||||||
|
|
||||||
if player[0] <= -10: # If player out of the screen (left)
|
if player[0] <= -10: # If player out of the screen (left)
|
||||||
player[0] = 510 # Set player position in right
|
player[0] = 510 # Set player position in right
|
||||||
if player[1] <= -10: # If player out of the screen (up)
|
if player[1] <= -10: # If player out of the screen (up)
|
||||||
player[1] = 510 # Set player position in down
|
player[1] = 510 # Set player position in down
|
||||||
if player[0] > 510: # If player out of the screen (right)
|
if player[0] > 510: # If player out of the screen (right)
|
||||||
player[0] = -10 # Set player position in left
|
player[0] = -10 # Set player position in left
|
||||||
if player[1] > 510: # If player out of the screen (down)
|
if player[1] > 510: # If player out of the screen (down)
|
||||||
player[1] = -10 # Set player position in up
|
player[1] = -10 # Set player position in up
|
||||||
|
|
||||||
playerRect = pygwin.rect(player[0]-10,player[1]-10,20,20) # Player rect
|
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((0,0,0),playerRect) # Drawing player rect
|
||||||
win.draw.rect((200,50,50),apple) # Drawing apple rect
|
win.draw.rect((200,50,50),apple) # Drawing apple rect
|
||||||
|
|
||||||
if playerRect.collide(apple): # If player rect collide apple rect
|
if playerRect.collide(apple): # If player rect collide apple rect
|
||||||
apple = pygwin.rect(random.randint(0,490),
|
apple = pygwin.rect(random.randint(0,490),
|
||||||
random.randint(0,490),20,20) # Change apple rect
|
random.randint(0,490),20,20) # Change apple rect
|
||||||
score += 1 # Update player score
|
score += 1 # Update player score
|
||||||
|
|
||||||
win.update(60) # Update window
|
win.update(60) # Update window
|
||||||
pygwin.close() # Close pygwin
|
pygwin.close() # Close pygwin
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import pygwin
|
import pygwin
|
||||||
import random
|
import random
|
||||||
|
|
||||||
win = pygwin.create('A Simple Game', (500,500))
|
win = pygwin.create('A Simple Game', (500,500))
|
||||||
|
@ -9,14 +9,14 @@ apple = pygwin.rect(random.randint(0,490),
|
||||||
score = 0
|
score = 0
|
||||||
|
|
||||||
record = pygwin.record(win,True) # Init recording
|
record = pygwin.record(win,True) # Init recording
|
||||||
record.start() # Start recording
|
record.start() # Start recording
|
||||||
|
|
||||||
run = True
|
run = True
|
||||||
while run:
|
while run:
|
||||||
for event in pygwin.getEvents():
|
for event in pygwin.getEvents():
|
||||||
if event.type == pygwin.QUIT:
|
if event.type == pygwin.QUIT:
|
||||||
run = False
|
run = False
|
||||||
record.stop() # Stop recording
|
record.stop() # Stop recording
|
||||||
win.fill((255,255,255))
|
win.fill((255,255,255))
|
||||||
|
|
||||||
playerRect = pygwin.rect(player[0]-10,player[1]-10,20,20)
|
playerRect = pygwin.rect(player[0]-10,player[1]-10,20,20)
|
||||||
|
@ -25,18 +25,18 @@ while run:
|
||||||
|
|
||||||
win.blit(score,(0,0))
|
win.blit(score,(0,0))
|
||||||
|
|
||||||
if pygwin.keyboard.isPressed('w'):
|
if pygwin.keyboard.isPressed('w'):
|
||||||
player[1] -= 5
|
player[1] -= 5
|
||||||
if pygwin.keyboard.isPressed('s'):
|
if pygwin.keyboard.isPressed('s'):
|
||||||
player[1] += 5
|
player[1] += 5
|
||||||
if pygwin.keyboard.isPressed('d'):
|
if pygwin.keyboard.isPressed('d'):
|
||||||
player[0] += 5
|
player[0] += 5
|
||||||
if pygwin.keyboard.isPressed('a'):
|
if pygwin.keyboard.isPressed('a'):
|
||||||
player[0] -= 5
|
player[0] -= 5
|
||||||
|
|
||||||
if player[0] <= -10:
|
if player[0] <= -10:
|
||||||
player[0] = 510
|
player[0] = 510
|
||||||
if player[1] <= -10:
|
if player[1] <= -10:
|
||||||
player[1] = 510
|
player[1] = 510
|
||||||
if player[0] > 510:
|
if player[0] > 510:
|
||||||
player[0] = -10
|
player[0] = -10
|
||||||
|
@ -49,5 +49,5 @@ while run:
|
||||||
score += 1
|
score += 1
|
||||||
|
|
||||||
win.update(60)
|
win.update(60)
|
||||||
record.render('Recording.mp4') # Render recording
|
record.render('Recording.mp4') # Render recording
|
||||||
pygwin.close()
|
pygwin.close()
|
||||||
|
|
|
@ -1,43 +1,43 @@
|
||||||
import pygwin
|
import pygwin
|
||||||
|
|
||||||
win = pygwin.create('UI example',(270,350))
|
win = pygwin.create('UI example',(270,350))
|
||||||
base = pygwin.ui.base(win) # Creating ui base
|
base = pygwin.ui.base(win) # Creating ui base
|
||||||
|
|
||||||
lbl = pygwin.ui.label('Label') # Creating label
|
lbl = pygwin.ui.label('Label') # Creating label
|
||||||
base.put(lbl,(130-(lbl.surface.size[0]/2),10)) # Putting label to base
|
base.put(lbl,(130-(lbl.surface.size[0]/2),10)) # Putting label to base
|
||||||
base.put(pygwin.ui.button('Button',width=250),(10,50)) # Putting button to base
|
base.put(pygwin.ui.button('Button',width=250),(10,50)) # Putting button to base
|
||||||
base.put(pygwin.ui.entry('Entry',width=123),(10,100)) # Putting entry to base
|
base.put(pygwin.ui.entry('Entry',width=123),(10,100)) # Putting entry to base
|
||||||
base.put(pygwin.ui.keySelect('Key',width=122),(138,100)) # Putting key selector to base
|
base.put(pygwin.ui.keySelect('Key',width=122),(138,100)) # Putting key selector to base
|
||||||
loadbar = pygwin.ui.loadingBar(250,25) # Creating loading bar
|
loadbar = pygwin.ui.loadingBar(250,25) # Creating loading bar
|
||||||
base.put(loadbar,(10,150)) # Putting loading bar to base
|
base.put(loadbar,(10,150)) # Putting loading bar to base
|
||||||
slider = pygwin.ui.slider(250) # Creating slider
|
slider = pygwin.ui.slider(250) # Creating slider
|
||||||
base.put(slider,(10,170)) # Putting slider to base
|
base.put(slider,(10,170)) # Putting slider to base
|
||||||
cb = pygwin.ui.checkBox(25,borderWidth=2) # Creating checkbox
|
cb = pygwin.ui.checkBox(25,borderWidth=2) # Creating checkbox
|
||||||
base.put(cb,(10,220)) # Putting checkbox to base
|
base.put(cb,(10,220)) # Putting checkbox to base
|
||||||
base.put(pygwin.ui.label('Checkbox',20),(45,225)) # Putting checkbox label to base
|
base.put(pygwin.ui.label('Checkbox',20),(45,225)) # Putting checkbox label to base
|
||||||
ta = pygwin.ui.textarea('Textarea',width=250,maxSymbols=20) # Creating textarea
|
ta = pygwin.ui.textarea('Textarea',width=250,maxSymbols=20) # Creating textarea
|
||||||
ta.text += '0123456789\n0123456789' # Set text to textarea
|
ta.text += '0123456789\n0123456789' # Set text to textarea
|
||||||
ta.focus = True # Focus textarea
|
ta.focus = True # Focus textarea
|
||||||
ta._generate() # Generate textarea surface
|
ta._generate() # Generate textarea surface
|
||||||
ta.focus = False # Unfocus textarea
|
ta.focus = False # Unfocus textarea
|
||||||
base.put(ta,(10,255)) # Putting textarea to base
|
base.put(ta,(10,255)) # Putting textarea to base
|
||||||
tta = pygwin.ui.tip('textarea',
|
tta = pygwin.ui.tip('textarea',
|
||||||
*ta.surface.size,
|
*ta.surface.size,
|
||||||
waitBeforeShowing=30) # Creating textarea tip
|
waitBeforeShowing=30) # Creating textarea tip
|
||||||
base.put(tta,(10,255)) # Putting textarea tip to base
|
base.put(tta,(10,255)) # Putting textarea tip to base
|
||||||
|
|
||||||
run = True
|
run = True
|
||||||
while run:
|
while run:
|
||||||
for event in pygwin.getEvents():
|
for event in pygwin.getEvents():
|
||||||
if event.type == pygwin.QUIT:
|
if event.type == pygwin.QUIT:
|
||||||
run = False
|
run = False
|
||||||
base.draw() # Drawing base
|
base.draw() # Drawing base
|
||||||
if cb.get(): # If checkbox
|
if cb.get(): # If checkbox
|
||||||
loadbar.set(slider.get()) # If checkbox
|
loadbar.set(slider.get()) # If checkbox
|
||||||
else:
|
else:
|
||||||
loadbar.step() # Step loading bar
|
loadbar.step() # Step loading bar
|
||||||
if loadbar.get() == loadbar.length: # If loading bar is full
|
if loadbar.get() == loadbar.length: # If loading bar is full
|
||||||
loadbar.set(0) # Reset loading bar
|
loadbar.set(0) # Reset loading bar
|
||||||
tta.responceWidth,tta.responceHeight=ta.surface.size # Set responce width, height to textarea tip
|
tta.responceWidth,tta.responceHeight=ta.surface.size # Set responce width, height to textarea tip
|
||||||
win.update(30)
|
win.update(30)
|
||||||
pygwin.close()
|
pygwin.close()
|
||||||
|
|
|
@ -2,8 +2,8 @@ import pygwin
|
||||||
import random
|
import random
|
||||||
|
|
||||||
win = pygwin.create('A Simple Game', (500,500))
|
win = pygwin.create('A Simple Game', (500,500))
|
||||||
win.denyDrag() # Prohibit dragging the window
|
win.denyDrag() # Prohibit dragging the window
|
||||||
start_pos = win.position # Start window pos
|
start_pos = win.position # Start window pos
|
||||||
|
|
||||||
player = [250,250]
|
player = [250,250]
|
||||||
apple = pygwin.rect(random.randint(0,490),
|
apple = pygwin.rect(random.randint(0,490),
|
||||||
|
@ -22,26 +22,26 @@ while run:
|
||||||
set_position = list(win.position)
|
set_position = list(win.position)
|
||||||
if pygwin.keyboard.isPressed('w'):
|
if pygwin.keyboard.isPressed('w'):
|
||||||
player[1] -= 5
|
player[1] -= 5
|
||||||
set_position[1] -= 5 # Move window up
|
set_position[1] -= 5 # Move window up
|
||||||
if pygwin.keyboard.isPressed('s'):
|
if pygwin.keyboard.isPressed('s'):
|
||||||
player[1] += 5
|
player[1] += 5
|
||||||
set_position[1] += 5 # Move window down
|
set_position[1] += 5 # Move window down
|
||||||
if pygwin.keyboard.isPressed('d'):
|
if pygwin.keyboard.isPressed('d'):
|
||||||
player[0] += 5
|
player[0] += 5
|
||||||
set_position[0] += 5 # Move window right
|
set_position[0] += 5 # Move window right
|
||||||
if pygwin.keyboard.isPressed('a'):
|
if pygwin.keyboard.isPressed('a'):
|
||||||
player[0] -= 5
|
player[0] -= 5
|
||||||
set_position[0] -= 5 # Move window left
|
set_position[0] -= 5 # Move window left
|
||||||
win.move(*set_position) # Set position
|
win.move(*set_position) # Set position
|
||||||
|
|
||||||
playerRect = pygwin.rect(player[0]-10,player[1]-10,20,20)
|
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.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
|
playerRect.y += start_pos[1]-win.position[1] # Set player rect y pos relatively start window position
|
||||||
win.draw.rect((0,0,0),playerRect)
|
win.draw.rect((0,0,0),playerRect)
|
||||||
# print(playerRect)
|
|
||||||
atemp = apple.copy() # Create copy of apple rect
|
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.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.y += start_pos[1]-win.position[1] # Set apple y pos relatively start window position
|
||||||
win.draw.rect((200,50,50),atemp)
|
win.draw.rect((200,50,50),atemp)
|
||||||
|
|
||||||
if atemp.collide(playerRect):
|
if atemp.collide(playerRect):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue