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

Python rect.Rect类代码示例

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

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



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

示例1: _get_slide_rect

 def _get_slide_rect(self):
     slide_rect = Rect((0, 0), (self._length, self._height))
     try:
         slide_rect.center = self.get_fus_center()
     except AttributeError:
         slide_rect.center = self.get_ghost_center()
     return slide_rect
开发者ID:YannThorimbert,项目名称:ThorPy-1.4.1,代码行数:7,代码来源:slider.py


示例2: __init__

	def __init__(self, pos=None, size=None, value=5, pic=None):
		""" Generates a new instance of this class.

		Generates a new instance of this class and sets the fields.
		If no picture is given a the rectangle determined by position and size will be filled.

		Args:
			pos: The position of the collectable.
			size: The size of the collectable.
			value: The value of the collectable.
			pic: The picture to display the collectable.
		"""
		if pos is None:
			pos = [0, 0]
		if size is None:
			size = [0, 0]
		self._pos = pos
		self._value = value
		if pic is None:
			self._pic = Surface(size)
			pygame.draw.rect(self._pic, (0, 255, 0), Rect((0, 0), size))
			self._collision_rect = Rect(pos, size())
		else:
			self._pic = pic
			self._collision_rect = Rect(pos, pic.get_size())
开发者ID:donhilion,项目名称:JumpAndRun,代码行数:25,代码来源:collectable.py


示例3: reload

    def reload(self, fileName, x, y, z, rotate, scale):
        filePath = _rootDir + '/' + fileName
        import game.gameWindow as gameWindow
        scene = gameWindow.getScene()

        prevRect = copy(self.rect)

        if self.fileName is None or self.fileName != fileName or rotate != 0 or scale != 1:
            self.fileName = fileName
            self.image = pygame.image.load(filePath).convert_alpha(scene)
            self.rect = self.image.get_rect()
        self.rect.x = x
        self.rect.y = y
        if rotate != 0 or scale != 1:
            self.image = pygame.transform.rotozoom(self.image, rotate, scale)
            transformedRect = self.image.get_rect()
            transformedRect.center = self.rect.center
            self.rect = transformedRect

        if prevRect is not None:

            rectToUpdate = Rect(prevRect.x - 1, prevRect.y - 1, prevRect.width + 2, prevRect.height + 2)
            r2 = Rect(self.rect.x - 1, self.rect.y - 1, self.rect.width + 2, self.rect.height + 2)
            rectToUpdate.union_ip(r2)
            addRectToUpdate(rectToUpdate)
        else:
            rectToUpdate = Rect(self.rect.x - 1, self.rect.y - 1, self.rect.width + 2, self.rect.height + 2)
            addRectToUpdate(rectToUpdate)

        if self.z is not None:
            self.remove()
        _spritesList[z].add(self)
        self.z = z
开发者ID:mouton5000,项目名称:DiscreteEventApplicationEditor,代码行数:33,代码来源:SpriteRegistery.py


示例4: Select

class Select(Sprite):
    def __init__(self):
        Sprite.__init__(self)
        self.image = pygame.image.load('images/selector.png').convert()
        self.image.set_colorkey(PUCE, RLEACCEL)
        self.rect=Rect(10, 10, 30, 30)
        self.index = 0

    def setX(self, x):
        newpos = (self.rect.topleft[0] + x)
        if (newpos > 0) and (newpos < COLUMNS * 40 + 10):
            self.rect.move_ip(x,0)
            if x > 0:
                self.index += 1
            else:
                self.index -= 1

    def setY(self, y):
        newpos = (self.rect.topleft[1] + y)
        if (newpos > 0) and (newpos < ROWS * 40 + 10):
            self.rect.move_ip(0, y)
            if y > 0:
                self.index += COLUMNS
            else:
                self.index -= COLUMNS
开发者ID:bry,项目名称:pybomber2,代码行数:25,代码来源:color_picker.py


示例5: backup_attack_loop

    def backup_attack_loop(self):
        g = self.g
        self.image = self.orginalImage.subsurface((160, 0, 32, 32))

        speed = self.walktimer
        self.walktimer += 1
        if self.walktimer > 6:
            self.walktimer = 6


        self.timer += 1
        timergate = self.timer % 100
        if timergate >= 80:
            if timergate == 80:
                self.face_the_player()
            if timergate == 85:
                Shot(g, self.direction, (self.rect.x + 16, self.rect.y + 8), 'shot8', 'enemy')
            self.walking = 0
        else:
            self.walking = 1
        if timergate % 100 == 0:
            self.face_the_player()

        dx = self.rect.x - g.player.rect.x
        if dx <40 and dx > -40:
            if self.dy == 10.0:
                self.dy = -10.0

        if self.walking:
            self.rect.x += (1 - (self.direction * 2)) * speed
            framen = self.timer / 2  % 3
            self.image = self.orginalImage.subsurface((32 + framen * 32, 0, 32, 32))
        else:
            self.walktimer = 0

        self.dy += .5
        if self.dy > 10.0:
            self.dy = 10.0
        self.rect.y += self.dy

        if self.rect.x < 416:
            self.direction = 0

        
        self.image = pygame.transform.flip(self.image, self.direction, 0)
        # hitting the bullets and player
        s = Rect(self.rect)
        if s.colliderect (g.player.rect):
            g.player.touch(self)
        for b in g.bullets:
            if b.owner == 'player':
                drect = (b.rect.x + 30, b.rect.y )
                if s.collidepoint(drect):
                    b.destroy()
                    self.health -= b.get_damage()
                    e = Effect(self.g, 'health', (self.rect.x, self.rect.y))
                    e.healthchange = -b.get_damage()
                    self.image = g.make_image_white(self.image)
开发者ID:torleif,项目名称:Dystopian-Future,代码行数:58,代码来源:character.py


示例6: render

    def render(self):
        self.check()
        if self.disabled: return

        pos = self.rect.center

        t = self.mod["eyeType"]

        color0 = (255,255,255)
        color1 = (0,0,0)

        radius = (self.mod["eyeSkill"] + 2) * 3

        color = skinColor(self.mod)

        # we have to determine how big the eye will be before drawing
        size = (radius * 2, radius * 2)
        rect = Rect((0,0), size)

        image = Surface(size)
        image.fill(self.colorkey)
        image.set_colorkey(self.colorkey)

        # locking the surface makes multiple drawing operations quicker
        image.lock()

        # draw the border of the eye
        if radius < 10:
            steps = 16
        else:
            steps = 8

        for t in range(0,360,steps):
            t = radians(t)
            new_color = Color(color.r, color.g, color.b)
            h, s, v, a = new_color.hsva
            v = int(sin(t) * 50) + 50
            if v < 0: v = 0 - v
            new_color.hsva = (h, s, v, a)
            x = int(rect.centerx + cos(t) * (radius - 4))
            y = int(rect.centery + sin(t) * (radius - 4))
            draw.circle(image, new_color, (x, y), 3)

        # draw the white and pupil
        draw.circle(image, color0, rect.center, radius - 3)
        draw.circle(image, color1, rect.center, (radius - 3) / 3)

        image.unlock()

        rect.center = pos

        self.rect = rect
        self.image = image
开发者ID:MacLeek,项目名称:mh,代码行数:53,代码来源:mob.py


示例7: update_image

    def update_image(self):
        """Updates image"""
        area = Rect(self.row * self.frame_width,
                    self._col * self.frame_height,
                    0, 0)
        area.x = self.row * self.frame_width
        area.y = self._col * self.frame_height
        area.width = area.x + self.frame_width
        area.height = area.y + self.frame_height

        self.image.fill(Animation.colorkey)
        self.image.blit(self.surface, (0, 0), area)

        self.valid = True
开发者ID:crimson-king,项目名称:Bomberman,代码行数:14,代码来源:animation.py


示例8: attend_to_surroundings

 def attend_to_surroundings(self):
     """ arrange the areas of awareness and attack
     depending on the orientation as a number on
     the octoclock.
        0
      7   1
     6     2
      5   3
        4
     """
     centre_of_attention = octoclock_direction(self.orientation, self.rect)
     self.rect_of_awareness = Rect(0, 0, *self.area_of_awareness)
     self.rect_of_awareness.center = centre_of_attention
     self.rect_of_attack = Rect(0, 0, *self.area_of_attack)
     self.attend_to_attack_area(centre_of_attention)
开发者ID:scavpy,项目名称:Scav-Threads-PyWeek-Sep-2012,代码行数:15,代码来源:units.py


示例9: get_clip

 def get_clip(self):
     """ get_clip() -> Rect
     get the current clipping area of the Surface
     """
     self.check_surface()
     c_rect = self._c_surface.clip_rect
     return Rect._from4(c_rect.x, c_rect.y, c_rect.w, c_rect.h)
开发者ID:caseyc37,项目名称:pygame_cffi,代码行数:7,代码来源:surface.py


示例10: __init__

 def __init__(self, img_name, rect, game):
     self.game = game
     self.image = pygame.image.load(img_name).convert_alpha()
     self.rect = Rect(rect.centerx, rect.y, 40, 40)
     self.x = choice([-5, 5])
     self.y = choice([-5, 5])
     super().__init__()
开发者ID:JotaVeUltra,项目名称:DevInVale2015,代码行数:7,代码来源:sprites.py


示例11: Asteroid

class Asteroid(Sprite):
    def __init__(self, img_name, width, height, game):
        super().__init__()
        self.image = pygame.image.load(img_name).convert_alpha()
        self.rect = Rect(randrange(game.width - width), -100, width, height)
        self.y_speed = randrange(15, 25)
        self.game = game

    def update(self, *args):
        x_move = 0
        y_move = self.y_speed

        self.rect = self.rect.move(x_move, y_move)
        if self.rect.top > self.game.height:
            super().kill()

    def kill(self):
        self.game.elements['exploding_asteroids'].add(AnimatedAsteroid(join('gfx', 'asteroid_exploded.png'),
                                                                       self.rect,
                                                                       4,
                                                                       self.game))
        if self.game.newPU:
            self.game.elements['power-ups'].add(PowerUp(join('gfx', 'PowerUp.png'), self.rect, self.game))
            self.game.newPU = False
        super().kill()
开发者ID:JotaVeUltra,项目名称:DevInVale2015,代码行数:25,代码来源:sprites.py


示例12: __init__

 def __init__(self, parent):
     self.parent = parent
     self.rect = pygame.Rect(0, 0, 0, 0)
     self.rect_rel = pygame.Rect(0, 0, 0, 0)
     
     self.move_offset_x = 0
     self.move_offset_y = 0
     
     self.input_xy = OrderedDict()
     self.output_xy = OrderedDict()
     
     self.inputs = OrderedDict()
     self.outputs = []
     
     self.output_cache = {}
     self.input_cache = {}
     self.res = {}
     
     self.name = "cell"    
     self.fcs = "cell"    
     
     self.drawable = False
     self.border = Rect(0,0,0,0)
     
     self.need_redraw = False
     self.need_body_update = False
     self.zoom = False
开发者ID:fhorinek,项目名称:pi8bit,代码行数:27,代码来源:cell.py


示例13: __init__

    def __init__(self, screen_res, level_rect, x_speed=15, y_speed=15,
                 left_threshold=10, right_threshold=75, up_threshold=10,
                 down_threshold=75):
        """

        :param screen_res: A tuple of int. (w, h)
        :param level_rect: A rectangle that covers all of the level
        :param x_speed: The horizontal speed of the camera
        :param y_speed: The vertical speed of the camera
        :param left_threshold:
            The percentage of screen to reach in order for the camera to scroll
            left
        :param right_threshold:
            The percentage of screen to reach in order for the camera to scroll
            right
        :param up_threshold:
            The percentage of screen to reach in order for the camera to scroll
            up
        :param down_threshold:
            The percentage of screen to reach in order for the camera to scroll
            down
        """
        self.level_rect = level_rect
        self.horizontal_speed = x_speed
        self.vertical_speed = y_speed
        self.screen_res = screen_res
        self.rect = Rect((0, 0), screen_res)

        self.x_bound = self.level_rect.width - self.rect.width
        self.y_bound = self.level_rect.height - self.rect.height

        self.right_threshold = self.rect.width * right_threshold / 100
        self.left_threshold = self.rect.width * left_threshold / 100
        self.up_threshold = self.rect.height * up_threshold / 100
        self.down_threshold = self.rect.height * down_threshold / 100
开发者ID:XrXr,项目名称:RapidPygame,代码行数:35,代码来源:camera.py


示例14: __init__

 def __init__(self, x, y, kind, resourcemgr):
     super(Button, self).__init__(x, y, kind, resourcemgr)
     set_button_stats(self)
     self.rect = Rect(x, y, self.w, self.h)
     self.was_hit = False
     self.set_areas()
     self.area = self.areas[MOUSE_POS.OUT]
开发者ID:drtchops,项目名称:iancraft,代码行数:7,代码来源:buttons.py


示例15: get_rect

 def get_rect(self, **kwargs):
     r = Rect._from4(0, 0, self._w, self._h)
     if kwargs:
         for attr, value in kwargs.items():
             # Logic copied form pygame/surface.c - blame them
             setattr(r, attr, value)
     return r
开发者ID:caseyc37,项目名称:pygame_cffi,代码行数:7,代码来源:surface.py


示例16: fill

    def fill(self, color, rect=None, special_flags=0):
        """ fill(color, rect=None, special_flags=0) -> Rect
        fill Surface with a solid color
        """
        self.check_opengl()

        c_color = create_color(color, self._format)
        sdlrect = ffi.new('SDL_Rect*')
        if rect is not None:
            sdlrect.x, sdlrect.y, sdlrect.w, sdlrect.h = rect_vals_from_obj(rect)
        else:
            sdlrect.w = self._w
            sdlrect.h = self._h

        if self.crop_to_surface(sdlrect):
            if special_flags:
                res = sdl.surface_fill_blend(self._c_surface, sdlrect,
                                             c_color, special_flags)
            else:
                with locked(self._c_surface):
                    # TODO: prep/unprep
                    res = sdl.SDL_FillRect(self._c_surface, sdlrect, c_color)

            if res == -1:
                raise SDLError.from_sdl_error()

        return Rect._from4(sdlrect.x, sdlrect.y, sdlrect.w, sdlrect.h)
开发者ID:caseyc37,项目名称:pygame_cffi,代码行数:27,代码来源:surface.py


示例17: __init__

    def __init__(self, location, *groups):
        super().__init__(*groups)

        self.rect = Rect(location, self.image.get_size())
        self.vertical_velocity = self.default_vertical_velocity = 200
        self.rightward_velocity = 100
        self.vertical_velocity_decay = 40
        self.jump_velocity = -300
开发者ID:whiteandnerdy,项目名称:pythonplayground,代码行数:8,代码来源:enemy.py


示例18: getEndGameSplash

def getEndGameSplash(winnerName=None, winnerColor=None):
    """If winningName and winnerColor are both None,
       display a tie game screen.
    """

    screen = Display.get_surface()
    splashGroup = SpriteGroup()
    if winnerName != None and winnerColor != None:
        # Create winning bomberman image
        fatalityRect = Rect((0, 0, 500, 500))
        fatalityRect.centerx = screen.get_rect().centerx
        fatalityRect.centery = screen.get_rect().centery
        fatalityAnimation = WorldlessWidget(Surface((500, 500)), fatalityRect)
        fatalImage = pygame.image.load("images/fatality.png").convert()
        fatalImage.set_colorkey(LAVENDER)
        bmanColor = Surface((fatalImage.get_width(), fatalImage.get_height()))
        bmanColor.fill(winnerColor)
        bmanColor.blit(fatalImage, bmanColor.get_rect())
        winnerFrames = createFrames(bmanColor)
        fatalityAnimation.startAnimation(winnerFrames, 0, 12)
        splashGroup.add(fatalityAnimation)

        # Create text for winning player
        winnerText = TextBar(winnerName + " Wins!", (0, 0, 200, 50), 50)
        imgWidth = winnerText.image.get_width()
        winnerText.rect.left = (screen.get_size()[X] - imgWidth) / 2
        splashGroup.add(winnerText)
    else:
        tieText = TextBar("TIE GAME!", (0, 20, 250, 50), 35)
        imgWidth = tieText.image.get_width()
        tieText.rect.left = (screen.get_size()[X] - imgWidth) / 2
        splashGroup.add(tieText)

    escMessage = TextBar("Press Escape to exit.", (0, 60, 250, 50), 25)
    imgWidth = escMessage.image.get_width()
    escMessage.rect.left = (screen.get_size()[X] - imgWidth) / 2
    splashGroup.add(escMessage)

    pressKeyText = TextBar(
        "Press a key or button when ready. Next round will start when everyone is ready.", (0, 90, 250, 50), 25
    )
    imgWidth = pressKeyText.image.get_width()
    pressKeyText.rect.left = (screen.get_size()[X] - imgWidth) / 2
    splashGroup.add(pressKeyText)

    return splashGroup
开发者ID:bry,项目名称:pybomber2,代码行数:46,代码来源:splashes.py


示例19: draw_board

    def draw_board(self):

        image_indexes = {
            None: 0,
            O: 1,
            X: 2
        }

        for row in range(3):
            for col in range(3):

                board_index = row * 3 + col

                # Cell rectangle
                cell = Rect(TILE_WIDTH * col, TILE_HEIGHT * row, TILE_WIDTH, TILE_HEIGHT)

                # Check if mouse is over a cell
                mouse_over = self.mouse_pos is not None and cell.collidepoint(self.mouse_pos)

                # Winner movement
                if self.game.winner and board_index in self.game.winner_movement:
                    fill_index = image_indexes[self.game.board[board_index]]
                    state_index = 3
                    self.screen.blit(self.tileset[fill_index][state_index], cell)

                # Mouse interaction
                elif mouse_over and self.is_human_turn():
                    if self.game.board[board_index] == None:
                        fill_index = image_indexes[self.game.turn]
                        state_index = 1
                    else:
                        fill_index = image_indexes[self.game.board[board_index]]
                        state_index = 2
                    self.screen.blit(self.tileset[fill_index][state_index], cell)

                # Normal rendering
                else:
                    fill_index = image_indexes[self.game.board[board_index]]
                    if self.game.winner == False: # Draw
                        state_index = 2
                    else:
                        state_index = 0
                    self.screen.blit(self.tileset[fill_index][state_index], cell)

        pygame.display.flip()
开发者ID:Longaray,项目名称:adversarial-search,代码行数:45,代码来源:interface.py


示例20: __init__

 def __init__(self, x, y, sheet, kind, mgr):
     super(Tile, self).__init__(x, y, kind)
     self.mgr = mgr
     self.resourcemgr = mgr.resourcemgr
     self.sheet = sheet
     set_tile_stats(self)
     self.rect = Rect(x, y, self.tile_width, self.tile_height)
     self.area = self.mgr.areas[self.kind]
     self.flags = FLAGS.TILE
开发者ID:drtchops,项目名称:iancraft,代码行数:9,代码来源:tiles.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python sprite.spritecollide函数代码示例发布时间:2022-05-25
下一篇:
Python mouse.set_visible函数代码示例发布时间: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