Hello.
I have a little problem in my game, that I am coding with pygame.
I've tried adding ammo, to my shurikans, that you can't spam them.
I've set the SHURIKAN_AMMO to 20, and I can shoot 2 times. When it is at 500, I can shoot like 56 times.
Here's the code (parts of it):
Piethon.
I have a little problem in my game, that I am coding with pygame.
I've tried adding ammo, to my shurikans, that you can't spam them.
I've set the SHURIKAN_AMMO to 20, and I can shoot 2 times. When it is at 500, I can shoot like 56 times.
Here's the code (parts of it):
class Player(pg.sprite.Sprite): def __init__(self, game, x, y): self.weapon = 'shurikan' self.shoot_ammo = True self.SHURIKAN_AMMO = 500 def get_keys(self): if keys[pg.K_SPACE]: if self.weapon == 'shurikan' and self.shoot_ammo == True: self.SHURIKAN_AMMO -= 1 if self.SHURIKAN_AMMO < 0: self.SHURIKAN_AMMO = 0 if self.SHURIKAN_AMMO == 0: self.shoot_ammo = False if self.SHURIKAN_AMMO > 0: self.shoot() def shoot(self): if self.shoot_ammo == True: now = pg.time.get_ticks() if now - self.last_shot > WEAPONS[self.weapon]['rate']: self.last_shot = now dir = vec(1, 0).rotate(-self.rot) pos = self.pos + BARREL_OFFSET.rotate(-self.rot) self.vel = vec(-WEAPONS[self.weapon]['rate'], 0).rotate(-self.rot) for i in range(WEAPONS[self.weapon]['count']): spread = uniform(-WEAPONS[self.weapon]['spread'], WEAPONS[self.weapon]['spread']) Blowpipe(self.game, pos, dir.rotate(spread))I have made a list, for the different weapons, where rate, spread and other things are in. This is the one, for the shurikan:
WEAPONS['shurikan'] = {'img': 'shurikan.png', 'speed': 575, 'lifetime': 800, 'rate': 400, 'kickback': 0, 'spread': 2, 'damage': 12, 'size': 'shurikan', 'count': 1}I really don't know, why this is happening. If you have an idea, then please tell me. Thanks so much.
Piethon.