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


Python sprite.Group类代码示例

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


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

示例1: build_wave

    def build_wave(self):
        """Creates the rectangular formation of enemies
        Enemy sprites are stored in the inherited Group and the instance formation
        """

        # build the formation and store in a 2d array indexed col, row
        self.formation = []
        for current_col in range(0, self.cols):
            col_list = []
            for current_row in range(0, self.rows):
                new_enemy = Enemy(self.window_size, self.sprite_filename, self.speed, current_col, current_row)

                left_pos = current_col * (self.gap + new_enemy.rect.width) + self.gap
                top_pos = current_row * (self.gap + new_enemy.rect.height) + self.gap
                new_enemy.rect = new_enemy.image.get_rect(left=left_pos, top=top_pos)

                col_list.append(new_enemy)
                Group.add(self, new_enemy)
            self.formation.append(col_list)

        self.leftmost_col = 0  # the left- and rightmost cols with living enemies
        self.rightmost_col = self.cols - 1
        self.move_delay_step = 0  # counts the frames between moves
        self.shoot_delay_step = 0  # counts the frames between shots
        self.current_vector = EAST  # the wave always starts by moving right
开发者ID:rubiximus,项目名称:invader-shootan,代码行数:25,代码来源:enemy_group.py

示例2: __init__

    def __init__(self):
        Microgame.__init__(self)
        self.character_select = True
        self.player1_selector = Player1_Selector()
        self.player2_selector = Player2_Selector()
        self.falco = Falco_Selector()
        self.fox = Fox_Selector()
        self.samus = Samus_Selector()
        self.snake = Snake_Selector()
        self.pit = Pit_Selector()
        self.mewtwo = Mewtwo_Selector()
        self.zelda = Zelda_Selector()
        self.character_possibilities = Group(self.falco, self.fox, self.samus, self.snake, self.pit, self.mewtwo, self.zelda)
        self.sprites = OrderedUpdates(self.falco, self.fox, self.samus, self.snake, self.pit, self.mewtwo, self.zelda, self.player1_selector, self.player2_selector)
        self.player1 = Fox()
        self.player2 = Falco()
        self.p1victory = pygame.image.load(join('games', 'ssb', 'p1_win.png'))
        self.p2victory = pygame.image.load(join('games', 'ssb', 'p2_win.png'))

        self.platform = Final_Destination()

        self.p1win = False
        self.p2win = False
        self.wincondition = False

        self.a_track = False
        self.d_track = False
        self.lshift_track = False
        self.quote_track = False
        self.l_track = False
        self.rshift_track = False

        self.playergroup = Group(self.player1, self.player2)
        self.player1_projectiles = Group()
        self.player2_projectiles = Group()
开发者ID:oneski,项目名称:SAAST-Summer-Program-Project,代码行数:35,代码来源:game.py

示例3: __init__

    def __init__ ( self, color, initial_position, size, player = None ):
        """Creates a new ViewManager object."""
        #Sprite
        pygame.sprite.Sprite.__init__(self)

        self.image = pygame.Surface(size)
        self.image.fill(color)

        self.rect = self.image.get_rect()
        self.rect.topleft = initial_position

        #Drawable objects
        if (player == None):
            self.player = Character()
        else: self.player = player

        #Draw starting objects
        #self.setup()

        #Sprite Groups
        self.activeObjects = Group()
        self.activeBackground = Group()
        self.activeAvatar = pygame.sprite.GroupSingle()
        
        #Collision
        self.collision = CollisionManager()
开发者ID:MystWalker,项目名称:Fey,代码行数:26,代码来源:ViewManager.py

示例4: Player

class Player (Sprite):
    size = 20,20
    color = 255,255,0
    shottimer = 0
    
    def __init__(self, loc, bounds):
        Sprite.__init__(self)  # required for sprites
        self.image = Surface(self.size)
        self.rect = self.image.get_rect()
        
        self.rect.center = loc
        self.bounds = bounds  # passes the bounds to the object so it can be saved.
        
        self.image.fill(self.color)
        self.bullets = Group()
    
    def update(self):
        if self.shottimer > 0:
            self.shottimer -= 1
        self.rect.center = pygame.mouse.get_pos()
        self.rect.clamp_ip(self.bounds) #makes sure it doesn't go outside the provided rectangle
        
    def shoot(self):
        if not self.alive(): #return just stops everything in hte function
            return
        if self.shottimer == 0:
            bullet = Bullet(self.bounds)
            self.bullets.add(bullet) #adds the new bullet to the Bullets list
        
            bullet.rect.midbottom = self.rect.midtop
            self.shottimer = 10
开发者ID:Grug16,项目名称:CS112-Spring2012,代码行数:31,代码来源:player.py

示例5: Level

class Level(object):

    _map = {
        "%": "flower",
        "~": "grass",
        ".": "path"
    }

    def __init__(self, name, tilesheet):
        # load level data
        path = os.path.join(DATA_DIR, "levels", name) + ".lvl"
        with open(path, "r") as f:
            data = f.read().strip().split("\n")

        # parse level data
        data = [ [ self._map.get(c) for c in row ] for row in data ]

        # build the level
        self.tiles, size = tilesheet.build(data)
        self.bounds = Rect((0,0), size)

        # find path
        self.path = Group()
        for tile in self.tiles:
            if tile.type == "path":
                self.path.add(tile)

        # render
        self.render_background()

        

    def render_background(self):
        self.background = Surface(self.bounds.size)
        self.tiles.draw(self.background)        
开发者ID:AKilgore,项目名称:CS112-Spring2012,代码行数:35,代码来源:level.py

示例6: __init__

    def __init__(self, bounds):
        Group.__init__(self)

        self.bounds = bounds

        self.spawn_rate = COIN_SPAWN_RATE * 1000
        self.spawn_timer = 0
开发者ID:sgoodspeed,项目名称:samKeenanGame,代码行数:7,代码来源:coin.py

示例7: _create_image

 def _create_image(self):
     grp = Group()
     for word in self.words:
         if len(grp.sprites()) == 0:
             word.scale(self.ratio+0.2)
             pm_w = word.rect.width
             pm_h = word.rect.height
             pm_x, pm_y = place_primary(pm_w, pm_h)
             word.rect.x, word.rect.y = pm_x, pm_y
             arch_x = pm_x + pm_w/2
             arch_y = pm_y + pm_h/2
         else:
             word.scale(self.ratio)
             for x, y in archimedean_spiral(False):
                 if self.debug:
                     rs = Surface((5, 5))
                     rs.fill((0, 0, 255))
                     rs.set_alpha(100)
                     self.sf.blit(rs, (x + arch_x, y + arch_y))
                 word.set_position(x + arch_x, y + arch_y)
                 x_out = CANVAS_WIDTH - CANVAS_PADDING < word.rect.x + word.rect.width or word.rect.x < CANVAS_PADDING
                 y_out = CANVAS_HEIGHT - CANVAS_PADDING < word.rect.y + word.rect.height or word.rect.y < CANVAS_PADDING
                 out_of_bound = x_out or y_out
                 if spritecollideany(word, grp, collide_mask) is None and not out_of_bound:
                     if self.debug:
                         rs = Surface((5, 5))
                         rs.fill((0, 255, 0))
                         rs.set_alpha(100)
                         self.sf.blit(rs, (x + arch_x, y + arch_y))
                     break
         self.sf.blit(word.image, word.rect)
         grp.add(word)
开发者ID:nullicorn,项目名称:scwordcloudapp,代码行数:32,代码来源:wordcloud.py

示例8: Player

class Player(Sprite):

    def __init__(self, game):
        Sprite.__init__(self)
        self.game = game
        self.image = game.get_tile_surface('rot.hoch')
        self.mask = mask.from_surface(self.image)
        self.g = Group(self)
        self.pos = Vector(300, 510)
        self.speed = 4
        self.direction = RIGHT

    def set_direction(self, direction):
        if direction in [LEFT, RIGHT]:
            self.direction = direction

    def get_shot(self):
        return Shot(self.game, (self.pos.x, self.pos.y - 16), UP)

    def move(self):
        self.pos += self.direction * self.speed
        if self.pos.x < MIN_X:
            self.pos.x = MIN_X
        elif self.pos.x > MAX_X:
            self.pos.x = MAX_X

    def draw(self):
        self.rect = Rect(self.pos.x, self.pos.y, 32, 32)
        self.g.draw(self.game.screen.display)
开发者ID:krother,项目名称:tilegamelib,代码行数:29,代码来源:invaders.py

示例9: touches

 def touches(self, group):
     touching = Group()
     coll = self.rect.inflate(2,1) # grow 1px to allow for edges
     for sprite in group:
         if coll.colliderect(sprite.rect):
             touching.add(sprite)
     return touching
开发者ID:habahut,项目名称:CS112-Spring2012,代码行数:7,代码来源:player.py

示例10: update

    def update(self, dt):
        Group.update(self, dt)

        self.spawn_timer += dt
        if self.spawn_timer >= self.spawn_rate:
            self.spawn()
            self.spawn_timer = 0
开发者ID:RMeiselman,项目名称:CS112-Spring2012,代码行数:7,代码来源:main.py

示例11: __init__

 def  __init__(self, moving_sprite,
               speedx = 0,
               maxspeedx = -1,
               speedy = 0,
               maxspeedy = -1,
               posx = 0,
               posy = 0,
               thrust_strength = 0,
               accelx = 0,
               accely = 0,
               gravity = 1000,
               decrease_speed_ratio = 2.0):
     Group.__init__(self)
     self.moving_sprite = moving_sprite
     self.speedx = speedx
     self.speedy = speedy
     self.maxspeedx = maxspeedx
     self.maxspeedy = maxspeedy
     self.posx = posx
     self.posy = posy
     self.thrust_strength = thrust_strength
     self.accelx = accelx
     self.accely = accely
     self.gravity = gravity
     self.decrease_speed_ratio = decrease_speed_ratio
     self.bumping_walls = []
开发者ID:benoxoft,项目名称:Bomberbirds,代码行数:26,代码来源:movement.py

示例12: Player

class Player(Sprite):
    color = 255, 255, 0
    size = 20, 20
    
    def __init__(self, loc, bounds):
        Sprite.__init__(self)

        self.image = Surface(self.size)
        self.rect = self.image.get_rect()

        self.rect.center = loc
        self.bounds = bounds

        self.image.fill(self.color)
        self.bullets = Group()

    def update(self):
        self.rect.center = pygame.mouse.get_pos()
        self.rect.clamp_ip(self.bounds)

    def shoot(self):
        if not self.alive():
            return

        bullet = Bullet(self.bounds)
        bullet.rect.midbottom = self.rect.midtop
        self.bullets.add(bullet)
开发者ID:AKilgore,项目名称:CS112-Spring2012,代码行数:27,代码来源:player.py

示例13: Player

class Player(Sprite):
    color = 255,25,69
    size = 20,20

    def __init__(self, loc, bounds):
        Sprite.__init__(self) #makes player a sprite object

        self.image = Surface(self.size)
        self.rect = self.image.get_rect() 

        self.rect.center = loc
        self.bounds = bounds

        self.image.fill(self.color)
        self.bullets = Group()

    def update(self):
        self.rect.center = pygame.mouse.get_pos() #player moves/stays with mouse
        self.rect.clamp_ip(self.bounds) #cant leave screen bounds

    def shoot(self):
        if not self.alive():
            return #stop doing anything in this function
        bullet = Bullet(self.bounds)
        bullet.rect.midbottom = self.rect.midtop 
        self.bullets.add(bullet)
开发者ID:jlevey3,项目名称:CS112-Spring2012,代码行数:26,代码来源:player.py

示例14: run_game

def run_game():
    pygame.init()

    ai_settings = Settings()

    """ Screen settings and such"""
    screen = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height))

    pygame.display.set_caption("Alien Invasion")
    stats = GameStats(ai_settings)

    bg_color = (230, 230, 230)
    """background screen color; grey"""

    ship = Ship(ai_settings, screen)
    bullets = Group()
    aliens = Group()
    gf.create_fleet(ai_settings, screen, ship, aliens)

    while True:
        gf.check_events(ai_settings, screen, ship, bullets)
        ship.update()
        gf.update_bullets(ai_settings, screen, ship, aliens, bullets)
        gf.update_aliens(ai_settings, stats, screen, ship, aliens, bullets)
        gf.update_screen(ai_settings, screen, ship, aliens, bullets)

        for bullet in bullets.copy():
            if bullet.rect.bottom <= 0:
                bullets.remove(bullet)
        print(len(bullets))
开发者ID:MasonWhite000,项目名称:AlienInvasion,代码行数:31,代码来源:Alien_Invasion.py

示例15: Level

class Level(object):

    def __init__(self):
        self.bounds = Rect((0,0), LEVEL_SIZE)
        print "self.bounds = ", self.bounds

        self.ceilingCoord = 0
        self.floorCoord = self.bounds.height - 40
        self.leftWall = 0
        self.rightWall = self.bounds.width - 40
        
        # make rects for level
        self.blocks = Group(Block(0,0,40,self.bounds.height), # left wall
                            Block(self.bounds.width - 40, 0, 40, self.bounds.height), # right wall
                            Block(0, self.bounds.height - 40, self.bounds.width, 40), # floor
                            Block(200,self.floorCoord-80, 20, 80), # extra bit
                            Spike(350, self.floorCoord, 40), # DEATH SPIKE
                            NinjaStar(350, self.floorCoord - 130) # ninja star 
                            )

        
        
        # render
        self.render_background()

    def render_background(self):
        self.background = Surface(self.bounds.size)
        self.background.fill((80,80,80))
        self.blocks.draw(self.background)
开发者ID:habahut,项目名称:CS112-Spring2012,代码行数:29,代码来源:level.py


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