Starsector API
Loading...
Searching...
No Matches
GBGoInDirectionWithWobble.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.ghosts;
2
3import org.lwjgl.util.vector.Vector2f;
4
5import com.fs.starfarer.api.util.Misc;
6
7
9
10 protected float direction;
11 protected int maxBurn;
12 protected float phase = (float) Math.random();
13 protected float wobbleRate;
14 protected float maxWobble;
15
16 public GBGoInDirectionWithWobble(float duration, float direction, float wobbleRate, float maxWobble, int maxBurn) {
17 super(duration);
18 this.direction = direction;
19 this.wobbleRate = wobbleRate;
20 this.maxWobble = maxWobble;
21 this.maxBurn = maxBurn;
22 }
23
24
25
26 @Override
27 public void advance(float amount, SensorGhost ghost) {
28 super.advance(amount, ghost);
29
30 float pi = (float) Math.PI;
31 float sin = (float) Math.sin(phase * pi * 2f);
32 phase += amount * wobbleRate;
33
34 float maxAngleOffset = maxWobble;
35 float angle = direction + sin * maxAngleOffset;
36
37 Vector2f loc = Misc.getUnitVectorAtDegreeAngle(angle);
38 loc.scale(10000f);
39 Vector2f.add(loc, ghost.getEntity().getLocation(), loc);
40 ghost.moveTo(loc, maxBurn);
41
42
43 //System.out.println("Move angle: " + angle);
44 //System.out.println("Velocity: [" + (int)ghost.getEntity().getVelocity().x + "," + (int)ghost.getEntity().getVelocity().y + "]");
45 //System.out.println("Location: [" + (int)ghost.getEntity().getLocation().x + "," + (int)ghost.getEntity().getLocation().y + "]");
46
47 }
48
49
50
51}
52
53
54
55
56
57
58
59
60
61
62
63
64
GBGoInDirectionWithWobble(float duration, float direction, float wobbleRate, float maxWobble, int maxBurn)
void moveTo(Vector2f dest, float maxBurn)