Ejemplo n.º 1
0
while not state.done:
    screen.fill((0, 0, 0))

    player.rotate()
    for event in pygame.event.get():
        if event.type == pygame.QUIT or (event.type == pygame.KEYDOWN
                                         and event.key == pygame.K_ESCAPE):
            state.set_done()
        if event.type == pygame.MOUSEBUTTONDOWN:
            e_shoot_time = time.time()
            if e_shoot_time - s_shoot_timer > 0.09:
                state.increment_num_shots()
                color = color_generator.next()
                state.add_shot(
                    Bullet(
                        math.atan2(player.direction_y - (player.y + 32),
                                   player.direction_x - (player.x + 26)),
                        player.x + 32, player.y + 32, color))
                s_shoot_timer = e_shoot_time

    # shooting
    for bullet in state.shots:
        velx = math.cos(bullet.orientation) * 10
        vely = math.sin(bullet.orientation) * 10
        bullet.move(velx, vely)
        if bullet.x < -64 or bullet.y > size[
                0] + 40 or bullet.y < -64 or bullet.y > size[1] + 80:
            state.remove_shot(bullet)

        for projectile in state.shots:
            projectile.image.fill((0, 0, 0, 255), None, pygame.BLEND_RGB_MULT)