954,525 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Pygame Questions

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
colts18
Newbie Poster
5 posts since Jan 2011
Reputation Points: 10
Solved Threads: 0
 

You have not posted how you are actually using the classes.

pyTony
pyMod
Moderator
5,359 posts since Apr 2010
Reputation Points: 782
Solved Threads: 852
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: