001package com.fs.starfarer.api.impl.campaign.world;
002
003import java.awt.Color;
004
005import org.lwjgl.util.vector.Vector2f;
006
007import com.fs.starfarer.api.EveryFrameScript;
008import com.fs.starfarer.api.campaign.SectorEntityToken;
009import com.fs.starfarer.api.util.IntervalUtil;
010import com.fs.starfarer.api.util.Misc;
011
012public class MoteParticleScript implements EveryFrameScript {
013
014        protected float moteSpawnRate = 1f;
015        protected SectorEntityToken entity;
016        protected IntervalUtil moteSpawn = new IntervalUtil(0.01f, 0.1f);
017        
018        public MoteParticleScript(SectorEntityToken entity, float moteSpawnRate) {
019                super();
020                this.entity = entity;
021                this.moteSpawnRate = moteSpawnRate;
022        }
023
024        public void advance(float amount) {
025                float days = Misc.getDays(amount);
026                moteSpawn.advance(days * moteSpawnRate);
027                if (moteSpawn.intervalElapsed()) {
028                        spawnMote(entity);
029                }
030        }
031
032        
033        public static void spawnMote(SectorEntityToken from) {
034                if (!from.isInCurrentLocation()) return;
035                float dur = 1f + 2f * (float) Math.random();
036                dur *= 2f;
037                float size = 3f + (float) Math.random() * 5f;
038                size *= 3f;
039                Color color = new Color(255,100,255,175);
040                
041                Vector2f loc = Misc.getPointWithinRadius(from.getLocation(), from.getRadius());
042                Vector2f vel = Misc.getUnitVectorAtDegreeAngle((float) Math.random() * 360f);
043                vel.scale(5f + (float) Math.random() * 10f);
044                vel.scale(0.25f);
045                Vector2f.add(vel, from.getVelocity(), vel);
046                Misc.addGlowyParticle(from.getContainingLocation(), loc, vel, size, 0.5f, dur, color);
047        }
048
049        public boolean isDone() {
050                return false;
051        }
052
053        public boolean runWhilePaused() {
054                return false;
055        }
056}
057
058
059
060
061
062
063
064
065
066
067
068