Esempio n. 1
0
def enemy_shoot(hero, shots):
    if hero.weapon.ammo > 0 and hero.shoot_count < 0:
        x, y, = hero.rect.center
        y1 = -6
        s = True
        shoots = []
        hero.weapon.sound.play()
        if hero.direction:
            s = Shot((x + 100, y + y1), (x + hero.wx_l, y + y1), hero.weapon.hit)
            if hero.weapon.bullet_num != 1:
                for i in range(hero.weapon.bullet_num):
                    shoot = Shot((x + 100, y - 20 + 10 * i), (x + hero.wx_l, y + y1), hero.weapon.hit)
                    shoot.image = pygame.image.load('bullit_r.png').convert()
                    shoots.append(shoot)
            s.image = pygame.image.load('bullit_r.png').convert()
        else:
            s = Shot((x - 100, y + y1), (x + hero.wx_r, y + y1), hero.weapon.hit)
            if hero.weapon.bullet_num != 1:
                for i in range(hero.weapon.bullet_num):
                    shoots.append(Shot((x - 100, y - 20 + 10 * i), (x + hero.wx_r, y + y1), hero.weapon.hit))

        if type(s) == Shot:
            hero.weapon.shoot()
            hero.shoot_count = 50
            shots.append(s)
            if shoots != []:
                shots += shoots
            return True
        else:
            return False
Esempio n. 2
0
 def shoot(self, now, all_sprites, bullets):
     self.snd_player_shoot.play()
     self.last_shot = now
     new_shot1 = Shot((self.pos[0] + 8, self.pos[1]), self.firing_speed)
     new_shot2 = Shot((self.pos[0] + 24, self.pos[1]), self.firing_speed)
     all_sprites.add(new_shot1)
     all_sprites.add(new_shot2)
     bullets.add(new_shot1)
     bullets.add(new_shot2)
Esempio n. 3
0
 def get_shots(self):
     shots = []
     i = 0
     s = 0
     for frame in self.cutting_list:
         shot = Shot(num=s, start=i, end=frame)
         shots.append(shot)
         s += 1
         i = frame
     if i < 16200:
         shot = Shot(num=s, start=i, end=16200)
         shots.append(shot)
     self.shots = shots
 def fire (self, pos):
     # Is this a hit
     for this_ship in self.ships:
         if (this_ship.fire(pos)):
             # Hit
             self.shots.append(Shot("hit",self.grid.grid_pos_to_screen_pos(pos)))
             #check if this ship sunk
             if this_ship.is_sunk():
                 # Ship sunk so make it visible
                 this_ship.hidden = False
             return True
     self.shots.append(Shot("miss",self.grid.grid_pos_to_screen_pos(pos)))
     return False
Esempio n. 5
0
 def update(self, enemies, on_screen_shots, register):
     if self.t_num != 0 and self.t_num != 7:
         aim_spot = (0, 0)
         for e in enemies:
             if is_in_circle(e.center(), self.box.center, self.range()):
                 aim_spot = e.pos()
                 if self.coolness <= 0:
                     on_screen_shots.append(
                         Shot(self.box.center, e.id, self.color(),
                              self.speed(), self.power()))
                     register(on_screen_shots[
                         len(on_screen_shots) -
                         1])  # register this bullet to be drawn
                     if self.t_num == 1:
                         on_screen_shots[len(on_screen_shots) -
                                         1].poison = True
                     if self.t_num == 2:
                         on_screen_shots[len(on_screen_shots) -
                                         1].ice = True
                     self.coolness = self.cooldown()
                     break
         if self.coolness > 0:
             self.coolness -= 1
         # point at the first enemy in range
         self.gun.update(aim_spot)
Esempio n. 6
0
    def handle_shot(self, laser_color, x, y):	
        if (self._pause_shot_detection):
            return 

        timestamp = 0

        # Start the shot timer if it has not been started yet,
        # otherwise get the time offset
        if self._shot_timer_start is None:
            self._shot_timer_start = time.time()
        else:
            timestamp = time.time() - self._shot_timer_start

        tree_item = None

        if "green" in laser_color:
            tree_item = self._shot_timer_tree.insert("", "end",
                values=[timestamp, "green"])
        else:
            tree_item = self._shot_timer_tree.insert("", "end",
                values=[timestamp, laser_color])
        self._shot_timer_tree.see(tree_item)

        new_shot = Shot((x, y), self._webcam_canvas,
            self._preferences[configurator.MARKER_RADIUS],
            laser_color, timestamp)
        self._shots.append(new_shot)
        new_shot.draw_marker()

        # Process the shot to see if we hit a region and perform
        # a training protocol specific action and any if we did
        # command tag actions if we did
        self.process_hit(new_shot, tree_item)
def compile_shots(data, total_len, shot_len, heat_table):
    shot_list = []
    for i in range(min(heat_table.shape[0], total_len)):
        new_shot = Shot(i, i * shot_len, shot_len, heat_table)
        shot_list.append(new_shot)
        #print(new_shot.anchor)
    return shot_list
Esempio n. 8
0
 def test_dst(self):
     s = Shot(dst="dir/that/does_not/exist", num=2)
     s.console.print = MagicMock()
     s()
     s.console.print.assert_called_with(
         "dst must be a directory when num > 1. got:dir/that/does_not/exist\n",
         style="red")
Esempio n. 9
0
 def test_src(self):
     s = Shot(src="dir/that/does_not/exist")
     s.console.print = MagicMock()
     s()
     s.console.print.assert_called_with(
         "src must be a directory. got:dir/that/does_not/exist\n",
         style="red")
Esempio n. 10
0
    def test_start_and_num(self, check_output_mock, copy_mock, glob_mock):
        """
        should copy the 2 latest screenshots, starting from the 2nd latest
        """
        check_output_mock.side_effect = [b"/tmp/tests\n"]
        glob_mock.side_effect = [[
            "/tmp/tests/1", "/tmp/tests/2", "/tmp/tests/3", "/tmp/tests/4"
        ]]

        check_output_calls = [
            call(["defaults", "read", "com.apple.screencapture", "location"])
        ]
        copy_mock_calls = [
            call("/tmp/tests/2", "."),
            call("/tmp/tests/3", ".")
        ]

        s = Shot(start=2, num=2)
        s.console.print = MagicMock()
        s()
        s.console.print.assert_called_with(
            "Copied the following files from /tmp/tests to . successfully!\n['2', '3']",
            style="green",
        )
        check_output_mock.assert_has_calls(check_output_calls)
        copy_mock.assert_has_calls(copy_mock_calls)
Esempio n. 11
0
    def test_changing_extension_yes(self, check_output_mock, copy_mock,
                                    glob_mock):
        """
        should warn the user the extension is being changed
        """
        # make sure dst is treated as file
        # self.mock_isdir.return_value = True
        self.mock_isdir.side_effect = [False, False]
        check_output_mock.side_effect = [b"/tmp/tests\n"]
        glob_mock.side_effect = [["/tmp/tests/first.txt"]]
        print_mock_calls = [
            call(
                "Warning: src and dst extensions don't match. {'src': '.txt', 'dst': '.md'}",
                style="yellow",
            ),
            call(
                "Copied the following files from /tmp/tests to ./first.md successfully!\n['first.txt']",
                style="green",
            ),
        ]

        copy_mock_calls = [call("/tmp/tests/first.txt", "./first.md")]
        s = Shot(yes=True, dst="./first.md")
        s.console.print = MagicMock()
        s()
        s.console.print.assert_has_calls(print_mock_calls)
        copy_mock.assert_has_calls(copy_mock_calls)
Esempio n. 12
0
    def test_not_enough_files_yes(self, check_output_mock, copy_mock,
                                  glob_mock):
        """
        should warn the user there are not enough files, but still copy the ones available
        """
        check_output_mock.side_effect = [b"/tmp/tests\n"]
        glob_mock.side_effect = [["/tmp/tests/1"]]

        check_output_calls = [
            call(["defaults", "read", "com.apple.screencapture", "location"])
        ]
        copy_mock_calls = [call("/tmp/tests/1", ".")]
        print_mock_calls = [
            call(
                "Warning: there are not enough files to copy with {'start': 1, 'num': 2}",
                style="yellow",
            ),
            call(
                "Copied the following files from /tmp/tests to . successfully!\n['1']",
                style="green",
            ),
        ]

        s = Shot(num=2, yes=True)
        s.console.print = MagicMock()
        s()
        s.console.print.assert_has_calls(print_mock_calls)
        check_output_mock.assert_has_calls(check_output_calls)
        copy_mock.assert_has_calls(copy_mock_calls)
Esempio n. 13
0
def events():
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()
        elif event.type == pygame.KEYDOWN:
            if event.key == pygame.K_SPACE:
                new_shot = Shot(shots_group, WINDOW_SIZE)
                new_shot.rect.center = player.rect.center
Esempio n. 14
0
 def shoot(self, e):
     if self.overheatTime == 0:
         shotPos = self.getx(self.spaceship) + SHIPSIZE / 2
         self.shotList.append(Shot(4, 10, 0, -20, self.create_rectangle(shotPos - 2, HEIGHT - SHIPSIZE, shotPos + 2, HEIGHT - SHIPSIZE - 10, width=0, fill="blue", tag="SpaceShipShot")))
         self.accShots += 1
         self.cooldown += 60
         if self.cooldown >= 200:
             self.cooldown = 199
             self.overheatTime = 70
Esempio n. 15
0
 def doShoot(self):
     # Get ranom number to decide if aliens shoot in this tick.
     # The higher the level the smaller the range for the random number
     rand = randint(1, int(100 / (self.level * 2)))
     # if randint is one, a random alien shoots
     if rand == 1:
         if len(self.alienList) > 0:
             randAlien = self.alienList[randint(0, len(self.alienList) - 1)]
             shotPosx = self.getx(randAlien.id) + (randAlien.sizex / 2) - 3
             shotPosy = self.gety(randAlien.id) + randAlien.sizey
             self.shotList.append(Shot(7, 6, 0, 4, self.create_rectangle(shotPosx, shotPosy, shotPosx + 6, shotPosy + 7, width=1, tag="alienShot", fill="red")))
     # if randint is two, the bomber shoots, but only if there is no shot
     # on the pitch yet
     elif rand == 2 and len(self.find_withtag("bomber")) > 0 and len(self.find_withtag("bomberShot")) <= 1 and self.getx(self.bomber.id) > BORDER and self.bomberCooldown == 0:
         self.shotList.append(Shot(12, 12, 0, 3, self.create_image(self.getx(self.bomber.id) + (self.bomber.sizex / 2), self.gety(self.bomber.id) + self.bomber.sizey, image=self.bomber_shot_img, tag="bomberShot", anchor="nw")))
         self.bomberCooldown = 100
     elif self.bomberCooldown > 0:
         self.bomberCooldown -= 1
Esempio n. 16
0
def test_cp_multiple(tmp_path):
    src_dir, dst_dir, src_file = setup_dirs(tmp_path, nfiles=2)
    expected_output_path_one = dst_dir / "foo1.txt"
    expected_output_path_two = dst_dir / "foo2.txt"
    assert os.path.exists(expected_output_path_one) == False
    assert os.path.exists(expected_output_path_two) == False
    Shot(src=str(src_dir), dst=str(dst_dir), num=2)()
    assert os.path.exists(expected_output_path_one) == True
    assert os.path.exists(expected_output_path_two) == True
Esempio n. 17
0
 def __init__(self, x: int, y: int, game_ref: 'Game', cam_ref: 'Camera',
              spd: int) -> None:
     self.x = x
     self.y = y
     self.update = self.idle
     self.cam_ref = cam_ref
     self.max_timer = spd * FREQ
     self.timer = self.max_timer
     self.shot = Shot(self.x, self.y)
     game_ref.game_objects["shot"].append(self.shot)
Esempio n. 18
0
 def test_no_files(self, check_output_mock, glob_mock):
     """
     should warn the user no files were found
     """
     check_output_mock.side_effect = [b"/tmp/tests/empty\n"]
     glob_mock.side_effect = [[]]
     s = Shot()
     s.console.print = MagicMock()
     s()
     s.console.print.assert_called_with(
         "No files found in /tmp/tests/empty", style="red")
Esempio n. 19
0
def test_cp_file_exists(tmp_path):
    """
    should fail because src and dst are the same.
    print error and systemexist.
    """
    src_dir, dst_dir, src_file = setup_dirs(tmp_path)
    with pytest.raises(SystemExit) as context:
        s = Shot(src=str(src_dir), dst=str(src_dir))
        s._confirm = lambda: True  # avoid capturing stdin during test
        s()
    assert (1, ) == context.value.args
Esempio n. 20
0
def test_mv(tmp_path):
    """
    src file should not exist after running shot, dst file should
    """
    src_dir, dst_dir, src_file = setup_dirs(tmp_path)
    expected_output_path = dst_dir / "foo1.txt"
    assert os.path.exists(src_file) == True
    assert os.path.exists(expected_output_path) == False
    Shot(src=str(src_dir), dst=str(dst_dir), mv=True)()
    assert os.path.exists(src_file) == False
    assert os.path.exists(expected_output_path) == True
Esempio n. 21
0
def test_debug_mv_file_exists(tmp_path):
    """
    should fail because src and dst are the same.
    latest file will be foo, will fail to copy since it already exists.
    """
    src_dir, dst_dir, src_file = setup_dirs(tmp_path)
    with pytest.raises(Exception) as context:
        s = Shot(src=str(src_dir), dst=str(src_dir), mv=True, debug=True)
        s._confirm = lambda: True  # avoid capturing stdin during test
        s()
    assert f"Destination path '{src_file}' already exists" in context.value.args
Esempio n. 22
0
def test_mv_to_file(tmp_path):
    """
    dst dir exists but dst/bar.txt does not.
    shot should create it by copying src/foo1.txt to dst/bar.txt
    """
    src_dir, dst_dir, src_file = setup_dirs(tmp_path)
    expected_output_path = dst_dir / "bar.txt"
    assert os.path.exists(src_file) == True
    assert os.path.exists(expected_output_path) == False
    Shot(src=str(src_dir), dst=str(expected_output_path), mv=True)()
    assert os.path.exists(src_file) == False
    assert os.path.exists(expected_output_path) == True
Esempio n. 23
0
def test_cp(tmp_path):
    """
    src file should be unchanged, dst file should exist after running shot
    """
    src_dir, dst_dir, src_file = setup_dirs(tmp_path)
    expected_output_path = dst_dir / "foo1.txt"
    assert os.path.exists(src_file) == True
    assert os.path.exists(expected_output_path) == False
    Shot(src=str(src_dir), dst=str(dst_dir))()
    assert os.path.exists(src_file) == True
    assert os.path.exists(expected_output_path) == True
    tear_down_dirs(tmp_path)
Esempio n. 24
0
 def take_screenshot(self, widget):
     shot = Shot()
     shot.start()
     time.sleep(0.5)
     screenshot = gtk.gdk.Pixbuf.get_from_drawable(
         gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8, shot.width,
                        shot.height), gtk.gdk.get_default_root_window(),
         gtk.gdk.colormap_get_system(), shot.sX, shot.sY, 0, 0, shot.width,
         shot.height)
     filename = "/tmp/droplr.png"
     screenshot.save(filename, "png")
     self.upload_file_and_notify(filename)
Esempio n. 25
0
def main():
    somAtivado = True
    timer = 10
    gameLoop = True
    gameover = False
    clock = pygame.time.Clock()

    while gameLoop:
        clock.tick(60)
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                gameLoop = False

            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_SPACE and not gameover:
                    shoot.play()
                    newShot = Shot(objectGroup, shotGroup)
                    newShot.rect.center = player.rect.center

                if event.key == pygame.K_m:
                    if somAtivado:
                        pygame.mixer.music.stop()
                        somAtivado = False
                    else:
                        pygame.mixer.music.play(-1)
                        somAtivado = True

        # Tempo para a criação dos asteroides
        if not gameover:
            timer += 1
            if timer > 30:
                timer = 0
                if random.random() < 0.4:
                    newAsteroid = Asteroid(objectGroup, asteroidGroup)

            # Colisão dos asteroides
            collisions = pygame.sprite.spritecollide(
                player, asteroidGroup, False, pygame.sprite.collide_mask)
            if collisions:
                print("Game Over!")
                gameover = True

            # Shots
            hits = pygame.sprite.groupcollide(shotGroup, asteroidGroup, True,
                                              True, pygame.sprite.collide_mask)

            # Update
            objectGroup.update()

        # Draw
        objectGroup.draw(tela)
        pygame.display.update()
Esempio n. 26
0
    def move(self, grid, fire_beams, pos, num_column, mandalorian, columns, ice_balls, boss):
        if self.__alive == 0:
            return 0
        temp = {}
        for i in self.__coordinates:
            temp[i] = []
            for j in self.__coordinates[i]:
                if grid[i][j].shot == 1:
                    grid[i][j] = Playarea()
                temp[i].append(j + 6)

        for i in self.__coordinates:
            for j in self.__coordinates[i]:
                for k in range(0, 7):
                    if (j + k) < columns and grid[i][j + k].fire == 1:
                        mandalorian.score += 2
                        self.__alive = 0
                        num = grid[i][j + k].beam_num
                        fire_beams[num].self_destruct(grid)
                        return 0
                    if (j + k) < columns and grid[i][j + k].ice == 1:
                        mandalorian.score += 1
                        self.__alive = 0
                        num = grid[i][j + k].ice_num
                        ice_balls[num].self_destruct(grid)
                        return 0
                    if (j + k) < columns and grid[i][j + k].boss == 1:
                        mandalorian.score += 3
                        self.__alive = 0
                        boss.life -= 1
                        if boss.life <= 0:
                            return 1
                        return 0
                    if (j + k) >= pos + num_column:
                        self.__alive = 0

        if self.__alive == 0:
            return 0

        self.__coordinates.clear()
        t1 = 0
        for i in temp:
            t2 = 0
            self.__coordinates[i] = []
            for j in temp[i]:
                self.__coordinates[i].append(j)
                if grid[i][j].points == 0 and grid[i][j].attr == 0 and grid[i][j].boost == 0:
                    grid[i][j] = Shot(self.__display[t1][t2])
                t2 += 1
            t1 += 1

        return 0
Esempio n. 27
0
    def test_dry_run(self, check_output_mock, glob_mock):
        """
        should show the command that would copy the latest screenshot to the current directory
        """
        check_output_mock.side_effect = [b"/tmp/tests\n"]
        glob_mock.side_effect = [["/tmp/tests/first"]]

        check_output_calls = [
            call(["defaults", "read", "com.apple.screencapture", "location"])
        ]

        assert Shot(dry_run=True)() == "cp /tmp/tests/first ."
        check_output_mock.assert_has_calls(check_output_calls)
Esempio n. 28
0
 def player_update(self):
     """check keyboards arrow and move the player"""
     key = pygame.key.get_pressed()
     if key[K_SPACE] and len(self.bullet) < 12:
         self.bullet.append(Shot(self.rect.x, self.rect.y))
     if key[K_RIGHT] and self.rect.x < 608:
         self.rect.x += self.speed
     elif key[K_LEFT] and self.rect.x > 2:
         self.rect.x -= self.speed
     elif key[K_DOWN] and self.rect.y < 445:
         self.rect.y += self.speed
     elif key[K_UP] and self.rect.y > 10:
         self.rect.y -= self.speed
Esempio n. 29
0
	def shoot(self):
		if self.repair:
			return

		if not self._reload and self.missiles:
			vx, vy = angleVector(2.0 * math.pi * self.barrel / 32)
			pos = list(self._pos)
			pos[0] += 20 * vx
			pos[1] += 20 * vy
			self._map.explosions.add(Shot(pos))
			self._map.missiles.add(Missile(self._engine, self._map, self, pos, (vx, vy)))
			self._reload = 40
			self.missiles -= 1
			self.updateImage()
Esempio n. 30
0
    def add_shot(self, for_player):
        if len(self.shots) > self.maxShots:
            return
        shot_left = bool(random.getrandbits(1))

        pos_x = for_player.position_x
        if shot_left:
            pos_x += (for_player.image.get_width() / 2)

        pos_y = for_player.position_y
        new_shot = Shot(start_pos_x=pos_x, start_pos_y=pos_y)
        new_shot.speed_y = -self.shotSpeed
        self.shots.append(new_shot)
        self.bulledSound.play()