i have made this bullet class but i have a problem with the firerate. Sometimes i'm not able to shoot even when the little delay (700ms) between the two shots has ended. I guess it's due to the pygame.time.set_timer(). Anyways i'm looking for a quick solution because i wanna move on to work on another part of this game.
...
class Singlebullet(object):
def __init__(self):
self.img = pygame.image.load(r'C:\Users\Salem\Documents\MyGame1\bullet.png')
self.state = 'ready'
self.speed = 0
self.firerate = 700
def shoot(self):
if current_bullet_type == 'single':
if self.state == 'ready':
self.x = myplane.x + 71
self.y = myplane.y
if self.state == 'fire':
self.speed = -13
for event in events:
if event.type == pygame.KEYDOWN or event.type == pygame.KEYUP:
if event.key == pygame.K_SPACE:
self.state = 'fire'
pygame.time.set_timer(pygame.USEREVENT+1, self.firerate)
if event.type == pygame.USEREVENT+1:
self.state = 'ready'
MyScrollingScreen.blit(self.img, (self.x, self.y))
self.y += self.speed
s1 = Singlebullet()
...
while running:
...
s1.shoot()
...