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


Python pygame.Rect方法代码示例

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


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

示例1: _pygame_init

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import Rect [as 别名]
def _pygame_init(self, config):
        self._bgcolor = (52,52,52)
        self._fgcolor = (149,193,26)
        self._bordercolor = (255,255,255)
        self._fontcolor = (255,255,255)
        self._font = pygame.font.Font(None, 40)

        #positions and sizes:
        self.screenwidth = pygame.display.Info().current_w
        self.screenheight = pygame.display.Info().current_h
        self.pwidth=0.8*self.screenwidth
        self.pheight=0.05*self.screenheight
        self.borderthickness = 2

        #create rects:
        self.borderrect   =  pygame.Rect((self.screenwidth / 2) - (self.pwidth / 2),
                                         (self.screenheight / 2) - (self.pheight / 2),
                                         self.pwidth,
                                         self.pheight) 
开发者ID:adafruit,项目名称:pi_video_looper,代码行数:21,代码来源:usb_drive_copymode.py

示例2: draw_copy_progress

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import Rect [as 别名]
def draw_copy_progress(self, copied, total):
        perc = 100 * copied / total
        assert (isinstance(perc, float))
        assert (0. <= perc <= 100.)

        progressrect =  pygame.Rect((self.screenwidth / 2) - (self.pwidth / 2) + self.borderthickness,
                                                                (self.screenheight / 2) - (self.pheight / 2) + self.borderthickness,
                                                                (self.pwidth-(2*self.borderthickness))*(perc/100),
                                                                self.pheight - (2*self.borderthickness))


        #border
        pygame.draw.rect(self._screen, self._bordercolor, self.borderrect, self.borderthickness)
        #progress
        pygame.draw.rect(self._screen, self._fgcolor, progressrect)
        #progress_text
        self.draw_progress_text(str(int(round(perc)))+"%")

        pygame.display.update(self.borderrect) 
开发者ID:adafruit,项目名称:pi_video_looper,代码行数:21,代码来源:usb_drive_copymode.py

示例3: __init__

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import Rect [as 别名]
def __init__(self, pos, length, height, space, mass=5.0):
        moment = 1000
        body = pm.Body(mass, moment)
        body.position = Vec2d(pos)
        shape = pm.Poly.create_box(body, (length, height))
        shape.color = (0, 0, 255)
        shape.friction = 0.5
        shape.collision_type = 2
        space.add(body, shape)
        self.body = body
        self.shape = shape
        wood = pygame.image.load("../resources/images/wood.png").convert_alpha()
        wood2 = pygame.image.load("../resources/images/wood2.png").convert_alpha()
        rect = pygame.Rect(251, 357, 86, 22)
        self.beam_image = wood.subsurface(rect).copy()
        rect = pygame.Rect(16, 252, 22, 84)
        self.column_image = wood2.subsurface(rect).copy() 
开发者ID:estevaofon,项目名称:angry-birds-python,代码行数:19,代码来源:polygon.py

示例4: plot_byte

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import Rect [as 别名]
def plot_byte(screen, data: List[int], offset: int):
    """ Draws a pixel at the given X, Y coordinate
    """
    global TABLE

    byte_ = TABLE[data[offset]]
    attr = get_attr(data, offset)

    ink_ = attr & 0x7
    paper_ = (attr >> 3) & 0x7
    bright = (attr >> 6) & 0x1

    paper = tuple(x + bright for x in PALETTE[paper_])
    ink = tuple(x + bright for x in PALETTE[ink_])
    palette = [paper, ink]

    x0, y0 = get_xy_coord(offset)

    for x, bit_ in enumerate(byte_):
        screen.fill(palette[bit_], pygame.Rect(x0 + x * SCALE, y0, SCALE, SCALE)) 
开发者ID:boriel,项目名称:zxbasic,代码行数:22,代码来源:scrview.py

示例5: __init__

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import Rect [as 别名]
def __init__(self, level):
        global sprites

        # to know where to place
        self.level = level

        # bonus lives only for a limited period of time
        self.active = True

        # blinking state
        self.visible = True

        self.rect = pygame.Rect(random.randint(0, 416 - 32), random.randint(0, 416 - 32), 32, 32)

        self.bonus = random.choice([
            self.BONUS_GRENADE,
            self.BONUS_HELMET,
            self.BONUS_SHOVEL,
            self.BONUS_STAR,
            self.BONUS_TANK,
            self.BONUS_TIMER
        ])

        self.image = sprites.subsurface(16 * 2 * self.bonus, 32 * 2, 16 * 2, 15 * 2) 
开发者ID:uvipen,项目名称:AirGesture,代码行数:26,代码来源:battle_city_utils.py

示例6: __init__

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import Rect [as 别名]
def __init__(self, pos_init, width, height, color):
        pygame.sprite.Sprite.__init__(self)

        self.pos = vec2d(pos_init)
        self.color = color
        self.width = width
        self.height = height

        image = pygame.Surface((width, height))
        image.fill((0, 0, 0))
        image.set_colorkey((0, 0, 0))

        pygame.draw.rect(
            image,
            color,
            (0, 0, self.width, self.height),
            0
        )

        self.image = image
        # use half the size
        self.rect = pygame.Rect(pos_init, (self.width / 2, self.height / 2))
        self.rect.center = pos_init 
开发者ID:ntasfi,项目名称:PyGame-Learning-Environment,代码行数:25,代码来源:snake.py

示例7: getRenderedText

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import Rect [as 别名]
def getRenderedText(self):
            fits = False
            surf = None
            while not fits:
                d = GUI.MultiLineText.render_textrect(self.text, self.font.get(self.size), pygame.Rect(self.computedPosition[0], self.computedPosition[1], self.computedWidth, self.height),
                                                      self.color, (0, 0, 0, 0), self.justification, self.use_freetype)
                surf = d[0]
                fits = d[1] != 1
                self.textLines = d[2]
                if not fits:
                    self.height += self.lineHeight
                    self.computedHeight = self.height
            self.setDimensions()
            #if self.linkedScroller != None:
            #    self.linkedScroller.refresh(False)
            return surf 
开发者ID:furmada,项目名称:PythonOS,代码行数:18,代码来源:pyos.py

示例8: render_cell

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import Rect [as 别名]
def render_cell(self, x, y):
        """ Draw the cell specified by the field coordinates. """
        cell_coords = pygame.Rect(
            x * self.CELL_SIZE,
            y * self.CELL_SIZE,
            self.CELL_SIZE,
            self.CELL_SIZE,
        )
        if self.env.field[x, y] == CellType.EMPTY:
            pygame.draw.rect(self.screen, Colors.SCREEN_BACKGROUND, cell_coords)
        else:
            color = Colors.CELL_TYPE[self.env.field[x, y]]
            pygame.draw.rect(self.screen, color, cell_coords, 1)

            internal_padding = self.CELL_SIZE // 6 * 2
            internal_square_coords = cell_coords.inflate((-internal_padding, -internal_padding))
            pygame.draw.rect(self.screen, color, internal_square_coords) 
开发者ID:YuriyGuts,项目名称:snake-ai-reinforcement,代码行数:19,代码来源:pygame.py

示例9: draw

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import Rect [as 别名]
def draw(self):
        show_arrow = True
        show_dist = False
        for pos, v in self.field.items():
            if v.length_squared() > 0:
                if show_dist:
                    start_color = (200, 50, 0)
                    end_color = DARKGRAY
                    p_rect = pg.Rect((p.pos.x // TILESIZE) * TILESIZE, (p.pos.y // TILESIZE) * TILESIZE, TILESIZE, TILESIZE)
                    pg.draw.rect(screen, start_color, p_rect)
                    rect = pg.Rect(pos[0] * TILESIZE, pos[1] * TILESIZE, TILESIZE, TILESIZE)
                    r = self.distance[pos] / self.max_distance
                    col = color_gradient(start_color, end_color, r)
                    pg.draw.rect(screen, col, rect)
                if show_arrow:
                    rot = v.angle_to(vec(1, 0))
                    img = self.vec_images[rot]
                    rect = img.get_rect()
                    rect.center = (pos[0] * TILESIZE + TILESIZE / 2, pos[1] * TILESIZE + TILESIZE / 2)
                    screen.blit(img, rect)
                    # draw_text(str(self.distance[pos]), 12, WHITE, rect.centerx, rect.centery, align="center") 
开发者ID:kidscancode,项目名称:pygame_tutorials,代码行数:23,代码来源:part08.py

示例10: checkCrash

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import Rect [as 别名]
def checkCrash(player, upperPipes, lowerPipes):
    """returns True if player collders with base or pipes."""
    pi = player["index"]
    player["w"] = IMAGES["player"][0].get_width()
    player["h"] = IMAGES["player"][0].get_height()

    # if player crashes into ground
    if (player["y"] + player["h"] >= BASEY - 1) or (player["y"] + player["h"] <= 0):
        return [True, True]
    else:

        playerRect = pygame.Rect(player["x"], player["y"], player["w"], player["h"])
        pipeW = IMAGES["pipe"][0].get_width()
        pipeH = IMAGES["pipe"][0].get_height()

        for uPipe, lPipe in zip(upperPipes, lowerPipes):
            # upper and lower pipe rects
            uPipeRect = pygame.Rect(uPipe["x"], uPipe["y"], pipeW, pipeH)
            lPipeRect = pygame.Rect(lPipe["x"], lPipe["y"], pipeW, pipeH)

            # player and upper/lower pipe hitmasks
            pHitMask = HITMASKS["player"][pi]
            uHitmask = HITMASKS["pipe"][0]
            lHitmask = HITMASKS["pipe"][1]

            # if bird collided with upipe or lpipe
            uCollide = pixelCollision(playerRect, uPipeRect, pHitMask, uHitmask)
            lCollide = pixelCollision(playerRect, lPipeRect, pHitMask, lHitmask)

            if uCollide or lCollide:
                return [True, False]

    return [False, False] 
开发者ID:chncyhn,项目名称:flappybird-qlearning-bot,代码行数:35,代码来源:flappy.py

示例11: checkCrash

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import Rect [as 别名]
def checkCrash(player, upperPipes, lowerPipes):
    """returns True if player collders with base or pipes."""
    pi = player["index"]
    player["w"] = PLAYER[IM_WIDTH]
    player["h"] = PLAYER[IM_HEIGTH]

    # if player crashes into ground
    if (player["y"] + player["h"] >= BASEY - 1) or (player["y"] + player["h"] <= 0):
        return [True, True]
    else:

        playerRect = pygame.Rect(player["x"], player["y"], player["w"], player["h"])
        pipeW = PIPE[IM_WIDTH]
        pipeH = PIPE[IM_HEIGTH]

        for uPipe, lPipe in zip(upperPipes, lowerPipes):
            # upper and lower pipe rects
            uPipeRect = pygame.Rect(uPipe["x"], uPipe["y"], pipeW, pipeH)
            lPipeRect = pygame.Rect(lPipe["x"], lPipe["y"], pipeW, pipeH)

            # player and upper/lower pipe hitmasks
            pHitMask = HITMASKS["player"][pi]
            uHitmask = HITMASKS["pipe"][0]
            lHitmask = HITMASKS["pipe"][1]

            # if bird collided with upipe or lpipe
            uCollide = pixelCollision(playerRect, uPipeRect, pHitMask, uHitmask)
            lCollide = pixelCollision(playerRect, lPipeRect, pHitMask, lHitmask)

            if uCollide or lCollide:
                return [True, False]

    return [False, False] 
开发者ID:chncyhn,项目名称:flappybird-qlearning-bot,代码行数:35,代码来源:learn.py

示例12: __init__

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import Rect [as 别名]
def __init__(self, x, y, width, height, SCREENWIDTH, SCREENHEIGHT, **kwargs):
		pygame.sprite.Sprite.__init__(self)
		self.init_state = [x, y, width, height]
		self.rect = pygame.Rect(x, y, width, height)
		self.base_speed = 10
		self.SCREENWIDTH = SCREENWIDTH
		self.SCREENHEIGHT = SCREENHEIGHT 
开发者ID:CharlesPikachu,项目名称:Games,代码行数:9,代码来源:Sprites.py

示例13: reset

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import Rect [as 别名]
def reset(self):
		self.rect = pygame.Rect(self.init_state[0], self.init_state[1], self.init_state[2], self.init_state[3])
		return True 
开发者ID:CharlesPikachu,项目名称:Games,代码行数:5,代码来源:Sprites.py

示例14: drawGrids

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import Rect [as 别名]
def drawGrids(self):
		for x in range(NUMGRID):
			for y in range(NUMGRID):
				rect = pygame.Rect((XMARGIN+x*GRIDSIZE, YMARGIN+y*GRIDSIZE, GRIDSIZE, GRIDSIZE))
				self.drawBlock(rect, color=(0, 0, 255), size=1) 
开发者ID:CharlesPikachu,项目名称:Games,代码行数:7,代码来源:utils.py

示例15: isValidPos

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import Rect [as 别名]
def isValidPos(self, col, row):
		if col >= 0 and row >= 0 and col < self.num_cols and row < self.num_rows:
			block_size = Config.get('block_size')
			temp1 = self.walls + self.boxes
			temp2 = pygame.Rect(col * block_size, row * block_size, block_size, block_size)
			return temp2.collidelist(temp1) == -1
		else:
			return False 
开发者ID:CharlesPikachu,项目名称:Games,代码行数:10,代码来源:Game12.py


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