コード例 #1
1
ファイル: _shadow.py プロジェクト: YannThorimbert/ThorPy-1.0
 def _get_raw_shadow(self):
     target_img = self.target.get_image(self.capture_state)
     r = target_img.get_rect()
     #the shadow will be larger in order to make free space for fadeout.
     r.inflate_ip(2*self.shadow_radius, 2*self.shadow_radius)
     img = Surface(r.size)
     img.fill((255, 255, 255, 255))
     img.blit(target_img, (self.shadow_radius, self.shadow_radius))
     if self.sun_angle <= 0.:
         raise Exception("Sun angle must be greater than zero.")
     elif self.sun_angle != 45. and self.vertical:
         w, h = img.get_size()
         new_h = h / tan(self.sun_angle * pi / 180.)
         screen_size = functions.get_screen().get_size()
         new_h = abs(int(min(new_h, max(screen_size))))
         img = scale(img, (w, new_h))
     if self.angle_mode == "flip":
         img = flip(img, self.mode_value[0], self.mode_value[1])
     elif self.angle_mode == "rotate":
         img = rotate(img, self.mode_value)
     else:
         raise Exception("angle_mode not available: " + str(self.angle_mode))
     shadow = pilgraphics.get_shadow(img,
                                     radius=self.shadow_radius,
                                     black=self.black,
                                     alpha_factor=self.alpha_factor,
                                     decay_mode=self.decay_mode,
                                     color=self.color)
     return shadow
コード例 #2
0
def main():
    import pygame
    from pygame import surfarray,transform
    screen_size = (DIM[0]*4,DIM[1]*4)
    screen = pygame.display.set_mode(screen_size)
    pygame.display.init()
    pygame.init()
    board = create_board(*DIM)
    board = initialize_board(
        board,
        [[5,5],[5,6]],
    )
    rate = .25
    next = time.time() -1
    small = pygame.Surface( DIM )
    blitter = pygame.Surface( screen_size )
    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                raise SystemExit(0)
        if time.time() > next:
            next = time.time() + rate 
            board = cycle(board)
            surfarray.blit_array(small,board)
            transform.scale( small, screen_size, blitter )
        screen.blit( blitter, (0,0) )
        #surfarray.blit_array(screen,board)
        pygame.display.flip()
コード例 #3
0
ファイル: verbose.py プロジェクト: paulmadore/luckyde
def preview_img(screen, img):
    # generate an image preview
    square_width = 200
    square_height = 175
    (img_width, img_height) = img.get_size()
    small_img = img
    # display a preview image in dimensions that won't distort it:
    if img_width > img_height:
        if (not img_width < square_width and not img_height < square_height) or (img_width > square_width) or (img_height > square_height) or (img_width > square_width and img_height > square_height):
            r = float(img_width) / float(img_height)
            new_width = square_width
            new_height = int(new_width / r)
            scale_val = new_width, new_height
            small_img = scale(img, scale_val)
    if img_width < img_height:
        if (not img_width < square_width and not img_height < square_height) or (img_width > square_width) or (img_height > square_height) or (img_width > square_width and img_height > square_height):
            r = float(img_height) / float(img_width)
            new_height = square_height
            new_width = int(new_height / r)
            scale_val = new_width, new_height
            small_img = scale(img, scale_val)
    if img_width == img_height: 
        if (not img_width < square_width and not img_height < square_height) or (img_width > square_width) or (img_height > square_height) or (img_width > square_width and img_height > square_height):
            r = float(img_width) / float(img_height)
            new_height = square_height
            new_width = square_width
            scale_val = new_width, new_height
            small_img = scale(img, scale_val)
    (img_width, img_height) = small_img.get_size()
    return (small_img, img_width, img_height)
コード例 #4
0
    def get_player_sprites(self, sprite_sheet):
        """Creates a dict containing all player sprites with grouped by facing. Not generally applicable."""

        # Order of sprites' facings in sprite sheet
        sprite_sheet_direction = [Direction.DOWN, Direction.LEFT, Direction.RIGHT, Direction.UP]

        sprites = {}
        for i in range(0, 12, 3):
            direction_sprites = []
            scaled_sprite_size = (self.sprite_width * self.scale_factor, self.sprite_height * self.scale_factor)

            # Get all sprites with certain alignment
            sprite_move_1 = Rect(self.get_sprite_location(i), (self.sprite_width, self.sprite_height))
            sprite_stationary = Rect(self.get_sprite_location(i + 1), (self.sprite_width, self.sprite_height))
            sprite_move_2 = Rect(self.get_sprite_location(i + 2), (self.sprite_width, self.sprite_height))

            current_direction = sprite_sheet_direction[i // 3]

            # Current sprite sheet has duplicate sprites for left and right facing, thus reordering to allow animation
            if current_direction == Direction.RIGHT or current_direction == Direction.LEFT:
                direction_sprites = [scale(sprite_sheet.subsurface(rect), scaled_sprite_size) for rect in
                                     [sprite_move_1, sprite_stationary, sprite_move_2]]
            else:
                direction_sprites = [scale(sprite_sheet.subsurface(rect), scaled_sprite_size) for rect in
                                     [sprite_move_1, sprite_move_2, sprite_stationary]]

            # Add sprites to sprite dict with alignment as key
            sprites[sprite_sheet_direction[i // 3]] = direction_sprites

        return sprites
コード例 #5
0
    def get_surface(self):
        W, H = functions.get_screen_size()
        if isinstance(self.img_path, str):  # load image
            surface = load_image(self.img_path)
        else:  # take image
            surface = self.img_path
        if 0 < self.alpha < 255:
            surface.set_alpha(self.alpha, RLEACCEL)
        if self.mode == "scale to screen":
            surface = scale(surface, (W, H))
            self.size = (W, H)
        elif self.mode == "cut to screen":
            new_surface = Surface((W, H))
            new_surface.blit(surface, (0, 0))
            self.size = (W, H)
        elif self._resized:
            surface = scale(surface, self._resized)
        elif self.mode:
            functions.debug_msg("Unrecognized mode : ", self.mode)
##        elif self._resized:
##            surface = scale(surface, self._resized)
        if self.colorkey:
            surface.set_colorkey(self.colorkey, RLEACCEL)
        surface.set_clip(self.clip)
        if self.alpha < 255:
            return surface.convert_alpha()
        else:
            return surface.convert()
コード例 #6
0
ファイル: overworld.py プロジェクト: MacLeek/mh
    def activate(self):
        GameState.activate(self)

        w, h = sd.get_size()

        self.cr_open = scale(res.loadImage("open.png", 0, 1), (20,30))
        self.cr_grasp = scale(res.loadImage("grasp.png", 0, 1), (20, 25))
        self.cr_arrow = res.loadImage("next_arrow.png", 0, 1)

        self.cr = KeyCursor(self.cr_open)
        self.cr_state = HAND_OPEN

        self.cr_bounds = Rect(0,0,w,h).inflate(-w*.2, -h*.2)
        self.cr_bounds.height -= 30
        self.cr_bounds.width -= 20
        self.cr_pos = list(self.cr_bounds.center)
        self.cr_speed = 0
        self.cr.enable()

        self.map_pos = self.cr_pos[:]

        path = res.mapPath("overworld3.tmx")

        self.tilemap = BufferedTilemapRenderer(path,
                       (w,h), force_colorkey=(128,0,63))

        self.camera = OverworldCamera([], self.tilemap, ((0,0), (w,h)))
        self.camera.center(self.cr_pos)
        self.tilemap.redraw()


        self.cleared = 0
コード例 #7
0
ファイル: load_img.py プロジェクト: paulmadore/luckyde
def fit_image(img, screen):
    "resize the image to fit the imgv window"
    rect = screen.get_rect()
    gl.SCALE_UP = 0
    if gl.REAL_WIDTH > gl.REAL_HEIGHT:
        r = float(gl.REAL_WIDTH) / float(gl.REAL_HEIGHT)
        new_width = screen.get_width()
        new_height = int(new_width / r)
        scale_val = new_width, new_height
        img = scale(img, scale_val)
        gl.SHRUNK = 1
    elif gl.REAL_WIDTH < gl.REAL_HEIGHT:
        r = float(gl.REAL_HEIGHT) / float(gl.REAL_WIDTH)
        new_height = screen.get_height()
        new_width = int(new_height / r)
        scale_val = new_width, new_height
        img = scale(img, scale_val)
        gl.SHRUNK = 1
    elif gl.REAL_WIDTH == gl.REAL_HEIGHT:
        r = float(gl.REAL_WIDTH) / float(gl.REAL_HEIGHT)
        new_height = screen.get_height()
        new_width = screen.get_width()
        if new_height > new_width:
            scale_val = int(new_width / r), int(new_width / r)
        elif new_width > new_height:
            scale_val = int(new_height / r), int(new_height / r)
        else:
            scale_val = new_width, new_height
        img = scale(img, scale_val)
    else:
        new_height = new_width = screen.get_width()
        scale_val = new_width, new_height
        img = scale(img, scale_val)
    return img
コード例 #8
0
ファイル: mindmixer.py プロジェクト: sfavors3/MindMixer
 def __init__(self,imagefile,soundfile,trgtimg,trgtsnd):
     self.image = scale(image.load(imagefile), SIZE).convert()
     self.fill = scale(image.load(BASE),SIZE).convert()
     self.sound = mixer.Sound(soundfile)
     self.trgtimg = trgtimg
     self.trgtsnd = trgtsnd
     self.result = [not(self.trgtimg),not(self.trgtsnd)]
コード例 #9
0
ファイル: HopFrog.py プロジェクト: Antunello/HopFrog
 def drawMapView(self, surface, increment = 1):
     """Drawing the Map with Player and Beetles"""
     beetle_color_vect=["beetle_right.png","beetle_left.png","beetle_up.png","beetle_down.png"]
     life_imm=["./start_end/life_empty.png","./start_end/life_last.png","./start_end/life_mid.png","./start_end/life_full.png"]
     surface.blit(self.mp.getMapView(self.viewRect), ORIGIN)
     
     for i in range(number_beetles):
         imagePath_2=os.path.join("sprites", beetle_color_vect[beetle[i].color])
         img_2=pg.image.load(imagePath_2)
         image_2=scale(img_2, beetle[i].size)
         image_2.convert()
         surface.blit(image_2,beetle[i].position)
 
     imagePath = os.path.join("sprites", player.color)
     img = pg.image.load(imagePath)
     image=scale(img, player.size)
     image.convert()
             #surface.blit(image,player.position)
         #if(self.index_life>0):
     surface.blit(image,player.position)
         #else:
             #print 'todo: add image of damage'
         
     image_life = pg.image.load(life_imm[player.life])
     image_life.convert()
     surface.blit(image_life, ORIGIN)
コード例 #10
0
def update_display():
    if DOUBLE_SIZE:
        #group.clear(screen_buffer, background)
        #dirty = group.draw(screen_buffer)
        scale(screen_buffer, (644, 406), screen)
        #pygame.transform.scale2x(screen_buffer, screen)

    pygame.display.update()
コード例 #11
0
 def __init__(self, width, client, **kwds):
     font = self.predict_font(kwds)
     h = font.get_linesize()
     d = 2 * self.predict(kwds, "margin")
     kwds["align"] = kwds.get("align", "l")
     ScrollPanel.__init__(self, inner_width=width, **kwds)
     self.icons = {
         True: scale(folder_image, (self.row_height, self.row_height)),
         False: scale(file_image, (self.row_height, self.row_height)),
     }
     self.client = client
     self.names = []
コード例 #12
0
ファイル: gfx.py プロジェクト: mikezucc/opencv-tests
def update_display():
    if DOUBLE_SIZE:
        #group.clear(screen_buffer, background)
        #dirty = group.draw(screen_buffer)
        scale(screen_buffer, (644, 406), screen)
        #pygame.transform.scale2x(screen_buffer, screen)
    currSurf = pygame.display.get_surface()
    currSurf = pygame.Surface((644, 406), pygame.SRCALPHA, 32)
    #mask.fill
    #mask.set_alpha(255)
    #currSurf.blit(mask,(0,0),special_flags=(pygame.BLEND_RGBA_SUB))
    #self.world.view.set_background(pygame.Surface((644, 406), pygame.SRCALPHA, 32))
    pygame.display.update()
コード例 #13
0
 def resize(self):
     if self.marker <= 1:
         charRow = self.charactor.sector.idNum / NUM_COLS
         baseW, baseH = self.image.get_rect().width*3/4, self.image.get_rect().height*3/4
         self.image = trans.scale(self.image,(baseW + (baseW/3) * charRow, baseH + (baseH/3) * charRow))
     elif self.marker == 2: #red closer, first player closer
         charCol = self.charactor.sector.idNum % NUM_COLS
         baseW, baseH = self.image.get_rect().width*3/4, self.image.get_rect().height*3/4
         self.image = trans.scale(self.image,(baseW + (baseW/3) * (NUM_COLS - charCol), baseH + (baseH/3) * (NUM_COLS - charCol)))
     elif self.marker == 3: #blue closer, 
         charCol = self.charactor.sector.idNum % NUM_COLS
         baseW, baseH = self.image.get_rect().width*3/4, self.image.get_rect().height*3/4
         self.image = trans.scale(self.image,(baseW + (baseW/3) * charCol, baseH + (baseH/3) * charCol))
コード例 #14
0
def test_scale(surface):
   """Simple scale tests"""
   obj = _make_object()

   surface.blit(obj, (20, 20))
   obj1 = transform.scale(obj, (100, 100))
   surface.blit(obj1, (80, 80))
   obj2 = transform.scale(obj1, (60, 60))
   surface.blit(obj2, (160, 160))
   obj3 = transform.scale(obj, (60, 60))
   surface.blit(obj3, (240, 160))
   obj1 = transform.scale2x(obj)
   surface.blit(obj1, (240, 240))
   obj1 = transform.scale2x(obj2)
   surface.blit(obj1, (320, 320))
コード例 #15
0
ファイル: zoom.py プロジェクト: paulmadore/luckyde
def command_zoom_out(new_img, new_img_width, new_img_height, img, screen, file, num_imgs, rect, zoom_type):
    wait_cursor()
    start = start_timer()
    if new_img.get_width() >= gl.MIN_WIDTH and new_img.get_height() >= gl.MIN_HEIGHT:
        gl.ZOOM_EXP -= 1
        if zoom_type == "normal":
            gl.ZOOM_DOUBLE = 0
            new_img = scale(img, (new_img.get_width() / 1.1, new_img.get_height() / 1.1))
        else:
            gl.ZOOM_DOUBLE = 1
            new_img = scale(img, (new_img.get_width() / 2, new_img.get_height() / 2))
        rect = get_center(screen, new_img)
        my_update_screen(new_img, screen, rect, file, num_imgs, check_timer(start))
    normal_cursor()
    return (new_img, img, rect)
コード例 #16
0
ファイル: buffalo.py プロジェクト: ZakFarmer/OregonTrail
	def __init__(self, posX, posY, picture, size, resourcePath):
		self.picture = picture
		self.size = size
		self.resourcePath = resourcePath
		self.maxHealth = 100 * self.size
		self.health = self.maxHealth
		self.preimage = image.load(self.resourcePath + "img/" + self.picture + "_buffalo.png")
		self.image = scale(self.preimage, (int(self.preimage.get_width() * self.size),
										   int(self.preimage.get_height() * self.size)))
		self.healthFont = font.Font(None, 20)
		self.healthBarContainer = Surface((int(75 * self.size), int(12 * self.size))).convert()
		self.healthBarShader = Surface((self.healthBarContainer.get_width() + 6,
										self.healthBarContainer.get_height() + 6)).convert()
		self.healthNumber = self.healthFont.render(str(self.health), 1, (0, 0, 0))
		self.healthBarShader.fill((175, 175, 175))
		self.healthBar = Surface(self.healthBarContainer.get_size()).convert()
		self.healthColour = ()
		if (self.health >= 50):
			self.healthColour = (float((self.maxHealth - self.health) * 2 / self.maxHealth * 255), 255, 0)
		else:
			self.healthColour = (255, float(self.health * 2 / self.maxHealth * 255), 0)
		try:
			self.healthBar.fill(self.healthColour)
		except TypeError:
			self.healthBar.fill((0, 0, 0))
		self.healthBarContainer.blit(self.healthBar, (0, 0))
		self.value = 20 * self.size
		self.rect = Rect((0, 0), self.image.get_size())
		self.rect.x = posX
		self.rect.y = posY
		self.status = "alive"
		self.targetY = posY
コード例 #17
0
ファイル: hazard.py プロジェクト: Jesse-calkin/GGJ2014
    def __init__(self, start_location):
        # Call the parent class (Sprite) constructor - like calling super
        pygame.sprite.Sprite.__init__(self)

        self.group.empty()
        self.group.add(self)

        sprite_sheet = SpriteSheet("resources/sprites/pac.png")
        frame = sprite_sheet.getImage(35, 25, 35, 18)
        self.frames.append(frame)

        # TODO: size these hazards based off sprites.
        height = 50
        width = 100

        start_y = 0
        start_x = 0

        if start_location == "bottom":
            start_y = constants.SCREEN_HEIGHT - height
            start_x = constants.SCREEN_WIDTH

        elif start_location == "bottom_rotate":
            start_y = constants.SCREEN_HEIGHT - height
            start_x = constants.SCREEN_WIDTH - 75
            self.rotates = True

        start_y = 0 if start_location == "top" else constants.SCREEN_HEIGHT - height
        self.rect = pygame.Rect(start_x, start_y, width, height)
        self.root_image = scale(self.frames[0], [self.rect.w, self.rect.h])
        self.image = self.root_image
コード例 #18
0
 def __init__(self, y, gravity):
     img1 = image.load('bird.png').convert_alpha()
     self.img= transform.scale(img1,(60,60))
     self.speedY = 0
     self.rect = self.img.get_rect().move(200, y)# getting the new position after moving 
     self.oldY = y
     self.gravity = gravity
コード例 #19
0
ファイル: utils.py プロジェクト: xarts19/Dugong
    def get(self, res_name, size=None, rotate=0):
        res = None
        if res_name in self._loaded_resources:
            res = self._loaded_resources[res_name]
        else:
            if res_name == 'levels_info':
                res = load_levels_info()
            elif res_name == 'tile_types':
                LOGGER.debug("Loading tiles data")
                from configs.tiletypes import TILE_TYPES
                res = TILE_TYPES
            elif res_name == 'unit_types':
                LOGGER.debug("Loading units data")
                from configs.unittypes import UNIT_TYPES
                res = UNIT_TYPES
            else:
                identifiers = res_name.split(':')
                path = os.path.join(*identifiers)
                res = load_image(path)
            self._loaded_resources[res_name] = res

        if size:
            res = pytrans.scale(res, size)
        if rotate:
            res = pygame.transform.rotate(res, rotate)

        return res
コード例 #20
0
ファイル: main.py プロジェクト: Roolymoo/fantasygame
def _resolve_params(data, obj_col):
    """(dict, list) -> NoneType
    For each object in obj_col, resolve the non-type parameters on it, and render the object if applicable."""
    for obj in obj_col:
        if data["img"]:
            obj.img = load_img(data["img"])
        if data["flip"]:
            horiz, vert = None, None
            args = data["flip"].strip("()").split(",")
            if args[0] == "false":
                horiz = False
            else:
                horiz = True
            if args[1] == "false":
                vert = False
            else:
                vert = True

            obj.img = transform.flip(obj.img, horiz, vert)
        if data["rotate"]:
            obj.img = transform.rotate(obj.img, int(data["rotate"].split("=")[-1]))
        if data["scale"]:
            obj.img = transform.scale(obj.img, tuple(int(i) for i in data["scale"].strip("()").split(",")))

        obj.render(screen, update_queue)
コード例 #21
0
ファイル: display.py プロジェクト: grisevg/RayCastPy
    def drawRaycastedView(self,rays):
        default_texture = 1
        default_type = 0
        strip_no = 0
        strip_width = self.raycast.strip_width
        x = 0
        last_slice_meta = (None, None, None, None)
        last_slice = None
        for ray in rays:
            this_slice_meta = (default_texture, default_type, ray['texture_x'], ray['distance'])
            if (this_slice_meta != last_slice_meta):
                last_slice_meta = this_slice_meta
                strip_height = round(self.raycast.distance_to_plane / ray['distance'])
                y = round((self.size[1]-strip_height)/2)
                required_slice = round((self.texture_size/strip_width)*ray['texture_x']) - 1
                try:
                    last_slice = transform.scale(self.wall_textures[default_texture][default_type][required_slice], (strip_width, strip_height))
                except Exception as e:
                    pass
            try:
                self.screen.blit(last_slice,(x,y))
            except Exception as e:
                pass

            x += strip_width
            strip_no = strip_no + 1
コード例 #22
0
ファイル: PygameUI.py プロジェクト: traleig1/MTris
 def draw(o,image,pt):
   if image is None: return
   x,y = pt
   h,w = image.get_height(), image.get_width()
   screenCoords = (x,o.height-y-h)
   scaledImage = scale(image,o._scalePt(w,h))
   o._screen.blit(scaledImage,o._scalePt(*screenCoords))
コード例 #23
0
 def loadFrames(self, key, size=(TILE_SIZE, TILE_SIZE)):
    self.__frames[key] = []
       
    # load and scale image
    sheet = image.load(key)
    if SCALE != 1:
       sheet = transform.scale(sheet, [SCALE * x for x in sheet.get_size()])
    sheet = sheet.convert()
    
    # load all frames
    i = 0
    for x in range(0, sheet.get_size()[0], size[0]):
       self.__frames[key].append([])
       j = 0
       
       for y in range(0, sheet.get_size()[1], size[1]):
       
          self.__frames[key][i].append(Surface(size))
          frameArea = Rect((x, y), size)
          self.__frames[key][i][j].blit(sheet, (0,0), frameArea)
          self.__frames[key][i][j].set_colorkey(TRANSPARENT_COLOR)
          
          j += 1
          
       i += 1
コード例 #24
0
 def prepare_size(self,asked_width):
     he = self.head_end
     hl = self.head_line
     hm = self.head_mid
     fe = self.foot_end
     fl = self.foot_line
     self.min_header_width = mhw = he.get_width()*2 + hm.get_width()
     self.min_footer_width = mfw = fe.get_width()*2
     cwidth,cheight = self.content_size()
     self.width = max(asked_width,cwidth,mhw,mfw)
     topgap = (self.width-self.min_header_width)/2
     bottomgap = self.width-self.min_footer_width
     self.top_line = scale(hl,(topgap,hl.get_height()))
     self.bottom_line = scale(fl,(bottomgap,fl.get_height()))
     self.headheight = he.get_height()
     self.footheight = fe.get_height()
コード例 #25
0
ファイル: LemonadeGui.py プロジェクト: FOSSRIT/lemonade-stand
    def ingredient_count(self, items, money):
        # sides are at 650 and 675
        #            /1200    /900
        #            13/24   27/36
        ingredient_block = Surface((self.game_engine.width * 11/24,
                                    self.game_engine.height * 9/36))
        ingredient_block.fill((255, 255, 255))
        
        icon_size = int(ingredient_block.get_width() / (len(items) * 1.5))
        icon_width = ingredient_block.get_width() / len(items)
        j = icon_size / 3
        render_top = 15 + icon_size
        for name, count in items.items():
            icon = image.load("images/icon-%s.gif" % name).convert()
            icon = transform.scale(icon, (icon_size, icon_size))
            ingredient_block.blit(icon, (j, 10))

            # Put an item count under the icon.
            ren = self.__font.render(str(count), True, (0, 0, 0))
            fw, fh = ren.get_size()
            render_left = j + (icon_size / 2) - (fw / 2)
            ingredient_block.blit(ren, (render_left, render_top))
            j += icon_width

        ren = self.__font.render("Funds: %s" % format_money(money), True, (0, 0, 0))
        fw, fh = ren.get_size()
        render_left = ingredient_block.get_width() / 2 - fw / 2
        render_top = (ingredient_block.get_height() - render_top) / 2 + render_top
        ingredient_block.blit(ren, (render_left, render_top))

        return ingredient_block
コード例 #26
0
ファイル: livescounter.py プロジェクト: Fenixin/yogom
 def update(self, platforms, new_sprites_group, player):
     
     final_lives = None
     
     # Check if we have to blink
     if self.current_lives != glo.lives:
         #~ print "Lives changed! Time to blink!"
         self.last_lives = self.current_lives
         self.current_lives = glo.lives
         self.blinking = True
         self.blink_update_counter = 0
     
     if self.blinking:
         first_period = True if (self.blink_update_counter % self.updates_per_blink) / (self.updates_per_blink / 2) else False
         self.blink_update_counter += 1
         if self.blink_update_counter == self.updates_blinking:
             self.blinking = False
         if first_period:
             final_lives = self.current_lives
         else:
             final_lives = self.last_lives
         #~ print "Blinking: final_lives = ", final_lives, "; first_period = ", first_period, "; blink_update_counter = ", self.blink_update_counter
     else:
         final_lives = glo.lives
     
     if final_lives != self.lives_in_counter:
         #~ print "Updating image!"
         self.lives_in_counter = final_lives
     # Update it every frame...
     self.image = self.get_lives_image(self.text, final_lives, scale(player.image,(12,12)), 3, self.lives_pos_offset)
コード例 #27
0
ファイル: me.py プロジェクト: bluepeppers/me
    def draw(self):
        viewport = display.get_surface()
        if self.menu_state == "ok":
            self.menu_state = "dim_out_1"
        if self.menu_state == "dim_out_1":
            if not self.dimmer:
                self.dimmer = pygame.Surface(display.get_surface().get_size())
                self.dimmer.fill((0, 0, 0))
            self.dimmer.set_alpha(self.dim)
            self.dim += 1
            viewport.blit(self.dimmer, (0, 0))
            if self.dim > 30:
                self.menu_state = "dim_in_zoom"
                self.dimmer = None
        if self.menu_state in ("dim_in_zoom", "wait"):
            if not self.dimmer:
                self.dimmer = pygame.Surface(display.get_surface().get_size())
            scaled = transform.scale(self.screen, self.zoom_size)
            viewport.blit(scaled,
                          ((-scaled.get_width() + VWIDTH)/2,
                           (-scaled.get_height() + VHEIGHT)/2))

            self.draw_score(viewport)
            self.draw_highscores(viewport)
            self.scores.add_score(self.points)

            if self.menu_state == "dim_in_zoom":
                self.dimmer.set_alpha(self.dim)
                self.dim -= 1
                self.zoom_size[0] -= 10
                self.zoom_size[1] -= 10

            viewport.blit(self.dimmer, (0, 0))
            if self.dim < 4:
                self.menu_state = "wait"
コード例 #28
0
def pause(display):
    global main_score
    screen = display.get_surface()

    hsfont = font.Font(FONT, 100)
    ysfont = font.Font(FONT,100)
    hs = hsfont.render("HIGH SCORE :-->" + str(highscore/2), True, HIGHSCORE_COLOR)
    
    y_score = ysfont.render("YOUR SCORE :-->"+str(main_score/2), True, Y_SCORE_COLOR)
    
    main_score = 0
    #score = 0

  
    pause_img=image.load('pause.png').convert_alpha()
    pause_img=transform.scale(pause_img, (1200, 700)) 
 
    screen.blit(pause_img, (0, 0,))
    screen.blit(hs, (200, 60))
    screen.blit(y_score, (200, 200))
    display.flip()

    while True:
        for i in event.get():
            if i.type == MOUSEBUTTONDOWN or i.type == KEYDOWN:
                    return main()
コード例 #29
0
ファイル: paddle.py プロジェクト: Kranek/BlockBuster
    def change_size(self, new_width):
        """
        Function used to change the size of the palette. Rebuilds image from source and
        generates new collision Rect
        :param new_width: new Paddle width in pixels (min. 22px)
        :return:
        """
        paddleAsset = Assets.paddles[self.paddle_color]
        new_width = max(new_width, 22)  # 22 = (border(8) + colorbar(3))*2
        paddle_mid = Surface((38, 15))  # (2*paddle.rect.width, paddle.rect.height))
        # paddle_mid.blit(self.image, (0, 0), Rect(11, 0, 38, 15))
        paddle_mid.blit(paddleAsset, (0, 0), Rect(11, 0, 38, 15))
        paddle_mid = transform.scale(paddle_mid, (new_width-22, self.rect.height))
        new_paddle = Surface((new_width, self.rect.height), SRCALPHA)  # blank surface
        # new_paddle.fill(pygame.Color(0, 0, 0, 0), new_paddle.get_rect())
        new_paddle.blit(paddle_mid, (11, 0))
        new_paddle.blit(paddleAsset, (0, 0), Rect(0, 0, 11, 15))
        new_paddle.blit(paddleAsset, (new_width - 11, 0),
                        Rect(paddleAsset.get_rect().width - 11, 0, 11, 15))
        paddle_new_x = self.rect.x + self.rect.width/2 - new_paddle.get_rect().width/2
        self.rect = Rect(paddle_new_x, self.rect.y, new_paddle.get_rect().width,
                         new_paddle.get_rect().height)
        self.mask = mask.from_surface(new_paddle)
        self.image = new_paddle
        self.attachment_points[1] = (self.rect.width-8, 0)
        # self.paddle.attachment_points[1] =

        if self.rect.x <= PLAYFIELD_PADDING[0]:
            self.rect.x = PLAYFIELD_PADDING[0] + 1
        elif self.rect.x + self.rect.width >= LEVEL_WIDTH - PLAYFIELD_PADDING[0]:
            self.rect.x = LEVEL_WIDTH - PLAYFIELD_PADDING[0] - self.rect.width - 1
コード例 #30
0
ファイル: DrawAHat.py プロジェクト: Foued70/pycam
def overlayAHat(surf, face):
    # Draw an image of a hat on top of the face.
    width_factor, height_factor = 5/5, 3/5
    scaled_hat = transform.scale(hat, (int(width_factor*face.width), int(height_factor*face.height)))
    hat_x = int(face.left + (face.width/2) - width_factor*face.width/2)    
    hat_y = int(face.top - height_factor*face.height/2)
    surf.blit(scaled_hat, (hat_x, hat_y))
コード例 #31
0
 def __init__(self, position):
     super(ChickenThigh, self).__init__(position)
     self.name = "chicken_thigh"
     self.image = transform.scale(
         load_image("assets/images/sprites/chicken_thigh.png"),
         OBJECT_SURFACE)
     self.rect = self.image.get_rect()
     self.rect.center = (self.x, self.y)
コード例 #32
0
def scroll_view(screen, image, direction, view_rect):
    dx = dy = 0
    src_rect = None
    zoom_view_rect = screen.get_clip()
    image_w, image_h = image.get_size()
    if direction == DIR_UP:
        if view_rect.top > 0:
            screen.scroll(dy=zoom_factor)
            view_rect.move_ip(0, -1)
            src_rect = view_rect.copy()
            src_rect.h = 1
            dst_rect = zoom_view_rect.copy()
            dst_rect.h = zoom_factor
    elif direction == DIR_DOWN:
        if view_rect.bottom < image_h:
            screen.scroll(dy=-zoom_factor)
            view_rect.move_ip(0, 1)
            src_rect = view_rect.copy()
            src_rect.h = 1
            src_rect.bottom = view_rect.bottom
            dst_rect = zoom_view_rect.copy()
            dst_rect.h = zoom_factor
            dst_rect.bottom = zoom_view_rect.bottom
    elif direction == DIR_LEFT:
        if view_rect.left > 0:
            screen.scroll(dx=zoom_factor)
            view_rect.move_ip(-1, 0)
            src_rect = view_rect.copy()
            src_rect.w = 1
            dst_rect = zoom_view_rect.copy()
            dst_rect.w = zoom_factor
    elif direction == DIR_RIGHT:
        if view_rect.right < image_w:
            screen.scroll(dx=-zoom_factor)
            view_rect.move_ip(1, 0)
            src_rect = view_rect.copy()
            src_rect.w = 1
            src_rect.right = view_rect.right
            dst_rect = zoom_view_rect.copy()
            dst_rect.w = zoom_factor
            dst_rect.right = zoom_view_rect.right
    if src_rect is not None:
        scale(image.subsurface(src_rect),
              dst_rect.size,
              screen.subsurface(dst_rect))
        pygame.display.update(zoom_view_rect)
コード例 #33
0
    def initPygame(self, scale_factor=5):
        import pygame
        from pygame.transform import scale

        # pygame.quit()
        pygame.init()  # pylint: disable=E1101

        self.scale_factor = scale_factor
        # Open Pygame window
        self.window = pygame.display.set_mode(
            (200 * scale_factor, 100 * scale_factor))
        # Load images
        path = os.path.join("learnrl", "environments", "multi_agents",
                            "crosses_and_noughts")
        self.empty_grid_img = pygame.image.load(
            os.path.join(path, "images", "empty_grid.png")).convert()
        self.empty_grid_img = scale(
            self.empty_grid_img,
            (scale_factor * self.empty_grid_img.get_width(),
             scale_factor * self.empty_grid_img.get_height()))

        self.black_background = pygame.image.load(
            os.path.join(path, "images", "black_background.png")).convert()
        self.black_background = scale(
            self.black_background,
            (scale_factor * self.black_background.get_width(),
             scale_factor * self.black_background.get_height()))

        cross_img = pygame.image.load(os.path.join(path, "images",
                                                   "cross.png")).convert()
        cross_img = scale(cross_img, (scale_factor * cross_img.get_width(),
                                      scale_factor * cross_img.get_height()))

        nought_img = pygame.image.load(
            os.path.join(path, "images", "nought.png")).convert()
        nought_img = scale(nought_img,
                           (scale_factor * nought_img.get_width(),
                            scale_factor * nought_img.get_height()))

        self.rect_size = scale_factor * cross_img.get_width()

        self.images = {1: cross_img, 2: nought_img}

        self.states_images = {}
        self.window.blit(self.empty_grid_img, (0, 0))
        pygame.display.flip()
コード例 #34
0
ファイル: enemy.py プロジェクト: svilaa/HackUPCGame-20
 def __init__(self, img, x, y, x_change, y_change, width, height):
     self.width = width
     self.height = height
     self.enemyImg = transform.scale(image.load(img),(self.width, self.height))
     self.enemyX = x
     self.enemyY = y
     self.enemyX_change = x_change
     self.enemyY_change = y_change
コード例 #35
0
ファイル: scoreboard.py プロジェクト: Ye-Rham/Alien-Invaders
 def prep_ships(self):
     self.ships = Group()
     for ship_number in range(self.stats.ships_left):
         ship = Ship(self.ai_settings, self.screen, self.spritesheet)
         ship.images[0] = scale(ship.images[0], (48, 24))
         ship.rect.x = 10 + ship_number * ship.rect.width/2
         ship.rect.y = 10
         self.ships.add(ship)
コード例 #36
0
ファイル: bullet.py プロジェクト: mehdigorjian/airplane_game
 def __init__(self, x, y):
     self.x = x + 28
     self.y = y
     b_im = image.load(IMAGE_BULLET)
     self.img = transform.scale(
         b_im, (b_im.get_width() // 4, b_im.get_height() // 2))
     self.vel = -10
     self.acc = -0.5
コード例 #37
0
 def _set_original_image(self, res_container: ResourceContainer):
     sprite_sheet = res_container.resources['red_fighter']
     temp_rect = Rect((0, 0, 32, 32))
     self._original_image = Surface(temp_rect.size, SRCALPHA)
     self._original_image.blit(sprite_sheet, (0, 0), temp_rect)
     self._original_image = transform.scale(
         self._original_image, (int(32*2.5), int(32*2.5)))
     self._original_image = transform.rotate(self._original_image, -90)
コード例 #38
0
 def __init__(self, position):
     super(ToiletPaper, self).__init__(position)
     self.name = "toilet_paper"
     self.image = transform.scale(
         load_image("assets/images/sprites/toilet_paper.png"),
         OBJECT_SURFACE)
     self.rect = self.image.get_rect()
     self.rect.center = (self.x, self.y)
コード例 #39
0
    def resize_image(self):
      img = image.load(self.file_path)
      filename = os.path.splitext(self.file_path)[0]
      file_ext = os.path.splitext(self.file_path)[1]
      scaled = scale(img, (640, 480))
      image.save(scaled, filename + '-640' + file_ext)

      print(image)
コード例 #40
0
ファイル: player.py プロジェクト: svilaa/HackUPCGame-20
 def __init__(self, img, x, y):
     self.width = 64
     self.height = 64
     self.playerImg = transform.scale(image.load(img),
                                      (self.width, self.height))
     self.playerX = x - (self.width / 2)
     self.playerY = y - (self.height)
     self.playerX_change = 0
コード例 #41
0
def mostrar():

    Aurelio = ['verde', 'roxo', 'amarelo', 'azul', 'vermelho', 'cinza']

    apag = transform.scale(image.load('Tela_inicial/Apagar.png'), (50, 250))
    tela.blit(apag, (930, 40))
    display.flip()

    for n in range(len(senha)):
        correto = transform.scale(
            image.load('cores/' + Aurelio[senha[n] - 1] + '.png'), (40, 40))
        tela.blit(correto, (930, 50 + (65 * n)))
        display.flip()

    sleep(3)

    setup_tabuleiro()
コード例 #42
0
def draw_input(screen, text, clear, font_obj):
	source = pytr.scale(pyim.load("offwhite.png"), (480, 30))
	screen.blit(source, source.get_rect().move(0, 600))
	if clear:
		text = ""
	#Text rendering
	textsurface = font_obj.render(str(text), True, (20, 20, 20))
	screen.blit(textsurface,(10, 605))
コード例 #43
0
ファイル: LemonadeGui.py プロジェクト: nswarup14/Lemonade
    def draw_store(self, key):
        """Draws the store interface, including currently selected items."""

        store = image.load("images/store-outline.gif").convert()
        store = transform.scale(store, (self.game_engine.width, self.game_engine.height))

        # Store apron text.
        #block_arr = [Surface((self.game_engine.width / 4, self.game_engine.height / 6))] * 3
        #h = self.game_engine.width * 7 / 24
        #j = self.game_engine.width / 12
        #for num, block in enumerate(block_arr):
        #    store.blit(block, (j, 20))
        #    j += h

        # Store item display.
        spacer = self.game_engine.width / (len(ITEMS) * 4)
        icon_size = (self.game_engine.width - (len(ITEMS) + 1) * spacer) / len(ITEMS)
        j = spacer
        for num, name in enumerate(ITEMS):
            outline = Surface((icon_size, icon_size))
            if num == key:
                outline.fill((255, 255, 0))
            else:
                outline.fill((0, 255, 0))
            icon = image.load("images/icon-%s.gif" % name).convert()
            icon = transform.scale(icon, (icon_size * 8 / 10, icon_size * 8 / 10))
            outline.blit(icon, (icon_size / 10, icon_size / 10))
            store.blit(outline, (j, self.game_engine.height / 4))

            # Put pricing info under the item.
            ren = self.__font.render("%s for %d" % (format_money(ITEMS[name]["cost"] * ITEMS[name]["bulk"]),
                            ITEMS[name]["bulk"]), True, (0, 0, 0))
            fw, fh = ren.get_size()
            render_left = j + (icon_size / 2) - (fw / 2)
            store.blit(ren, (render_left, self.game_engine.height / 4 + icon_size + 5))

            # Put an item count under the icon.
            ren = self.__font.render(self.__input_string[0][num], True, (0, 0, 0))
            fw, fh = ren.get_size()
            render_left = j + (icon_size / 2) - (fw / 2)
            store.blit(ren, (render_left, self.game_engine.height * 5 / 8))
            
            j += icon_size + spacer

        return store
コード例 #44
0
 def __init__(self, pos_x, pos_y, force, half_entity_width, width, height):
     self.x_pos = pos_x + half_entity_width
     self.y_pos = pos_y
     self.velocity = force
     self.do_find_player_start_x = True
     self.width = width
     self.height = height
     self.bullet_model = transform.scale(Resources.bullet_model,
                                         (self.width, self.height))
コード例 #45
0
ファイル: card.py プロジェクト: puhlenbruck/kpoker
 def __init__(self, base_image):
     self._card_base = base_image
     self._suite_icons = {
         Suite.SPADES: transform.scale(
             pygame.image.load("res/spade.png").convert_alpha(), _icon_size
         ),
         Suite.HEARTS: transform.scale(
             pygame.image.load("res/heart.png").convert_alpha(), _icon_size
         ),
         Suite.DIAMONDS: transform.scale(
             pygame.image.load("res/diamond.png").convert_alpha(), _icon_size
         ),
         Suite.CLUBS: transform.scale(
             pygame.image.load("res/club.png").convert_alpha(), _icon_size
         ),
     }
     self._card_font = pygame.font.SysFont("Arial", 30)
     self._icon_vertical_spacing = -5
コード例 #46
0
ファイル: template.py プロジェクト: hjpotter92/TwentyNine
 def Generate(self):
     draw.rect(self.__card, (0, 0, 0), (0, 0, 70, 100), 1)
     if self.__load_image:
         print "Face not yet available"
         return
     self.__suit = transform.scale(self.__suit, (12, 12))
     for x in xrange(len(self.__face_placements)):
         if self.__face_placements[x] == 1:
             self.__card.blit(self.__suit, positions[x])
     text = self.__font.render(self.__face, 1, self.__text_colour)
     text_size = self.__font.size(self.__face)
     self.__suit = transform.scale(self.__suit, (6, 6))
     self.__card.blit(text, (2, 4))
     self.__card.blit(self.__suit, (2, 15))
     text = transform.rotate(text, 180)
     self.__suit = transform.rotate(self.__suit, 180)
     self.__card.blit(text, (68 - text_size[0], 84))
     self.__card.blit(self.__suit, (64, 80))
コード例 #47
0
ファイル: snaryadi.py プロジェクト: TvgGaminz/AGTM
 def __init__(self, hero, shoot_x, shoot_y, side):
     pygame.sprite.Sprite.__init__(self)
     # Координаты в комнате
     self.rect = pygame.Rect(hero.rect.x + hero.rect.width / 2,
                             hero.rect.y + hero.rect.height / 2, 20, 20)
     # Владелец
     self.hero = hero
     self.side = side
     # Картинка
     if self.side == "hero":
         self.image = scale(pygame.image.load("ball.png"), (20, 20))
     else:
         self.image = scale(pygame.image.load("projecticle.png"), (20, 20))
     # Физическая скорость
     self.speed = 20
     # Рассчет координатной скорости
     self.xspeed = self.speed / (shoot_x**2 + shoot_y**2)**0.5 * shoot_x
     self.yspeed = self.speed / (shoot_x**2 + shoot_y**2)**0.5 * shoot_y
コード例 #48
0
ファイル: DrawAHat.py プロジェクト: michaelhuang14/pycam
def overlayAHat(surf, face):
    # Draw an image of a hat on top of the face.
    width_factor, height_factor = 5 / 5, 3 / 5
    scaled_hat = transform.scale(
        hat,
        (int(width_factor * face.width), int(height_factor * face.height)))
    hat_x = int(face.left + (face.width / 2) - width_factor * face.width / 2)
    hat_y = int(face.top - height_factor * face.height / 2)
    surf.blit(scaled_hat, (hat_x, hat_y))
コード例 #49
0
 def load_resource(self, resource_type, unit_type, value, index, x_scale,
                   y_scale):
     image_path = f"resources/animation/{resource_type}/{unit_type.lower()}/sprites/{value}/{index}.png"
     self.animation_loader_logger.log_debug_message('> ' + image_path)
     loaded_image = image.load(image_path)
     normalized_image = transform.scale(
         loaded_image, (round(loaded_image.get_width() * x_scale),
                        round(loaded_image.get_height() * y_scale)))
     return normalized_image
コード例 #50
0
 def __init__(self):
     self.x = W_WIDTH//2 + 30
     self.y = W_HEIGHT - 35
     self.w = 100
     self.h = 17
     self.color = WHITE
     self.inner_color = GREEN
     self.inner_h = self.h
     self.img = transform.scale(image.load(IMAGE_PLAYER), (15,15))
コード例 #51
0
ファイル: gui.py プロジェクト: AudaciousAxolotl/WaterBender
 def fit(self, zoom_factor=1):
     self.zoom_factor = zoom_factor
     self.draw_subject = transform.scale(
         self.subject, (int(VIEWPORT_SIZE * self.zoom_factor),
                        int(VIEWPORT_SIZE * self.zoom_factor)))
     self.center = ((self.draw_subject.get_width() - VIEWPORT_SIZE) / 2,
                    (self.draw_subject.get_height() - VIEWPORT_SIZE) / 2)
     self.subject_location[0] = self.center[0]
     self.subject_location[1] = self.center[1]
コード例 #52
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
コード例 #53
0
def load_scaled(path, dim: set):
    """
    Load an image and scale.

    Arguments:
    path - Path to image.
    dim - Dimensions of image.
    """
    return scale(load(path), dim)
コード例 #54
0
def renderer():
    # Amplia os desenhos na picture
    screen.blit(transform.scale(picture, SCREEN_SIZE), SCREEN_ORIGIN)

    # Renderiza no display
    pygame.display.flip()

    # Limita a quantidade de quadros por segundos
    game_clock.tick_busy_loop(60)
コード例 #55
0
 def process(self, zipprocessor):
     """Scale each image in the directory to user's size"""
     for filename in os.listdir(zipprocessor.temp_directory):
         im = image.load(zipprocessor._full_filename(filename))
         users_sizes = input(
             "Enter the size for image scaling for example - '640 400'"
         ).split()
         scaled = scale(im, (int(users_sizes[0]), int(users_sizes[1])))
         image.save(scaled, zipprocessor._full_filename(filename))
コード例 #56
0
def yield_random_surface(
        asset_path: str, path_arr: Sequence[str],
        brick_dim: Tuple[int, int]) -> Iterator[pygame.Surface]:
    while True:
        image_path = random.choice(path_arr)
        path_to_image = os.path.join(asset_path, image_path)
        brick_surf = image.load(path_to_image)
        brick_surf = transform.scale(brick_surf, brick_dim)
        yield brick_surf
コード例 #57
0
 def __init__(self, window, img_path, sprite_x, sprite_y, size_x, size_y,
              player_speed):
     super().__init__()
     self.window = window
     self.image = transform.scale(image.load(img_path), (size_x, size_y))
     self.speed = player_speed
     self.rect = self.image.get_rect()
     self.rect.x = sprite_x
     self.rect.y = sprite_y
コード例 #58
0
    def _set_original_image(self, resource_container: ResourceContainer):
        sprite_sheet = resource_container.resources['treasure']
        temp_rect = Rect((0, 0, 254, 254))
        scale = 0.3
        self._original_image = Surface(temp_rect.size, SRCALPHA)

        self._original_image.blit(sprite_sheet, (0, 0), temp_rect)
        self._original_image = transform.scale(
            self._original_image, (int(254 * scale), int(254 * scale)))
コード例 #59
0
 def process_files(self):        
     '''Scale each image in the directory to 640x480'''        
     for filename in os.listdir(self.processor.temp_directory):   
         try:
             im = image.load(self.processor._full_filename(filename))            
             scaled = scale(im, (640,480))            
             image.save(scaled, self.processor._full_filename(filename))
         except:
             pass
コード例 #60
0
    def _set_original_image(self, res_container: ResourceContainer):
        sprite_sheet = res_container.resources['first_boss']
        temp_rect = Rect((0, 0, 904, 862))

        scale = 0.4
        self._original_image = Surface(temp_rect.size, SRCALPHA)
        self._original_image.blit(sprite_sheet, (0, 0), temp_rect)
        self._original_image = transform.scale(
            self._original_image, (int(512 * scale), int(512 * scale)))