Example #1
0
    def _gen_asteroid(self):
        """Generates a new asteroid

        Returns:
            a new, randomly generated asteroid
        """
        # Get a random size, with probability depending on the game
        # rules
        size = weighted_choice(self.curr_level.size_weights)

        # Generate a position out of bounds, and a random direction
        # to move towards
        possible_x = range(-60, -10, 10) + range(WINDOW_WIDTH+20,
                                                 WINDOW_WIDTH+70, 10)
        possible_y = range(-60, -10, 10) + range(WINDOW_HEIGHT+20,
                                                 WINDOW_HEIGHT+70, 10)
        pos = Vector(rand.choice(possible_x), rand.choice(possible_y))
        direction = rand_direction(pos)

        # Generate random linear and rotational speeds
        lin_speed = rand.uniform(Asteroid.min_lin_speed,
                                 Asteroid.max_lin_speed)
        rot_speed = rand.uniform(0, Asteroid.max_rot_speed)

        return Asteroid(size, direction, lin_speed, rot_speed, pos=pos)
Example #2
0
    def ad_gen_particles():
        fragments = []
        for i in range(1, 11):
            lin_speed = rand.uniform(0.5, 1.5)

            # Note that we generate random directions relative to the
            # middle of the screen, because rand_direction is based on
            # having a reference position in game bounds
            fragment = Entity((-1, 1, 1, 1, 1, -1, -1, -1),
                              rand_direction(Vector(WINDOW_WIDTH//2,
                                                    WINDOW_HEIGHT//2)),
                              lin_speed)
            fragments.append(fragment)
        return fragments
Example #3
0
    def _get_random_asteroid(self, size):
        """Creates a random asteroid that results from the destruction
        of this asteroid

        Parameters:
            size: the size that the new asteroid will have
        Returns:
            a new random asteroid, based on the characteristcs of
            this asteroid
        """
        # Generate random speeds
        lin_speed = rand.uniform(self.min_lin_speed, self.max_lin_speed)
        rot_speed = rand.uniform(0, self.max_rot_speed)

        # Get random direction
        direction = rand_direction(self.pos)

        return Asteroid(size, direction, lin_speed, rot_speed, pos=self.pos,
                        shape_index=self.shape_index)