Python Forum
[PyGame] Ammo is random, but it shouldn't
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGame] Ammo is random, but it shouldn't
#1
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):

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.
Reply


Messages In This Thread
Ammo is random, but it shouldn't - by Piethon - Oct-04-2019, 10:29 AM
RE: Ammo is random, but it shouldn't - by metulburr - Oct-04-2019, 11:12 AM
RE: Ammo is random, but it shouldn't - by Piethon - Oct-04-2019, 02:43 PM
RE: Ammo is random, but it shouldn't - by metulburr - Oct-04-2019, 02:54 PM
RE: Ammo is random, but it shouldn't - by Piethon - Oct-05-2019, 08:57 AM
RE: Ammo is random, but it shouldn't - by metulburr - Oct-05-2019, 11:36 AM

Forum Jump:

User Panel Messages

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