Python Forum
Pygmae big problems with gamescore and fps
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pygmae big problems with gamescore and fps
#2
What is your frame rate?

What does this mean?
Quote:let him 3 sec shoot
Are 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)
Reply


Messages In This Thread
RE: Pygmae big problems with gamescore and fps - by deanhystad - May-06-2023, 02:32 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020