0

Code, for reference:

import pygame
import sys

# initialise pygame, setup sprite class
pygame.init()
class dguy(pygame.sprite.Sprite):
    def __init__(self,picture_path):
        super().__init__()
        self.image = pygame.image.load(picture_path)
        self.rect = self.image.get_rect()
        self.shot = pygame.mixer.Sound("PYG/doomshooter/bfgshot.mp3")
    def shoot(self):
        self.shot.play()
    def update(self):
        self.rect.center = pygame.mouse.get_pos()

# create imp
class enemy(pygame.sprite.Sprite):
    def __init__(self,picture_path,px,py):
        super().__init__()
        self.image = pygame.image.load(picture_path)
        self.rect = self.image.get_rect()
        self.rect.center = [px,py]
# shot
class shot(pygame.sprite.Sprite):
    def __init__(self,picture_path,px,py):
        super().__init__()
        self.image = pygame.image.load(picture_path)
        self.rect = self.image.get_rect()
        self.rect.center = [px,py]
    def laserupdate(self):
        mousepos = list(pygame.mouse.get_pos())
        mousepos[0] += 160
        self.rect.center = mousepos
        pygame.sprite.spritecollide(laser,targetsprts,True)
#ball
class orb(pygame.sprite.Sprite):
    def __init__(self, picture_path,px,py):
        super().__init__()
        self.image = pygame.image.load(picture_path)
        self.rect=self.image.get_rect()
        self.rect.center = [px,py]
    def orbupdate(self):
        self.rect.center = ball.rect.center - (1,0)
        pygame.sprite.spritecollide(ball,sprts,True)

# screen
width=640
height=320
screen = pygame.display.set_mode((width,height))
bg = pygame.image.load("PYG/doomshooter/bigwall.png")
pygame.mouse.set_visible(False)

#game
game = True

#sprites
doomguy = dguy("PYG/doomshooter/bfg9000.png")
sprts = pygame.sprite.Group()
sprts.add(doomguy)

imp = enemy("PYG\doomshooter\hand.png",450,250)
targetsprts = pygame.sprite.Group()
targetsprts.add(imp)

laser = shot("PYG/doomshooter/longbfgshot.png",1,1)
shots = pygame.sprite.Group()
shots.add(laser)

ball = orb("PYG/doomshooter/orb.png",0 ,0)
orbs = pygame.sprite.Group()
orbs.add(ball)

#time
clock = pygame.time.Clock()
# game loop

while game:
    screen.fill((1,1,1))
    screen.blit(bg,(0,0))
    targetsprts.draw(screen)
    sprts.draw(screen)
    sprts.update()
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            game = False
        if event.type == pygame.MOUSEBUTTONDOWN:
            doomguy.shoot()
            laser.laserupdate()
            for i in range(30):
                shots.draw(screen)
    pygame.display.update()
    clock.tick(60)
pygame.quit()
exit()

^piracy allowed if you'd like

so, basically, I want all objects in sprite group orbs (mainly just variable ball, but I'm used to sprite groups) to spawn at the location of group targetsprts every set number of ticks/seconds. tried a few tutorials but it didn't work. even more basically, I need a timer.

PS: I'd appreciate any support with the code that is not related to the question above.

Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
Neoro
  • 7
  • 3
  • 2
    Pls provide a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). People aren’t likely to read a lot of code. – Dinux Aug 06 '23 at 16:35

0 Answers0