###########################################################
# LoadParticles - Railshooter Module
# Stores all Particle Effect Code
###########################################################

# DESCRIPTION:
# This Class contains the code used to create the Particle Systems 
# used in this game demo.  To be able to use Particles at all, you 
# first must use base.enableParticles().  Afterwards, you simple call 
# any one of the functions below to create a particle effect.

# To create your own Particle Effects, you need to use the Particle Panel.  
# You can load the Particle Panel by running LoadParticlePanel.py, which is 
# contained in the Railshooter directory.  Using this panel, you can tweak
# the particle effect to your liking and then save it out as a PTF Text File.
# Afterwards, open the PTF file and copy the text into a Python Panda File, 
# following the examples below.


from direct.showbase.ShowBaseGlobal import *
from direct.interval.IntervalGlobal import *
from direct.particles import ParticleEffect
from direct.particles import Particles
from direct.particles import ForceGroup
from direct.task import Task
from pandac.PandaModules import *
import random

# Import Railshooter Modules
import ClassGlobals
import Level1


########################################
# Enable Particle Effects
########################################
base.enableParticles()


########################################
# Wind Trail Particle Effect
########################################
def windTrail(x, y, z):

    f = ParticleEffect.ParticleEffect()
    f.reset()
    f.setPos(x, y, z)
    f.setHpr(0.000, 0.000, 0.000)
    f.setScale(1.0, 1.0, 1.0)
    p0 = Particles.Particles('particles-1')
    # Particles parameters
    p0.setFactory("PointParticleFactory")
    p0.setRenderer("SpriteParticleRenderer")
    p0.setEmitter("PointEmitter")
    p0.setPoolSize(1024)
    p0.setBirthRate(0.002)
    p0.setLitterSize(1)
    p0.setLitterSpread(0)
    p0.setSystemLifespan(0.0000)
    p0.setLocalVelocityFlag(1)
    p0.setSystemGrowsOlderFlag(0)
    # Factory parameters
    p0.factory.setLifespanBase(0.800)
    p0.factory.setLifespanSpread(0.0000)
    p0.factory.setMassBase(1.0000)
    p0.factory.setMassSpread(0.0000)
    p0.factory.setTerminalVelocityBase(400.0000)
    p0.factory.setTerminalVelocitySpread(0.0000)
    # Point factory parameters
    # Renderer parameters
    p0.renderer.setAlphaMode(BaseParticleRenderer.PRALPHAOUT)
    p0.renderer.setUserAlpha(0.4)
    # Sprite parameters
    p0.renderer.setTexture(loader.loadTexture('ParticleEffects/WindTrail.png'))
    p0.renderer.setColor(Vec4(1.00, 1.00, 1.00, 1.00))
    p0.renderer.setXScaleFlag(1)
    p0.renderer.setYScaleFlag(1)
    p0.renderer.setAnimAngleFlag(0)
    p0.renderer.setInitialXScale(0.020)
    p0.renderer.setFinalXScale(0.0100)
    p0.renderer.setInitialYScale(0.020)
    p0.renderer.setFinalYScale(0.0100)
    p0.renderer.setNonanimatedTheta(0.0000)
    p0.renderer.setAlphaBlendMethod(BaseParticleRenderer.PPNOBLEND)
    p0.renderer.setAlphaDisable(0)
    # Emitter parameters
    p0.emitter.setEmissionType(BaseParticleEmitter.ETEXPLICIT)
    p0.emitter.setAmplitude(1.0000)
    p0.emitter.setAmplitudeSpread(0.0000)
    p0.emitter.setOffsetForce(Vec3(0.0000, -5.0000, 0.0000))
    p0.emitter.setExplicitLaunchVector(Vec3(1.0000, 0.0000, 0.0000))
    p0.emitter.setRadiateOrigin(Point3(0.0000, 0.0000, 0.0000))
    f.addParticles(p0)

    t = Sequence(
        Func(f.start, ClassGlobals.p1.airblade, ClassGlobals.p1.player),
        name = 'WindTrail')
    t.start()

    
########################################
# Light Cloud SCUD Particle Effect
########################################

def cloudSCUD():
    f = ParticleEffect.ParticleEffect()
    f.reset()
    f.setPos(0.000, 1500.000, 0.000)
    f.setHpr(0.000, 0.000, 0.000)
    f.setScale(1.000, 1.000, 1.000)
    p0 = Particles.Particles('particles-1')
    # Particles parameters
    p0.setFactory("PointParticleFactory")
    p0.setRenderer("SpriteParticleRenderer")
    p0.setEmitter("BoxEmitter")
    p0.setPoolSize(256)
    p0.setBirthRate(0.2000)
    p0.setLitterSize(1)
    p0.setLitterSpread(0)
    p0.setSystemLifespan(0.0000)
    p0.setLocalVelocityFlag(1)
    p0.setSystemGrowsOlderFlag(0)
    # Factory parameters
    p0.factory.setLifespanBase(4.0000)
    p0.factory.setLifespanSpread(0.0000)
    p0.factory.setMassBase(1.0000)
    p0.factory.setMassSpread(0.0000)
    p0.factory.setTerminalVelocityBase(400.0000)
    p0.factory.setTerminalVelocitySpread(0.0000)
    # Point factory parameters
    # Renderer parameters
    p0.renderer.setAlphaMode(BaseParticleRenderer.PRALPHAIN)
    p0.renderer.setUserAlpha(0.25)
    # Sprite parameters
    p0.renderer.setTexture(loader.loadTexture('ParticleEffects/Cloud.png'))
    p0.renderer.setColor(Vec4(1.00, 1.00, 1.00, 1.00))
    p0.renderer.setXScaleFlag(0)
    p0.renderer.setYScaleFlag(0)
    p0.renderer.setAnimAngleFlag(0)
    p0.renderer.setInitialXScale(0.100)
    p0.renderer.setFinalXScale(0.100)
    p0.renderer.setInitialYScale(0.100)
    p0.renderer.setFinalYScale(0.100)
    p0.renderer.setNonanimatedTheta(0.0000)
    p0.renderer.setAlphaBlendMethod(BaseParticleRenderer.PPBLENDLINEAR)
    p0.renderer.setAlphaDisable(0)
    # Emitter parameters
    p0.emitter.setEmissionType(BaseParticleEmitter.ETEXPLICIT)
    p0.emitter.setAmplitude(30.0000)
    p0.emitter.setAmplitudeSpread(0.0000)
    p0.emitter.setOffsetForce(Vec3(0.0000, 0.0000, 0.0000))
    p0.emitter.setExplicitLaunchVector(Vec3(0.0000, 0.0000, 0.0000))
    p0.emitter.setRadiateOrigin(Point3(0.0000, 0.0000, 0.0000))
    # Box parameters
    p0.emitter.setMinBound(Point3(-20.0000, -20.0000, -20.0000))
    p0.emitter.setMaxBound(Point3(20.0000, 20.0000, 20.0000))
    f.addParticles(p0)

    t = Sequence(
        Func(f.start, ClassGlobals.p1.player, Level1.renderUnlitDummy),
        name = 'Clouds')
    t.start()

