0

I'm making a game where a spaceship shoots at aliens. The problem is that when I call the shoot function twice I don't get two projectiles, but one get destroyed. I think I have to store the two projectiles in the same variable, but I don't know how to do that. Here it is some code:

class Obj :
    def __init__ (self, x, y, img):
        self.x = x
        self.y = y
        self.img = img
    def blit (self):
        window.blit (self.img, (self.x, self.y))

class Player (Obj):
    def command (self, up, down, shoot):
        keys = pg.key.get_pressed()
        self.up = up
        self.down = down
        self.shoot = shoot     
        if keys[up]:
            self.y -= 1
        if keys[down]:
            self.y += 1
        if keys[shoot]:
            self.Shoot()
    def Shoot(self):
        global Prt
        Prt = Ammo(self.x, self.y, prt_img)
        Prt.blit()
        Prt.Move(0.5)
quamrana
  • 37,849
  • 12
  • 53
  • 71
Dark
  • 43
  • 3
  • 3
    Read about [Lists](https://docs.python.org/3/tutorial/datastructures.html) – Rabbid76 May 29 '20 at 19:36
  • As Rabbid76 already commented, you should use `collection` such as `list` to remember your `Ammo`s. I would like to give some suggestion in Python / OO programming based on your code: * Better use `object` as base class of your `Obj`. (https://stackoverflow.com/questions/54867/what-is-the-difference-between-old-style-and-new-style-classes-in-python) * Try image that : `Player` trigger/use `Weapon`, then `Weapon` fired with `Ammo` being `shoot`(shot). * A `Weapon` has limited `Ammo` (that's the point of this quesion) and can be `reload` * `Ammo` has stauts of `Shot`, `Mounted` etc. – Samuel Chen May 29 '20 at 19:48

0 Answers0