Ejemplo n.º 1
0
 def __init__(self, screen):
     sprite.Sprite.__init__(self)
     self.image = surface.Surface(screen)
     self.image.fill((255, 255, 255))
     self.rect = self.image.get_rect()
     self.playButton = surface.Surface(
         [int(screen[1] * 0.5), int(screen[1] * 0.5)])
     self.playButton.fill(Color("white"))
     rect = self.playButton.get_rect()
     rect.center = self.rect.center
     draw.circle(self.playButton, Color("yellow"), [
         int(self.playButton.get_width() / 2),
         int(self.playButton.get_width() / 2)
     ], int(self.playButton.get_width() / 2))
     rect = self.playButton.get_size()
     rect = Rect([(int(rect[0] * 0.25), int(rect[1] * 0.35)),
                  (int(rect[0] * 0.5), int(rect[1] * 0.3))])
     # rect = (self.rect.centerx, int(screen[1]*0.5*0.25), self.rect.centery, int(screen[1]*0.5*0.15))
     # rect = Rect(rect[0]-rect[1], rect[2]-rect[3], rect[1]*2, rect[3]*2)
     draw.polygon(self.playButton, Color("orange"), [
         rect.topleft, (rect.x + 0.25 * rect.w, rect.centery),
         rect.bottomleft, rect.midright
     ])
     self.image.blit(
         self.playButton,
         tuple(
             map(lambda val: int(val - self.playButton.get_width() / 2),
                 self.rect.center)))
     del rect
     self.complete = True
     self.actualizar = False
     self.code = 1
Ejemplo n.º 2
0
    def test_from_threshold(self):
        """ Does mask.from_threshold() work correctly?
        """

        a = [16, 24, 32]

        for i in a:
            surf = surface.Surface((70, 70), 0, i)
            surf.fill((100, 50, 200), (20, 20, 20, 20))
            my_mask = mask.from_threshold(surf, (100, 50, 200, 255),
                                          (10, 10, 10, 255))

            self.assertEqual(my_mask.count(), 400)
            self.assertEqual(my_mask.get_bounding_rects(),
                             [Rect((20, 20, 20, 20))])

        for i in a:
            surf = surface.Surface((70, 70), 0, i)
            surf2 = surface.Surface((70, 70), 0, i)
            surf.fill((100, 100, 100))
            surf2.fill((150, 150, 150))
            surf2.fill((100, 100, 100), (40, 40, 10, 10))
            my_mask = mask.from_threshold(surf, (0, 0, 0, 0),
                                          (10, 10, 10, 255), surf2)

            self.assertEqual(my_mask.count(), 100)
            self.assertEqual(my_mask.get_bounding_rects(),
                             [Rect((40, 40, 10, 10))])
Ejemplo n.º 3
0
    def __init__(self, size):

        self.position = Position(size.x - 288, size.y - 64)

        self.energy_limit = 3
        self.energy = 3
        self.can_shoot = True
        self.cool_down = 0

        self.bar_surface = pygame.image.load('energybar.png')
        self.bar_red = surface.Surface((256, 32))
        self.bar_red.fill((255, 0, 0))

        self.surface = surface.Surface((256, 32))
Ejemplo n.º 4
0
def create_surface(depth):
    """Create a suitable 800x600 pygame surface for the test cases."""
    if depth == 32:
        surf = surface.Surface((800, 600), depth=32, flags=SRCALPHA)
        surf.fill((0, 0, 0, 0xff))
    elif depth in (16, 24):
        surf = surface.Surface((800, 600), depth=depth)
        surf.fill((0, 0, 0, 0xff))
    elif depth == 8:
        surf = surface.Surface((800, 600), depth=8)
        surf.fill(0)
    else:
        raise RuntimeError('Unsupported bit depth for tests: %d' % depth)
    return surf
Ejemplo n.º 5
0
    def __init__(self):
        self.gameSurf = display.get_surface().copy()
        self.drawWindow = display.get_surface()

        backgroundColor = (31, 97, 141, 150)
        title = SysFont('lucidaconsole', 35)
        subtitle = SysFont('lucidaconsole', 25)

        #distance between title and subtitle text
        textMargin = 10
        #distance between edge of text and full opacity background
        textBackgroundMargin = 10

        self.titleSurf = title.render("Cheat mode", True, Color('black'))
        self.subtitleSurf = subtitle.render("Click to exit", True,
                                            Color('black'))

        self.textBackgroundSurf = surface.Surface(
            (self.subtitleSurf.get_width() + 2 * textBackgroundMargin + 75,
             self.titleSurf.get_height() + self.subtitleSurf.get_height() +
             textMargin + 2 * textBackgroundMargin + 25), constants.SRCALPHA)

        self.textBackgroundSurf.fill(backgroundColor)

        self.titlePos = (self.drawWindow.get_width() / 2 -
                         self.titleSurf.get_width() / 2,
                         self.drawWindow.get_height() / 2 -
                         self.titleSurf.get_height() - textMargin / 2)
        self.subtitlePos = (self.drawWindow.get_width() / 2 -
                            self.subtitleSurf.get_width() / 2,
                            self.drawWindow.get_height() / 2 + textMargin / 2)
        self.textBackgroundPos = (self.drawWindow.get_width() / 2 -
                                  self.textBackgroundSurf.get_width() / 2,
                                  self.drawWindow.get_height() / 2 -
                                  self.textBackgroundSurf.get_height() / 2)
Ejemplo n.º 6
0
    def test_from_surface(self):
        """  Does the mask.from_surface() work correctly?
        """

        mask_from_surface = mask.from_surface

        surf = surface.Surface((70, 70), SRCALPHA, 32)

        surf.fill((255, 255, 255, 255))

        amask = mask.from_surface(surf)
        #amask = mask_from_surface(surf)

        self.assertEqual(amask.get_at((0, 0)), 1)
        self.assertEqual(amask.get_at((66, 1)), 1)
        self.assertEqual(amask.get_at((69, 1)), 1)

        surf.set_at((0, 0), (255, 255, 255, 127))
        surf.set_at((1, 0), (255, 255, 255, 128))
        surf.set_at((2, 0), (255, 255, 255, 0))
        surf.set_at((3, 0), (255, 255, 255, 255))

        amask = mask_from_surface(surf)
        self.assertEqual(amask.get_at((0, 0)), 0)
        self.assertEqual(amask.get_at((1, 0)), 1)
        self.assertEqual(amask.get_at((2, 0)), 0)
        self.assertEqual(amask.get_at((3, 0)), 1)

        surf.fill((255, 255, 255, 0))
        amask = mask_from_surface(surf)
        self.assertEqual(amask.get_at((0, 0)), 0)
Ejemplo n.º 7
0
 def __init__(self,x:int,y:int):
     self.gridLoc = self.x, self.y = x, y
     
     self.uId = getIndex((x,y))
     self.coords = x*sHEIGHT,y*sWIDTH
     self.surf = surface.Surface(SQUARE_SIZE)
     self.rect = Rect(self.coords,SQUARE_SIZE)
Ejemplo n.º 8
0
	def __init__(self, base, **kargs):
		sprite.Sprite.__init__(self)
		kargs.setdefault("tipo", 1)
		self.tipo = kargs["tipo"] # 1: habitable, -1: no habitable
		if isinstance(base, surface.Surface):
			self.image = base
		else:
			if isinstance(base, (tuple, list)):
				self.image = surface.Surface(base)
			elif isinstance(base, int):
				self.image = surface.Surface((base, base))
			self.image.fill(Color(kargs["color"]))
		self.rect = self.image.get_rect()
		if "pos" in kargs:
			self.rect.move_ip(self.image.get_width()*kargs["pos"][0], self.image.get_height()*kargs["pos"][1])
		self.actualizar = False
Ejemplo n.º 9
0
 def __init__(self, screen):
     sprite.Sprite.__init__(self)
     self.image = surface.Surface(screen)
     self.image.fill((255, 255, 255))
     self.rect = self.image.get_rect()
     self.complete = True
     self.actualizar = False
Ejemplo n.º 10
0
 def __init__(self, *groups):
     _layer = 3
     Base.__init__(self, groups)
     self.image = surface.Surface((600, 50))
     self.rect = self.image.get_rect(topleft=(0, 0))
     self.image.fill(WHITE)
     #desenhar quadrados
     start = 145
     for cores in color_dict.values():
         if cores != BLACK and cores != WHITE:
             draw.rect(self.image, cores, Rect((start, 0), (50, 50)))
             self.image.blit(
                 numeros.render(f'{int((start-95)/50)}', True, BLACK),
                 (start + 25, 0))
         elif cores == WHITE:
             self.image.blit(
                 numeros.render(f'{int((start-95)/50)}', True, BLACK),
                 (start + 25, 0))
         else:
             draw.rect(self.image, BLACK, Rect(start, 0, 50, 50))
             self.image.blit(
                 numeros.render(f'{int((start-95)/50)}', True, WHITE),
                 (start + 25, 0))
         draw.rect(self.image, BLACK, Rect(start, 0, 50, 50), 1)
         start += 50
     draw.line(self.image, RED, (550, 0), (600, 50), 5)
     draw.line(self.image, RED, (600, 0), (550, 50), 5)
     draw.rect(self.image, BLACK, Rect(550, 0, 50, 50), 1)
     self.image.blit(numeros.render(f'{0}', True, BLACK), (563, 0))
Ejemplo n.º 11
0
 def __init__(self, loading=False):
     self.is_active = False
     self.surface = surface.Surface((int(SCREEN_SIZE[0] * 2 / 3), int(SCREEN_SIZE[1] * 2 / 3)))
     self.surface.fill(BROWN)
     self.rect = pygame.rect.Rect(int(SCREEN_SIZE[0]/6), int(SCREEN_SIZE[1]/6), self.surface.get_width(), self.surface.get_height())
     font_text = font.Font(FONT, 36)
     title = font_text.render("Quest Board", False, WHITE)
     will_deplete_font = font.Font(FONT, 16)
     will_deplete = will_deplete_font.render("Will deplete area?", False, WHITE)
     self.quest_text = font.Font(FONT, 20)
     self.surface.blit(title, (int(self.surface.get_width()/2 - title.get_width()/2), 16))
     self.surface.blit(will_deplete, (int(self.surface.get_width() - will_deplete.get_width() - 8), 36))
     self.close_button = Button("Close", FONT, 24)
     self.close_button.update_location(location=(int(SCREEN_CENTER[0] - self.close_button.get_width() / 2), int(SCREEN_SIZE[1] / 6 * 5)))
     self.active_quests = []
     self.failed_quests = []
     self.completed_quests = []
     self.completed_quests_text = self.quest_text.render("Completed Quests: " + str(len(self.completed_quests)), False, WHITE)
     self.completed_quests_rect = (self.rect.left + self.completed_quests_text.get_width()/4, self.rect.bottom - 36)
     self.failed_quests_text = self.quest_text.render("Failed Quests: " + str(len(self.failed_quests)), False, WHITE)
     self.failed_quests_rect = (self.rect.left + int(self.rect.width/2 + title.get_width()/2 + self.failed_quests_text.get_width()/4), self.rect.bottom - 36)
     if not loading:
         while len(self.active_quests) < 5:
             self.generate_quest()
     self.active = False
Ejemplo n.º 12
0
    def __init__(self, rangoCelda, maxSize, estructura=dict()):
        sprite.Sprite.__init__(self)
        self.rangeSize = (rangoCelda[0], rangoCelda[1])
        self.sizeCelda = self.rangeSize[0]
        self.dimension = (int(maxSize[0] / self.sizeCelda),
                          int(maxSize[1] / self.sizeCelda))
        color = estructura["color"] if "color" in estructura else dict()
        bgcolor = color.pop("0") if len(color) and "0" in color else "gray"
        self.celdas = CeldasTablero(self.sizeCelda,
                                    self.dimension,
                                    colors=color,
                                    estructura=estructura["celdas"]
                                    if "celdas" in estructura else None)
        del color
        sizeSurf = tuple(map(lambda val: val * self.sizeCelda, self.dimension))
        self.image = surface.Surface(sizeSurf)
        self.image.fill(Color(bgcolor))
        del sizeSurf, bgcolor
        self.celdas.draw(self.image)
        self.rect = self.image.get_rect()
        self.rect.center = (int(maxSize[0] / 2), int(maxSize[1] / 2))

        # Draw Serpiente
        self.snake = Snake(
            self,
            0,
            pos=(5, 5),
            velocidad=estructura["vel"] if "vel" in estructura else None)
        self.snake.draw(self.image)
Ejemplo n.º 13
0
 def __init__(self, size):
     self.creatures = {}
     self.background = surface.Surface(size).convert()
     self.background.fill((0, 0, 0))
     self.creatures_to_add = []
     self.creatures_to_remove = []
     self.width = size[0]
     self.height = size[1]
Ejemplo n.º 14
0
 def __init__(self, type, x, y, x_offset, y_offset):
     self.state = 0
     self.type = type
     self.surface = surface.Surface((PLOT_SIZE, PLOT_SIZE))
     self.rect = self.surface.get_rect(topleft=(x, y))
     self.surface.fill((100, 100, 100))
     self.x_offset, self.y_offset = x_offset, y_offset
     self.revealed = False
Ejemplo n.º 15
0
 def __init__(self, *groups):
     _layer = 2
     Base.__init__(self, groups)
     self.image = surface.Surface((50, 50))
     self.image.fill(WHITE)
     draw.circle(self.image, BLACK, (25, 25), radius, 1)
     self.image.set_colorkey((255, 255, 255))
     self.rect = self.image.get_rect(center=mouse.get_pos())
Ejemplo n.º 16
0
 def __init__(self, screen):
     sprite.Sprite.__init__(self)
     self.code = 2
     self.start = time.get_ticks()
     self.image = surface.Surface(screen)
     self.image.fill(Color("white"))
     font.init()
     self.label = font.Font.render("Niveles", True, Color("yellow"))
Ejemplo n.º 17
0
def _make_object():
    """Create a vaguely interesting object to transform."""
    obj = surface.Surface((40, 80), depth=32)
    draw.line(obj, (255, 0, 0, 255), (10, 10), (10, 40), 3)
    draw.line(obj, (255, 255, 0, 255), (10, 10), (40, 10), 3)
    draw.line(obj, (255, 128, 128, 255), (40, 10), (40, 40), 2)
    draw.lines(obj, (255, 255, 255, 255), 1, [(20, 20), (20, 30), (30, 30)])
    return obj
Ejemplo n.º 18
0
def surface_setup(image, image_size, image_offset=(0, 0), color_key=None, scaling=None):
    return_surface = surface.Surface(image_size)
    return_surface.blit(image, (0, 0), rect.Rect(image_offset, image_size))
    if scaling is not None:
        return_surface = transform.scale(return_surface, (int(image_size[0] * scaling), int(image_size[1] * scaling)))
    if color_key is not None:
        return_surface.set_colorkey(color_key)
    return_surface = return_surface.convert()
    return return_surface
Ejemplo n.º 19
0
 def __init__(self, screen, escena="0"):
     sprite.Sprite.__init__(self)
     self.code = "4"
     self.subcode = escena
     self.image = surface.Surface(screen)
     self.escena = Escena(screen, escena)
     self.escena.draw(self.image)
     self.rect = self.image.get_rect()
     self.complete = True
     self.actualizar = False
Ejemplo n.º 20
0
 def graphicInit(self, text, font):
     self.__format = self.ALPHA_NUMERIC_FORM
     self.__backgroundColor = (255, 255, 255)
     self.__opaque = True
     self.__imagen = surface.Surface(self.getDimensions(), flags = pygame.SRCALPHA)
     self.__font = pygame.font.SysFont("arial", 20) if font == None else font
     self.__text = text
     self.__fontColor = (0, 0, 0)
     
     self.reDraw()
Ejemplo n.º 21
0
    def _fullscreen(self):
        if self.fullscreen:
            self.f_screen = pygame.display.set_mode(self.fullscreen_size,
                                                    pygame.locals.FULLSCREEN)
            fator = self.f_screen.get_height() / 480.0

            self.f_size = (int(640 * fator), int(480 * fator))
            self.scaled = surface.Surface(self.f_size, 32)
            self.px = 840 - self.f_size[0] / 2
        else:
            self.f_screen = pygame.display.set_mode(self.screen_size)
Ejemplo n.º 22
0
    def __init__(self, game_manager, screen_width, screen_height):
        ui_manager, process_ui_event = create_settings_menu(
            game_manager, screen_width, screen_height)
        super().__init__("settings", ui_manager)
        self.screen_width = screen_width
        self.screen_height = screen_height

        self.background = surface.Surface(
            (screen_width, screen_height)).convert_alpha()
        self.background.fill((7, 99, 36))
        self.process_ui_event = process_ui_event
Ejemplo n.º 23
0
	def __init__(self, rangoCelda, maxSize, estructura = None):
		sprite.Sprite.__init__(self)
		self.rangeSize = (rangoCelda[0], rangoCelda[1])
		self.sizeCelda = self.rangeSize[0]
		self.dimension = (int(maxSize[0]/self.sizeCelda), int(maxSize[1]/self.sizeCelda))
		self.celdas = CeldasTablero(self.sizeCelda, self.dimension)
		sizeSurf = tuple(map(lambda val: val*self.sizeCelda, self.dimension))
		self.image = surface.Surface(sizeSurf)
		del sizeSurf
		self.celdas.draw(self.image)
		self.rect = self.image.get_rect()
Ejemplo n.º 24
0
	def __init__(self, size, bgcolor):
		sprite.Sprite.__init__(self)
		self.image = surface.Surface(size)
		self.image.fill(Color(bgcolor))
		self.rect = self.image.get_rect()
		self.tableroCnt = TableroCnt()
		tablero = Tablero([42, 48], size)
		tablero.rect.center = self.rect.center
		self.tableroCnt.add(tablero)
		self.tableroCnt.draw(self.image)
		self.actualizar = False
Ejemplo n.º 25
0
    def set_up_player(self):
        self.collide_image = surface.Surface(
            (self.rect.width, self.rect.width))
        self.collide_image.set_colorkey(self.collide_image.get_at((0, 0)))
        draw.rect(self.collide_image, WHITE, self.collide_image.get_rect(), 4,
                  4)

        self.collision_image = surface.Surface(
            (self.rect.width, self.rect.width))
        self.collision_image.set_colorkey(self.collision_image.get_at((0, 0)))
        draw.circle(self.collision_image, BLACK,
                    (self.collision_image.get_width() / 2,
                     self.collision_image.get_height() / 2), 16)
        self.mask = mask.from_surface(self.collision_image)

        self.collide_rect = rect.Rect(self.rect.left,
                                      self.rect.top + self.rect.width,
                                      self.rect.width, self.rect.width)
        self.facing_direction = (0, 1)
        self.interact_rect = self.collide_rect.move(0,
                                                    self.collide_rect.height)
Ejemplo n.º 26
0
 def __init__(self, screen, animation, start=time.get_ticks()):
     sprite.Sprite.__init__(self)
     self.complete = False
     self.start = start
     self.animation = animation
     self.color = Color("yellow")
     self.image = surface.Surface(
         (int(screen[1] * 0.4), int(screen[1] * 0.4)))
     self.rect = self.image.get_rect()
     self.rect.center = (int(screen[0] * 0.5), int(screen[1] * 0.5))
     self.actualizar = False
     self.code = 0
Ejemplo n.º 27
0
    def on_match_start(self):
        """Called upon the start of a match, which comprises a series of rounds"""
        background = surface.Surface(self.screen.get_size())
        self.background = background.convert_alpha()
        self.background.fill((7, 99, 36))

        self.match_pov = None
        self.on_match_init()
        self.on_pov_init()

        random.shuffle(self.sound_manager.music_playlist)
        self.sound_manager.start_playlist()
    def __init__(self, gameWon):
        self.gameSurf = display.get_surface().copy()
        self.drawWindow = display.get_surface()
        self.transparentSurf = surface.Surface(
            display.get_surface().get_size(), constants.SRCALPHA)

        color = (0, 255, 0, 127) if gameWon else (255, 0, 0, 127)
        text = "You Won!" if gameWon else "You Lost..."
        backgroundColor = (0, 255, 0) if gameWon else (255, 0, 0)
        title = SysFont('lucidaconsole', 25)
        subtitle = SysFont('lucidaconsole', 15)

        #distance between title and subtitle text
        textMargin = 10
        #distance between edge of text and full opacity background
        textBackgroundMargin = 10

        self.transparentSurf.fill(color)
        self.titleSurf = title.render(text, True, Color('black'))
        self.subtitleSurf = subtitle.render("Click to play again", True,
                                            Color('black'))

        self.textBackgroundSurf = surface.Surface(
            (self.subtitleSurf.get_width() + 2 * textBackgroundMargin,
             self.titleSurf.get_height() + self.subtitleSurf.get_height() +
             textMargin + 2 * textBackgroundMargin))

        self.textBackgroundSurf.fill(backgroundColor)

        self.titlePos = (self.drawWindow.get_width() / 2 -
                         self.titleSurf.get_width() / 2,
                         self.drawWindow.get_height() / 2 -
                         self.titleSurf.get_height() - textMargin / 2)
        self.subtitlePos = (self.drawWindow.get_width() / 2 -
                            self.subtitleSurf.get_width() / 2,
                            self.drawWindow.get_height() / 2 + textMargin / 2)
        self.textBackgroundPos = (self.drawWindow.get_width() / 2 -
                                  self.textBackgroundSurf.get_width() / 2,
                                  self.drawWindow.get_height() / 2 -
                                  self.textBackgroundSurf.get_height() / 2)
Ejemplo n.º 29
0
    def render(self,
               text,
               antialias=True,
               color=(255, 255, 255),
               background=None):
        """Render the font onto a new Surface and return it.
        We ignore 'antialias' and use system settings.
        
        text -- (unicode) string with the text to render
        antialias -- attempt to antialias the text or not
        color -- three or four-tuple of 0-255 values specifying rendering 
            colour for the text 
        background -- three or four-tuple of 0-255 values specifying rendering 
            colour for the background, or None for trasparent background
        
        returns a pygame image instance
        """
        #log.debug( 'render: %r, antialias = %s, color=%s, background=%s', text, antialias, color, background )
        if not text:
            return surface.Surface((0, 0))
        layout = self._createLayout(text)
        # determine pixel size
        (logical, ink) = layout.get_pixel_extents()
        ink = pygame.rect.Rect(ink)

        # Create a new Cairo ImageSurface
        csrf, cctx = _cairoimage.newContext(ink.w, ink.h)
        cctx = pangocairo.CairoContext(cctx)

        # Mangle the colors on little-endian machines. The reason for this
        # is that Cairo writes native-endian 32-bit ARGB values whereas
        # Pygame expects endian-independent values in whatever format. So we
        # tell our users not to expect transparency here (avoiding the A issue)
        # and we swizzle all the colors around.

        # render onto it
        if background is not None:
            background = _cairoimage.mangle_color(background)
            cctx.set_source_rgba(*background)
            cctx.paint()

        #log.debug( 'incoming color: %s', color )
        color = _cairoimage.mangle_color(color)
        #log.debug( '  translated color: %s', color )

        cctx.new_path()
        cctx.layout_path(layout)
        cctx.set_source_rgba(*color)
        cctx.fill()

        # Create and return a new Pygame Image derived from the Cairo Surface
        return _cairoimage.asImage(csrf)
Ejemplo n.º 30
0
    def __init__(self, e_inicial="", fullscr=True):
        self.estados = {}
        self.estado_inicial = e_inicial

        pygame.init()
        pygame.mixer.init()
        self.screen_size = (640, 480)
        self.fullscreen_size = (1366, 768)
        pygame.mouse.set_visible(False)
        self.screen = surface.Surface(self.screen_size, 32)
        #        modes = pygame.display.list_modes(32)
        self.fullscreen = fullscr
        self._fullscreen()