Ejemplo n.º 1
0
    def __init__(self, pos=Vector(0, 0), rot=0.0):
        """Creates a new Ship

        Args:
            pos: the position of the ship
            rot: the rotation of the ship

        Returns:
            a new Ship instance
        """

        # Get the initial direction of the ship using the rotation
        direction = Vector(cos(radians(rot)), sin(radians(rot)))

        # Initially, the ship isn't moving
        self._movement = Vector.zero()

        # Initialize bullet list
        self.bullets = []
        self._last_shoot = self._shoot_delay
        self._last_teleport = self._teleport_delay
        self.teleport_up = True
        self.effect_player = EffectPlayer.instance()
        Entity.__init__(self, (20, 0, -30, 20, -30, -20), direction,
                        lin_speed=1.0, rot_speed=2.0, pos=pos, rot=rot,
                        scale=0.5)
Ejemplo n.º 2
0
    def __init__(self, size, direction, lin_speed, rot_speed,
                 shape_index=None, pos=Vector(0, 0), rot=0.0):
        """Creates a new Asteroid

        Args:
            size: the size of the Asteroid, which should be a value
                  from Asteroid.Size
            shape_index: the index of the shape to grab from _shapes.
                         If None, then we'll grab a random one
            pos: the position of the asteroid
            rot: the rotation of the asteroid
        Returns:
            a new Asteroid
        """
        self.size = size

        # If we haven't grabbed the shapes from asteroids.txt, do so
        if Asteroid._shapes is None:
            self._get_shapes()

        # Two cases:
        # 1. a shape index wasn't supplied, generate a random one
        # (this is for newly generated asteroids)
        # 2. a shape index was supplied, use that (this is for
        # asteroids which resulted from the destruction of a larger
        # one)
        if shape_index is None:
            self.shape_index = rand.randrange(0, len(Asteroid._shapes))
        else:
            self.shape_index = shape_index

        # Get the relevant data from the tuple
        self._shape = Asteroid._shapes[self.shape_index][0]
        self._def_scale = Asteroid._shapes[self.shape_index][1]

        # For each size, we apply a scaling factor on top of the
        # default scale to make smaller asteroids smaller and larger
        # asteroids larger
        # As with the definition of default scale, a medium sized
        # asteroid just uses the default scale (scale_factor = 1.0)
        if size == Asteroid.Size.SMALL:
            scale_factor = 0.7
        elif size == Asteroid.Size.MEDIUM:
            scale_factor = 1.0
        elif size == Asteroid.Size.LARGE:
            scale_factor = 1.2
        elif size == Asteroid.Size.HUGE:
            scale_factor = 1.5

        # Grab the EffectPlayer
        from effect import EffectPlayer
        self.effect_player = EffectPlayer.instance()

        Entity.__init__(self, self._shape, direction, lin_speed=lin_speed,
                        rot_speed=rot_speed, pos=pos, rot=rot,
                        scale=self._def_scale * scale_factor)
Ejemplo n.º 3
0
    def __init__(self):
        """Initializes player variables and creates his Ship

        Returns:
            a new Player
        """
        # Create the player in the (approximate) middle of the screen
        # and face him upwards
        self.ship = Ship(pos=Vector(WINDOW_WIDTH // 2, WINDOW_HEIGHT // 2),
                         rot=90)
        self.is_vulnerable = True
        self.is_dead = False
        self.lives_left = 3
        self.game_over = False
        self.score = 0
        self.bullets = self.ship.bullets
        self.effect_player = EffectPlayer.instance()