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


Python pygame.rect方法代码示例

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


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

示例1: enemy_new

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import rect [as 别名]
def enemy_new(g,t,value):
    g.clayer[t.ty][t.tx] = 0
    s = tilevid.Sprite(g.images['enemy'],t.rect)
    g.sprites.append(s)
    s.loop = enemy_loop
##In enemy_new(), I've added a lot more detail.
##- A move function to handle the type of movement the enemy will do.
##- A record of the origin and entering frame of the enemy (useful for the move functions.)
##- Set up the groups and agroups and a hit handler for the enemy.
##::
    s.move = value['move']
    s.origin = pygame.Rect(s.rect)
    s.frame = g.frame
    s.groups = g.string2groups('enemy')
    s.agroups = g.string2groups('player')
    s.hit = enemy_hit
##

##When an enemy is hit, the game quits.
##:: 
开发者ID:parogers,项目名称:pgu,代码行数:22,代码来源:tilevid5.py

示例2: player_loop

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import rect [as 别名]
def player_loop(g,s):
    ##In player_loop(), I now check if the player has gone off screen (due to blocks
    ##in the players way.  If that happens, the game quits.
    ##::
    if s.rect.right < g.view.left: g.quit = 1
    ##
    
    s.rect.x += SPEED
    
    keys = pygame.key.get_pressed()
    dx,dy = 0,0
    if keys[K_UP]: dy-=1
    if keys[K_DOWN]: dy+=1
    if keys[K_LEFT]: dx-=1
    if keys[K_RIGHT]: dx+=1
    s.rect.x += dx*5
    s.rect.y += dy*5
    s.rect.clamp_ip(g.view) 
开发者ID:parogers,项目名称:pgu,代码行数:20,代码来源:tilevid4.py

示例3: __init__

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import rect [as 别名]
def __init__(self, ishape, pos):
        if not isinstance(ishape, tuple):
            ishape = ishape, None
        image, shape = ishape
        if shape == None:
            shape = pygame.Rect(0, 0, image.get_width(), image.get_height())
        if isinstance(shape, tuple): shape = pygame.Rect(shape)
        self.image = image
        self._image = self.image
        self.shape = shape
        self.rect = pygame.Rect(pos[0], pos[1], shape.w, shape.h)
        self._rect = pygame.Rect(self.rect)
        self.irect = pygame.Rect(pos[0]-self.shape.x, pos[1]-self.shape.y,
            image.get_width(), image.get_height())
        self._irect = pygame.Rect(self.irect)
        self.groups = 0
        self.agroups = 0
        self.updated = 1 
开发者ID:parogers,项目名称:pgu,代码行数:20,代码来源:vid.py

示例4: setimage

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import rect [as 别名]
def setimage(self, ishape):
        """Set the image of the Sprite.

        Arguments:
            ishape -- an image, or an image, rectstyle.  The rectstyle will
                      describe the shape of the image, used for collision detection.

        """
        if not isinstance(ishape, tuple):
            ishape = ishape, None
        image, shape = ishape
        if shape == None:
            shape = pygame.Rect(0, 0, image.get_width(), image.get_height())
        if isinstance(shape, tuple):
            shape = pygame.Rect(shape)
        self.image = image
        self.shape = shape
        self.rect.w, self.rect.h = shape.w, shape.h
        self.irect.w, self.irect.h = image.get_width(), image.get_height()
        self.updated = 1 
开发者ID:parogers,项目名称:pgu,代码行数:22,代码来源:vid.py

示例5: run_codes

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import rect [as 别名]
def run_codes(self, cdata, rect):
        """Run codes.

        Arguments:
            cdata -- a dict of code:(handler function, value)
            rect -- a tile rect of the parts of the layer that should have
                 their codes run

        """
        tw, th = self.tiles[0].image.get_width(), self.tiles[0].image.get_height()

        x1, y1, w, h = rect
        clayer = self.clayer
        t = Tile()
        for y in range(y1, y1 + h):
            for x in range(int(x1), int(x1 + w)):
                n = clayer[y][x]
                if n in cdata:
                    fnc, value = cdata[n]
                    t.tx, t.ty = x, y
                    t.rect = pygame.Rect(x*tw, y*th, tw, th)
                    fnc(self, t, value) 
开发者ID:parogers,项目名称:pgu,代码行数:24,代码来源:vid.py

示例6: _draw_agent

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import rect [as 别名]
def _draw_agent(center_point, screen, base_size=30):
    '''
    Args:
        center_point (tuple): (x,y)
        screen (pygame.Surface)

    Returns:
        (pygame.rect)
    '''
    tri_bot_left = center_point[0] - base_size, center_point[1] + base_size
    tri_bot_right = center_point[0] + base_size, center_point[1] + base_size
    tri_top = center_point[0], center_point[1] - base_size
    tri = [tri_bot_left, tri_top, tri_bot_right]
    tri_color = (98, 140, 190)

    return pygame.draw.polygon(screen, tri_color, tri) 
开发者ID:david-abel,项目名称:simple_rl,代码行数:18,代码来源:taxi_visualizer.py

示例7: __init__

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import rect [as 别名]
def __init__(self, parent, coords, crank_images, click_sound):
        pygame.sprite.Sprite.__init__(self)
        self.parent = parent
        self.coords = coords
        self.image = crank_images[0]
        self.crank_images = crank_images
        self.rect = self.image.get_rect()
        self.click_sound = click_sound
        self.is_spinning: bool = False
        self.rotation = 0
        self.rect.move_ip(*in_pixels(coords))
        # The crank should center itself around its assigned screen location
        self.rect.move_ip(-self.rect.w / 2, -self.rect.h / 2)
        self.rotation_speed = 0
        self.rotation_speed_inc = .5
        self.rotation_speed_base_decay = .015
        self.rotation_speed_decay = self.rotation_speed_base_decay
        self.rotation_speed_mul = 1.2
        self.rotation_speed_start = 1
        self.base_max_rotation_speed = 25
        self.max_rotation_speed = self.base_max_rotation_speed
        self.min_rotation_speed = .5
        self.speed_intervals = [0, 20, 100] 
开发者ID:python-discord,项目名称:code-jam-5,代码行数:25,代码来源:__main__.py

示例8: player_new

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import rect [as 别名]
def player_new(g,t,value):
    g.clayer[t.ty][t.tx] = 0
    s = tilevid.Sprite(g.images['player'],t.rect)
    g.sprites.append(s)
    s.loop = player_loop 
开发者ID:parogers,项目名称:pgu,代码行数:7,代码来源:tilevid3.py

示例9: player_loop

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import rect [as 别名]
def player_loop(g,s):
    s.rect.x += SPEED
    
    keys = pygame.key.get_pressed()
    dx,dy = 0,0
    if keys[K_UP]: dy-=1
    if keys[K_DOWN]: dy+=1
    if keys[K_LEFT]: dx-=1
    if keys[K_RIGHT]: dx+=1
    s.rect.x += dx*5
    s.rect.y += dy*5
    s.rect.clamp_ip(g.view) 
开发者ID:parogers,项目名称:pgu,代码行数:14,代码来源:tilevid3.py

示例10: enemy_new

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import rect [as 别名]
def enemy_new(g,t,value):
    g.clayer[t.ty][t.tx] = 0
    s = tilevid.Sprite(g.images['enemy'],t.rect)
    g.sprites.append(s)
    s.loop = enemy_loop 
开发者ID:parogers,项目名称:pgu,代码行数:7,代码来源:tilevid3.py

示例11: enemy_loop

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import rect [as 别名]
def enemy_loop(g,s):
    if s.rect.right < g.view.left:
        g.sprites.remove(s)
##
##Here I initialize the image data.  The columns are (name,file_name,shape)
##:: 
开发者ID:parogers,项目名称:pgu,代码行数:8,代码来源:tilevid3.py

示例12: player_new

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import rect [as 别名]
def player_new(g,t,value):
    g.clayer[t.ty][t.tx] = 0
    s = tilevid.Sprite(g.images['player'],t.rect)
    g.sprites.append(s)
    s.loop = player_loop
    s.groups = g.string2groups('player')
    s.score = 0
    g.player = s
    ##In player_new() I add the shoot handler.
    ##::
    s.shoot = player_shoot
    ## 
开发者ID:parogers,项目名称:pgu,代码行数:14,代码来源:tilevid5.py

示例13: shot_new

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import rect [as 别名]
def shot_new(g,t,value):
    s = tilevid.Sprite(g.images['shot'],(t.rect.right,t.rect.centery-2))
    g.sprites.append(s)
    s.agroups = g.string2groups('enemy')
    s.hit = shot_hit
    s.loop = shot_loop 
开发者ID:parogers,项目名称:pgu,代码行数:8,代码来源:tilevid5.py

示例14: shot_loop

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import rect [as 别名]
def shot_loop(g,s):
    s.rect.x += 8
    if s.rect.left > g.view.right:
        g.sprites.remove(s)
## 
开发者ID:parogers,项目名称:pgu,代码行数:7,代码来源:tilevid5.py

示例15: enemy_loop

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import rect [as 别名]
def enemy_loop(g,s):
    ##In enemy_loop() we call the move handler.
    ##::
    s.move(g,s)
    ##
    if s.rect.right < g.view.left:
        g.sprites.remove(s)

##The enemy movement handlers.
##:: 
开发者ID:parogers,项目名称:pgu,代码行数:12,代码来源:tilevid5.py


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