本文整理汇总了Python中stage.Stage.checkcollide方法的典型用法代码示例。如果您正苦于以下问题:Python Stage.checkcollide方法的具体用法?Python Stage.checkcollide怎么用?Python Stage.checkcollide使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stage.Stage
的用法示例。
在下文中一共展示了Stage.checkcollide方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Vacuum
# 需要导入模块: from stage import Stage [as 别名]
# 或者: from stage.Stage import checkcollide [as 别名]
#.........这里部分代码省略.........
self.clock.tick(25)
#handle input events
ok = self.handle_keys()
if ok == False:
return
if self.game_started == False:
start_text = self.font.render('Press any key to start', 2, (0,0,0))
self.screen.blit(start_text, (150, 200))
pygame.display.flip()
continue
if self.game_paused == 1:
start_text = self.font.render('Game paused', 2, (255,255,255))
self.screen.blit(start_text, (150, 200))
pygame.display.flip()
continue
new_enemies = self.level.getenemies()
for enemy_y in new_enemies:
#if random.randint(0,50) == 0:
alien = Alien(enemy_y)
alien.set_target(self.ship)
self.enemies.add(alien)
#aliens damaging the player, remove them
damage = pygame.sprite.spritecollide(self.ship, self.enemies, True)
self.process_powerups()
#check colisions with stage
if self.level.checkcollide(self.ship.rect):
#add some fancy explosions in the damage area
self.explosions.add(Explosion(pygame.Rect(self.ship.rect.x,self.ship.rect.y,0,0)))
damage.append(1)
#Apply damages to the player
if len(damage) > 0:
self.background.warning()
self.ship.damage()
self.lifemeter.shake()
self.explosions.add(Explosion(self.ship.rect))
self.sounds['warning'].play()
self.lifemeter.life = self.ship.life
if self.lifemeter.life < 1:
self.game_finished = True
self.sounds['warning'].stop()
#print (pygame.sprite.spritecollide(ship, level, True))
#aliens hit by the fire, remove them
penetration = self.ship.powerup['penetrate']
for fireball in self.fire:
hit = pygame.sprite.spritecollide(fireball, self.enemies, True)
for dead in hit:
if dead.has_powerup():
powerup = Powerup(dead.rect, dead.value)
self.powerups.add(powerup)
self.explosions.add(Explosion(pygame.Rect(dead.rect.x,dead.rect.y,0,0)))
self.score+=dead.value*1000
if penetration == False:
fireball.kill()
#draw the level
示例2: Vacuum
# 需要导入模块: from stage import Stage [as 别名]
# 或者: from stage.Stage import checkcollide [as 别名]
#.........这里部分代码省略.........
elif powerup_obtained.type == 1 and self.ship.powerup['speedup'] < 5:
self.ship.powerup['speedup'] += 1
self.powerup_speed.set_status(self.ship.powerup['speedup'])
self.hud.add(Flying_Label( self.ship.rect, 'Speed up'))
#print "Increase speed to {0}".format(self.ship.powerup['speedup'])
elif powerup_obtained.type == 2 and Laser.max_lasers < 5:
Laser.max_lasers += 1
Laser.move += 2
self.powerup_weapon.set_status(Laser.max_lasers)
print "Increase lasers to {0}".format(Laser.max_lasers)
self.hud.add(Flying_Label( self.ship.rect, 'Lasers'))
elif powerup_obtained.type == 3 and self.ship.powerup['penetrate'] == False:
print "Activate penetration"
self.hud.add(Flying_Label( self.ship.rect, 'Penetration'))
self.ship.powerup['penetrate'] = True
elif powerup_obtained.type == 4:
print "Activate buddy"
self.buddies.add(Buddy(self.ship))
self.ship.buddies += 1
self.powerup_buddy.set_status(self.ship.buddies)
else:
print "No more powerups available"
def add_explosion(self, rect):
self.explosions.add(Explosion(rect.copy()))
def add_enemylaser(self, laser):
self.enemylasers.add(laser)
def process_stagecollisions(self):
damage = []
#check colisions with stage
side = self.level.checkcollide(self.ship.rect)
if side != 0:
#add some fancy explosions in the damage area
self.explosions.add(Explosion(pygame.Rect(self.ship.rect.x,self.ship.rect.y + side *self.ship.rect.height,0,0)))
damage.append(1)
return damage
def process_damage(self, damage):
#Apply damages to the player
if len(damage) > 0:
self.background.warning()
self.ship.damage()
self.lifemeter.shake()
self.add_explosion(self.ship.rect)
self.sounds['warning'].play()
self.lifemeter.life = self.ship.life
if self.lifemeter.life < 1:
self.game_finished = True
self.sounds['warning'].stop()
def process_killedaliens(self):
#aliens hit by the fire, remove them
penetration = self.ship.powerup['penetrate']
for fireball in self.fire:
hit = pygame.sprite.spritecollide(fireball, self.enemies, True)
#Check collisions with masks since the minibosses can have funny shapes
enemies_hit = []
for miniboss in self.minibosses:
if pygame.sprite.collide_mask(fireball, miniboss):
fireball.kill()
enemies_hit.append(miniboss)
for strike in enemies_hit: