В игре нужно добавить задержку между выстрелами

Гамлет Варданян

Новичок
Пользователь
Май 20, 2022
1
0
1
Подскажите пожалуйста как это можно сделать?

class Gun:
def __init__(self, x, y):
self.x = x
self.y = y #Все виды оружия
def gun_on_hand(self, win):
win.blit(weapon, (x, y))

class snaryad():
def __init__(self, x, y, radius, color, facing):
self.x = x
self.y = y
self.radius = radius
self.color = color #Патроны
self.facing = facing
self.vel = 15 * facing
self.shotDelay = 60
self.timer = 0

def draw(self, win):
pygame.draw.circle(win, self.color, (self.x + 15, self.y + 15),self.radius)


def drawWindow():
win.blit(bg_image, (0, 0))
global animCount
global stand
if animCount + 1 >= 30:
animCount = 0
if left:
win.blit(playerLeft[animCount // 5], (x, y))
animCount += 1
stand = True
elif right:
win.blit(playerRight[animCount // 5], (x, y))
animCount += 1
stand = False
elif stand:
win.blit(playerStand[1], (x, y)) #Все передвижения

elif isJump:
win.blit(playerJump, (x, y))
else:
win.blit(playerStand[0], (x, y))
for bullet in bullets:
bullet.draw(win)
if lastMove == 'right':
win.blit(weapon[0], (x + 7, y + 4))
elif lastMove == 'left':
win.blit(weapon[1], (x + 2 , y + 4))
pygame.display.update()

while run:
#Основной код
Clock.tick(30)

for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False

for bullet in bullets:
if bullet.x < 1460 and bullet.x > 0:
bullet.x += bullet.vel
else:
bullets.pop(bullets.index(bullet))
keys = pygame.key.get_pressed()

if keys[pygame.K_f]:
timer = 1
if lastMove == "right":
facing = 1
else:
facing = -1
if len(bullets) < 15 :
bullets.append(snaryad(round(x + widht // 2),round(y + height // 2), 3, (255, 0, 0), facing))
if keys[pygame.K_LEFT] and x > 15:
x -= speed
left = True
right = False
lastMove = "left"
elif keys[pygame.K_RIGHT] and x < 1460 - widht - 15:
x += speed
left = False
right = True
lastMove = "right"
else:
left = False
right = False
animCount = 0
if not(isJump):

if keys[pygame.K_UP] and y > 20:
y -= speed
if keys[pygame.K_DOWN] and y < 850 - height - 15:
y += speed
if keys[pygame.K_SPACE]:
isJump = True
else:
if jumpCount >= -5:
if jumpCount < 0:
y += (jumpCount ** 2) / 2
else:
y -= (jumpCount ** 2) / 2
jumpCount -= 1
else:
isJump = False
jumpCount = 5
drawWindow()



pygame.QUIT
 

Форум IT Специалистов