001package com.fs.starfarer.api.impl.campaign.ghosts;
002
003import org.lwjgl.util.vector.Vector2f;
004
005import com.fs.starfarer.api.util.Misc;
006
007
008public class GBGoInDirectionWithWobble extends BaseGhostBehavior {
009        
010        protected float direction;
011        protected int maxBurn;
012        protected float phase = (float) Math.random();
013        protected float wobbleRate;
014        protected float maxWobble;
015        
016        public GBGoInDirectionWithWobble(float duration, float direction, float wobbleRate, float maxWobble, int maxBurn) {
017                super(duration);
018                this.direction = direction;
019                this.wobbleRate = wobbleRate;
020                this.maxWobble = maxWobble;
021                this.maxBurn = maxBurn;
022        }
023
024
025
026        @Override
027        public void advance(float amount, SensorGhost ghost) {
028                super.advance(amount, ghost);
029                
030                float pi = (float) Math.PI;
031                float sin = (float) Math.sin(phase * pi * 2f);
032                phase += amount * wobbleRate;
033                
034                float maxAngleOffset = maxWobble;
035                float angle = direction + sin * maxAngleOffset;
036                
037                Vector2f loc = Misc.getUnitVectorAtDegreeAngle(angle);
038                loc.scale(10000f);
039                Vector2f.add(loc, ghost.getEntity().getLocation(), loc);
040                ghost.moveTo(loc, maxBurn);
041                
042                
043                //System.out.println("Move angle: " + angle);
044                //System.out.println("Velocity: [" + (int)ghost.getEntity().getVelocity().x + "," + (int)ghost.getEntity().getVelocity().y + "]");
045                //System.out.println("Location: [" + (int)ghost.getEntity().getLocation().x + "," + (int)ghost.getEntity().getLocation().y + "]");
046                
047        }
048        
049        
050        
051}
052
053
054
055
056
057
058
059
060
061
062
063
064