So keys is defined as:
Well...my shoot stuff is in a sprites.py file, in the class player. In that player class there is an __init__, a get_keys(self), a shoot(self) and an update(self) section. In my main.py file, there is an event loop.
So you mean I should do it like this? :
Well...now it is always one less, than the SHURIKAN_AMMO. At least, it is not random anymore, but do you now, why it is always one less, than it's supposed to be?
Edit: I've debugged it again and it always goes down by 1 when I shoot. But when the Ammo is 1, I somehow can't shoot anymore. I've tried adding something like this in the event loop:
Thank you so much for you help!
keys = pg.key.get_pressed()I imported pygame as pg. So you mean, I should make an event loop?
Well...my shoot stuff is in a sprites.py file, in the class player. In that player class there is an __init__, a get_keys(self), a shoot(self) and an update(self) section. In my main.py file, there is an event loop.
So you mean I should do it like this? :
def events(self): for event in pg.event.get(): if event.type == pg.KEYDOWN: if event.key == pg.K_SPACE: if self.player.weapon == 'shurikan' and self.player.shoot_ammo == True: self.player.SHURIKAN_AMMO -= 1 if self.player.SHURIKAN_AMMO < 0: self.player.SHURIKAN_AMMO = 0 if self.player.SHURIKAN_AMMO == 0: self.player.shoot_ammo = False if self.player.SHURIKAN_AMMO > 0: self.player.shoot()That is now in my main.py. I set the ammo to 5. I can shoot 4 times. When it is 10, I can shoot 9 times.
Well...now it is always one less, than the SHURIKAN_AMMO. At least, it is not random anymore, but do you now, why it is always one less, than it's supposed to be?
Edit: I've debugged it again and it always goes down by 1 when I shoot. But when the Ammo is 1, I somehow can't shoot anymore. I've tried adding something like this in the event loop:
# Event loop if self.player.BLOWPIPE_AMMO == 1: self.player.shoot()But somehow, that didn't work.
Thank you so much for you help!