コード例 #1
0
 def test_brightness_radius(self):
     s0 = stars.Star(Point(1, 0, 0), 'A', 1, 'and', None)
     s1 = stars.Star(Point(1, 0, 0), 'A', 3, 'and', None)
     s2 = stars.Star(Point(1, 0, 0), 'A', 3, 'and', None)
     sky = stars.StarrySky(Point(1, 0, 0), Point(0, 1, 0), [s0, s1, s2])
     st = sky.get_stars()
     self.assertFalse(st[0].r == st[1].r)
コード例 #2
0
 def test_brightness(self):
     s0 = stars.Star(Point(1, 0, 0), 'A', 1, 'and', None)
     s1 = stars.Star(Point(1, 0, 0), 'A', 3, 'and', None)
     s2 = stars.Star(Point(1, 0, 0), 'A', 3, 'and', None)
     sky = stars.StarrySky(Point(1, 0, 0), Point(0, 1, 0), [s0, s1, s2])
     st = sky.get_stars()
     self.assertTrue(st[0].m == 1)
コード例 #3
0
def open_tsv(data_tsv, fov_ra: float, fov_dec: float, ra_user_input: float,
             dec_user_input: float) -> list:
    """
    in order not to load memory, the function checks if the star enters the field of view and then
    adds to array
    """
    fov_ra_min = ra_user_input - fov_ra / 2
    fov_ra_max = ra_user_input + fov_ra / 2
    fov_dec_min = dec_user_input - fov_dec / 2
    fov_dec_max = dec_user_input + fov_dec / 2
    with open(data_tsv) as fd:
        list_of_db = []
        for row in fd:
            list_row = row.split('\t')
            try:
                if fov_ra_min < float(list_row[const_and_inp.INDEX_RA]) < fov_ra_max and \
                        fov_dec_min < float(list_row[const_and_inp.INDEX_DEC]) < fov_dec_max:
                    list_of_db.append(
                        stars.Star(int(list_row[const_and_inp.INDEX_ID]),
                                   float(list_row[const_and_inp.INDEX_RA]),
                                   float(list_row[const_and_inp.INDEX_DEC]),
                                   float(list_row[const_and_inp.INDEX_MAG])))
            except ValueError:
                pass

        return list_of_db
コード例 #4
0
 def test_scale(self):
     sky = stars.StarrySky(Point(1, 0, 0), Point(0, 1, 0), [])
     sky.resize(Point(100, 100))
     s0 = stars.Star(Point(0, 0, 0), 'A', 1, 'and', None)
     sky.scale(s0)
     self.assertAlmostEqual(s0.x, 50)
     self.assertAlmostEqual(s0.y, 50)
コード例 #5
0
def open_tsv(data_tsv, fov_ra: float, fov_dec: float, ra_user_input: float,
             dec_user_input: float) -> list:
    """
    in order not to load memory, the function checks if the star enters the field of view and then adds to array.
    the function generates an error if there is a mismatch in the main database, for example, if it is not possible
    to convert the column value to float, an error appears that indicates the line where the error was found, and the
    function also gives an error if the path to the database is not specified correctly data
    """
    fov_ra_min = ra_user_input - fov_ra / 2
    fov_ra_max = ra_user_input + fov_ra / 2
    fov_dec_min = dec_user_input - fov_dec / 2
    fov_dec_max = dec_user_input + fov_dec / 2
    try:
        with open(data_tsv) as fd:
            list_of_db = []
            index = 0
            row_error = 0
            for row in fd:
                index += 1
                list_row = row.split('\t')
                try:
                    if fov_ra_min < float(list_row[const_and_inp.INDEX_RA]) < fov_ra_max and \
                            fov_dec_min < float(list_row[const_and_inp.INDEX_DEC]) < fov_dec_max:
                        list_of_db.append(
                            stars.Star(
                                int(list_row[const_and_inp.INDEX_ID]),
                                float(list_row[const_and_inp.INDEX_RA]),
                                float(list_row[const_and_inp.INDEX_DEC]),
                                float(list_row[const_and_inp.INDEX_MAG])))
                except ValueError:
                    row_error += 1
                    if row_error > 2:
                        print(
                            f'there is an incorrectness in the database row. row index : {index}'
                        )
    except FileNotFoundError:
        raise Exception(
            f'the specified path to the database is not correct: {data_tsv}')

    return list_of_db
コード例 #6
0
 def test_is_not_bright(self):
     sky = stars.StarrySky(Point(1, 0, 0), Point(0, 1, 0), [])
     s = stars.Star(Point(0, 0), 'A', 5, 'and', None)
     self.assertFalse(sky.is_bright(s))
コード例 #7
0
def main():

    pygame.init()
    fpsClock = pygame.time.Clock()

    # Create Screen Object
    screen = pygame.display.set_mode((WIDTH, HEIGHT))
    pygame.display.set_caption('Space Invaders')

    asteroid_group = pygame.sprite.Group()
    dead = []

    # Create Game Objects
    liststars = []
    for i in range(MAX_STARS):
        star = stars.Star()
        liststars.append(star)

    #asteroid_list = pygame.sprite.Group()
    the_ship = spaceship.Spaceship()

    for i in range(MAX_ASTEROIDS):
        the_asteroid = asteroid.Asteroid()
        asteroid_group.add(the_asteroid)

    while True:
        #make asteroids
        if (len(asteroid_group) < MAX_ASTEROIDS):
            the_asteroid = asteroid.Asteroid()
            asteroid_group.add(the_asteroid)

        velocity = serial_in()
        print(velocity)
        the_ship.Vx = velocity[0]
        the_ship.Vy = -1 * velocity[1]
        if (velocity[2] == 0):
            dead = [1, 1]

        # Process Events
        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit
                sys.exit()
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_UP:
                    the_ship.Vy -= 1
                    if the_ship.Vy < -5:
                        the_ship.Vy = -5
                elif event.key == pygame.K_DOWN:
                    the_ship.Vy += 1
                    if the_ship.Vy > 5:
                        the_ship.Vy = 5
                elif event.key == pygame.K_LEFT:
                    the_ship.Vx -= 1
                    if the_ship.Vx < -5:
                        the_ship.Vx = -5
                elif event.key == pygame.K_RIGHT:
                    the_ship.Vx += 1
                    if the_ship.Vx > 5:
                        the_ship.Vx = 5
                elif event.key == pygame.K_SPACE:
                    the_ship.fire()

        if len(dead) > 0:
            end_game(screen)
            s.write('p')
            pygame.quit
            sys.exit()

        else:
            # Update game logic
            map(lambda star: star.move(screen), liststars)
            pygame.sprite.groupcollide(the_ship.phasor_list, asteroid_group,
                                       True, True)
            for rock in asteroid_group:
                if rock.off_screen:
                    rock.kill
            dead = pygame.sprite.spritecollide(the_ship, asteroid_group, True)
            #draw world
            asteroid_group.update()
            the_ship.update()

            # Draw updated World
            draw(screen)
            the_ship.draw(screen)
            asteroid_group.draw(screen)
            pygame.display.update()
        fpsClock.tick(FPS)