pygame 딜레이

조회수 83회

레이저가 나올때 잠깐 딜레이시켰다가 나오는거 어떻게 할까요??

import pygame
import random
import time

successes, failures = pygame.init()
print("Initializing pygame: {0} successes and {1} failures.".format(successes, failures))

screen = pygame.display.set_mode((720, 480))
clock = pygame.time.Clock()
FPS = 60

GRAY = (100, 100, 100)
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
YELLOW = (255, 255, 0)

razers = []

class H_Razer(pygame.sprite.Sprite):
    def __init__(self):
        super().__init__()
        self.image = pygame.Surface((720, 20))
        self.image.fill(WHITE)
        self.rect = self.image.get_rect()  # Get rect of some size as 'image'.
        self.velocity = [0, 0]
        self.rect.top = random.randint(0,470)
        self.time = time.time()
    def update(self):
        self.rect.move_ip(*self.velocity)

class V_Razer(pygame.sprite.Sprite):
    def __init__(self):
        super().__init__()
        self.image = pygame.Surface((20, 480))
        self.image.fill(WHITE)
        self.rect = self.image.get_rect()  # Get rect of some size as 'image'.
        self.velocity = [0, 0]
        self.rect.left = random.randint(5,710)
        self.time = time.time()
    def update(self):
        self.rect.move_ip(*self.velocity)

class Player(pygame.sprite.Sprite):
    def __init__(self):
        super().__init__()
        self.image = pygame.Surface((30, 30))
        self.image.fill(WHITE)
        self.rect = self.image.get_rect()  # Get rect of some size as 'image'.
        self.velocity = [0, 0]
        self.rect.top = 225
        self.rect.left = 335

    def update(self):
        self.rect.move_ip(*self.velocity)

for i in range(2):
    razer = H_Razer()
    razers.append(razer)
    razer = V_Razer()
    razers.append(razer)

player = Player()
running = True
while running:
    dt = clock.tick(FPS) / 1000 
    screen.fill(BLACK) 
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
        elif event.type == pygame.KEYDOWN:
            if event.key == pygame.K_w:
                player.velocity[1] = -300 * dt  # 200 pixels per second
            elif event.key == pygame.K_s:
                player.velocity[1] = 300 * dt
            elif event.key == pygame.K_a:
                player.velocity[0] = -300 * dt
            elif event.key == pygame.K_d:
                player.velocity[0] = 300 * dt
        elif event.type == pygame.KEYUP:
            if event.key == pygame.K_w or event.key == pygame.K_s:
                player.velocity[1] = 0
            elif event.key == pygame.K_a or event.key == pygame.K_d:
                player.velocity[0] = 0
    player.update()
    screen.blit(player.image, player.rect)
    for razer in razers:
        if int(razer.time) + 1 == int(time.time()):
            razers.remove(razer)
        screen.blit(razer.image, razer.rect)
    if not len(razers):
        for i in range(2):
            razer = H_Razer()
            razers.append(razer)
            razer = V_Razer()
            razers.append(razer)
    pygame.display.update()  # Or pygame.display.flip()

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)