class ShrinkingIonField(IonField):
    """IonField which will smoothly shrink from the top and bottom every frame"""

    def __init__(self, left, top, width, height, noise_width, noise_height, delay, shrink_rate):
        IonField.__init__(self, left, top, width, height, noise_width, noise_height, delay)

        self.shrink_rate = shrink_rate
        self.crop_top = int(shrink_rate / 2)

    def update(self):
        self.shrink()
        IonField.update(self)


    def shrink(self):
        self.height = max(self.height - self.shrink_rate, 0)

        #copy the existing noise, cropping off the top and bottom
        temp_image = Surface((self.width, self.height))
        temp_image.blit(self.image, Rect(0, 0, 0, 0), Rect(0, self.crop_top, self.width, self.height))
        self.image = temp_image
        
        self.mask = Mask((self.width, self.height))
        self.mask.fill()

        self.top = self.top + self.crop_top

        self.rect = Rect(self.left, self.top, self.width, self.height)
class ShrinkingIonField(IonField):
    """IonField which will smoothly shrink from the top and bottom every frame"""
    def __init__(self, left, top, width, height, noise_width, noise_height,
                 delay, shrink_rate):
        IonField.__init__(self, left, top, width, height, noise_width,
                          noise_height, delay)

        self.shrink_rate = shrink_rate
        self.crop_top = int(shrink_rate / 2)

    def update(self):
        self.shrink()
        IonField.update(self)

    def shrink(self):
        self.height = max(self.height - self.shrink_rate, 0)

        #copy the existing noise, cropping off the top and bottom
        temp_image = Surface((self.width, self.height))
        temp_image.blit(self.image, Rect(0, 0, 0, 0),
                        Rect(0, self.crop_top, self.width, self.height))
        self.image = temp_image

        self.mask = Mask((self.width, self.height))
        self.mask.fill()

        self.top = self.top + self.crop_top

        self.rect = Rect(self.left, self.top, self.width, self.height)
Beispiel #3
0
def create_rectangular_mask(canvas_width, canvas_height, offset_x, offset_y,
                            mask_width, mask_height):
    m = Mask((canvas_width, canvas_height))

    for x in range(offset_x, offset_x + mask_width):
        for y in range(offset_y, offset_y + mask_height):
            m.set_at((x, y), 1)

    return m
    def shrink(self):
        self.height = max(self.height - self.shrink_rate, 0)

        #copy the existing noise, cropping off the top and bottom
        temp_image = Surface((self.width, self.height))
        temp_image.blit(self.image, Rect(0, 0, 0, 0),
                        Rect(0, self.crop_top, self.width, self.height))
        self.image = temp_image

        self.mask = Mask((self.width, self.height))
        self.mask.fill()

        self.top = self.top + self.crop_top

        self.rect = Rect(self.left, self.top, self.width, self.height)
Beispiel #5
0
 def __init__(self, rect_dims, *groups):
     super().__init__(*groups)
     self.rect: pygame.Rect = pygame.Rect(rect_dims)
     self.image = pygame.Surface(self.rect.size)
     self.image.fill(Color('white'))
     self.mask: Mask = Mask((self.rect.width, self.rect.height), fill=True)
     self.dirty = 0  # will never be updated
Beispiel #6
0
 def blit(self):
     """
     If the shot should explode: Paint a blast! Otherwise, just do what any
     other shot would do.
     """
     if self.counter >= self.__timeout:
         size = self.__timeout - self.counter
         rad = self.__radius - size
         pos = map(int, self.get_position())
         rect = circle(self.surface, (255, 102, 0), pos, rad)
         self.rect = rect
         self.image = Surface((rect.width, rect.height))
         self.mask = Mask((rect.width, rect.height))
         self.mask.fill()  # Everything in this mask is set
     else:
         super(Mine, self).blit()
Beispiel #7
0
    def __init__(self, manager):
        State.__init__(self, manager)

        self.sprite = Sprite()
        self.sprite.image = Surface((0, 0))
        self.sprite.rect = Rect(0, 0, 1, options.height)
        self.sprite.mask = Mask((1, options.height))
        self.sprite.mask.fill()

        self.STATE_NUMBER = manager.DEACTIVATED
Beispiel #8
0
    def __init__(self, left, top, width, height, noise_width, noise_height,
                 delay):
        Sprite.__init__(self)

        self.top = top
        self.left = left
        self.width = width
        self.height = height

        self.image = Surface((self.width, self.height))
        self.rect = Rect(left, top, self.width, self.height)
        self.rect = Rect(left, top, 0, 0)
        self.mask = Mask((self.width, self.height))
        self.mask.fill()

        self.noise_width = noise_width
        self.noise_height = noise_height

        self.tick = 0
        self.delay = delay
Beispiel #9
0
class IonField(Sprite):
    """Sprite that draws a bunch of random horizontal lines inside a rectangle."""
    
    def __init__(self, left, top, width, height, noise_width, noise_height, delay):
        Sprite.__init__(self)

        self.top = top
        self.left = left
        self.width = width
        self.height = height

        self.image = Surface((self.width, self.height))
        self.rect = Rect(left, top, self.width, self.height)
        self.rect = Rect(left, top, 0, 0)
        self.mask = Mask((self.width, self.height))
        self.mask.fill()

        self.noise_width = noise_width
        self.noise_height = noise_height

        self.tick = 0
        self.delay = delay


    def update(self):
        self.tick = self.tick + 1
        if self.tick % self.delay == 0:
            self.generate_noise()


    def draw(self, screen):
        screen.blit(self.image, self.rect)
    

    def generate_noise(self):
        for col in range(0, self.image.get_width(), self.noise_width):
            for row in range(0, self.image.get_height(), self.noise_height):
                c = choice(COLORS)
                draw.rect(self.image, c, Rect(col, row, self.noise_width, self.noise_height))
    def shrink(self):
        self.height = max(self.height - self.shrink_rate, 0)

        #copy the existing noise, cropping off the top and bottom
        temp_image = Surface((self.width, self.height))
        temp_image.blit(self.image, Rect(0, 0, 0, 0), Rect(0, self.crop_top, self.width, self.height))
        self.image = temp_image
        
        self.mask = Mask((self.width, self.height))
        self.mask.fill()

        self.top = self.top + self.crop_top

        self.rect = Rect(self.left, self.top, self.width, self.height)
Beispiel #11
0
class IonField(Sprite):
    """Sprite that draws a bunch of random horizontal lines inside a rectangle."""
    def __init__(self, left, top, width, height, noise_width, noise_height,
                 delay):
        Sprite.__init__(self)

        self.top = top
        self.left = left
        self.width = width
        self.height = height

        self.image = Surface((self.width, self.height))
        self.rect = Rect(left, top, self.width, self.height)
        self.rect = Rect(left, top, 0, 0)
        self.mask = Mask((self.width, self.height))
        self.mask.fill()

        self.noise_width = noise_width
        self.noise_height = noise_height

        self.tick = 0
        self.delay = delay

    def update(self):
        self.tick = self.tick + 1
        if self.tick % self.delay == 0:
            self.generate_noise()

    def draw(self, screen):
        screen.blit(self.image, self.rect)

    def generate_noise(self):
        for col in range(0, self.image.get_width(), self.noise_width):
            for row in range(0, self.image.get_height(), self.noise_height):
                c = choice(COLORS)
                draw.rect(self.image, c,
                          Rect(col, row, self.noise_width, self.noise_height))
Beispiel #12
0
class Mine(Shot):
    """
    Mines are shots that creates a blast after a timeout, damaging anything
    within that blast zone.
    """
    minefile = join(GFX_PATH, "mine.png")

    def __init__(self, common, init_pos, init_dir, speed, timeout, radius):
        super(Mine, self).__init__(common, Mine.minefile, init_pos, init_dir,
                                   speed, Shot.largedamage)
        self.__timeout = timeout
        self.__radius = radius

    def update(self, *_):
        if self.counter < self.__timeout:
            super(Mine, self).update()
        elif self.counter - self.__timeout > self.__radius:
            self.kill()

    # TODO: Find a neater way to do this
    def blit(self):
        """
        If the shot should explode: Paint a blast! Otherwise, just do what any
        other shot would do.
        """
        if self.counter >= self.__timeout:
            size = self.__timeout - self.counter
            rad = self.__radius - size
            pos = map(int, self.get_position())
            rect = circle(self.surface, (255, 102, 0), pos, rad)
            self.rect = rect
            self.image = Surface((rect.width, rect.height))
            self.mask = Mask((rect.width, rect.height))
            self.mask.fill()  # Everything in this mask is set
        else:
            super(Mine, self).blit()
Beispiel #13
0
    def __init__(self, left, top, width, height, noise_width, noise_height, delay):
        Sprite.__init__(self)

        self.top = top
        self.left = left
        self.width = width
        self.height = height

        self.image = Surface((self.width, self.height))
        self.rect = Rect(left, top, self.width, self.height)
        self.rect = Rect(left, top, 0, 0)
        self.mask = Mask((self.width, self.height))
        self.mask.fill()

        self.noise_width = noise_width
        self.noise_height = noise_height

        self.tick = 0
        self.delay = delay