import pygame

class Bullet():

    def __init__(self,width,height,x,y,color,direction = "normal"):
        self.width  = width
        self.height = height
        self.x      = x
        self.y      = y
        self.speed  = 7
        self.color  = color
        self.direction = direction
        self.alive  = True
        self.hit    = False
        self.image = pygame.image.load("bullet.png")
        return

    def checkHitBaddie(self,x,y,w,h):
        if self.hitRectangle(x, y, w, h):
            self.setAlive(False)
            self.hit = True

    def checkBackWall(self,back_wall):
        if (self.x + self.width) > back_wall:
            self.setAlive(False)
        return

    def moveBullet(self):
        if self.direction == "up":
            self.y -= (self.speed/2)
        if self.direction == "down":
            self.y += (self.speed/2)
        self.x += self.speed
        return

    def setAlive(self,alive):
        self.alive = alive
        return
    
    def getHit(self):
        return self.hit

    def hitRectangle(self, x, y, w, h):
        if( ((self.x + self.width) >= x) and
            (self.x <= x + w) ):
            if( ((self.y + self.height) >= y) and
                (self.y <= y + h)) :
                return True
        return False
    
    def draw(self, surface):
        surface.blit(self.image, (self.x, self.y))
        return
        
