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
#5
So keys is defined as:

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!
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