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


Python Surface.get_height方法代码示例

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


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

示例1: create_dialog

# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import get_height [as 别名]
 def create_dialog(self):
     f = font.Font(font.get_default_font(), 30)
     text = f.render(self.text, True, (255, 255, 255))
     dialog = Surface((text.get_width() + 20, text.get_height() + 20))
     self.stroke(dialog, (255, 0, 0))
     dialog.blit(text, ((dialog.get_width() - text.get_width()) / 2, (dialog.get_height() - text.get_height()) / 2))
     return dialog
开发者ID:ivolo,项目名称:Grand-Theft-Australian-Zoo,代码行数:9,代码来源:dialogEvent.py

示例2: ingredient_count

# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import get_height [as 别名]
    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
开发者ID:FOSSRIT,项目名称:lemonade-stand,代码行数:33,代码来源:LemonadeGui.py

示例3: make_background

# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import get_height [as 别名]
	def make_background(self,img_file,desktop_size):
		in_img = image.load(img_file)
		out_img = Surface(desktop_size)
		for x in range((out_img.get_width() // in_img.get_width()) + 1):
			for y in range((out_img.get_height() // in_img.get_height()) + 1):
				out_img.blit(in_img, (in_img.get_width() * x, in_img.get_height() * y))
		return out_img
开发者ID:giorgiocarta,项目名称:patterns,代码行数:9,代码来源:imageExample.py

示例4: make_background

# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import get_height [as 别名]
 def make_background(self, img_file, desktop_size):
     in_img = image.load(img_file)
     out_img = Surface(desktop_size)
     out_img.fill((0, 0, 0))
     left = (out_img.get_width() - in_img.get_width()) / 2
     top = (out_img.get_height() - in_img.get_height()) / 2
     out_img.blit(in_img, (left, top))
     return out_img
开发者ID:jainarchita,项目名称:60-days-of-python,代码行数:10,代码来源:strategy.py

示例5: IonField

# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import get_height [as 别名]
class IonField(Sprite):
    """Sprite that draws a bunch of random horizontal lines inside a rectangle."""
    
    def __init__(self, left, top, width, height, noise_width, noise_height, delay):
        Sprite.__init__(self)

        self.top = top
        self.left = left
        self.width = width
        self.height = height

        self.image = Surface((self.width, self.height))
        self.rect = Rect(left, top, self.width, self.height)
        self.rect = Rect(left, top, 0, 0)
        self.mask = Mask((self.width, self.height))
        self.mask.fill()

        self.noise_width = noise_width
        self.noise_height = noise_height

        self.tick = 0
        self.delay = delay


    def update(self):
        self.tick = self.tick + 1
        if self.tick % self.delay == 0:
            self.generate_noise()


    def draw(self, screen):
        screen.blit(self.image, self.rect)
    

    def generate_noise(self):
        for col in range(0, self.image.get_width(), self.noise_width):
            for row in range(0, self.image.get_height(), self.noise_height):
                c = choice(COLORS)
                draw.rect(self.image, c, Rect(col, row, self.noise_width, self.noise_height))
开发者ID:rubiximus,项目名称:yars-revenge,代码行数:41,代码来源:ion_field.py

示例6: TowerFrame

# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import get_height [as 别名]
class TowerFrame():
    """ Creates a frame full of information for the selected tower """
    def __init__(self, tower, extra_attributes=None):
        self.tower = tower
        self.image = Surface((200, 300)).convert()
        self.image.fill((200, 115, 0))
        self.s_width = self.image.get_width()
        self.s_height = self.image.get_height()

        # Can't divide by 0
        if self.tower.fire_rate == 0:
            dps_calc = 0
        else:
            dps_calc = self.tower.damage/self.tower.fire_rate

        tower_attributes = {"Name": self.tower.name,
                            "Fire Rate": self.tower.fire_rate,
                            "Damage": self.tower.damage,
                            "DPS": dps_calc,
                            "Damage Done": self.tower.damage_done}
        if extra_attributes is None:
            extra_attributes = dict()
        self.t_attributes = dict(tower_attributes.items() + extra_attributes.items())

        # Upgrades
        self.font = font.Font(None, 18)
        self.upgrade_button = Surface((100, 50)).convert()
        self.upgrade_button.fill((0, 255, 0))
        self.upgrade_button.blit(self.font.render("Upgrade", 1, (0, 0, 0)),
                                 (self.upgrade_button.get_width()/2 - self.font.size("Upgrade")[0]/2,
                                  self.upgrade_button.get_height()/2 - self.font.size("Upgrade")[1]/2))
        self.image.blit(self.upgrade_button, (self.image.get_width() - self.upgrade_button.get_width(),
                                              self.image.get_height() - self.upgrade_button.get_height()))

        level_text = "Level: " + str(self.tower.level)
        self.image.blit(self.font.render(level_text, 1, (0, 0, 0)),
                       (self.image.get_width() - self.upgrade_button.get_width(),
                        self.image.get_height() - self.upgrade_button.get_height() - self.font.size(level_text)[1]))
        self.image.blit(self.tower.image, (self.s_width/2 - self.tower.image.get_width()/2, 2))

        y_value = self.tower.image.get_width() + 7

        # Blits the tower description
        for desc in self.length_splitter(self.font, self.tower.description, self.image.get_width() - 5):
            self.image.blit(self.font.render(desc, 1, (0, 0, 0)), (5, y_value))
            y_value += self.font.get_height() + 1
        y_value += 5

        # Blits the tower's attributes in this order, tacking all extra stuff at the end
        for attr in ["Name", "Fire Rate", "Damage", "DPS", "Damage Done"]+extra_attributes.keys():
            value = self.t_attributes[attr]
            self.image.blit(self.font.render(attr + ": " + str(value), 1, (0, 0, 0)), (5, y_value))
            y_value += self.font.get_height() + 1
        #self.image = OutlinedSurface(self.image, 5).surface

    @staticmethod
    # Used to split text up into lines that will fit the surface
    def length_splitter(font, text, maxlength):
        ret_list = []
        explode = text.split()
        t_str = ""
        while len(explode) > 0:
            if font.size(t_str + explode[0])[0] > maxlength:
                ret_list.append(t_str)
                t_str = ""
            else:
                t_str += explode.pop(0) + " "
                if len(explode) == 0:
                    ret_list.append(t_str)
        return ret_list
开发者ID:brandonsturgeon,项目名称:Tower_Defense,代码行数:72,代码来源:tower_frame.py

示例7: Gameboard

# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import get_height [as 别名]

#.........这里部分代码省略.........
        
        
    def draw(self):
        self.gameSurface.fill((0,0,0))
        #self.gameSurface.fill((217,62,245))
        origin = (0, 0)
#        this_scroll = 0
        self.scroll_amount = 0
        if self.last_frame_time > 0:
            cur_time = self.default_timer()
            self.gap_time = cur_time - self.last_frame_time
#            print "Pixels per second: {0}\nGap Time: {1}\nScrollAmount: {2}".format(self.pixels_per_second, self.gap_time, this_scroll)
            self.last_frame_time = cur_time
        else:
            self.gap_time = 0
            self.last_frame_time = self.default_timer()
            
        this_scroll = self.pixels_per_second * self.gap_time
    
        self.frac_scroll += this_scroll
        if self.frac_scroll >= 1:
            self.scroll_amount = math.floor(self.frac_scroll)
            self.pixel_offset += self.scroll_amount
#            print "Now scrolling {0} pixel(s)".format(whole_part)
            self.frac_scroll -= self.scroll_amount

        if self.pixel_offset > 96:
            self.pixel_offset = self.pixel_offset - 96
            if self.pixel_offset < 0:
                self.pixel_offset = 0
                     
        self.gameSurface.blit(self.mainScreenBackground, origin)
        
        window_rect = Rect(self.pixel_offset, 0, self.gameSurface.get_width(), self.gameSurface.get_height()) 
#        print window_rect
        self.gameSurface.blit(self.backgroundSurface, origin, window_rect)
        
        #All other drawing
        self.bridge_group.update(self.scroll_amount)
        self.bridge_group.draw(self.gameSurface)
        
        self.mine_group.update(self.scroll_amount)
        self.mine_group.draw(self.gameSurface)
        
        self.enemy_group.update(self.scroll_amount)
        self.enemy_group.draw(self.gameSurface)
        
        self.samurai_sprite_group.update()
        self.samurai_sprite_group.draw(self.gameSurface) 
        
        self.healthpack_group.update(self.scroll_amount)
        self.healthpack_group.draw(self.gameSurface)
        
        self.ki_potion_group.update(self.scroll_amount)
        self.ki_potion_group.draw(self.gameSurface)
        
        self.shield_group.update(self.scroll_amount)
        self.shield_group.draw(self.gameSurface)
        
        self.sword_group.update(self.scroll_amount)
        self.sword_group.draw(self.gameSurface)
        
        #self.testSword = VerticalSlash(400,400)
        #self.attack_group.add(self.testSword)
        self.attack_group.update()
        self.attack_group.draw(self.gameSurface)
开发者ID:SamuraiJam,项目名称:SamuraiJam,代码行数:70,代码来源:Gameboard.py

示例8: Weapon

# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import get_height [as 别名]
class Weapon(Item):
    def __init__(self, game, name):
        """
        Slightly depreciated weapon class. Will need major rewriting.
        Used for loading and applying weapon characteristics to the player.
        """
        self.game = game
        #setup base vars of all weapon(s)
        self.type = None
        self.shown = True
        self.range = 10
        self.damage = 1
        self.cooldown = 500 # in MS
        self.speed = 4
        self.projectile = None
        self.loadWeapon(name)

        # attack based vars
        self.attacking = False

    def loadWeapon(self, name):
        """
        Uses the weapon config file to load all weapon characteristics.
        """
        config_file = open(os.path.join('rec', 'weapon', name, 'config.py')).read()
        exec(config_file)
        self.hold_image = img_load(os.path.join('rec', 'weapon', name, 'hold.png')).convert_alpha()
        if os.path.exists(os.path.join('rec', 'weapon', name, 'attack.png')):
            self.attack_image = img_load(os.path.join('rec', 'weapon', name, 'attack.png')).convert_alpha()
        else:
            self.attack_image = Surface([1, 1])

    def getSurface(self, name):
        fi_name = name.lower().replace(' ', '_') + '.png'
        return img_load(os.path.join(self.game.main_path, 'rec', 'weapon', name, fi_name))

    def preUpdate(self, ttime):
        """
        Called before the update function, can be overriden for new functionality.
        """
        pass

    def update(self, ttime):
        """
        Main weapon update, should not be overriden.
        """
        self.preUpdate(ttime)
        if self.type == 'short':
            self.shortUpdate()
        elif self.type == 'long':
            self.longUpdate()
        elif self.type == 'ranged':
            self.rangedUpdate()
        else:
            pass

    def shortAttack(self):
        self.attacking = True
        if self.game.Player.player_face == 'front':
            # I do not know why this vector needs to be 0 while the others are like, 1
            self.directional_attack_image = rotate(self.attack_image, 180)
            self.sub_vector = [0, 0]
        elif self.game.Player.player_face == 'left':
            self.directional_attack_image = rotate(self.attack_image, 90)
            self.sub_vector = [-1, 0]
        elif self.game.Player.player_face == 'back':
            self.directional_attack_image = rotate(self.attack_image, 0)
            self.sub_vector = [0, -1]
        elif self.game.Player.player_face == 'right':
            self.directional_attack_image = rotate(self.attack_image, 270)
            self.sub_vector = [0.8, 0] # editing this seems to change the speed of the right dagger swing a bit

        self.game.Player.can_move = False
        self.receding = False
        self.potent = True
        self.weapon_rect = Rect(1, 1, 1, 1)
        p_coords = [self.game.Player.player_r.x, self.game.Player.player_r.y]
        a_coords = [p_coords[0] + self.game.Player.getRigging()[0], p_coords[1] + self.game.Player.getRigging()[1]]
        if self.game.Player.player_face == 'right' or self.game.Player.player_face == 'left':
            a_coords = [a_coords[0] - self.attack_image.get_height(), a_coords[1] - self.attack_image.get_width()]
        self.blit_pos = a_coords
        self.attack_ticks = self.range


    def shortUpdate(self):
        if self.attacking:
            for repeats in xrange(self.speed):
                self.game.Player.player_state = 3
                self.blit_pos[0] += self.sub_vector[0]
                self.blit_pos[1] += self.sub_vector[1]
                if self.receding:
                    self.attack_ticks += 1
                elif not self.receding:
                    self.attack_ticks -= 1
                # check all monsters for touching weapon
                for index, monster in enumerate(self.game.EntityHandler.monsters):
                    if monster.rect.colliderect(self.weapon_rect):
                        if self.potent:
                            monster.takeDamage(index, self.damage)
                            self.potent = False
#.........这里部分代码省略.........
开发者ID:ajay05,项目名称:Necromonster,代码行数:103,代码来源:equipment.py

示例9: Buffalo

# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import get_height [as 别名]
class Buffalo():
	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
		
	def update(self):
		self.preimage = image.load(self.resourcePath + "img/" + self.status + "_buffalo.png")
		self.image = scale(self.preimage, (int(self.preimage.get_width() * self.size),
										   int(self.preimage.get_height() * self.size)))
										   
		self.healthBarContainer = Surface((int(75 * self.size), int(12 * self.size))).convert()
		self.healthNumber = self.healthFont.render(str(int(self.health)), 1, (255, 255, 255))
		self.healthBarShader = Surface((self.healthBarContainer.get_width() + 6,
										self.healthBarContainer.get_height() + 6)).convert()
		self.healthBarShader.fill((175, 175, 175))
		if (self.health <= 0):
			self.healthBar = Surface((0, 0)).convert()
		else:
			self.healthBar = Surface((int(self.healthBarContainer.get_width() / self.maxHealth * self.health),
											self.healthBarContainer.get_height())).convert()
											
			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.healthBarContainer.blit(self.healthNumber, (self.healthBarContainer.get_width() / 2 -
														 self.healthNumber.get_width() / 2,
														 self.healthBarContainer.get_height() / 2 -
														 self.healthNumber.get_height() / 2))
		self.healthBarShader.blit(self.healthBarContainer, (3, 3))
		
		if (self.status == "alive"):
			self.rect.x += float(3 - self.size)
			if (self.rect.y != self.targetY):
				if (self.rect.y < self.targetY):
					self.rect.y += float(3 - self.size)
				elif (self.rect.y > self.targetY):
					self.rect.y -= float(3 - self.size)
			return self.rect.center
开发者ID:ZakFarmer,项目名称:OregonTrail,代码行数:76,代码来源:buffalo.py

示例10: surface_with_node

# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import get_height [as 别名]
def surface_with_node(surface, node, angle, offset_in, current_resize_offset, widthscalar, heightscalar):
    transformedlists = transformtopointlists(node.plantshapelist,
                                        node.shiftchance, angle,
                                        widthscalar, heightscalar)

    mainloffset = None
    mainltranslated = None

    def currentoffset():
        return (offset_in[0] + current_resize_offset[0], offset_in[1] + current_resize_offset[1])

    def surface_offset(pointlist_bounds):
        return Rect(currentoffset()[0]-node.anchor[0]+pointlist_bounds[0], currentoffset()[1]-node.anchor[1]+pointlist_bounds[1], pointlist_bounds.width, pointlist_bounds.height)

    # go through all the plantshapes and their corresponding transformed lists
    for i in range(len(transformedlists)):
        currentlist = transformedlists[i]
        bounds = getlistbounds(currentlist)

        # make the surface
        shape_surface = Surface((bounds.width, bounds.height), SRCALPHA)
        # translate points into this surface
        shiftedlist = offsetpointlist(currentlist, (-bounds[0], -bounds[1]))

        # draw the plant shape onto the new surface
        plantshape = node.plantshapelist[i]
        if plantshape.fillcolor != None:
        
            gfxdraw.filled_polygon(shape_surface, shiftedlist, plantshape.fillcolor)
        if plantshape.outlinecolor != None:
            gfxdraw.polygon(shape_surface, shiftedlist, plantshape.outlinecolor)


        # apply the texture if any
        for ptexture in plantshape.textures:
            addtexture(shape_surface, ptexture)

            
        # now check if resizing is needed
        newsurfacerect = surface.get_rect().union(surface_offset(bounds))
        
        if not newsurfacerect == surface.get_rect():
            
            new_surface = Surface((newsurfacerect.width, newsurfacerect.height), SRCALPHA)
            new_surface.blit(surface, (-newsurfacerect.x, -newsurfacerect.y))

            current_resize_offset = (current_resize_offset[0]-newsurfacerect.x, current_resize_offset[1]-newsurfacerect.y)

            surface = new_surface
            
            devprint("Resized surface to " + str(new_surface.get_width()) + " by " + str(new_surface.get_height()))

        surface.blit(shape_surface, surface_offset(bounds))

        # also save the first list for other nodes to go off of
        if i == 0:
            # save the offset of l without the resizing
            mainloffset = surface_offset(bounds)
            # also remove the current resize offset
            mainloffset = (mainloffset[0] - current_resize_offset[0], mainloffset[1]-current_resize_offset[1])
            mainltranslated = shiftedlist
            
            
    return surface, mainltranslated, mainloffset, current_resize_offset
开发者ID:oflatt,项目名称:pythonRpgProject,代码行数:66,代码来源:drawplant.py

示例11: __init__

# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import get_height [as 别名]
class SnakeUI:
    """Snake's game menu

    """
    def __init__(self, main_ui, game=None):
        if game != None:
            self.snake_game = game
        else:
            level_manager = LevelManager(LEVELS_DIRECTORY)
            self.snake_game = Game(level_manager)
        self.last_move = GameMoves.PASS
        self.main_ui = main_ui
        level = self.snake_game.current_level
        self.maze_size = (level.maze_height, level.maze_width)
        self.game_surface = Surface(transform(self.maze_size, 2, 2))
        #colors and images
        self.green_color = Color(151, 255, 148)
        self.white_color = Color(255, 255, 255)
        self.black_color = Color(0, 0, 0)
        self.apple = image.load('images/apple.png')
        self.block = image.load('images/block.png')
        self.brick = image.load('images/brick.jpg')
        #fonts
        self.info_font = font.Font(None, 23)
        self.is_running = True

    def draw(self):
        if self.is_running and self.main_ui.frame % GUI_GAME_SPEED == 0:
            self.snake_game.move(self.last_move)
            self.last_move = GameMoves.PASS
        level = self.snake_game.current_level
        if self.maze_size != (level.maze_width, level.maze_height):
            self.maze_size = (level.maze_height, level.maze_width)
            self.game_surface = Surface(transform(self.maze_size, 2, 2))
        self.game_surface.fill(self.green_color)
        self.__draw_apple()
        self.__draw_snake()
        self.__draw_barrier()
        self.__draw_level_info()
        surface_width = self.main_ui.surface.get_width()
        surface_height = self.main_ui.surface.get_height()
        game_width = self.game_surface.get_width()
        game_height = self.game_surface.get_height()
        y_pos = surface_width / 2 - game_width / 2
        x_pos  = surface_height / 2 - game_height / 2
        game_surface_pos = (y_pos, x_pos)
        self.main_ui.surface.blit(self.game_surface, game_surface_pos)

    def __draw_apple(self):
        apple_position = transform(self.snake_game.current_level.apple, 1, 1)
        self.game_surface.blit(self.apple, apple_position)

    def __draw_snake(self):
        level = self.snake_game.current_level
        for block in level.snake:
            self.game_surface.blit(self.block, transform(block, 1, 1))

    def __draw_barrier(self):
        level = self.snake_game.current_level
        for brick in level.barrier:
            self.game_surface.blit(self.brick, transform(brick, 1, 1))
        brick_height = self.brick.get_height()
        brick_width = self.brick.get_width()
        maze_height = self.game_surface.get_height()
        maze_width = self.game_surface.get_width()
        for x in range(0, maze_width, brick_width):
            self.game_surface.blit(self.brick, (x, 0))
        for x in range(0, maze_width, brick_width):
            self.game_surface.blit(self.brick, (x, maze_height - brick_height))
        for y in range(0, maze_height, brick_height):
            self.game_surface.blit(self.brick, (0, y))
        for y in range(0, maze_height, brick_height):
            self.game_surface.blit(self.brick, (maze_width - brick_width, y))

    def __draw_level_info(self):
        level = self.snake_game.current_level
        current_level = level.level
        snake_len = level.snake_length
        snake_max_len = level.snake_max_length
        info ='Level: {0} Snake Length: {1}/{2}'\
            .format(current_level, snake_len, snake_max_len)
        info_surface = self.info_font.render(info, False, self.black_color)
        self.main_ui.surface.blit(info_surface, (10, 10))

    def handle_events(self):
        for current_event in pygame.event.get():
            if current_event.type == QUIT:
                pygame.quit()
                sys.exit()
            elif  current_event.type == KEYDOWN:
                if current_event.key == K_LEFT:
                   self.last_move = GameMoves.LEFT
                elif current_event.key == K_RIGHT:
                    self.last_move = GameMoves.RIGHT
                elif current_event.key == K_UP:
                    self.last_move = GameMoves.UP
                elif current_event.key == K_DOWN:
                    self.last_move = GameMoves.DOWN
                elif current_event.key == K_ESCAPE:
                    self.main_ui.state = GameMenuUI(self.main_ui, self)
开发者ID:ngkolev,项目名称:snake,代码行数:102,代码来源:snakegui.py

示例12: Shop

# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import get_height [as 别名]
class Shop():
	def __init__(self, name, inventory, priceModifier, groupInventory, groupMoney, itemPrices, position, blitPosition, money, resourcePath):
		self.yValue = 40
		self.groupInventory = groupInventory
		self.groupMoney = groupMoney
		self.priceModifier = priceModifier
		self.itemPrices = itemPrices
		self.inventory = inventory
		self.position = position
		self.blitPosition = blitPosition
		self.resourcePath = resourcePath
		self.buyButtonList = []
		self.sellButtonList = []
		self.xPos = (-self.position * 40) + 1280
		
		self.shopSurface = Surface((500, 300)).convert()
		self.sepLine = Surface((self.shopSurface.get_width(), 10)).convert()
		self.sepLine.fill((0, 0, 0))
		
		self.invContainer = Surface((self.shopSurface.get_width() - 20,
									 self.shopSurface.get_height() / 2 - 35)).convert()
		self.invContainer.fill((255, 255, 255))
		self.titleFont = font.Font("res/fonts/west.ttf", 17)
		self.textFont = font.Font("res/fonts/west.ttf", 15)
		
		if (name == ""):
			self.name = (choice(SHOP_PREFIX) + "'s " + choice(SHOP_SUFFIX)).capitalize()
		else:
			self.name = name
			
		if (self.inventory == {}):
			inventoryRandom = copy(self.groupInventory)
			for key in list(inventoryRandom.keys()):
				inventoryRandom[key] = randint(0, 10)
				
			inventoryRandom["Food"] *= 20
			self.inventory = inventoryRandom
			
		if (money is None):
			self.money = randint(200, 500)
		else:
			self.name = name
		self.render()
		
	def get_surface(self):
		self.render()
		return self.shopSurface
		
	def update(self, groupInv, groupMoney):
		self.groupInventory = groupInv
		self.groupMoney = groupMoney
		self.render()
		
	def move(self, moveValue):
		self.xPos += (2 * moveValue)
		self.render()
		
	def render(self):
		self.yValue = 40
		self.shopSurface.fill((133, 94, 66))
		self.shopSurface.blit(self.titleFont.render(self.name + " - $" + str(self.money), 1, (0, 0, 255)), (10, 5))
		self.shopSurface.blit(self.invContainer, (10, 25))
		self.shopSurface.blit(self.invContainer, (10, self.shopSurface.get_height() / 2 + 30))
		self.shopSurface.blit(self.textFont.render("Inventory", 1, (255, 0, 0)), (10, 25))
		self.shopSurface.blit(self.textFont.render("Amount", 1, (255, 0, 0)), (130, 25))
		self.shopSurface.blit(self.textFont.render("Price", 1, (255, 0, 0)), (200, 25))
		
		for key in list(self.inventory.keys()):
			self.shopSurface.blit(self.textFont.render(key + ":", 1, (0, 0, 0)), (10, self.yValue))
			self.shopSurface.blit(self.textFont.render(str(self.inventory[key]), 1,
													   (0, 0, 0)), (150, self.yValue))
			self.shopSurface.blit(self.textFont.render("$"+str(self.itemPrices[key] * self.priceModifier), 1, 
													   (0, 0, 0)), (200, self.yValue))
			if (len(self.buyButtonList) < len(self.inventory.keys())):
				buttonPos = tuple(map(sum, zip(self.blitPosition, (250, self.yValue))))
				self.buyButtonList.append(TransactionButton(transaction = "buy",
															item = key,
															imagePosition = (250, self.yValue),
															rectPosition = buttonPos,
															resourcePath = self.resourcePath))
			self.yValue += 30
			
		for button in self.buyButtonList:
			self.shopSurface.blit(button.image, button.imagePosition)
			
		self.shopSurface.blit(self.sepLine, (0, float(self.shopSurface.get_height()) / 2))
		self.shopSurface.blit(self.titleFont.render("You - $" + str(self.groupMoney), 1, (0, 0, 255)),
												    (10, float(self.shopSurface.get_height()) / 2 + 10))
		self.shopSurface.blit(self.titleFont.render("Inventory", 1, (255, 0, 0)),
													(10, float(self.shopSurface.get_height()) / 2 + 30))
		self.shopSurface.blit(self.titleFont.render("Amount", 1, (255, 0, 0)),
													(130, float(self.shopSurface.get_height()) / 2 + 30))
		self.shopSurface.blit(self.titleFont.render("Price", 1, (255, 0, 0)),
													(200, float(self.shopSurface.get_height()) / 2 + 30))
													
		self.yValue = (float(self.shopSurface.get_height()) / 2) + 45
		
		
		for key in list(self.groupInventory.keys()):
			self.shopSurface.blit(self.textFont.render(key + ":", 1, (0, 0, 0)), (10, self.yValue))
#.........这里部分代码省略.........
开发者ID:ZakFarmer,项目名称:OregonTrail,代码行数:103,代码来源:shop.py

示例13: change_vaus_behavior

# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import get_height [as 别名]
def change_vaus_behavior(state, vaus):
    if state == 'C':
        pass
    elif state == 'L':
        '''
        VAUS LASER
        '''
        surfaces = []
        laser_sheet_area = Surface((160, 8))    # 32 * 5
        laser1_posx = 0
        laser2_posx = 32
        laser3_posx = 64
        laser4_posx = 96
        laser5_posx = 128

        # En este caso el área 1 coincide con el área del recuadro para el estado inicial
        area1 = (0, 0, 32, 8)
        surfaces.append(area1)

        area2 = Surface((32, 8))
        area2_borderlaser = (64, 8, 8, 8)
        area2_normalbody = (80, 0, 8, 7)
        area2_borderright = (112, 0, 8, 8)  # borde izquierdo vaus láser
        area2.blit(vaus.animation_sheet.subsurface(area2_borderlaser), (0, 0))
        area2.blit(vaus.animation_sheet.subsurface(area2_normalbody), (8, 0))
        area2.blit(vaus.animation_sheet.subsurface(area2_normalbody), (16, 0))
        area2.blit(vaus.animation_sheet.subsurface(area2_borderright), (24, 0))
        surfaces.append((laser2_posx, 0, area2.get_width(), area2.get_height()))

        area3 = Surface((32, 8))
        # Vamos reciclando piezas del vaus láser de áreas anteriores (por ejemplo, podemos reusar el borde del láser)
        area3_laserbody = (80, 8, 8, 7)
        area3.blit(vaus.animation_sheet.subsurface(area2_borderlaser), (0, 0))
        area3.blit(vaus.animation_sheet.subsurface(area3_laserbody), (8, 0))
        area3.blit(vaus.animation_sheet.subsurface(area2_normalbody), (16, 0))
        area3.blit(vaus.animation_sheet.subsurface(area2_borderright), (24, 0))
        surfaces.append((laser3_posx, 0, area3.get_width(), area3.get_height()))

        area4 = Surface((32, 8))
        area4.blit(vaus.animation_sheet.subsurface(area2_borderlaser), (0, 0))
        area4.blit(vaus.animation_sheet.subsurface(area3_laserbody), (8, 0))
        area4.blit(vaus.animation_sheet.subsurface(area3_laserbody), (16, 0))
        area4.blit(vaus.animation_sheet.subsurface(area2_borderright), (24, 0))
        surfaces.append((laser4_posx, 0, area4.get_width(), area4.get_height()))

        area5 = (0, 16, 32, 8)
        surfaces.append((laser5_posx, 0, area5[2], area5[3]))

        laser_sheet_area.blit(vaus.animation_sheet.subsurface(area1), (laser1_posx, 0))
        laser_sheet_area.blit(area2, (laser2_posx, 0))
        laser_sheet_area.blit(area3, (laser3_posx, 0))
        laser_sheet_area.blit(area4, (laser4_posx, 0))
        laser_sheet_area.blit(vaus.animation_sheet.subsurface(area5), (laser5_posx, 0))

        vaus.animation_sheet = laser_sheet_area
        vaus.frames = 5
        vaus.current_frame = 0
        vaus.animate = True
        vaus.shoot = True
        return surfaces

    elif state == 'E':
        '''
        VAUS ELONGATED
        '''
        # Creamos superficie uniendo subsuperficies de una misma sprite sheet
        # 4 fotogramas
        # Listado en blanco de áreas, sobre el que se iterará en play_animation() (sprite_factory.py)
        surfaces = []
        elongated_sheet_area = Surface((120, 8))
        elongated1_posx = 0
        elongated2_posx = 32    # Ancho elongated1
        elongated3_posx = 72   # Ancho elongated1 más ancho elongated2 (32 + 40 = 72)
        # areax = área calculada DE LA SPRITE SHEET ORIGINAL
        # Original: 32x8
        # Esta primera área vale tanto para el sprite en la original como para el sprite en la nueva sprite sheet
        area1 = (0, 0, 32, 8)
        surfaces.append(area1)

        # Elongated 1: 40x8
        area2 = Surface((40, 8))
        area2_borderleft = (64, 0, 8, 8)
        area2_center = (80, 0, 8, 7)  # x3
        area2_borderright = (112, 0, 8, 8)
        area2.blit(vaus.animation_sheet.subsurface(area2_borderleft), (0, 0))
        area2.blit(vaus.animation_sheet.subsurface(area2_center), (8, 0))
        area2.blit(vaus.animation_sheet.subsurface(area2_center), (16, 0))
        area2.blit(vaus.animation_sheet.subsurface(area2_center), (24, 0))
        area2.blit(vaus.animation_sheet.subsurface(area2_borderright), (32, 0))
        # Ubicación del segundo sprite en la nueva sprite sheet
        surfaces.append((elongated2_posx, 0, area2.get_width(), area2.get_height()))

        # Elongated final: 48x8
        area3 = (0, 8, 48, 8)
        # Ubicación del tercer sprite en la nueva sprite sheet
        surfaces.append((elongated3_posx, 0, area3[2], area3[3]))

        # Pintamos las áreas en la superficie en blanco
        elongated_sheet_area.blit(vaus.animation_sheet.subsurface(area1), (elongated1_posx, 0))
        elongated_sheet_area.blit(area2, (elongated2_posx, 0))
#.........这里部分代码省略.........
开发者ID:skeleborg,项目名称:pyrkanoid,代码行数:103,代码来源:powerups.py

示例14: Shop

# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import get_height [as 别名]
class Shop():
    def __init__(self, name, inventory, price_mod, group_inventory,
                 group_money, item_prices, position, blit_position, money, resource_path):
        self.yvalue = 40
        self.group_inventory = group_inventory
        self.group_money = group_money
        self.price_mod = price_mod
        self.item_prices = item_prices
        self.inventory = inventory
        self.position = position
        self.blit_position = blit_position
        self.resource_path = resource_path
        self.buy_button_list = []
        self.sell_button_list = []
        # TODO: figure out what these magic numbers mean
        self.x_pos = (-self.position * 40) + 1280

        # Gui stuff #

        # Main Window
        self.shop_surface = Surface((500, 300)).convert()
        # Separator Line
        self.sep_line = Surface((self.shop_surface.get_width(), 10)).convert()
        self.sep_line.fill((0, 0, 0))
        # Inventory container box
        self.inv_container = Surface((self.shop_surface.get_width()-20,
                                             self.shop_surface.get_height()/2 - 35)).convert()
        self.inv_container.fill((255, 255, 255))
        # Font creation
        self.title_font = font.Font(None, 30)
        self.text_font = font.Font(None, 20)

        # Random name generation
        if name == "":
            self.name = capitalize(choice(SHOP_NAME_PREFIX) + "'s " + choice(SHOP_NAME_SUFFIX))
        else:
            self.name = name
        # Random inventory generation
        if self.inventory == {}:
            # TODO: The shop should have random items, not just what the group currently has
            inventory_random = copy(self.group_inventory)

            # Assign a random value between 1,10 to each inventory item
            for key in list(inventory_random.keys()):
                inventory_random[key] = randint(0, 10)

            # Inflate food count
            inventory_random["Food"] *= 20
            self.inventory = inventory_random

        # Random money generation
        if money is None:
            self.money = randint(200, 500)
        else:
            self.name = name
        self.render()

    # Used to get the surface created in self.render()
    def get_surface(self):
        self.render()
        return self.shop_surface

    # Updates the group_inv and group_money to blit in self.render
    def update(self, group_inv, group_m):
        self.group_inventory = group_inv
        self.group_money = group_m
        self.render()

    def move(self, move_value):
        self.x_pos += (2 * move_value)
        self.render()

    def render(self):
        self.yvalue = 40
        self.shop_surface.fill((133, 94, 66))
        self.shop_surface.blit(self.title_font.render(self.name + " - $"+str(self.money), 1, (0, 0, 255)), (10, 5))
        self.shop_surface.blit(self.inv_container, (10, 25))
        self.shop_surface.blit(self.inv_container, (10, self.shop_surface.get_height()/2 + 30))
        self.shop_surface.blit(self.text_font.render("Inventory", 1, (255, 0, 0)), (10, 25))
        self.shop_surface.blit(self.text_font.render("Amount", 1, (255, 0, 0)), (130, 25))
        self.shop_surface.blit(self.text_font.render("Price", 1, (255, 0, 0)), (200, 25))

        #Blit the shop's inventory
        for key in list(self.inventory.keys()):
            self.shop_surface.blit(self.text_font.render(key+":", 1, (0, 0, 0)), (10, self.yvalue))
            self.shop_surface.blit(self.text_font.render(str(self.inventory[key]), 1,
                                                        (0, 0, 0)), (150, self.yvalue))
            self.shop_surface.blit(self.text_font.render("$"+str(self.item_prices[key]*self.price_mod), 1,
                                                        (0, 0, 0)), (200, self.yvalue))
            if len(self.buy_button_list) < len(self.inventory.keys()):
                button_pos = tuple(map(sum, zip(self.blit_position, (250, self.yvalue))))
                self.buy_button_list.append(TransactionButton(transaction="buy",
                                                              item=key,
                                                              image_position=(250, self.yvalue),
                                                              rect_position=button_pos,
                                                              resource_path=self.resource_path))
            self.yvalue += 30

        # Shows each button
        for button in self.buy_button_list:
#.........这里部分代码省略.........
开发者ID:brandonsturgeon,项目名称:Oregon_Trail,代码行数:103,代码来源:shop.py

示例15: Surface

# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import get_height [as 别名]
from factions import *

pygame.init()

screen = display.set_mode((800,600),HWSURFACE)
display.set_caption('Regime Change')

background = Surface(screen.get_size())
background.fill((128,128,128))

text = font.SysFont('Courier', 10)

plot = background.subsurface(Rect(0,
                                  0,
                                  background.get_width(),
                                  background.get_height()/2))
chart = background.subsurface(Rect(0,
                                   plot.get_height(),
                                   background.get_width(),
                                   background.get_height()-plot.get_height()))

values = 'militarism', 'moralism'
society = Society([Faction('aristocracy', (0,0,255), random(), values),
                   Faction('merchant class', (0,255,0), random(), values),
                   Faction('populace', (255,0,0), random(), values)])
for f in society.factions:
    for v in f.values.keys():
        f.values[v] = random()

charts = [chart.subsurface(Rect(i * chart.get_width()/len(society.factions),
                                0,
开发者ID:tps12,项目名称:Dorftris,代码行数:33,代码来源:regimes.py


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