May-06-2023, 02:32 PM
(This post was last modified: May-06-2023, 02:32 PM by deanhystad.)
What is your frame rate?
What does this mean?
What does this mean?
Quote:let him 3 sec shootAre you stopping your game for 3 seconds each time a laser is shot? That cannot be allowed. You can make the beam grow, but you need to let the game proceed at the same time. Like this:
import pygame class Beam(pygame.sprite.Sprite): def __init__(self, speed = 10): super().__init__() self.x, self.y = 0, 0 self.length = 0 self.shooting = False self.speed = speed def at(self, x, y): self.x, self.y = x, y def shoot(self): self.length = 0 self.shooting = True def draw(self, screen): if self.shooting: self.length += self.speed end = self.y + self.length start = max(self.y, end-100) pygame.draw.line(screen, (255, 0, 0), (self.x, start), (self.x, end), width=5) self.shooting = end < screen.get_height() pygame.init() clock = pygame.time.Clock() screen = pygame.display.set_mode((200, 400)) beam = Beam() beam.at(100, 50) running = True while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False elif event.type == pygame.MOUSEBUTTONDOWN: beam.shoot() screen.fill("black") beam.draw(screen) pygame.display.flip() clock.tick(30)