当前位置: 首页>>代码示例>>Python>>正文


Python Surface.fill方法代码示例

本文整理汇总了Python中pygame.Surface.fill方法的典型用法代码示例。如果您正苦于以下问题:Python Surface.fill方法的具体用法?Python Surface.fill怎么用?Python Surface.fill使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pygame.Surface的用法示例。


在下文中一共展示了Surface.fill方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _get_raw_shadow

# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import fill [as 别名]
 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
开发者ID:YannThorimbert,项目名称:ThorPy-1.0,代码行数:31,代码来源:_shadow.py

示例2: rotated_bolt_image

# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import fill [as 别名]
	def rotated_bolt_image(self, angle):
		image = Surface((32, 32))
		image.set_colorkey(DEFAULT_COLORKEY)
		image.fill(DEFAULT_COLORKEY)
		image.blit(self.projectile_image, (0, 0))
		image = pygame.transform.rotate(image, angle)
		return image
开发者ID:brandr,项目名称:Tower_Defense,代码行数:9,代码来源:tower.py

示例3: makebackground

# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import fill [as 别名]
    def makebackground(self, surface):
        surface.fill((0,0,0))
        
        template = Surface(2*(min(self.zoom.width, self.zoom.height),))
        template.fill((0,0,0,255))
        width,height = template.get_size()

        ylim = surface.get_height()/height
        xlim = surface.get_width()/width

        data = self._data
        noise = [[pnoise2(self._selected[1][0]+x,
                          self._selected[0][0]+y,
                          4, 0.85) * 50
                  for x in range(xlim)]
                 for y in range(ylim)]

        hmin = hmax = 0
        for y in range(ylim):
            for x in range(xlim):
                yd = len(data)*float(y)/ylim
                xd = len(data[0])*float(x)/xlim

                h = self._height(data, yd, xd)
                n = noise[y][x]
                if h < 0:
                    h += -n if n > 0 else n
                else:
                    h += n if n > 0 else -n
                if h < hmin:
                    hmin = h
                if h > hmax:
                    hmax = h

        self.rects = []
        for y in range(ylim):
            for x in range(xlim):
                block = template.copy()
                yd = len(data)*float(y)/ylim
                xd = len(data[0])*float(x)/xlim

                h = self._height(data, yd, xd)
                n = noise[y][x]
                if h < 0:
                    h += -n if n > 0 else n
                else:
                    h += n if n > 0 else -n
                if h < 0:
                    color = 0, 0, int(255 * (1 - h/hmin))
                else:
                    color = 0, int(255 * h/hmax), 0
                block.fill(color)
                if self.selection:
                    if self.selection[0][0] <= yd <= self.selection[0][1]:
                        if self.selection[1][0] <= xd <= self.selection[1][1]:
                            block.fill((255,0,0,32),
                                       special_flags = BLEND_ADD)
                rect = Rect(x*width, y*height, width, height)
                surface.blit(block, rect.topleft)
                self.rects.append((rect, (yd, xd)))
开发者ID:tps12,项目名称:Dorftris,代码行数:62,代码来源:neighborhood.py

示例4: Ship

# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import fill [as 别名]
class Ship(Sprite):
    width = 20
    height = 20

    def __init__(self, x, y, vx, vy, bounds, color):
        Sprite.__init__(self)

        self.vx = vx
        self.vy = vy
        self.bounds = bounds
        self.color = color

        self.rect = Rect(x, y, self.width, self.height)
        self.image = Surface(self.rect.size)
        self.draw_image()
        
    def draw_image(self):
        self.image.fill(self.color)

    def update(self, dt):
        dt /= 1000.0
        dx = int(self.vx * dt)
        dy = int(self.vy * dt)
        self.rect.x += dx
        self.rect.y += dy
开发者ID:sambwhit,项目名称:CS112-Spring2012,代码行数:27,代码来源:ships.py

示例5: get_image

# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import fill [as 别名]
 def get_image(self):
     """Draw the rectange on a transparent surface."""
     img = Surface(self.rect.size).convert_alpha()
     img.fill((0, 0, 0, 0), special_flags=pg.BLEND_RGBA_MULT)
     draw.rect(img, self.model.color, img.get_rect(), 1)
     img.fill((255, 255, 255, 128), special_flags=pg.BLEND_RGBA_MULT)
     return img
开发者ID:YoannQDQ,项目名称:pyweek-dojo,代码行数:9,代码来源:view.py

示例6: block

# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import fill [as 别名]
    def block(self, color, shadow = False):
        colors = {'blue':   (27, 34, 224),
                  'yellow': (225, 242, 41),
                  'pink':   (242, 41, 195),
                  'green':  (22, 181, 64),
                  'red':    (204, 22, 22),
                  'orange': (245, 144, 12),
                  'cyan':   (10, 255, 226)}

        if shadow:
            end = [40]  # end is the alpha value
        else:
            end = []    # Adding this to the end will not change the array, thus no alpha value

        border = Surface((self.blocksize, self.blocksize), pygame.SRCALPHA, 32)
        border.fill(map(lambda c: c*0.5, colors[color]) + end)

        borderwidth = 2

        box = Surface((self.blocksize-borderwidth*2, self.blocksize-borderwidth*2),
                        pygame.SRCALPHA, 32)
        boxarr = pygame.PixelArray(box)
        for x in range(len(boxarr)):
            for y in range(len(boxarr)):
                boxarr[x][y] = tuple(map(lambda c: min(255, int(c*random.uniform(0.8, 1.2))),
                                    colors[color]) + end)

        del boxarr # deleting boxarr or else the box surface will be 'locked' or something like that and won't blit
        border.blit(box, Rect(borderwidth, borderwidth, 0, 0))

        return border
开发者ID:noiron,项目名称:NotingImportant,代码行数:33,代码来源:matris.py

示例7: Shield

# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import fill [as 别名]
class Shield(Sprite):
    color = 255,255,255
    transparent = 0,0,0
    size = 120,120
    kind = "null"
    
    def __init__(self, parent, kind):
        self.parent=parent
        Sprite.__init__(self)
        self.kind = kind
        self.hiss_sfx = load_sfx("hiss")
        if kind == "baseball":
            self.color = 0,90,90
        elif kind == "cigar":
            self.color = 255,100,0
        elif kind == "health":
            self.color = 180, 200, 180
        self.image = Surface(self.size)
        self.rect = self.image.get_rect()
        self.rect.center = self.parent.rect.center
        self.image.fill(self.transparent)
        self.image.set_colorkey(self.transparent)
        pygame.draw.ellipse(self.image, (self.color), self.image.get_rect())
        pygame.draw.ellipse(self.image, self.transparent, self.image.get_rect().inflate(-10, -10))
        #pygame.draw.ellispe(self.image, (30,255,30), self.rect.center, ((self.rect.width)/2))
            
    def update(self):
        
        if not self.parent.alive():
            self.kill()
        
        self.rect.center = self.parent.rect.center
开发者ID:jlevey3,项目名称:Save-the-Robots-Game,代码行数:34,代码来源:robots.py

示例8: MortarTower

# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import fill [as 别名]
class MortarTower(Tower):
    def __init__(self, pos):
        Tower.__init__(self, pos)
        self.name = "Mortar Tower"
        self.image = Surface((40, 40)).convert()
        self.image.fill((0, 0, 255))
        self.projectile = Surface((15, 15)).convert()
        self.projectile.fill((255, 150, 0))
        self.projectile_speed = 3

        self.radius = 300
        self.fire_rate = 3
        self.damage = 15
        self.description = "A long-range tower that fires mortars which " \
                           "explode on impact, dealing damage to all nearby enemies."
        self.cost = 75

        self.frame = TowerFrame(self)

    def update_info(self):
        self.frame = TowerFrame(self)

    def upgrade(self):
        if self.level < 5:
            self.damage += 5
            self.radius += 10
            self.projectile_speed += 0.25
            self.level += 1
            self.update_info()
            return True
        return False
开发者ID:brandonsturgeon,项目名称:Tower_Defense,代码行数:33,代码来源:mortar_tower.py

示例9: Enemy

# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import fill [as 别名]
class Enemy(Sprite):
    size = width,height = 50,50
    color = 255,0,0
    vx, vy = 6,6

    def __init__(self,loc,bounds):
        Sprite.__init__(self)
        self.image = Surface(self.size)
        self.rect = self.image.get_rect()
        self.bounds = bounds


        self.image.fill(self.color)
        self.rect.bottomleft = loc

        self.vx = randrange(4,8)
        direction = 2 * randrange(2)- 1
        self.vx *= direction

    def update(self):
        self.rect.x += self.vx
        self.rect.y += self.vy

        if self.rect.left < self.bounds.left or self.rect.right > self.bounds.right:
            self.rect.x -= 2 * self.vx
            self.vx = -self.vx

        if self.rect.top > self.bounds.bottom:
            self.kill()
开发者ID:nigelgant,项目名称:CS112-Spring2012,代码行数:31,代码来源:enemy.py

示例10: Enemy

# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import fill [as 别名]
class Enemy(Sprite):
    width = 40
    height = 40
    
    y = -40
    
    def __init__(self):
        self.x = randrange(0,scrWidth-self.width)
        Sprite.__init__(self)

        #Self.rect and self.image
        self.rect = Rect((self.x,self.y),(self.width,self.height))
        self.image = Surface(self.rect.size)
        self.image.fill((0,0,0))
        self.image.set_colorkey((0,0,0))

        #Draw stuff
        pygame.draw.ellipse(self.image,red,self.image.get_rect())
        pygame.draw.ellipse(self.image,blue2,self.image.get_rect(),15)

        #Randomly picking trajectory
        self.down = randrange(1,5)
        self.side = randrange(-6,6,4)
    def update(self):
        "Movement behavior"
        
        self.rect.y += self.down
        self.rect.x += self.side
        
        if self.rect.right > scrWidth or self.rect.left < 0:
            self.side *=-1
        if self.rect.top > scrHeight:
            self.kill()
开发者ID:sgoodspeed,项目名称:CS112-Spring2012,代码行数:35,代码来源:game.py

示例11: Player

# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import fill [as 别名]
class Player(Sprite):
    color = 255,25,69
    size = 20,20

    def __init__(self, loc, bounds):
        Sprite.__init__(self) #makes player a sprite object

        self.image = Surface(self.size)
        self.rect = self.image.get_rect() 

        self.rect.center = loc
        self.bounds = bounds

        self.image.fill(self.color)
        self.bullets = Group()

    def update(self):
        self.rect.center = pygame.mouse.get_pos() #player moves/stays with mouse
        self.rect.clamp_ip(self.bounds) #cant leave screen bounds

    def shoot(self):
        if not self.alive():
            return #stop doing anything in this function
        bullet = Bullet(self.bounds)
        bullet.rect.midbottom = self.rect.midtop 
        self.bullets.add(bullet)
开发者ID:jlevey3,项目名称:CS112-Spring2012,代码行数:28,代码来源:player.py

示例12: Player

# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import fill [as 别名]
class Player(Sprite):
    color = 255, 255, 0
    size = 20, 20
    
    def __init__(self, loc, bounds):
        Sprite.__init__(self)

        self.image = Surface(self.size)
        self.rect = self.image.get_rect()

        self.rect.center = loc
        self.bounds = bounds

        self.image.fill(self.color)
        self.bullets = Group()

    def update(self):
        self.rect.center = pygame.mouse.get_pos()
        self.rect.clamp_ip(self.bounds)

    def shoot(self):
        if not self.alive():
            return

        bullet = Bullet(self.bounds)
        bullet.rect.midbottom = self.rect.midtop
        self.bullets.add(bullet)
开发者ID:AKilgore,项目名称:CS112-Spring2012,代码行数:29,代码来源:player.py

示例13: Impact

# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import fill [as 别名]
class Impact(Meteor):
    size = (100,100)
    COLOR = 0,140,0
    duration = 5
    dir = 0
    damage = 10
    
    def __init__(self,loc, bounds, duration, kind, dir = 0):
        
        #print "explosion!"
        self.dir = dir
        # Ice should have moving impacts
        Sprite.__init__(self)
        self.image = Surface(self.size)
        self.rect = self.image.get_rect()
        self.rect.center = loc
        self.image.fill(self.COLOR)
        self.bounds = bounds
        self.duration = duration
        self.kind = kind
        self.get_sprite()
        self.get_sound()
        self.impact_sfx.stop()

        self.impact_sfx.play()
    def get_sprite(self):
        #return

        #-----------This will attempt to load an image, and fill if it fails.
        try:
            self.image = load_image('explosion_'+self.kind)
            print "impact explosion yay"
        except:
            self.image.fill(self.COLOR)
            print "failed to find explosion"
        #Scale the image to the proper size and add random rotation
        #if randint(0,2) == 0:
        #    self.image = pygame.transform.flip(self.image, True, False)
        #self.image = pygame.transform.rotate(self.image, randint(-360,360))
        
        self.image = pygame.transform.scale(self.image, self.size) #temp
        #Anything that's pure white will be transparent
        self.image.set_colorkey((255,255,255))
        #-------
        
    def get_sound(self):
         self.impact_sfx = load_sfx("stockmeteorhit")
        
        
    def update(self):
        self.duration -= 1
        if self.duration <= 0:
            self.coord_x, self.coord_y = self.rect.center
            self.kill()
            
    #def collision(self, robot):
        
        
    def kill (self):
        Sprite.kill(self)
开发者ID:jlevey3,项目名称:Save-the-Robots-Game,代码行数:62,代码来源:meteors.py

示例14: load_transparent_image

# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import fill [as 别名]
	def load_transparent_image(self):
		image = Surface((32, 32))
		image.fill(DEFAULT_COLORKEY)
		image.set_colorkey(DEFAULT_COLORKEY)
		image.blit(self.image, (0, 0))
		image.set_alpha(120)
		self.transparent_image = image
开发者ID:brandr,项目名称:Tower_Defense,代码行数:9,代码来源:tower.py

示例15: Bomb

# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import fill [as 别名]
class Bomb(Sprite):
    width = 10
    height = 10
    color = 0,200,255
    fuse = 3000

    def __init__(self, pos):
        self.image = Surface((self.width, self.height))
        self.image.fill(self.color)

        self.rect = Rect(0,0,self.width, self.height)
        self.rect.center = pos

        self.time = fuse

    def update(self, dt):
        self.time -= dt
        step = self.time / 500

        if step % 2 == 0:
            color = 255,255,0
        else:
            color = 255,0,0

        self.image.fill(color, self.rect.inflate(-self.width/2, self.height/2))
开发者ID:HampshireCS,项目名称:cs143-Spring2012,代码行数:27,代码来源:shiphunt.py


注:本文中的pygame.Surface.fill方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。