Hey guys I am creating a game, I am using Python and Pygame and I am trying to tell the tank to disappear when the bullet hits it. I have started to create the code but I don't know how to clear only one object is it possible. I might have made a mistake somewhere else too this is my first game. Does someone know? Here is my bullet and enemy tank classes:
class Bullet:
def __init__(self):
self.bullet = pygame.image.load("tank_bullet.png")
self.y = 0
self.x = 0
self.speed = 0
self.forwardx = 1
self.forwardy = 0
self.fired = False
def draw(self, surface):
surface.blit(self.bullet, (self.x, self.y))
def update(self, dt):
self.x += self.forwardx * self.speed
self.y += self.forwardy * self.speed
if self.x > 640:
self.fired = False
def tank_hit(self, enemy_tank):
if self.x > enemy_tank.x:
tank_hit = True
else:
and my enemy tank:
class Enemy_tank:
def __init__(self):
self.enemy_tank = pygame.image.load("enemy_tank.png")
self.fire_countdown_2 = 0
def draw(self, surface):
surface.blit(self.enemy_tank, (200, -40))
def update(self, dt):
if(self.firecountdown_2 > 0):
self.firecountdown_2-= dt
def fire(self, enemy_bullet):
if(self.firecountdown_2 <=0) :
enemy_bullet.x = self.x
enemy_bullet.y = self.y
enemy_bullet.fired = True
enemy_bullet.speed = 10
self.firecountdown_2 = 1000