Answer the question
In order to leave comments, you need to log in
Can't pause in pygame, what's wrong?
import pygame
import random
q = width , height = (500 ,500 )
win = pygame.display.set_mode(q)
pygame.display.set_caption("Game")
clock = pygame.time.Clock()
stan = pygame.image. load("stan.png")
db = pygame.image.load("fon.png")
x = 50
y = 420
w = 60
l = 71
spe = 5
jup = False
jsp = 10
left = False
right = False
anim = 0
war_w = 20
war_l = 71
war_x = 420
war_y = 420
class warg:
def __init__(self, x, y, w, l, spe,):
self.x = x
self.y = y
self.w = w
self .l = l
self.spe = spe
def move (self):
if self.x >= self.w:
pygame.draw.rect(win, ( 0, 255, 0), (self.x, self.y ,self.w, self.l ) )
self.x -= 10
else:
self.x = 420
pygame.display.update()
def w0r_war_arr(array):
array.append(warg(420 + 50, 420, 20, 71, 10))
array.append(warg(420 + 300 , 420, 20, 71, 10))
array.append(warg(420 + 600, 420, 20, 71, 10))
def wer(array):
for war in array:
war .move()
def war_col(warg):
for barrier in warg:
if y + l >= warg.y:
if warg.x <= x <= warg.x + warg.w :
return False
elif warg.x <= x + w <= warg.x + warg.w:
return False
return True
def ris():
global anim
if anim + 1 >= 2 :
anim = 0
if left:
win.blit(stan, (x , y))
anim+= 1
elif right:
win.blit(stan, ( x , y))
anim+= 1
else:
win.blit(stan, (x , y))
if keys[pygame.K_w]:
pygame.display.flip()
else:
pygame.display.update()
pygame.init( )
war_arr= []
w0r_war_arr(war_arr)
game_over = False
paused = False
while not game_over:
clock.tick(30)
keys = pygame.key.get_pressed()
for event in pygame.event.get():
if event.type == pygame.QUIT:
game_over = True
elif keys[pygame.K_w]:
paused = True
if keys[pygame.K_LEFT] and x > 5:
x -= spe
left = True
right = False
elif keys[pygame .K_RIGHT] and x < 500 - w - 5:
x += spe
left = False
right = True
else:
left = False
right = False
anim = 0
if not(jup):
if keys[pygame.K_UP] and y > 5 :
y -= spe
if keys[pygame.K_DOWN] and y < 500 - l - 5 :
y += spe
if keys[pygame.K_SPACE] :
jup = True
else :
if jsp >= -10:
if jsp < 0:
y += (jsp ** 2) / 2
else:
y -= (jsp ** 2) / 2
jsp -= 1
else:
jup = False
jsp = 10
win.blit(db , (0 , 0 ))
wer( war_arr)
ris()
pygame.quit()
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question