def update(self): for entity in self.npcs: entity.update() for npc in self.npcs: bullet_collided = pygame.sprite.spritecollideany( self.player, npc.bullets) if bullet_collided: self.player.health -= 1 bullet_collided.kill() if self.player.health < 1: import game_over self.next_scene = game_over.GameOver( self.screen, "We all stumble at some point. Want to try again or take a break?", self.get_current_level()) player_bullet_collided = pygame.sprite.spritecollideany( npc, self.player.player_bullets) if player_bullet_collided: npc.hurt() player_bullet_collided.kill() if npc.health < 1: npc.kill() if len(self.npcs): if self.boss_block_rect.colliderect(self.player.rect): if self.boss_block_rect.centerx < self.player.rect.left: self.player.rect.left = self.boss_block_rect.right else: self.player.rect.right = self.boss_block_rect.left
def kill_bird(self): self.is_dead = True print("Bird died") arcade.play_sound(self.dying_sound_2) self.tear_down(self.sky_scraper_sprites) self.tear_down(self.answer_sprites) self.tear_down(self.wall_list) new_view = game_over.GameOver(self, self.score) self.window.show_view(new_view)
def on_update(self, delta_time): self.generateBlock() self.physicPlayer.update() self.handleBlocks() # Keep player inside screen if self.canMoveLeft() == False or self.canMoveRight() == False: self.player_sprite.change_x = 0 # Check if player touches a block collisions = arcade.check_for_collision_with_list( self.player_sprite, self.blocks) if len(collisions) > 0: gameOverView = game_over.GameOver() self.window.show_view(gameOverView)
def update(self): super().update() if self.player.rect.colliderect(self.exit_block_rect): self.next_scene = game_over.GameOver(self.screen)
def update(self, screen): # Draw stats score = "Score: " + str(self.score) level = "Level: " + str(self.level) blocks = "Blocks: " + str(len(self.block_group)) lives = "Lives: " + str(self.lives) self.ui.draw_text(score, location=(W / 20, 10), align=-1) self.ui.draw_text(level, location=(6 * W / 20, 10), align=-1) self.ui.draw_text(blocks, location=(11 * W / 20, 10), align=-1) self.ui.draw_text(lives, location=(16 * W / 20, 10), align=-1) # Update blocks if len(self.block_group) == 0: self.ball_group.remove() self.paddle_group.remove() # Begin next level when all blocks are done if level is available if self.level < len(LEVELS) - 1 and not self.fading_block_group: self.level += 1 self.nextState = lambda: Playing(self.lives, self.score, self. level) self.transition() # Otherwise give bonus for remaining lives and end game elif self.level >= len(LEVELS) - 1 and not self.fading_block_group: for life in range(self.lives): self.score += (life + 1) * 10000 self.nextState = lambda: go.GameOver(self.score) self.transition() self.block_group.update() # Move paddle self.paddle.X += self.paddle.velocity.x if self.paddle.X < 0: self.paddle.X = 0 elif self.paddle.X > W - self.paddle.frame_width: self.paddle.X = W - self.paddle.frame_width self.paddle_group.update() # Move ball if self.waiting: # Ball is resting on center of paddle self.ball.X = self.paddle.X + 36 self.ball.Y = self.paddle.Y - 16 # Update position of ball self.ball.X += self.ball.velocity.x self.ball.Y += self.ball.velocity.y if self.ball.X < 0: self.bop() self.ball.X = 0 self.ball.velocity.x *= -1 elif self.ball.X > W - self.ball.frame_width: self.bop() self.ball.X = W - self.ball.frame_width self.ball.velocity.x *= -1 if self.ball.Y < 0: self.bop() self.ball.Y = 0 self.ball.velocity.y *= -1 elif self.ball.Y > H - self.ball.frame_height: self.waiting = True self.lives -= 1 self.nextState = lambda: Playing(self.lives, self.score, self. level, self.block_group) self.transition() if self.lives < 1: self.nextState = lambda: go.GameOver(self.score) self.transition() # Check for collision between ball and paddle if pygame.sprite.collide_rect(self.ball, self.paddle): self.boop() self.ball.velocity.y = -abs(self.ball.velocity.y) bx = self.ball.X + 8 by = self.ball.Y + 8 px = self.paddle.X + self.paddle.frame_width / 2 #py = self.paddle.Y + self.paddle.frame_height / 2 if bx < px: self.ball.velocity.x = -abs(self.ball.velocity.x) else: self.ball.velocity.x = abs(self.ball.velocity.x) # Check for collision between ball and blocks hit_block = pygame.sprite.spritecollideany(self.ball, self.block_group) if hit_block != None: self.beep() self.score += 10 location = hit_block.position self.block_group.remove(hit_block) bx = self.ball.X + 8 by = self.ball.Y + 8 # Create fading block sprite filename = "resources\\breakout_block_fading.png" width, height, columns = 64, 32, 18 sprite = basesprite.BaseSprite(filename, width, height, columns, expire=True) sprite.position = location self.fading_block_group.add(sprite) # Above or below if hit_block.X + 5 < bx < hit_block.X + hit_block.frame_width - 5: if by < hit_block.Y + hit_block.frame_height / 2: self.ball.velocity.y = -abs(self.ball.velocity.y) else: self.ball.velocity.y = abs(self.ball.velocity.y) # left side elif bx < hit_block.X + 5: self.ball.velocity.x = -abs(self.ball.velocity.x) # Right side elif bx > hit_block.X + hit_block.frame_width - 5: self.ball.velocity.x = abs(self.ball.velocity.x) # Anything else else: self.ball.velocity.y *= -1 self.ball_group.update() self.fading_block_group.update() # Draw everything self.block_group.draw(screen) self.ball_group.draw(screen) self.paddle_group.draw(screen) self.fading_block_group.draw(screen)
def people_enemy(people, enemys): for i in range(len(enemys) - 1, -1, -1): if int(people.x) in range(int(enemys[i].diren.x) - 30, int(enemys[i].diren.x) + 30) and \ int(people.y) in range(int(enemys[i].diren.y) - 30, int(enemys[i].diren.y) + 30): cocos.director.director.push(game_over.GameOver())