コード例 #1
0
    def __init__(
            self,
            gl_,  # global variables
            layer_=-4,  # layer where the shooting sprite will be display
            timing_=16,  # refreshing rate, default is 16ms (60 fps)
            surface_name_=''):

        self.layer = layer_

        pygame.sprite.Sprite.__init__(self, self.containers)

        # change sprite layer
        if isinstance(gl_.All, pygame.sprite.LayeredUpdates):
            gl_.All.change_layer(self, layer_)

        self.images_copy = ShootingStar.image.copy()
        self.image = self.images_copy[0] if isinstance(
            ShootingStar.image, list) else self.images_copy
        self.w, self.h = pygame.display.get_surface().get_size()
        self.position = pygame.math.Vector2(randint(0, self.w),
                                            randint(-self.h, 0))
        self.rect = self.image.get_rect(midbottom=self.position)
        self.speed = pygame.math.Vector2(uniform(-30, 30), 60)
        self.rotation = -270 - int(degrees(atan2(self.speed.y, self.speed.x)))
        self.image = pygame.transform.rotozoom(self.image, self.rotation, 1)
        self.blend = pygame.BLEND_RGB_ADD
        self.timing = timing_
        self.gl = gl_
        self.dt = 0
        self.surface_name = surface_name_
        self.id_ = id(self)
        self.shooting_star_object = Broadcast(self.make_object())

        Broadcast.add_object_id(self.id_)
コード例 #2
0
    def __init__(self,
                 parent_,
                 pos_,
                 gl_,
                 timing_,
                 layer_,
                 texture_name_,
                 mute_=False):

        self.layer = layer_
        pygame.sprite.Sprite.__init__(self, self.containers)
        if isinstance(gl_.All, pygame.sprite.LayeredUpdates):
            if layer_:
                gl_.All.change_layer(self, layer_)

        self.images_copy = Explosion.images.copy()
        self.image = self.images_copy[0] if isinstance(
            self.images_copy, list) else self.images_copy
        self.timing = timing_
        self.length = len(self.images) - 1
        self.pos = pos_
        self.gl = gl_
        self.position = pygame.math.Vector2(*self.pos)
        self.rect = self.image.get_rect(center=self.pos)
        self.dt = 0
        self.blend = pygame.BLEND_RGB_ADD
        self.parent = parent_
        self.index = 0
        self.id_ = id(self)
        self.texture_name = texture_name_
        self.mute = mute_
        # Create the network object
        self.explosion_object = Broadcast(self.make_object())
        # Create sound object
        self.explosion_sound_object = Broadcast(
            self.make_sound_object('EXPLOSION_SOUND'))

        Broadcast.add_object_id(self.id_)
コード例 #3
0
    def __init__(self, gl_, timing_, pos_, surface_name_, layer_=0):

        pygame.sprite.Sprite.__init__(self, self.containers)

        if isinstance(gl_.All, pygame.sprite.LayeredUpdates):
            if layer_:
                gl_.All.change_layer(self, layer_)

        self.image = Transport.image
        self.image_copy = self.image.copy()
        self.rect = self.image.get_rect(center=pos_)
        self.timing = timing_
        self.gl = gl_
        self.dt = 0
        self.fxdt = 0
        self.layer = layer_
        self.blend = 0
        self.previous_pos = pygame.math.Vector2()            # previous position
        self.max_life = 5000
        self.life = 5000                                     # MirroredTransportClass max hit points
        self.damage = 10000                                  # Damage transfer after collision
        self.mask = pygame.mask.from_surface(self.image)     # Image have to be convert_alpha compatible
        self.pos = pos_
        self.index = 0
        self.impact = False
        self.vertex_array = []
        self.engine = self.engine_on()
        self.surface_name = surface_name_
        self.id_ = id(self)
        self.transport_object = Broadcast(self.make_object())
        self.impact_sound_object = Broadcast(self.make_sound_object('IMPACT'))
        half = self.gl.SCREENRECT.w >> 1
        self.safe_zone = pygame.Rect(half - 200, half, 400, self.gl.SCREENRECT.bottom - half)
        self.half_life = (self.max_life >> 1)

        Broadcast.add_object_id(self.id_)   # this is now obsolete since it is done from main loop
コード例 #4
0
    def __init__(self,
                 parent_,
                 gl_,
                 offset_: tuple,
                 timing_: int = 8,
                 blend_: int = 0,
                 layer_: int = 0,
                 texture_name_='EXHAUST'):
        """
        Create an exhaust effect for the player's

        :param parent_: Player's instance (MirroredPlayer1Class or MirroredPlayer2Class)
        :param gl_: Class GL (contains all the game constants
        :param offset_: tuple, offset location of the afterburner sprite (offset from the center)
        :param timing_: integer; Sprite refreshing time must be > 0
        :param blend_: integer; Sprite blending effect, must be > 0 or any of the following BLEND_RGBA_ADD,
        BLEND_RGBA_SUB, BLEND_RGBA_MULT, BLEND_RGBA_MIN, BLEND_RGBA_MAX BLEND_RGB_ADD,
        BLEND_RGB_SUB, BLEND_RGB_MULT, BLEND_RGB_MIN, BLEND_RGB_MAX
        :param layer_: integer; must be <= 0 (0 is the top layer)
        :param texture_name_: string corresponding to the texture used.
        """

        if parent_ is None:
            raise ValueError('Positional argument <parent_> cannot be None.')
        if gl_ is None:
            raise ValueError('Positional argument <gl_> cannot be None.')
        if offset_ is None:
            raise ValueError('Positional argument <offset_> cannot be None.')

        assert isinstance(offset_, tuple), \
            "Positional argument <offset_> is type %s , expecting tuple." % type(offset_)
        assert isinstance(timing_, int), \
            "Positional argument <timing_> is type %s , expecting integer." % type(timing_)
        assert isinstance(blend_, int), \
            "Positional argument <blend_> is type %s , expecting integer." % type(blend_)
        assert isinstance(layer_, int), \
            "Positional argument <layer_> is type %s , expecting integer." % type(layer_)
        assert isinstance(texture_name_, str), \
            "Positional argument <texture_name_> is type %s , expecting str." % type(texture_name_)

        if self.containers is None:
            raise ValueError(
                'AfterBurner.containers is not initialised.\nMake sure to assign the containers to'
                ' a pygame group prior instantiation.\ne.g: AfterBurner.containers = '
                'pygame.sprite.Group()')
        if self.images is None:
            raise ValueError(
                "AfterBurner.images is not initialised.\nMake sure to assign a texture to "
                "prior instantiation.\ne.g: AfterBurner.images = 'EXHAUST'")

        if timing_ < 0:
            raise ValueError('Positional argument timing_ cannot be < 0')

        self.layer = layer_
        pygame.sprite.Sprite.__init__(self, self.containers)

        if isinstance(gl_.All, pygame.sprite.LayeredUpdates):
            if layer_:
                gl_.All.change_layer(self, layer_)

        self.images = AfterBurner.images
        self.image = self.images[0] if isinstance(self.images,
                                                  list) else self.images
        self.parent = parent_
        self.offset = offset_
        x, y = self.parent.rect.centerx + self.offset[
            0], self.parent.rect.centery + self.offset[1]
        self.rect = self.image.get_rect(center=(x, y))
        self.timing = timing_
        self.dt = 0
        self.index = 0
        self.gl = gl_
        self.blend = blend_
        self.texture_name = texture_name_
        self.id_ = id(self)
        self.afterburner_object = Broadcast(self.make_object())

        Broadcast.add_object_id(self.id_)
コード例 #5
0
    def __init__(self,
                 asteroid_name_: str,
                 pos_: tuple,
                 gl_: GL,
                 blend_: int = 0,
                 timing_: int = 16,
                 layer_: int = -2,
                 particles_: bool = True):
        """
        Create debris after asteroid explosion or collision

        :param asteroid_name_: string; Parent name (not used)
        :param pos_: tuple, representing the impact position (x, y)
        :param gl_: class GL, global constants
        :param blend_: integer; Sprite blend effect, must be > 0 or any of the following BLEND_RGBA_ADD,
        BLEND_RGBA_SUB, BLEND_RGBA_MULT, BLEND_RGBA_MIN, BLEND_RGBA_MAX BLEND_RGB_ADD,
        BLEND_RGB_SUB, BLEND_RGB_MULT, BLEND_RGB_MIN, BLEND_RGB_MAX
        :param timing_: integer; Sprite refreshing time in milliseconds, must be >=0
        :param layer_: integer; Sprite layer must be <=0 (0 is the top layer)
        :param particles_: bool; Particles effect after asteroid desintegration
        """

        assert isinstance(asteroid_name_, str), \
            "Positional argument <asteroid_name_> is type %s , expecting string." % type(asteroid_name_)
        assert isinstance(pos_, tuple), \
            "Positional argument <pos_> is type %s , expecting tuple." % type(pos_)
        assert isinstance(timing_, int), \
            "Positional argument <timing_> is type %s , expecting integer." % type(timing_)
        assert isinstance(blend_, int), \
            "Positional argument <blend_> is type %s , expecting integer." % type(blend_)
        assert isinstance(layer_, int), \
            "Positional argument <layer_> is type %s , expecting integer." % type(layer_)
        assert isinstance(particles_, bool), \
            "Positional argument <particles_> is type %s , expecting boolean." % type(particles_)

        if self.containers is None:
            raise ValueError(
                'Debris.containers is not initialised.\nMake sure to assign the containers to'
                ' a pygame group prior instantiation.\ne.g: Debris.containers = '
                'pygame.sprite.Group()')
        if self.image is None:
            raise ValueError(
                "Debris.image is not initialised.\nMake sure to assign a texture to "
                "prior instantiation.\ne.g: Debris.image = 'CHOOSE_YOUR_TEXTURE'"
            )

        if timing_ < 0:
            raise ValueError('Positional argument timing_ cannot be < 0')
        if blend_ < 0:
            raise ValueError('Positional argument blend_ cannot be < 0')
        if layer_ > 0:
            raise ValueError('Positional argument layer_ cannot be > 0')

        self.layer = layer_

        pygame.sprite.Sprite.__init__(self, self.containers)

        # change sprite layer
        if isinstance(gl_.All, pygame.sprite.LayeredUpdates):
            gl_.All.change_layer(self, layer_)

        self.image = Debris.image
        self.rect = self.image.get_rect(center=pos_)
        self.speed = pygame.math.Vector2(uniform(-10, +10), uniform(-8, +8))
        self.damage = randint(5, 15)
        self.timing = timing_
        self.dt = 0
        self.fxdt = 0
        self.gl = gl_
        self.asteroid_name = asteroid_name_  # not used
        self.blend = blend_
        self.layer = layer_

        self.life = self.damage
        self.points = self.life
        self.rotation = 0
        self.scale = 1.0
        self.id_ = id(self)
        self.asteroid_object = Broadcast(self.make_object())

        self.vertex_array = []

        # todo create instances in the vertex_array (declare in global)
        #  before instanciating debris.
        #  make a copy of the vertex_array and goes through the list changing arguments:
        #  position_, vector_. Assign the list to self.vertex_array
        if particles_:
            angle = math.radians(uniform(0, 359))
            self.asteroid_particles_fx(position_=pygame.math.Vector2(
                self.rect.center),
                                       vector_=pygame.math.Vector2(
                                           math.cos(angle) * randint(5, 10),
                                           math.sin(angle) * randint(5, 10)),
                                       images_=FIRE_PARTICLES.copy(),
                                       layer_=self.layer,
                                       blend_=pygame.BLEND_RGB_ADD)
        Broadcast.add_object_id(self.id_)
コード例 #6
0
    def __init__(self,
                 asteroid_name_: str,
                 gl_,
                 blend_: int = 0,
                 rotation_: int = 0,
                 scale_: int = 1,
                 timing_: int = 8,
                 layer_: int = 0):
        """

        :param asteroid_name_: strings, MirroredAsteroidClass name
        :param gl_: class GL (contains all the game constant)
        :param blend_: integer, Sprite blend effect, must be > 0
        :param rotation_: integer, Object rotation in degrees
        :param scale_: integer, Object scale value, default 1 -> no transformation. must be > 0
        :param timing_: integer; Refreshing time in milliseconds, must be > 0
        :param layer_: integer; Layer used. must be <= 0 (0 is the top layer)
        """
        """
        assert isinstance(asteroid_name_, str), \
            "Positional argument <asteroid_name_> is type %s , expecting string." % type(asteroid_name_)
        assert isinstance(blend_, int), \
            "Positional argument <blend_> is type %s , expecting integer." % type(blend_)
        if blend_ < 0:
            raise ValueError('Positional attribute blend_ must be > 0')
        assert isinstance(rotation_, (float, int)), \
            "Positional argument <rotation_> is type %s , expecting float or integer." % type(rotation_)
        assert isinstance(scale_, (float, int)), \
            "Positional argument <scale_> is type %s , expecting float or integer." % type(scale_)
        if scale_ < 0:
            raise ValueError('Positional attribute scale_ must be > 0')
        assert isinstance(timing_, int), \
            "Positional argument <timing_> is type %s , expecting integer." % type(timing_)
        if timing_ < 0:
            raise ValueError('Positional attribute timing_ must be >= 0')

        assert isinstance(layer_, int), \
            "Positional argument <layer_> is type %s , expecting integer." % type(layer_)
        if layer_ > 0:
            raise ValueError('Positional attribute layer_ must be <= 0')
        """
        self.layer = layer_

        pygame.sprite.Sprite.__init__(self, self.containers)

        # change sprite layer
        if isinstance(gl_.All, pygame.sprite.LayeredUpdates):
            gl_.All.change_layer(self, layer_)

        self.images_copy = Asteroid.image.copy()
        self.image = self.images_copy[0] if isinstance(
            Asteroid.image, list) else self.images_copy
        self.w, self.h = pygame.display.get_surface().get_size()

        self.appearance_frame = 0  # randint(100, 100240)  # When the asteroid start moving

        if asteroid_name_ == 'MAJOR_ASTEROID':
            self.speed = pygame.math.Vector2(0, 1)
            self.rect = self.image.get_rect(center=((self.w >> 1),
                                                    -self.image.get_height()))
            # MirroredAsteroidClass life points (proportional to its size)
            self.life = 5000
            self.damage = self.life * 2
        else:

            self.rect = self.image.get_rect(center=(randint(0, self.w),
                                                    -randint(0, self.h) -
                                                    self.image.get_height()))
            # self.rect = self.image.get_rect(center=(self.w // 2, - self.image.get_height()))

            self.speed = pygame.math.Vector2(0, uniform(
                +4, +8))  # * round(self.appearance_frame / 4000))

            if self.speed.length() == 0:
                self.speed = pygame.math.Vector2(0, 1)

            # MirroredAsteroidClass life points (proportional to its size)
            self.life = randint(self.rect.w,
                                max(self.rect.w, (self.rect.w >> 1) * 10))
            # Collision damage, how much life point
            # will be removed from players and transport in case of collision
            self.damage = self.life >> 1

        self.timing = timing_
        self.rotation = rotation_
        self.scale = scale_
        self.dt = 0
        self.gl = gl_
        self.asteroid_name = asteroid_name_
        self.blend = blend_
        # No need to pre-calculate the mask as all asteroid instanciation is
        # done before the main loop
        self.mask = pygame.mask.from_surface(self.image)

        # MirroredAsteroidClass value in case of destruction.
        self.points = self.life

        self.layer = layer_
        self.index = 0
        self.has_been_hit = False
        self.id_ = id(self)
        self.asteroid_object = Broadcast(self.make_object())
        self.impact_sound_object = Broadcast(self.make_sound_object('IMPACT'))

        Broadcast.add_object_id(self.id_)