Exemplo n.º 1
0
    def render(self):
        self.canvas.fill(BACKGROUND_COLOUR)
        self.canvas.blit(self.track_surface, (0, 148))
        self.canvas.blit(self.platform_surface, (0, 0))

        title_copy = transform.rotozoom(self.title_surface, self.rot_val, self.zoom_val)
        title_shadow_copy = transform.rotozoom(self.title_surface, self.rot_val * 2.1, self.zoom_val + 0.5)
        title_center = (
            int(self.canvas.get_size()[0]/2 - title_copy.get_size()[0]/2),
            int(self.canvas.get_size()[1]/3 - title_copy.get_size()[1]/2),
        )

        title_shadow_center = (
            int(self.canvas.get_size()[0]/2 - title_shadow_copy.get_size()[0]/2),
            int(self.canvas.get_size()[1]/3 - title_shadow_copy.get_size()[1]/2),
        )
        subtitle_center = (
            int(self.canvas.get_size()[0]/2 - self.subtitle_surface.get_size()[0]/2),
            int((2*self.canvas.get_size()[1]/3) - self.subtitle_surface.get_size()[1]/2),
        )

        # shadow effect
        pixels_alpha = pygame.surfarray.pixels_alpha(title_shadow_copy)
        pixels_alpha[...] = (pixels_alpha * (50 / 255.0)).astype(numpy.uint8)
        del pixels_alpha  # unlock surface

        self.canvas.blit(title_shadow_copy, title_shadow_center)
        self.canvas.blit(title_copy, title_center)
        self.canvas.blit(self.subtitle_surface, subtitle_center)

        self.rot_val = 15 * math.sin((math.pi * self.rot_delta) + 2)
        self.zoom_val = math.sin(math.pi * self.zoom_delta) + 0.5
        self.zoom_delta = (self.zoom_delta + 0.0039) % 1
        self.rot_delta = (self.rot_delta + 0.008) % 2
Exemplo n.º 2
0
    def buildLabels(self):
        """\
        Pre-renders text labels to surfaces for different 45 degree
        angles.

        On exit:
        self.label is a list of surfaces containing rendered labels
        self.slabel is the same but coloured for when the particle is selected
        self.labelxo is a list of x-offsets for each label's centre.
        self.labelyo is a list of y-offsets fo reach label's centre.
        self.desclabel is the description label displayed when selected
        """
        from pygame.transform import rotozoom, rotate

        font = pygame.font.Font(None, 14)

        label = font.render(
            " " + abbreviate(self.name) + " ",
            True,
            (0, 0, 0),
        )
        self.label = []  # 'selected' labels
        self.labelxo = []
        self.labelyo = []
        self.label.append(rotate(label, 90))
        self.label.append(rotozoom(label, 45, 1.0))
        self.label.append(label)
        self.label.append(rotozoom(label, -45, 1.0))

        slabel = font.render(
            " " + abbreviate(self.name) + " ",
            True,
            (96, 96, 255),
        )
        self.slabel = []
        self.slabel.append(rotate(slabel, 90))
        self.slabel.append(rotozoom(slabel, 45, 1.0))
        self.slabel.append(slabel)
        self.slabel.append(rotozoom(slabel, -45, 1.0))

        #        print self.slabel[0].get_width(),self.slabel[0].get_height()

        self.radius = max(self.slabel[0].get_width(),
                          self.slabel[0].get_height()) / 2
        #        self.radius = max(self.slabel[0].get_width(),self.slabel[0].get_height())

        for l in self.label:
            self.labelxo.append(-l.get_width() / 2)
            self.labelyo.append(-l.get_height() / 2)

        font = pygame.font.Font(None, 20)
        self.desclabel = font.render(
            self.attributetype.upper() + " : " + self.name, True, (0, 0, 0),
            (255, 255, 255))
Exemplo n.º 3
0
    def __init__(self,
                 position,
                 sprite,
                 create_asteroid,
                 random_velocity,
                 size=3):
        """
        :param position: Position of the Asteroid
        :param create_asteroid: Callback to create an asteroid when this asteroid is split up. it should be split up
        into smaller asteroids based on the scale of the new size
        :param size Initial size of the asteroid, starts at 3. When it is split by a bullet to 2, then 1, then it is
        destroyed
        This will assign a size to an asteroid, using the default value 3, which represents a big asteroid.
        It will also scale the original sprite by using rotozoom(). This method is used for scaling if the angle is 0
        and the scale is anything other than 0. the size_to_scale lookup table contains scales for different sizes
        """
        self.size = size
        self.create_asteroid = create_asteroid
        size_to_scale = {
            3: 1,
            2: 0.5,
            1: 0.25,
        }
        scale = size_to_scale[size]
        sprite = rotozoom(sprite, 0, scale)

        # Notice the get_random_velocity uses the minimum value of 1,this is because the asteroid should always move
        # at least a bit.
        super().__init__(position, sprite, random_velocity)
Exemplo n.º 4
0
    def __init__(self, ID, position, name, filename=None, image=None):
        """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
        super(IconComponent, self).__init__(position=position, ID=ID)
        self.set_label(name)
        self.ptype = "component"
        self.shortname = abbreviate(name)
        self.left = 0
        self.top = 0
        self.selected = False
        self.image = None

        self.radius = _COMPONENT_RADIUS * 1.2
        if filename is None:
            import os, random
            assets = [x for x in os.listdir("assets") if x[-4:] == ".gif"]
            filename = "assets/" + assets[random.randint(0, len(assets) - 1)]

        if filename is not None:
            self.image = pygame.image.load(filename)
            self.image = self.image.convert()
            print "size:", self.image.get_width(), self.image.get_height()
            print "largest:", max(self.image.get_width(),
                                  self.image.get_height())
            largest = max(self.image.get_width(),
                          self.image.get_height()) * 1.0
            print "rescale:", largest / _COMPONENT_RADIUS
            from pygame.transform import rotozoom
            self.image = rotozoom(self.image, 0.0,
                                  ((_COMPONENT_RADIUS * 2) / largest))
            self.imagexo = -self.image.get_width() / 2
            self.imageyo = -self.image.get_height() / 2
Exemplo n.º 5
0
 def __init__(self, position, create_bullet_callback):
     self.create_bullet_callback = create_bullet_callback
     self.laser_sound = load_sound('laser')
     self.explosion_sound = load_sound("crush")
     self.direction = Vector2(UP)
     super().__init__(position, rotozoom(load_sprite("spaceship"), 0, 0.5),
                      Vector2(0))
Exemplo n.º 6
0
   def __init__(self, ID, position, name, filename=None, image=None):
       """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
       super(IconComponent,self).__init__(position=position, ID = ID )
       self.set_label(name)
       self.ptype = "component"
       self.shortname = abbreviate(name)
       self.left = 0
       self.top = 0
       self.selected = False
       self.image = None
       
       self.radius = _COMPONENT_RADIUS*1.2
       if filename is None:
           import os, random
           assets = [ x for x in os.listdir("assets") if x[-4:] == ".gif" ]
           filename = "assets/"+assets[random.randint(0, len(assets)-1)]
 
       if filename is not None:
           self.image = pygame.image.load(filename)
           self.image = self.image.convert()
           print "size:", self.image.get_width(), self.image.get_height()
           print "largest:", max(self.image.get_width(), self.image.get_height())
           largest = max(self.image.get_width(), self.image.get_height())*1.0
           print "rescale:", largest/_COMPONENT_RADIUS
           from pygame.transform import rotozoom
           self.image = rotozoom(self.image, 0.0, ((_COMPONENT_RADIUS*2)/largest))
           self.imagexo = - self.image.get_width()/2
           self.imageyo = - self.image.get_height()/2
Exemplo n.º 7
0
 def __init__(self, position, sprite, velocity):
     self.sprite = rotozoom(sprite, 0, 0.05)
     super().__init__(position, self.sprite, velocity)
     self.click_sound = load_sound("click_new2")
     self.bounces = 0
     self.clipping = 0
     return
Exemplo n.º 8
0
    def draw(self, surface):
        """
        Overrides the draw method of a Game Object

        Note that rotozoom() returns a new surface with a rotated image. However, in order to keep all the contents of
        the original sprite, the new image might have a different size. In that case, Pygame will add some additional,
        transparent background.

        The size of the new image can be significantly different than that of the original image. That’s why draw()
        recalculates the blit position of rotated_surface. Remember that blit() starts in the upper-left corner, so to
        center the rotated image, you also need to move the blit position by half the size of the image.
        """
        # uses the angle_to() method of the Vector2 class to calculate the angle by which one vector needs to be rotated
        # in order to point in the same direction as the other vector. This makes it painless to translate the
        # spaceship’s direction into the rotation angle in degrees.
        angle = self.direction.angle_to(UP)

        # rotates the sprite using rotozoom(). It takes the original image, the angle by which it should be rotated,
        # and the scale that should be applied to the sprite. In this case, you don’t want to change the size,
        # so you keep the scale as 1.0.
        rotated_surface = rotozoom(self.sprite, angle, 1.0)

        # recalculate the blit position, using the size of rotated_surface. The process is described below.
        rotated_surface_size = Vector2(rotated_surface.get_size())

        # contains the rotated_surface_size * 0.5 operation. That’s another thing you can do with vectors in Pygame.
        # When you multiply a vector by a number, all its coordinates are multiplied by that number.
        # As a result, multiplying by 0.5 will return a vector with half the length of the original.
        blit_position = self.position - rotated_surface_size * 0.5

        # uses the newly calculated blit position to put the image on the screen.
        surface.blit(rotated_surface, blit_position)
Exemplo n.º 9
0
    def __init__(self, game):
        self.game = game
        self.font = pygame.font.Font('res/font/ps2p.ttf', 14)
        self.schools_scores = json.load(open('./res/schools_scores.json', 'r'))
        self.schools = sorted(self.schools_scores.keys())
        self.selections = [
            random.randint(0, len(self.schools) - 1),
            random.randint(0, len(self.schools) - 1)
        ]

        self.players_is_ready = [False, False]

        # Gfx
        self.gfx_background = pygame.image.load('./res/img/ui/background.jpg')
        self.gfx_grid = pygame.image.load('./res/img/ui/menu.png').convert_alpha()
        self.gfx_vs = pygame.image.load('./res/img/ui/vs.png').convert_alpha()

        # Text
        self.txt_repo = pygame.font.Font('res/font/ps2p.ttf', 11).render("github.com/dciets/Arcade-CS-Games", 0, (255, 255, 255))
        self.txt_ready = [pygame.font.Font('res/font/ps2p.ttf', 42).render("READY", 0, (255, 255, 255)), pygame.font.Font('res/font/ps2p.ttf', 42).render("READY", 0, (255, 255, 255))]
        for i in range(2):
            self.txt_ready[i] = rotozoom(self.txt_ready[i], 35.0, 1.0)
        self.txt_wet_mode = [pygame.font.Font('res/font/ps2p.ttf', 20).render("< Wet mode! >", 0, (255, 255, 0)), pygame.font.Font('res/font/ps2p.ttf', 20).render("< Wet mode! >", 0, (255, 255, 0))]
        self.txt_dry_mode = [pygame.font.Font('res/font/ps2p.ttf', 20).render("< Dry mode! >", 0, (255, 255, 0)), pygame.font.Font('res/font/ps2p.ttf', 20).render("< Dry mode! >", 0, (255, 255, 0))]

        self.team_font = pygame.font.Font('res/font/ps2p.ttf', 30)
        self.txt_teams = [None, None]
        self.colors = [(0xff, 0x26, 0x47), (0x00, 0xea, 0xcc)]
        self.refresh_team(0)
        self.refresh_team(1)
Exemplo n.º 10
0
 def __init__(self):
     super(ExtraWindowFurniture,self).__init__()
     
     self.logo = pygame.image.load("kamaelia_logo.png")
     
     biggest = max( self.logo.get_width(), self.logo.get_height() )
     from pygame.transform import rotozoom
     self.logo = rotozoom(self.logo, 0.0, 64.0 / biggest)
    def render(self):
        pattern = pygame.Surface([32 * 6, 32 * 4])

        for y, row in enumerate(self._array):
            for x, c in enumerate(row):
                img = load.block(c)
                pattern.blit(img, [32 * x, 32 * y])
        pattern = transform.rotozoom(pattern, 0, 0.8).convert()
        return pattern
Exemplo n.º 12
0
    def __init__(self, position, create_asteroid_callback, size=3):
        self.create_asteroid_callback = create_asteroid_callback
        self.size = size

        size_to_scale = {3: 1.0, 2: 0.5, 1: 0.25}
        scale = size_to_scale[size]
        sprite = rotozoom(load_sprite("asteroid"), 0, scale)

        super().__init__(position, sprite, get_random_velocity(1, 3))
Exemplo n.º 13
0
    def __init__(self):
        """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
        super(ExtraWindowFurniture, self).__init__()

        self.logo = pygame.image.load("kamaelia_logo.png")

        biggest = max(self.logo.get_width(), self.logo.get_height())
        from pygame.transform import rotozoom
        self.logo = rotozoom(self.logo, 0.0, 64.0 / biggest)
Exemplo n.º 14
0
 def __init__(self):
     """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
     super(ExtraWindowFurniture,self).__init__()
     
     self.logo = pygame.image.load("kamaelia_logo.png")
     
     biggest = max( self.logo.get_width(), self.logo.get_height() )
     from pygame.transform import rotozoom
     self.logo = rotozoom(self.logo, 0.0, 64.0 / biggest)
Exemplo n.º 15
0
    def buildLabels(self):
        """\
        Pre-renders text labels to surfaces for different 45 degree
        angles.

        On exit:
        self.label is a list of surfaces containing rendered labels
        self.slabel is the same but coloured for when the particle is selected
        self.labelxo is a list of x-offsets for each label's centre.
        self.labelyo is a list of y-offsets fo reach label's centre.
        self.desclabel is the description label displayed when selected
        """
        from pygame.transform import rotozoom, rotate

        font = pygame.font.Font(None, 14)

        label = font.render(" "+abbreviate(self.name)+" ", True, (0,0,0), )
        self.label   = []   # 'selected' labels
        self.labelxo = []
        self.labelyo = []
        self.label.append(rotate(label, 90))
        self.label.append(rotozoom(label, 45, 1.0))
        self.label.append(label)
        self.label.append(rotozoom(label, -45, 1.0))

        slabel = font.render(" "+abbreviate(self.name)+" ", True, (96,96,255), )
        self.slabel  = []
        self.slabel.append(rotate(slabel, 90))
        self.slabel.append(rotozoom(slabel, 45, 1.0))
        self.slabel.append(slabel)
        self.slabel.append(rotozoom(slabel, -45, 1.0))

#        print self.slabel[0].get_width(),self.slabel[0].get_height()

        self.radius = max(self.slabel[0].get_width(),self.slabel[0].get_height())/2
#        self.radius = max(self.slabel[0].get_width(),self.slabel[0].get_height())

        for l in self.label:
            self.labelxo.append( - l.get_width()  / 2 )
            self.labelyo.append( - l.get_height() / 2 )

        font = pygame.font.Font(None, 20)
        self.desclabel = font.render(self.attributetype.upper()+" : "+self.name, True, (0,0,0), (255,255,255))
Exemplo n.º 16
0
    def __init__(self, position, create_meteroid_callback, size=3):
        self.size = size
        self.create_meteroid_callback = create_meteroid_callback
        self.explosion_sound = load_sound("meteriod_explo")
        self.explosion_sound.set_volume(100)

        size_to_scale = {3: .66, 2: 0.44, 1: 0.25}
        scale = size_to_scale[size]
        sprite = rotozoom(load_sprite("meteroid"), 0, scale)

        super().__init__(position, sprite, get_random_velocity(1, 2))
Exemplo n.º 17
0
    def rotate(self,angle):

        rotated_surface = transform.rotozoom(self.initial_image,angle,1).convert_alpha()
        rotated_rect = rotated_surface.get_rect(center = self.rect.center)

        self.Image = rotated_surface
        self.rect = rotated_rect     
       
        self.dx = Tank.Speed * math.sin(math.radians(-angle))
        self.dy = Tank.Speed * math.cos(math.radians(-angle))

        self.mask = mask.from_surface(self.Image)
Exemplo n.º 18
0
 def draw(self, surface):
     real_sprite = self.sprite
     if self._acceleration < 0:
         real_sprite = self._brake_sprite
     elif self._acceleration > 0:
         real_sprite = self._thrust_sprite
     angle = self.direction.angle_to(Vector2(0, -1))
     rotated_surface = rotozoom(real_sprite, angle, 1.0)
     rotated_surface_size = Vector2(rotated_surface.get_size())
     blit_position = self.position - rotated_surface_size * 0.5
     surface.blit(rotated_surface, blit_position)
     self._acceleration = 0
Exemplo n.º 19
0
    def update(self, dt):
        if hasattr(self.shape, "needs_remove"):
            self.kill()
        else:
            angle = round(degrees(self.shape.body.angle), 0)
            if not angle == self._old_angle:
                self.image = rotozoom(self.original_image, -angle, 1)
                self.rect = self.image.get_rect()
                self._old_angle = angle
                self.dirty = 1

            self.rect.center = self.shape.bb.center()
Exemplo n.º 20
0
def test_rotozoom(surface):
    obj = _make_object()
    x = 20
    y = 20
    space = obj.get_height()
    for angle in range(1, 200, 14):
        for scale in range(5, 20, 3):
            obj1 = transform.rotozoom(obj, angle, scale / 10.0)
            surface.blit(obj1, (x, y))
            x += obj1.get_width() + 5
            space = max(space, obj1.get_height())
            if x > 650:
                y += space + 5
                x = 20
Exemplo n.º 21
0
def test_rotozoom(surface):
    obj = _make_object()
    x = 20
    y = 20
    space = obj.get_height()
    for angle in range(1, 200, 14):
        for scale in range(5, 20, 3):
            obj1 = transform.rotozoom(obj, angle, scale / 10.0)
            surface.blit(obj1, (x, y))
            x += obj1.get_width() + 5
            space = max(space, obj1.get_height())
            if x > 650:
                y += space + 5
                x = 20
Exemplo n.º 22
0
    def buildLabels(self):
        from pygame.transform import rotozoom, rotate

        font = pygame.font.Font(None, 14)

        label = font.render(
            " " + abbreviate(self.name) + " ",
            True,
            (0, 0, 0),
        )
        self.label = []  # 'selected' labels
        self.labelxo = []
        self.labelyo = []
        self.label.append(rotate(label, 90))
        self.label.append(rotozoom(label, 45, 1.0))
        self.label.append(label)
        self.label.append(rotozoom(label, -45, 1.0))

        slabel = font.render(
            " " + abbreviate(self.name) + " ",
            True,
            (96, 96, 255),
        )
        self.slabel = []
        self.slabel.append(rotate(slabel, 90))
        self.slabel.append(rotozoom(slabel, 45, 1.0))
        self.slabel.append(slabel)
        self.slabel.append(rotozoom(slabel, -45, 1.0))

        for l in self.label:
            self.labelxo.append(-l.get_width() / 2)
            self.labelyo.append(-l.get_height() / 2)

        font = pygame.font.Font(None, 20)
        self.desclabel = font.render(
            self.postboxtype.upper() + " : " + self.name, True, (0, 0, 0),
            (255, 255, 255))
Exemplo n.º 23
0
    def __init__(self, game):
        self.game = game
        self.font = pygame.font.Font('res/font/ps2p.ttf', 14)
        self.schools_scores = json.load(open('./res/schools_scores.json', 'r'))
        self.schools = sorted(self.schools_scores.keys())
        self.selections = [
            random.randint(0,
                           len(self.schools) - 1),
            random.randint(0,
                           len(self.schools) - 1)
        ]

        self.players_is_ready = [False, False]

        # Gfx
        self.gfx_background = pygame.image.load('./res/img/ui/background.jpg')
        self.gfx_grid = pygame.image.load(
            './res/img/ui/menu.png').convert_alpha()
        self.gfx_vs = pygame.image.load('./res/img/ui/vs.png').convert_alpha()

        # Text
        self.txt_repo = pygame.font.Font('res/font/ps2p.ttf', 11).render(
            "github.com/dciets/Arcade-CS-Games", 0, (255, 255, 255))
        self.txt_ready = [
            pygame.font.Font('res/font/ps2p.ttf',
                             42).render("READY", 0, (255, 255, 255)),
            pygame.font.Font('res/font/ps2p.ttf',
                             42).render("READY", 0, (255, 255, 255))
        ]
        for i in range(2):
            self.txt_ready[i] = rotozoom(self.txt_ready[i], 35.0, 1.0)
        self.txt_wet_mode = [
            pygame.font.Font('res/font/ps2p.ttf',
                             20).render("< Wet mode! >", 0, (255, 255, 0)),
            pygame.font.Font('res/font/ps2p.ttf',
                             20).render("< Wet mode! >", 0, (255, 255, 0))
        ]
        self.txt_dry_mode = [
            pygame.font.Font('res/font/ps2p.ttf',
                             20).render("< Dry mode! >", 0, (255, 255, 0)),
            pygame.font.Font('res/font/ps2p.ttf',
                             20).render("< Dry mode! >", 0, (255, 255, 0))
        ]

        self.team_font = pygame.font.Font('res/font/ps2p.ttf', 30)
        self.txt_teams = [None, None]
        self.colors = [(0xff, 0x26, 0x47), (0x00, 0xea, 0xcc)]
        self.refresh_team(0)
        self.refresh_team(1)
Exemplo n.º 24
0
    def __init__(self, position, create_asteroid_callback, size=3):
        self.create_asteroid_callback = create_asteroid_callback
        self.size = size

        size_to_scale = {
            3: 1,
            2: 0.5,
            1: 0.25,
        }
        scale = size_to_scale[size]
        sprite = rotozoom(load_sprite("happy-covid"), 0, scale)

        super().__init__(
            # Adjust Possible Asteroid Velocity Range: get_random_velocity(x, y)
            position, sprite, get_random_velocity(1, 3) # (1, 3)
        )
Exemplo n.º 25
0
 def __init__(self):
     """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
     super(ExtraWindowFurniture,self).__init__()
     self.logo = None
     try:
         self.logo = pygame.image.load("kamaelia_logo.png")
     except pygame.error:
         try:
             self.logo = pygame.image.load("/usr/local/share/kamaelia/kamaelia_logo.png")
         except pygame.error:
             pass # Give up for now. FIXME: Could do something new
 
     if self.logo:
         biggest = max( self.logo.get_width(), self.logo.get_height() )
         from pygame.transform import rotozoom
         self.logo = rotozoom(self.logo, 0.0, 64.0 / biggest)
Exemplo n.º 26
0
    def update(self, *args, **kwargs):
        """
        Update the shape sprite.

        """
        if hasattr(self.shape, "needs_remove"):
            self.kill()
        else:
            angle = round(degrees(self.shape.body.angle), 0)
            if angle != self._old_angle:
                self.image = rotozoom(self.original_image, -angle, 1)
                self.rect = self.image.get_rect()
                self._old_angle = angle
                self.dirty = 1

            self.rect.center = self.shape.bb.center()
Exemplo n.º 27
0
 def __init__(self):
     """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
     super(ExtraWindowFurniture,self).__init__()
     self.logo = None
     try:
         self.logo = pygame.image.load("kamaelia_logo.png")
     except pygame.error:
         try:
             self.logo = pygame.image.load("/usr/local/share/kamaelia/kamaelia_logo.png")
         except pygame.error:
             pass # Give up for now. FIXME: Could do something new
 
     if self.logo:
         biggest = max( self.logo.get_width(), self.logo.get_height() )
         from pygame.transform import rotozoom
         self.logo = rotozoom(self.logo, 0.0, 64.0 / biggest)
Exemplo n.º 28
0
    def update(self, dt):
        if not self.visible:
            return

        if hasattr(self.shape, "needs_remove"):
            self.kill()
        else:
            angle = round(degrees(self.shape.body.angle), 0)
            if not angle == self._old_angle:
                self.image = rotozoom(self._original_image, -angle, 1)
                self.rect = self.image.get_rect()
                self._old_angle = angle
                self.dirty = 1
            if not self.rect.center == self.shape.body.position:
                self.rect.center = self.shape.body.position
                self.dirty = 1
Exemplo n.º 29
0
    def draw(self, screen):
        pos_a = self.__source.position
        pos_b = self.__destination.position
        draw.line(screen, self.__color.get_value()\
        , pos_a, pos_b, 5)
        mid_point = ((pos_a[0] + pos_b[0]) // 2, (pos_a[1] + pos_b[1]) // 2)
        angle = 360 - math.degrees(
            math.atan2(pos_b[1] - pos_a[1], pos_b[0] - pos_a[0]))
        img = transform.rotozoom(dir_img, angle, 0.075)
        img_width, img_height = img.get_size()
        left_corner = (mid_point[0] - img_width // 2,
                       mid_point[1] - img_height // 2)

        screen.blit(img, left_corner)
        val_text = font.render(str(self.__value), True, Blue.get_value(),
                               White.get_value())
        screen.blit(val_text, left_corner)
Exemplo n.º 30
0
 def draw_all(self, surface):
     if self.visible:
         surf_rect = surface.get_rect()
         bg_image = self.bg_image
         if bg_image:
             assert isinstance(bg_image, Surface)
             if self.scale_bg:
                 bg_width, bg_height = bg_image.get_size()
                 width, height = self.size
                 if width > bg_width or height > bg_height:
                     hscale = width / bg_width
                     vscale = height / bg_height
                     bg_image = rotozoom(bg_image, 0.0, max(hscale, vscale))
             r = bg_image.get_rect()
             r.center = surf_rect.center
             surface.blit(bg_image, r)
         else:
             bg = self.bg_color
             if bg:
                 surface.fill(bg)
         self.draw(surface)
         bw = self.border_width
         if bw:
             if self.has_focus() and hasattr(self, "highlight_color"):
                 bc = self.highlight_color
             else:
                 bc = self.border_color or self.fg_color
             frame_rect(surface, bc, surf_rect, bw)
         for widget in self.subwidgets:
             sub_rect = widget.rect
             if debug_rect:
                 print("Widget: Drawing subwidget %s of %s with rect %s" % (
                     widget, self, sub_rect))
             sub_rect = surf_rect.clip(sub_rect)
             if sub_rect.width > 0 and sub_rect.height > 0:
                 try:
                     sub = surface.subsurface(sub_rect)
                 except ValueError as e:
                     if str(e) == "subsurface rectangle outside surface area":
                         self.diagnose_subsurface_problem(surface, widget)
                     else:
                         raise
                 else:
                     widget.draw_all(sub)
         self.draw_over(surface)
Exemplo n.º 31
0
    def draw_all(self, surface):

        if self.visible:
            surf_rect = surface.get_rect()
            bg_image = self.bg_image
            if bg_image:
                if self.scale_bg:
                    bg_width, bg_height = bg_image.get_size()
                    width, height = self.size
                    if width > bg_width or height > bg_height:
                        hscale = width / bg_width
                        vscale = height / bg_height
                        bg_image = rotozoom(bg_image, 0.0, max(hscale, vscale))
                r = bg_image.get_rect()
                r.center = surf_rect.center
                surface.blit(bg_image, r)
            else:
                bg = self.bg_color
                if bg:
                    surface.fill(bg)
            self.draw(surface)
            bw = self.border_width
            if bw:
                bc = self.border_color or self.fg_color
                frame_rect(surface, bc, surf_rect, bw)
            for widget in self.subwidgets:
                sub_rect = widget.rect
                sub_rect = surf_rect.clip(sub_rect)

                self.debugSubWidgetDraws(sub_rect, widget)

                if sub_rect.width > 0 and sub_rect.height > 0:
                    try:
                        sub = surface.subsurface(sub_rect)
                    except ValueError as e:
                        if str(
                                e
                        ) == "subsurface rectangle outside surface area":
                            self.diagnose_subsurface_problem(surface, widget)
                        else:
                            raise
                    else:
                        widget.draw_all(sub)
            self.draw_over(surface)
Exemplo n.º 32
0
    def update_image(self):
        if self._needs_rescale:
            w = self.rect.width if self._width is None else self._width
            h = self.rect.height if self._height is None else self._height
            image = scale(self._original_image, (w, h))
            center = self.rect.center
            self.rect.size = w, h
            self.rect.center = center
        else:
            image = self._original_image

        if self._rotation:
            image = rotozoom(image, self._rotation, 1)
            rect = image.get_rect(center=self.rect.center)
            self.rect.size = rect.size
            self.rect.center = rect.center

        self._width, self._height = self.rect.size
        self._image = image
Exemplo n.º 33
0
    def update_image(self):
        if self._needs_rescale:
            w = self.rect.width if self._width is None else self._width
            h = self.rect.height if self._height is None else self._height
            image = scale(self._original_image, (w, h))
            center = self.rect.center
            self.rect.size = w, h
            self.rect.center = center
        else:
            image = self._original_image

        if self._rotation:
            image = rotozoom(image, self._rotation, 1)
            rect = image.get_rect(center=self.rect.center)
            self.rect.size = rect.size
            self.rect.center = rect.center

        self._width, self._height = self.rect.size
        self._image = image
Exemplo n.º 34
0
	def draw(self, group):
		blit = self.surface.blit
		psurface = self.particle_surface
		if not self.rotate_and_scale:
			for p in group:
				blit(psurface, (p.position.x, p.position.y))
		else:
			cache = self.surf_cache
			surfid = id(psurface)
			for p in group:
				size = int(p.size.x)
				rot = int(p.rotation.x)
				cachekey = (surfid, size, rot)
				try:
					surface = cache[cachekey]
				except KeyError:
					scale = p.size.x / psurface.get_width()
					surface = cache[cachekey] = rotozoom(psurface, rot, scale)
				blit(surface, (p.position.x, p.position.y))
Exemplo n.º 35
0
def load_image_rot(name, angle=0):
    """
    name: it will look it up in data/name (if you want to look for 
    data/tiles/name then you have to pass in tiles/name for name
    """
    global rotcache
    if name in cache:
        return list(cache[name])
    image = load(os.path.join(os.path.normpath(data_dir), name))
    rect = image.get_rect(center=(0,0))
    sub = []
    sub.append((image.convert_alpha(), rect))
    for angle in range(1, 360):
        rot_image = rotozoom(image, -angle, 1)
        rot_image = rot_image.convert_alpha()
        rect = rot_image.get_rect(center=(0,0))
        sub.append((rot_image, rect))
    cache[name] = sub
    return list(cache[name])
Exemplo n.º 36
0
	def draw(self, group):
		blit = self.surface.blit
		psurface = self.particle_surface
		if not self.rotate_and_scale:
			for p in group:
				blit(psurface, (p.position.x, p.position.y))
		else:
			cache = self.surf_cache
			surfid = id(psurface)
			for p in group:
				size = int(p.size.x)
				rot = int(p.rotation.x)
				cachekey = (surfid, size, rot)
				try:
					surface = cache[cachekey]
				except KeyError:
					scale = p.size.x / psurface.get_width()
					surface = cache[cachekey] = rotozoom(psurface, rot, scale)
				blit(surface, (p.position.x, p.position.y))
Exemplo n.º 37
0
 def draw_all(self, surface):
     if self.visible:
         surf_rect = surface.get_rect()
         bg_image = self.bg_image
         if bg_image:
             assert isinstance(bg_image, Surface)
             if self.scale_bg:
                 bg_width, bg_height = bg_image.get_size()
                 width, height = self.size
                 if width > bg_width or height > bg_height:
                     hscale = width / bg_width
                     vscale = height / bg_height
                     bg_image = rotozoom(bg_image, 0.0, max(hscale, vscale))
             r = bg_image.get_rect()
             r.center = surf_rect.center
             surface.blit(bg_image, r)
         else:
             bg = self.bg_color
             if bg:
                 surface.fill(bg)
         self.draw(surface)
         bw = self.border_width
         if bw:
             bc = self.border_color or self.fg_color
             frame_rect(surface, bc, surf_rect, bw)
         for widget in self.subwidgets:
             sub_rect = widget.rect
             if debug_rect:
                 print "Widget: Drawing subwidget %s of %s with rect %s" % (
                     widget, self, sub_rect)
             sub_rect = surf_rect.clip(sub_rect)
             if sub_rect.width > 0 and sub_rect.height > 0:
                 try:
                     sub = surface.subsurface(sub_rect)
                 except ValueError, e:
                     if str(e) == "subsurface rectangle outside surface area":
                         self.diagnose_subsurface_problem(surface, widget)
                     else:
                         raise
                 else:
                     widget.draw_all(sub)
         self.draw_over(surface)
Exemplo n.º 38
0
    def update(self,own_tank,angle):

        from TT import SCREEN_WIDTH, SCREEN_HEIGHT
        
        if self.situation == "stop":
            rotated_surface = transform.rotozoom(self.initial_image ,angle,1).convert_alpha()
            rotated_rect = rotated_surface.get_rect(center = self.rect.center)

            self.image = rotated_surface
            self.rect = rotated_rect   

            self.dx = own_tank.dx * 2.5
            self.dy = own_tank.dy * 2.5
            self.mask = mask.from_surface(self.image)
        
        if self.rect.left > 0 and self.rect.right < SCREEN_WIDTH and self.rect.top > 0 and self.rect.bottom < SCREEN_HEIGHT:
                self.rect.x += self.dx
                self.rect.y -= self.dy
                self.situation = "fired"
        else:
            self.kill()
Exemplo n.º 39
0
 def __init__(self, position, velocity):
     super().__init__(position, rotozoom(load_sprite("pizza"), 0, 0.5),
                      velocity)
Exemplo n.º 40
0
	def draw(self, destinationSurface, pixelsPerUnit):
		scale = pixelsPerUnit / self.pixelsPerUnit
		transformedSurface = rotozoom(self.surface, self.angle, scale)
		pixelX = destinationSurface.get_width()/2 + self.position[0]*pixelsPerUnit - transformedSurface.get_width()/2
		pixelY = destinationSurface.get_height()/2 + self.position[1]*pixelsPerUnit - transformedSurface.get_height()/2
		destinationSurface.blit(transformedSurface, (pixelX, pixelY))
Exemplo n.º 41
0
 def render(self):
     image = rotozoom(self.original, self._rotation, self._zoom)
     w2, h2 = image.get_size()
     image = smoothscale(image, (w2, int(h2 * self._perspective)))
     return image
Exemplo n.º 42
0
 def draw(self, surface):
     angle = self.direction.angle_to(UP)
     rotated_surface = rotozoom(self.sprite, angle, 1.0)
     rotated_surface_size = Vector2(rotated_surface.get_size())
     blit_position = self.position - rotated_surface_size * 0.5
     surface.blit(rotated_surface, blit_position)
Exemplo n.º 43
0
 def rotate(self, angle_deg):
     # self.img_rotated = rotate(self.img, angle_deg)
     self.img_rotated = rotozoom(self.img, angle_deg,
                                 1)  # filtered scale and rotation
Exemplo n.º 44
0
 def __init__(self, position, create_bullet_callback):
     self.create_bullet_callback = create_bullet_callback
     self.laser_sound = load_sound("laser")
     self.direction = Vector2(UP)
     sprite = rotozoom(load_sprite("puppy"), 0, .3)
     super().__init__(position, sprite, Vector2(0))
Exemplo n.º 45
0
 def render(self):
     image = rotozoom(self.original, self._rotation, self._zoom)
     w2, h2 = image.get_size()
     image = smoothscale(image, (w2, int(h2*self._perspective)))
     return image
Exemplo n.º 46
0
    def draw(self, surface, rect):
        onScreen = []

        if self.blank:
            self.blank = False
            self.maprender.blank = True

        visible_shapes = self.area.space.bb_query(toBB(self.extent))

        for child in [ child for child in self.area if child.avatar]:
            shape = child.shapes[0]
            if shape not in visible_shapes:
                continue

            bb = child.bb
            x = bb.left - self.extent.left - child.avatar.axis.x
            y = bb.top - self.extent.top

            if hasattr(shape, "radius"):
                w, h = child.avatar.image.get_size()
                angle = -(math.degrees(shape.body.angle)) % 360
                image = rotozoom(child.avatar.image.convert_alpha(), angle, 1.0)
                ww, hh = image.get_size()
                rrect = Rect(x, y-h, ww, hh)
                rrect.move_ip((w-ww)/2, (h-hh)/2)
            else:
                w, h = child.avatar.image.get_size()
                rrect = Rect(x, y - h, w, h)
                image = child.avatar.image
            onScreen.append((image, rrect, 1))

        if parallax:
            self.parallaxrender.draw(surface, rect, [])

        dirty = self.maprender.draw(surface, rect, onScreen)

        if DEBUG:
            def translate((x, y)):
                return x - self.extent.left, y - self.extent.top

            for shape in self.area.space.shapes:
                try:
                    points = [ translate(i) for i in shape.get_points() ]
                except AttributeError:
                    pass
                else:
                    draw.aalines(surface, (255,100,100), 1, points)
                    continue

                try:
                    radius = shape.radius
                    pos = shape.body.position
                    pos = translate(pos)
                    pos += shape.offset
                except AttributeError:
                    pass
                else:
                    pos = map(int, pos)
                    draw.circle(surface, (255,100,100), pos, int(radius), 1)
                    continue

        return dirty