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


Python Rect.height方法代码示例

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


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

示例1: get_item_at_pos

# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import height [as 别名]
    def get_item_at_pos (self, position):
        """L.get_item_at_pos (...) -> ListItem

        Gets the item at the passed position coordinates.
        """
        eventarea = self.rect_to_client ()
        if not eventarea.collidepoint (position):
            return None
        position = position[0] - eventarea.left, position[1] - eventarea.top
        
        border = base.GlobalStyle.get_border_size \
                 (self.__class__, self.style,
                  StyleInformation.get ("ACTIVE_BORDER")) * 2

        posy = self.vadjustment
        items = self.scrolledlist.items
        width = eventarea.width
        bottom = eventarea.bottom
        images = self.images
        spacing = self.scrolledlist.spacing

        for item in items:
            rect = Rect (images [item][1])
            rect.y = posy
            rect.width = width + border
            if rect.bottom > bottom:
                rect.height = bottom - rect.bottom + border
            if rect.collidepoint (position):
                return item
            posy += images[item][1].height + spacing + border
        return None
开发者ID:BGCX067,项目名称:eyestabs-svn-to-git,代码行数:33,代码来源:ListViewPort.py

示例2: update_body

# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import height [as 别名]
    def update_body(self):
        cell.Cell.update_body(self)

        val  = self.input("A0") * 1
        val += self.input("A1") * 2
        val += self.input("A2") * 4
        val += self.input("A3") * 8
        val += self.input("A4") * 16
        val += self.input("A5") * 32
        val += self.input("A6") * 64
        val += self.input("A7") * 128
                
        h = int(self.rect_rel.height / 3);
        pos = Rect(self.rect_rel)
        pos.height = h
        self.parent.draw_text(self.surface, "%02X" % val, pos)
        
        pos = Rect(self.rect_rel)
        pos.y = h * 1
        pos.height = h
        self.parent.draw_text(self.surface, "%03u" % val, pos)
        
        if (val < 0b01111111):
            sig = val
        else:
            sig = -(256 - val)
        
        pos = Rect(self.rect_rel)
        pos.y = h * 2
        pos.height = h
        self.parent.draw_text(self.surface, "%+04d" % sig, pos)
开发者ID:fhorinek,项目名称:pi8bit,代码行数:33,代码来源:outputs.py

示例3: create_platforms_rect

# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import height [as 别名]
	def create_platforms_rect(self, tiles, layer):
		""" Create a collision rect for each non-empty tile segment, that is, one or more tiles together """
		if len(tiles) < 1:
			return False

		x, y = tiles.pop(0)
		width = self.map.content['tilewidth']
		height = self.map.content['tileheight']
		rect = Rect((0, 0, 0, 0))
		rect.left = x * width
		rect.top = y * height
		rect.width = width
		rect.height = height
		# self.platforms.append(Platform(rect, layer))
		n_tiles_x, n_tiles_y = 0, 0

		# exclude the tiles we're about to create a platform for
		excluded_tiles = []
		for (n_x, n_y) in tiles:
			if abs(n_x - x) == n_tiles_x and n_y == y:
				rect.width += width
				n_tiles_x += 1
				excluded_tiles.append((n_x, n_y))
			if abs(n_y - y) == n_tiles_y and n_x == x:
				rect.height += height
				n_tiles_y += 1
				excluded_tiles.append((n_x, n_y))

		self.platforms.append(Platform(rect, layer))
		self.create_platforms_rect([t for t in tiles if not t in excluded_tiles], layer)
开发者ID:glhrmfrts,项目名称:rgb,代码行数:32,代码来源:physics.py

示例4: draw_sprite

# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import height [as 别名]
    def draw_sprite(self, sprite, ratio=None):
        if ratio is None:
            ratio = self.ratio

        # calculate the size of the shadow
        w = sprite.rect.width * ratio + 1
        h = w/2
        rect = Rect(0,0,w,h)
        
        # shrink the shadow according to height
        if hasattr(sprite, "height"):
            height0 = sprite.__class__.height
            ratio = (height0 - sprite.height) / float(height0)
            rect.width = max(8, rect.width * ratio)
            rect.height = max(4, rect.height * ratio)

        # move the the midbottom of the sprite
        rect.center = sprite.rect.midbottom
        rect.x -= 1
        rect.y -= 3

        # if the sprite has a height property, use it to move the shadow
        if hasattr(sprite, "height"):
            rect.y += sprite.height


        # draw to the layer
        pygame.draw.ellipse(self._layer, self.color, rect)
开发者ID:HampshireCS,项目名称:CS112-Spring2012,代码行数:30,代码来源:shadows.py

示例5: test_height

# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import height [as 别名]
 def test_height( self ):
     "Changing the height resizes the rect from the top-left corner"
     r = Rect( 1, 2, 3, 4 )
     new_height = 10
     old_topleft = r.topleft
     old_width = r.width
     
     r.height = new_height
     self.assertEqual( new_height, r.height )
     self.assertEqual( old_width, r.width )
     self.assertEqual( old_topleft, r.topleft )
开发者ID:CTPUG,项目名称:pygame_cffi,代码行数:13,代码来源:rect_test.py

示例6: update_body

# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import height [as 别名]
    def update_body(self):
        cell.Cell.update_body(self)
        
        h = int(self.rect_rel.height / 4);
        pos = Rect(self.rect_rel)
        pos.height = h
        self.parent.draw_text(self.surface, "MEMORY", pos)
        
        pos = Rect(self.rect_rel)
        pos.y = h * 1
        pos.height = h
        self.parent.draw_text(self.surface, self.filename, pos)
        
        pos = Rect(self.rect_rel)
        pos.y = h * 2
        pos.height = h
        self.parent.draw_text(self.surface, "address: %04X" % self.address, pos)

        pos = Rect(self.rect_rel)
        pos.y = h * 3
        pos.height = h
        self.parent.draw_text(self.surface, "data: %02X" % self.data, pos)
开发者ID:fhorinek,项目名称:pi8bit,代码行数:24,代码来源:memory.py

示例7: makeRooms

# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import height [as 别名]
    def makeRooms(self):
        numRooms = random.randint(NUMROOMSMIN, NUMROOMSMAX)
         
        for roomID in range(numRooms):
            attempts = 0
            room = Rect(0,0,0,0)
            room.width = random.randint(ROOMMIN, ROOMMAX)
            room.height = random.randint(ROOMMIN, ROOMMAX)

            posFound = False
            while not posFound:
                if attempts == MAXROOMALLOCATTEMPTS:
                    #print("Could not resolve room placement for room %i, bailing" % (roomID+1))
                    break

                room.x = random.randint(2, WORLDSIZE[0] - 1)
                room.y = random.randint(5, WORLDSIZE[1] - 1)

                if (room.x + room.width) >= (WORLDSIZE[0] - 1) or (room.y + room.height) >= (WORLDSIZE[1] - 4):
                    attempts += 1
                    continue

                posFound = True

                for r,w in self.roomInfo:
                    if r.inflate(2*ROOMSPACING, 2*ROOMSPACING).colliderect(room):
                        posFound = False
                        attempts += 1
                        break

            if not posFound:
                continue 

            #Place waypoint
            wpX = random.randint(room.x + 1 + int(CORTHICKNESS / 2), room.x + room.width - 1 - int(CORTHICKNESS / 2))
            wpY = random.randint(room.y + 1 + int(CORTHICKNESS / 2), room.y + room.height - 1 - int(CORTHICKNESS / 2) )
            self.roomInfo.append( (room, (wpX, wpY)) )

            for x in range(room.x, room.x + room.width):
                for y in range(room.y, room.y + room.height):
                    self.mapGrid[x][y] = "#"

        #Sort rooms in order of Y coordinates
        self.roomInfo.sort(key=lambda r: r[0].y)
开发者ID:nojan1,项目名称:closeQuarters,代码行数:46,代码来源:levelgen.py

示例8: calculateIntersectPoint

# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import height [as 别名]
def calculateIntersectPoint(p1, p2, p3, p4):
  
   p = getIntersectPoint(p1, p2, p3, p4)
  
   if p is not None:               
       width = p2[0] - p1[0]
       height = p2[1] - p1[1]       
       r1 = Rect(p1, (width , height))
       r1.normalize()
      
       width = p4[0] - p3[0]
       height = p4[1] - p3[1]
       r2 = Rect(p3, (width, height))
       r2.normalize()              
 
       # Ensure both rects have a width and height of at least 'tolerance' else the
       # collidepoint check of the Rect class will fail as it doesn't include the bottom
       # and right hand side 'pixels' of the rectangle
       tolerance = 1
       if r1.width &lt; tolerance:
        r1.width = tolerance
                    
       if r1.height &lt; tolerance:
        r1.height = tolerance
开发者ID:Exodus111,项目名称:Infinite-Adventure,代码行数:26,代码来源:geometry.py

示例9: intersection_pt

# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import height [as 别名]
def intersection_pt(p1, p2, p3, p4):
  
	p = getIntersectPoint(p1, p2, p3, p4)
  
	if p is not None:               
		width = p2[0] - p1[0]
		height = p2[1] - p1[1]       
		r1 = Rect(p1, (width , height))
		r1.normalize()

		width = p4[0] - p3[0]
		height = p4[1] - p3[1]
		r2 = Rect(p3, (width, height))
		r2.normalize()              
 
	   # Ensure both rects have a width and height of at least 'tolerance' else the
	   # collidepoint check of the Rect class will fail as it doesn't include the bottom
	   # and right hand side 'pixels' of the rectangle
		tolerance = 1
		if r1.width <tolerance:
			r1.width = tolerance
					
		if r1.height <tolerance:
			r1.height = tolerance
		
		if r2.width <tolerance:
			r2.width = tolerance
					
		if r2.height <tolerance:
			r2.height = tolerance
 
		for point in p:                 
			try:    
				res1 = r1.collidepoint(point)
				res2 = r2.collidepoint(point)
				if res1 and res2:
					point = [int(pp) for pp in point]                                
					return point
			except:
				# sometimes the value in a point are too large for PyGame's Rect class
				str = "point was invalid  ", point                
				print str
				
		# This is the case where the infinately long lines crossed but 
		# the line segments didn't
		return None            
	
	else:
		return None
		
		
# # Test script below...
# if __name__ == "__main__":
 
# 	# line 1 and 2 cross, 1 and 3 don't but would if extended, 2 and 3 are parallel
# 	# line 5 is horizontal, line 4 is vertical
# 	p1 = (1,5)
# 	p2 = (4,7)
	
# 	p3 = (4,5)
# 	p4 = (3,7)
	
# 	p5 = (4,1)
# 	p6 = (3,3)
	
# 	p7 = (3,1)
# 	p8 = (3,10)
	
# 	p9 =  (0,6)
# 	p10 = (5,6)
	
# 	p11 = (472.0, 116.0)
# 	p12 = (542.0, 116.0)  
	
# 	assert None != calculateIntersectPoint(p1, p2, p3, p4), "line 1 line 2 should intersect"
# 	assert None != calculateIntersectPoint(p3, p4, p1, p2), "line 2 line 1 should intersect"
# 	assert None == calculateIntersectPoint(p1, p2, p5, p6), "line 1 line 3 shouldn't intersect"
# 	assert None == calculateIntersectPoint(p3, p4, p5, p6), "line 2 line 3 shouldn't intersect"
# 	assert None != calculateIntersectPoint(p1, p2, p7, p8), "line 1 line 4 should intersect"
# 	assert None != calculateIntersectPoint(p7, p8, p1, p2), "line 4 line 1 should intersect"
# 	assert None != calculateIntersectPoint(p1, p2, p9, p10), "line 1 line 5 should intersect"
# 	assert None != calculateIntersectPoint(p9, p10, p1, p2), "line 5 line 1 should intersect"
# 	assert None != calculateIntersectPoint(p7, p8, p9, p10), "line 4 line 5 should intersect"
# 	assert None != calculateIntersectPoint(p9, p10, p7, p8), "line 5 line 4 should intersect"
	
# 	print "\nSUCCESS! All asserts passed for doLinesIntersect"
开发者ID:manikantareddyd,项目名称:Unsupervised-Learning-Manifolds,代码行数:88,代码来源:geometry.py

示例10: Rect

# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import height [as 别名]
       r1.normalize()
      
       width = p4[0] - p3[0]
       height = p4[1] - p3[1]
       r2 = Rect(p3, (width, height))
       r2.normalize()              

       # Ensure both rects have a width and height of at least 'tolerance' else the
       # collidepoint check of the Rect class will fail as it doesn't include the bottom
       # and right hand side 'pixels' of the rectangle
       tolerance = 1
       if r1.width < tolerance:
            r1.width = tolerance
                    
       if r1.height < tolerance:
            r1.height = tolerance
        
       if r2.width < tolerance:
            r2.width = tolerance
                    
       if r2.height < tolerance:
            r2.height = tolerance

       for point in p:                 
           try:    
               res1 = r1.collidepoint(point)
               res2 = r2.collidepoint(point)
               if res1 and res2:
                   point = [int(pp) for pp in point]                                
                   return point
           except:
开发者ID:jarriett,项目名称:will-it-fit,代码行数:33,代码来源:geometry.py

示例11: calculateIntersectPoint

# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import height [as 别名]
def calculateIntersectPoint(p1, p2, p3, p4):

    p = getIntersectPoint(p1, p2, p3, p4)

    if p is not None:
        width = p2[0] - p1[0]
        height = p2[1] - p1[1]
        r1 = Rect(p1, (width, height))
        r1.normalize()

        width = p4[0] - p3[0]
        height = p4[1] - p3[1]
        r2 = Rect(p3, (width, height))
        r2.normalize()

        # Ensure both rects have a width and height of at least 'tolerance' else the
        # collidepoint check of the Rect class will fail as it doesn't include the bottom
        # and right hand side 'pixels' of the rectangle
        tolerance = 1
        if r1.width < tolerance:
            r1.width = tolerance

        if r1.height < tolerance:
            r1.height = tolerance

        if r2.width < tolerance:
            r2.width = tolerance

        if r2.height < tolerance:
            r2.height = tolerance

        for point in p:
            try:
                res1 = r1.collidepoint(point)
                res2 = r2.collidepoint(point)
                if res1 and res2:
                    point = [int(pp) for pp in point]
                    return point
            except:
                # sometimes the value in a point are too large for PyGame's Rect class
                str = "point was invalid  ", point
                print(str)

        # This is the case where the infinately long lines crossed but
        # the line segments didn't
        return None

    else:
        return None
开发者ID:anasazi,项目名称:Swarm-AI---Zombies,代码行数:51,代码来源:geometry.py


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