• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python pygame.Surface类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: __init__

   def __init__(self, txt="Hello, World!"):
      self.text = txt
      self.__height = 15
      self.__width = self.__height * (12.0 / 20.0)
      self.__cols = 50
      self.__rows = 7
      self.__accentSize= 10
      self.__lineBuff = 2
      self.__lineHeight = self.__height + self.__lineBuff
      self.__buffer = (self.__accentSize + 4,self.__accentSize + 4)
      
      self.__size = ((self.__buffer[0] * 2) + self.__cols * self.__width  + 1,
                     (self.__buffer[1] * 2) + self.__rows * self.__lineHeight)
      
      self.__canvas = Surface(self.__size)
      self.__box = Surface(self.__size)      
      self.__myFont = font.SysFont("courier", self.__height)
      self.__color = (255,255,0)
      self.__bgColor = (0,0,100)
      self.__edgeColor = (255,255,200)
      self.__transparent = (255,0,255)
      self.__cursor = 0
      self.__nextCue = "(Press Space)"
      

      self.__canvas.set_colorkey(self.__transparent)
      self.__box.set_colorkey(self.__transparent)
      
      self.__preDrawBox()
开发者ID:elizabeth-matthews,项目名称:atlasChronicle,代码行数:29,代码来源:textBox.py


示例2: draw_grid

 def draw_grid(self, tileset):
     """Returns an image of a tile-based grid"""
     img = Surface((self.xsize * SIZE, self.ysize * SIZE))
     for pos, char in self:
         rect = get_tile_rect(pos)
         img.blit(tileset.image, rect, tileset.positions[char])
     return img
开发者ID:krother,项目名称:maze_run,代码行数:7,代码来源:chapter11_classes.py


示例3: makebackground

    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,代码行数:60,代码来源:neighborhood.py


示例4: draw_rectangle

def draw_rectangle(width, height, colour, position, window):
    rectangle = Surface((width, height))
    pixels = surfarray.pixels3d(rectangle)
    pixels[:][:] = colour
    del pixels
    rectangle.unlock()
    window.blit(rectangle, position)
开发者ID:douglassquirrel,项目名称:alexandra,代码行数:7,代码来源:client.py


示例5: Coche

class Coche(Rect):
    coche0 = image.load(os.path.join(imagesrep,'button0.png'))
    coche1 = image.load(os.path.join(imagesrep,'button1.png'))
    font = font.Font(os.path.join(thisrep,'MonospaceTypewriter.ttf'),8)

    def __init__(self,label='',fgcolor=(255,255,255),font=None):
        if not font: font = Coche.font
        Rect.__init__(self,Coche.coche0.get_rect())
        self.scr = display.get_surface()
        self.status = False
        label = Coche.font.render(label,1,fgcolor)
        Rlabel = label.get_rect()
        Rlabel.midleft = self.midright
        self.label = Surface(self.union(Rlabel).size,SRCALPHA)
        self.label.blit(label,Rlabel)
        
    
    def update(self,ev):
        if ev.type == MOUSEBUTTONUP and self.collidepoint(ev.pos):
            self.status ^= 1
            return True
    
    def screen(self):
        self.scr.blit(Coche.coche1 if self.status else Coche.coche0,self)
        self.scr.blit(self.label,self)
开发者ID:CaptainFalco,项目名称:_init_.py,代码行数:25,代码来源:Buttons.py


示例6: Bomb

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,代码行数:25,代码来源:shiphunt.py


示例7: RoboImages

class RoboImages(Sprite):
    color = 0,0,0
    size = 60,60
    def __init__(self, parent):
        Sprite.__init__(self)
        self.parent = parent
        self.name = parent.name
        if parent.name == "baby":
            self.size = 40,40
        self.color = parent.color
        self.image = Surface(self.size)
        self.rect = self.image.get_rect()
        self.rect.centerx = self.parent.rect.centerx
        self.rect.centery = self.parent.rect.centery
        self.dir = dir
        
    

        try:
            self.image = load_image(self.name+'bot')
            print "found family sprite"
        except:
            self.image.fill(self.color)
            print "failed to load family image"
        
        
        self.image = pygame.transform.scale(self.image, self.size)
        self.image.set_colorkey((255,255,255))
        
   
    def update(self):
        self.rect.center = self.parent.rect.center
        if not self.parent.alive():
            self.kill()
开发者ID:jlevey3,项目名称:Save-the-Robots-Game,代码行数:34,代码来源:robots.py


示例8: Player

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,代码行数:27,代码来源:player.py


示例9: draw_equipment_item

	def draw_equipment_item(self, pane):
		equip_item_pane = Surface((EQUIPMENT_ITEM_WIDTH, EQUIPMENT_ITEM_HEIGHT))
		self.draw_border(equip_item_pane)
		items = []
		equipment = self.player.inventory.items_of_type(Equipment)
		current_equipment = self.selected_party_member.equipment_set.equipment
		
		for e in equipment:
			if not e.equippable_in_slot(self.selected_equip_slot): continue
			if self.selected_party_member.party_class not in e.compatible_classes: continue
			if e.equipped and not e in current_equipment.values(): continue
			if self.selected_equip_slot == "left_hand" and e.equipped and e.equip_slot != self.selected_equip_slot and not e.left_equipped: continue
			if self.selected_equip_slot == "right_hand" and e.equipped and e.left_equipped: continue
			items.append(e)
		self.current_equip_items = items
		page_index = self.equipment_item_index/EQUIPMENT_PAGE_SIZE
		start = page_index*EQUIPMENT_PAGE_SIZE 
		end =  min(len(items), start + EQUIPMENT_PAGE_SIZE)
		for i in range(start, end):
			item = items[i]
			text = item.name
			if item.equipped: text += item.equip_tag()
			text_image = self.ui_font.render(text, True, WHITE)
			equip_item_pane.blit(text_image, (28, 8 + 40*(i%EQUIPMENT_PAGE_SIZE)))
		index = self.equipment_item_index%EQUIPMENT_PAGE_SIZE
		self.draw_pane_pointer(equip_item_pane, index)
		# TODO: multiple pages of equipment. Navigate w/ left and right arrow keys
		self.draw_equipment_page_numbers(equip_item_pane)
		pane.blit(equip_item_pane, (EQUIPMENT_ITEM_X, EQUIPMENT_ITEM_Y))
开发者ID:brandr,项目名称:RM_RPG,代码行数:29,代码来源:pausescreen.py


示例10: get_surface

    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()
开发者ID:YannThorimbert,项目名称:ThorPy-1.0,代码行数:28,代码来源:imageframe.py


示例11: __init__

    def __init__(self, move_time, nodes):
        sprite.Sprite.__init__(self)
        self.nodes = nodes
        self.orig_nodes = nodes
        self.move_time = move_time
        self.spawn_time = time.time()
        self.image = Surface((40, 40)).convert()
        self.image_inside = Surface((38, 38)).convert()
        self.image_inside.fill((0, 255, 0))
        self.image.blit(self.image_inside, (1, 1))
        self.pos = (80, 40)
        self.real_pos = (80, 40)
        self.rect = Rect(self.pos, self.image.get_size())
        self.speed = 2
        self.speed_mod = 1
        self.diag_speed = 2
        self.target_pos = (880, 560)
        self.value = 1
        self.cost = 0
        self.health = 100
        self.damage_mod = 1
        self.counter = 0
        self.cur_node = self.nodes[0]
        self.the_dir = (0, 0)
        self.can_move = False

        self.name = "Monster"
        self.description = "A basic monster with slow movement speed and moderate health."
开发者ID:brandonsturgeon,项目名称:Tower_Defense,代码行数:28,代码来源:monster.py


示例12: render

    def render(self, text, color):
        words = text.split()
        lines = []
        h = 0
        i = 0
        j = 1
        while i < len(words):
            found = False
            if j == len(words):
                found = True
            elif self._font.size(' '.join(words[i:j]))[0] >= self._width:
                j = max(1, j-1)
                found = True

            if found:
                line = self._font.render(' '.join(words[i:j]), True, color)
                lines.append(line)
                h += line.get_height()
                i = j
            else:
                j += 1
        image = Surface((self._width, h), flags=SRCALPHA)
        h = 0
        for line in lines:
            image.blit(line, (0, h))
            h += line.get_height()
        return image
开发者ID:tps12,项目名称:Dorftris,代码行数:27,代码来源:text.py


示例13: Bullet

class Bullet(GameObj):
    def __init__(self):
        super(Bullet, self).__init__()
        self.r = config.bulletR
        self.m = config.bulletM
        self.shape = ShapeCircle(self.r)
        self.t = 0
        self.length = 0
        self.I = 0
        self.damage = 0
        # image
        self.image = Surface(Size).convert_alpha()
        self.image.fill((0, 0, 0, 0))
        self.rect = Rect((0, 0), Size)
        draw.circle(self.image, (0, 0, 0, 0xff), self.rect.center, self.r)

    def size(self):
        return (self.r*2, self.r*2)

    def apply(self):
        self.length += self.v.length * self.dt
        self.dt = 0

    def update(self):
        self.rect.center = self.pos

    def boom(self):
        self.I = 5000000
        self.active = 0
开发者ID:ZhanruiLiang,项目名称:GeoTank,代码行数:29,代码来源:bullet.py


示例14: Sprite

class Sprite(DirtySprite):
    """The base sprite class that all sprites inherit."""

    def __init__(self, scene, size, color):
        DirtySprite.__init__(self)
        self.scene = scene
        self.image = Surface(size).convert_alpha()
        self.image.fill(color)
        self.rect = self.image.get_rect()
        self.x, self.y = 0, 0
        self.facing = [0,2]

    def move(self):
        """Move the sprite and set it to dirty for the current frame."""

        self.dirty = 1
        self.rect.move_ip([self.x, self.y])

    def update(self):
        """Update the sprite each frame."""

        if (self.x or self.y):
            self.facing = [self.x, self.y]
            self.move()
            self.collide()
开发者ID:derrida,项目名称:shmuppy,代码行数:25,代码来源:sprite.py


示例15: _blit_to_block

    def _blit_to_block(self, text_array, text_color=(255, 255, 255),
                       block_color=(0, 0, 0)):
        """
        Takes an array of strings with optional text and background colors,
        creates a Surface to house them, blits the text and returns the
        Surface.
        """

        rendered_text = []
        font_width = []
        font_height = []

        for text in text_array:
            ren = self.__font.render(text, True, text_color)
            rendered_text.append(ren)
            fw, fh = ren.get_size()
            font_width.append(fw)
            font_height.append(fh)

        block = Surface((max(font_width) + 20, sum(font_height) + 20))
        block.fill(block_color)

        h = 10
        for text in rendered_text:
            block.blit(text, (10, h))
            h += font_height[0]

        return block
开发者ID:FOSSRIT,项目名称:lemonade-stand,代码行数:28,代码来源:LemonadeGui.py


示例16: Player

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,代码行数:26,代码来源:player.py


示例17: _makebackground

    def _makebackground(self, size):
        self._renderer = TextRenderer(self._font, size[0])

        bg = Surface(size, flags=SRCALPHA)
        bg.fill((0,0,0))

        dy = 0
        bg, dy = self._addline(bg,
                           self._creature.physical(),
                           (255,255,255),
                           dy)
        appetites = self._creature.appetitereport()
        if appetites:
            bg, dy = self._addline(bg,
                               appetites,
                               (255,255,255),
                               dy)
        inventory = self._creature.inventoryreport()
        if inventory:
            bg, dy = self._addline(bg,
                               inventory,
                               (255,255,255),
                               dy)

        self._background = Surface(size, flags = bg.get_flags())
        
        self._scroll.draw(self._background, bg)
开发者ID:tps12,项目名称:Dorftris,代码行数:27,代码来源:desc.py


示例18: MortarTower

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,代码行数:31,代码来源:mortar_tower.py


示例19: create_tag_image

def create_tag_image(
        tags, 
        output, 
        size=(500,500), 
        background=(255, 255, 255), 
        layout=LAYOUT_MIX, 
        fontname=DEFAULT_FONT,
        rectangular=False):
    """
    Create a png tag cloud image
    """
    
    if not len(tags):
        return
    
    sizeRect, tag_store = _draw_cloud(tags,
                                      layout,
                                      size=size, 
                                      fontname=fontname,
                                      rectangular=rectangular)
    
    image_surface = Surface((sizeRect.w, sizeRect.h), SRCALPHA, 32)
    image_surface.fill(background)
    for tag in tag_store:
        image_surface.blit(tag.image, tag.rect)
    pygame.image.save(image_surface, output)
开发者ID:Xpitfire,项目名称:wordcloud,代码行数:26,代码来源:__init__.py


示例20: Enemy

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,代码行数:29,代码来源:enemy.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python _error.SDLError类代码示例发布时间:2022-05-25
下一篇:
Python pygame.Rect类代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap