Exemplo n.º 1
0
 def get_center(self):
     '''Get the center of the screen'''
     return Vector2(self.__width / 2, self.__height / 2)
Exemplo n.º 2
0
    def __init__(self,
                 total_particles=0,
                 image=None,
                 duration=0.0,
                 gravity=None,
                 pos_var=None,
                 origin=None,
                 angle=0.0,
                 angle_var=0.0,
                 speed=0.0,
                 speed_var=0.0,
                 tangential_accel=0.0,
                 tangential_accel_var=0.0,
                 radial_accel=0.0,
                 radial_accel_var=0.0,
                 size=1.0,
                 size_var=0.0,
                 life=1.0,
                 life_var=0.0,
                 start_color=None,
                 start_color_var=None,
                 end_color=None,
                 end_color_var=None,
                 emission_rate=None,
                 blend_additive=False,
                 position_type=POSITION_GROUPED):
        super(ParticleSystem, self).__init__()

        if image is None:
            image = batma.resource.load_image(
                os.path.join(os.path.dirname(__file__), 'assets', 'fire.png'))
        elif isinstance(image, basestring):
            image = batma.resource.load_image(image)

        if emission_rate is None:
            if life != 0 and total_particles != 0:
                emission_rate = total_particles / float(life)
            else:
                emission_rate = 1.0

        self.total_particles = total_particles
        self.image = image
        self.duration = duration
        self.gravity = gravity or Vector2(0, 0)
        self.pos_var = pos_var or Vector2(0, 0)
        self.origin = origin or Vector2(0, 0)
        self.angle = angle
        self.angle_var = angle_var
        self.speed = speed
        self.speed_var = speed_var
        self.tangential_accel = tangential_accel
        self.tangential_accel_var = tangential_accel_var
        self.radial_accel = radial_accel
        self.radial_accel_var = radial_accel_var
        self.size = size
        self.size_var = size_var
        self.life = life
        self.life_var = life_var
        self.start_color = start_color or batma.Color(0, 0, 0, 0)
        self.start_color_var = start_color_var or batma.Color(0, 0, 0, 0)
        self.end_color = end_color or batma.Color(0, 0, 0, 0)
        self.end_color_var = end_color_var or batma.Color(0, 0, 0, 0)
        self.emission_rate = emission_rate
        self.blend_additive = blend_additive
        self.position_type = position_type

        self.particle_pos = np.zeros((self.total_particles, 2), np.float32)
        self.particle_dir = np.zeros((self.total_particles, 2), np.float32)
        self.particle_rad = np.zeros((self.total_particles, 1), np.float32)
        self.particle_tan = np.zeros((self.total_particles, 1), np.float32)
        self.particle_grav = np.zeros((self.total_particles, 2), np.float32)
        self.particle_color = np.zeros((self.total_particles, 4), np.float32)
        self.particle_delta_color = np.zeros((self.total_particles, 4),
                                             np.float32)
        self.particle_life = -np.ones((self.total_particles, 1), np.float32)
        self.particle_size = np.zeros((self.total_particles, 1), np.float32)
        self.particle_start_pos = np.zeros((self.total_particles, 2),
                                           np.float32)

        self.active = True
        self.elapsed = 0
        self.emit_counter = 0
        self.particle_count = 0
        self.auto_remove_on_finish = False
Exemplo n.º 3
0
 def get_size(self):
     return Vector2(self.__width, self.__height)
Exemplo n.º 4
0
    def add_particle(self):
        a = self.particle_life < 0
        idxs = a.nonzero()
        idx = -1

        if len(idxs[0] > 0):
            idx = idxs[0][0]
        else:
            raise Exception('Non Empty Particle')

        self.particle_pos[idx][0] = self.origin[0] + self.pos_var[0] * rand()
        self.particle_pos[idx][1] = self.origin[1] + self.pos_var[1] * rand()

        self.particle_start_pos[idx][0] = self.origin[0]
        self.particle_start_pos[idx][1] = self.origin[1]

        a = math.radians(self.angle + self.angle_var * rand())
        v = Vector2(math.cos(a), math.sin(a))
        s = self.speed + self.speed_var * rand()

        dir = v * s

        self.particle_dir[idx][0] = dir[0]
        self.particle_dir[idx][1] = dir[1]

        self.particle_rad[
            idx] = self.radial_accel + self.radial_accel_var * rand()

        self.particle_tan[
            idx] = self.tangential_accel + self.tangential_accel_var * rand()

        life = self.particle_life[idx] = self.life + self.life_var * rand()

        sr = self.start_color[0] + self.start_color_var[0] * rand()
        sg = self.start_color[1] + self.start_color_var[1] * rand()
        sb = self.start_color[2] + self.start_color_var[2] * rand()
        sa = self.start_color[3] + self.start_color_var[3] * rand()

        self.particle_color[idx][0] = sr
        self.particle_color[idx][1] = sg
        self.particle_color[idx][2] = sb
        self.particle_color[idx][3] = sa

        er = self.end_color[0] + self.end_color_var[0] * rand()
        eg = self.end_color[1] + self.end_color_var[1] * rand()
        eb = self.end_color[2] + self.end_color_var[2] * rand()
        ea = self.end_color[3] + self.end_color_var[3] * rand()

        delta_color_r = (er - sr) / life
        delta_color_g = (eg - sg) / life
        delta_color_b = (eb - sb) / life
        delta_color_a = (ea - sa) / life

        self.particle_delta_color[idx][0] = delta_color_r
        self.particle_delta_color[idx][1] = delta_color_g
        self.particle_delta_color[idx][2] = delta_color_b
        self.particle_delta_color[idx][3] = delta_color_a

        self.particle_size[idx] = self.size + self.size_var * rand()

        self.particle_grav[idx][0] = self.gravity[0]
        self.particle_grav[idx][1] = self.gravity[1]

        self.particle_count += 1
Exemplo n.º 5
0
 def get_position(self):
     return Vector2(self.x, self.y)
Exemplo n.º 6
0
 def get_target(self, *args, **kwargs):
     from batma.maths.algebra import Vector2
     return Vector2(*args, **kwargs)
Exemplo n.º 7
0
 def set_scale(self, value):
     if isinstance(value, (int, long, float)):
         value = Vector2(value, value)
     self.__scale = value
Exemplo n.º 8
0
 def get_position(self):
     return Vector2(self.__x, self.__y)