本文整理汇总了Python中pygame.sprite.Group类的典型用法代码示例。如果您正苦于以下问题:Python Group类的具体用法?Python Group怎么用?Python Group使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Group类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: __init__
def __init__(self):
#setup
pygame.init()
pygame.font.init()
self.font = pygame.font.Font(None,24)
self.fontColor = (0,0,0)
pygame.mixer.init()
pygame.display.set_mode(SCREEN)
pygame.display.set_caption('#ElJuegoDeLasJoincic')
self.screen = pygame.display.get_surface()
self._quit=False
self.clock = pygame.time.Clock()
self.controller= Controller()
self.background = load_image("background.png")
self.menu_background = load_image("menu_background.png")
self.menu_iniciar = load_image("menu_iniciar.png")
self.menu_salir = load_image("menu_salir.png")
self.gameover = load_image("gameover.png")
self.cursor = load_image("cursor.png")
self.arrow = load_image("arrow.png")
self.player = Player()
self.group = Group()
self.protocolo = Protocolo()
self.group.add(self.player)
self.groupOyentes = Group()
self.groupTakitos = Group()
self.groupHUD = Group()
self.state= GAME_INIT
开发者ID:chiguire,项目名称:ElJuegoDeLasJoincic,代码行数:31,代码来源:game.py
示例17: _draw_cloud
def _draw_cloud(tag_list, surface, vertical=True, fontname='fonts/Arial.ttf', fontzoom=5, rectangular=False):
#Sort the tags by size and wordlength
tag_list.sort(key=lambda tag: len(tag['tag']))
tag_list.sort(key=lambda tag: tag['size'])
tag_list.reverse()
if rectangular:
spiral = _rectangular_spiral
else:
spiral = _archimedean_spiral
sizeRect = surface.get_rect()
tag_store = Group()
for tag in tag_list:
rot = 0
if vertical and randint(0, 2) == 0:
rot = 90
currentTag = Tag(tag, (0, 0), rot, fontname=fontname, fontzoom=fontzoom)
xpos = sizeRect.width - currentTag.rect.width
if xpos < 0: xpos = 0
xpos = randint(int(xpos * LOWER_START) , int(xpos * UPPER_START))
currentTag.rect.x = xpos
ypos = sizeRect.height - currentTag.rect.height
if ypos < 0: ypos = 0
ypos = randint(int(ypos * LOWER_START), int(ypos * UPPER_START))
currentTag.rect.y = ypos
_search_place(currentTag, tag_store, sizeRect, spiral, vertical)
tag_store.add(currentTag)
surface.blit(currentTag.image, currentTag.rect)
return tag_store
开发者ID:mooseburger,项目名称:PyTagCloud,代码行数:34,代码来源:__init__.py
示例18: load_tiles
def load_tiles(self, filename):
try:
self.tiles = Group()
self.walls = Group()
level = open(filename, 'r')
line = level.readline().strip()
while line != '[tiles]':
line = level.readline().strip()
self.sheet = int(level.readline().strip())
set_tile_stats(self)
self.set_areas()
y = -self.tile_height
line = level.readline().strip()
while line and line != '[units]':
x = 0
y += self.tile_height
for k in line.split(' '):
if not k.strip():
continue
tile = Tile(x, y, self.sheet, int(k), self)
self.tiles.add(tile)
if tile.kind in self.wall_kinds:
tile.flags |= FLAGS.WALL
self.walls.add(tile)
else:
tile.flags |= FLAGS.FLOOR
x += self.tile_width
line = level.readline().strip()
self.lw = x
self.lh = y + self.tile_height
level.close()
except IOError:
return self.load_default_tiles()
开发者ID:drtchops,项目名称:iancraft,代码行数:35,代码来源:tiles.py
示例19: load_default_tiles
def load_default_tiles(self, columns=40, rows=30, sheet=0,
kinds=(0, 1, 2)):
self.sheet = sheet
set_tile_stats(self)
self.set_areas()
self.lw = columns * self.tile_width
self.lh = rows * self.tile_height
self.tiles = Group()
self.walls = Group()
y = 0
t = 0
for r in xrange(rows):
x = 0
for c in xrange(columns):
tile = Tile(x, y, sheet, kinds[t % len(kinds)], self)
self.tiles.add(tile)
if tile.kind in self.wall_kinds:
tile.flags |= FLAGS.WALL
self.walls.add(tile)
else:
tile.flags |= FLAGS.FLOOR
x += self.tile_width
t += 1
y += self.tile_height
开发者ID:drtchops,项目名称:iancraft,代码行数:25,代码来源:tiles.py
示例20: _draw_cloud
def _draw_cloud(
tag_list,
surface,
layout=LAYOUT_MIX,
fontname=DEFAULT_FONT,
palette=DEFAULT_PALETTE,
fontzoom=5,
rectangular=False,
order=True):
#Sort the tags by size and word length
tag_list.sort(key=lambda tag: len(tag['tag']))
tag_list.sort(key=lambda tag: tag['size'])
tag_list.reverse()
if rectangular:
spiral = _rectangular_spiral
else:
spiral = _archimedean_spiral
sizeRect = surface.get_rect()
tag_store = Group()
if not order:
random.shuffle(tag_list)
for tag in tag_list:
rot = 0
flip = False
if layout == LAYOUT_MIX and randint(0, 2) == 0:
rot = 90
elif layout == LAYOUT_VERTICAL:
rot = 90
elif layout == LAYOUT_MOST_VERTICAL:
rot = 90
flip = True
elif layout == LAYOUT_MOST_HORIZONTAL:
flip = True
#set color if tag has no color
if not hasattr(tag, 'color'):
pass
currentTag = Tag(tag, (0, 0), rot, fontname=fontname, fontzoom=fontzoom)
xpos = sizeRect.width - currentTag.rect.width
if xpos < 0: xpos = 0
xpos = randint(int(xpos * LOWER_START) , int(xpos * UPPER_START))
currentTag.rect.x = xpos
ypos = sizeRect.height - currentTag.rect.height
if ypos < 0: ypos = 0
ypos = randint(int(ypos * LOWER_START), int(ypos * UPPER_START))
currentTag.rect.y = ypos
_search_place(currentTag, tag_store, sizeRect, spiral, flip)
tag_store.add(currentTag)
surface.blit(currentTag.image, currentTag.rect)
return tag_store
开发者ID:davepeake,项目名称:PyTagCloud,代码行数:59,代码来源:__init__.py
注:本文中的pygame.sprite.Group类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论