Beispiel #1
0
    // Update is called once per frame
    void Update()
    {
        base.Update();
        CenterIndicator.transform.position = transform.TransformPoint(center);
        foreach (GameObject obj in objectsInTrigger)
        {
            if (obj != null)
            {
                Rigidbody body = obj.GetComponent <Rigidbody>();

                if (body != null)
                {
                    Vector3   deltaPos      = obj.transform.position - transform.TransformPoint(center);
                    PolarVec2 polarDeltaPos = PolarVec2.FromCartesian(deltaPos.x, deltaPos.z);

                    //velocity is always tangential to dir to the center
                    polarDeltaPos.A += (reverseDir ? 1 : -1) * 90 * Mathf.Sign(polarDeltaPos.A);

                    body.velocity = -(polarDeltaPos.Cartesian3DHorizontal.normalized * constantVelocity);

                    //Debug.Log(/*"deltaPos: " + deltaPos + */" new velocity: " + polarDeltaPos.Cartesian3DHorizontal.ToString() + ", polar: " + polarDeltaPos.ToString());
                }
            }
        }
    }
Beispiel #2
0
    public static PolarVec2 FromCartesian(float x, float y)
    {
        PolarVec2 vector = new PolarVec2();

        vector.r     = Mathf.Sqrt(x * x + y * y);
        vector.Theta = Mathf.Atan2(y, x);

        return(vector);
    }
Beispiel #3
0
            public static void StartHive(int i, int j)
            {
                const float strength      = 2.4f;
                const float wallThickness = 4f;
                ushort      fleshID       = (ushort)ModContent.TileType <Riven_Flesh>();
                ushort      weakFleshID   = (ushort)ModContent.TileType <Weak_Riven_Flesh>();
                ushort      fleshWallID   = (ushort)ModContent.WallType <Riven_Flesh_Wall>();

                lesionCount = 0;
                int j2 = j;

                if (j2 > Main.worldSurface)
                {
                    j2 = (int)Main.worldSurface;
                }
                for (; !SolidTile(i, j2); j2++)
                {
                }
                Vector2 position = new Vector2(i, j2);

                for (int x = i - 30; x < i + 30; x++)
                {
                    for (int y = j2 - 25; y < j2 + 15; y++)
                    {
                        float diff = (((y - j2) * (y - j2) * 1.5f) + (x - i) * (x - i));
                        if (diff > 800)
                        {
                            continue;
                        }
                        Main.tile[x, y].ResetToType(fleshID);
                        if (diff < 750)
                        {
                            Main.tile[x, y].wall = fleshWallID;
                        }
                    }
                }
                Vector2 vector   = new Vector2(0, -1).RotatedByRandom(1.6f, genRand);
                int     distance = 0;

                while (Main.tile[(int)position.X, (int)position.Y].active() && Main.tileSolid[Main.tile[(int)position.X, (int)position.Y].type])
                {
                    //Main.tile[(int)position.X, (int)position.Y].ResetToType(TileID.EmeraldGemspark);
                    //SquareTileFrame((int)position.X, (int)position.Y);
                    position += vector;
                    if (++distance >= 160)
                    {
                        break;
                    }
                }
                vector = -vector;
                (Vector2 position, Vector2 velocity)last = (position, vector);
                //Tile t = Main.tile[(int)last.position.X, (int)last.position.Y];
                (int x, int y, Vector2 direction, double length)startValues = ((int)last.position.X, (int)last.position.Y, last.velocity.RotatedByRandom(0.5f, genRand), distance *genRand.NextFloat(0.4f, 0.6f));
                last = GenRunners.WalledVeinRunner(startValues.x, startValues.y, strength * genRand.NextFloat(0.9f, 1.1f), startValues.direction, startValues.length, weakFleshID, wallThickness);
                //t.ResetToType(TileID.AmethystGemspark);
                Vector2 manualVel = new Vector2(last.velocity.X, 0.2f);

                //t = Main.tile[(int)last.position.X, (int)last.position.Y];
                GenRunners.WalledVeinRunner((int)last.position.X, (int)last.position.Y, strength * genRand.NextFloat(0.9f, 1.1f), Vector2.Normalize(new Vector2(-manualVel.X, 0.2f)), genRand.NextFloat(distance * 0.4f, distance * 0.6f) * (Math.Abs(manualVel.X) + 0.5f), weakFleshID, wallThickness, wallType: fleshWallID);
                last = GenRunners.WalledVeinRunner((int)last.position.X, (int)last.position.Y, strength * genRand.NextFloat(0.9f, 1.1f), Vector2.Normalize(manualVel), genRand.NextFloat(distance * 0.4f, distance * 0.6f) / (Math.Abs(manualVel.X) + 0.5f), weakFleshID, wallThickness, wallType: fleshWallID);
                GenRunners.WalledVeinRunner((int)last.position.X, (int)last.position.Y, strength * genRand.NextFloat(0.9f, 1.1f), Vector2.Normalize(manualVel), genRand.NextFloat(distance * 0.4f, distance * 0.6f) / (Math.Abs(manualVel.X) + 0.5f), weakFleshID, wallThickness, wallType: fleshWallID);
                last = GenRunners.WalledVeinRunner((int)last.position.X, (int)last.position.Y, strength * genRand.NextFloat(0.9f, 1.1f), new Vector2(0, 1).RotatedByRandom(0.2f, genRand), genRand.NextFloat(distance * 0.4f, distance * 0.6f), weakFleshID, wallThickness, wallType: fleshWallID);
                //t.ResetToType(TileID.AmethystGemspark);
                manualVel.X = -manualVel.X;
                //t = Main.tile[(int)last.position.X, (int)last.position.Y];
                GenRunners.WalledVeinRunner((int)last.position.X, (int)last.position.Y, strength * genRand.NextFloat(0.9f, 1.1f), Vector2.Normalize(new Vector2(-manualVel.X, 0.2f)), genRand.NextFloat(distance * 0.4f, distance * 0.6f) * (Math.Abs(manualVel.X) + 0.5f), weakFleshID, wallThickness, wallType: fleshWallID);
                last = GenRunners.WalledVeinRunner((int)last.position.X, (int)last.position.Y, strength * genRand.NextFloat(0.9f, 1.1f), Vector2.Normalize(manualVel), genRand.NextFloat(distance * 0.4f, distance * 0.6f) / (Math.Abs(manualVel.X) + 0.5f), weakFleshID, wallThickness, wallType: fleshWallID);
                GenRunners.WalledVeinRunner((int)last.position.X, (int)last.position.Y, strength * genRand.NextFloat(0.9f, 1.1f), Vector2.Normalize(manualVel), genRand.NextFloat(distance * 0.4f, distance * 0.6f) / (Math.Abs(manualVel.X) + 0.5f), weakFleshID, wallThickness, wallType: fleshWallID);
                last = GenRunners.WalledVeinRunner((int)last.position.X, (int)last.position.Y, strength * genRand.NextFloat(0.9f, 1.1f), new Vector2(0, 1).RotatedByRandom(0.2f, genRand), genRand.NextFloat(distance * 0.4f, distance * 0.6f), weakFleshID, wallThickness, wallType: fleshWallID);
                //t.ResetToType(TileID.AmethystGemspark);
                for (int index = 0; index < 10; index++)
                {
                    //t = Main.tile[(int)last.position.X, (int)last.position.Y];
                    last = GenRunners.WalledVeinRunner((int)last.position.X, (int)last.position.Y, strength * genRand.NextFloat(0.9f, 1.1f), last.velocity.RotatedByRandom(0.8f, genRand), genRand.NextFloat(distance * 0.2f, distance * 0.3f), weakFleshID, wallThickness, wallType: fleshWallID);
                    if (index < 8)
                    {
                        GenRunners.WalledVeinRunner((int)last.position.X, (int)last.position.Y, strength * genRand.NextFloat(0.9f, 1.1f), last.velocity.RotatedBy(genRand.Next(2) * 2 - 1).RotatedByRandom(0.8f, genRand), genRand.NextFloat(distance * 0.4f, distance * 0.6f), weakFleshID, wallThickness, wallType: fleshWallID);
                    }
                    PolarVec2 vel = new PolarVec2(1, last.velocity.ToRotation());
                    OriginExtensions.AngularSmoothing(ref vel.Theta, MathHelper.PiOver2, 0.7f);
                    //t.ResetToType(TileID.AmethystGemspark);
                    last = (last.position, (Vector2)vel);
                }
                //t = Main.tile[(int)last.position.X, (int)last.position.Y];
                //t.ResetToType(TileID.AmethystGemspark);
                Point   caveCenter    = HiveCave((int)last.position.X, (int)last.position.Y);
                Vector2 cavernOpening = last.position - caveCenter.ToVector2();

                GenRunners.VeinRunner((int)last.position.X, (int)last.position.Y, strength, cavernOpening.SafeNormalize(Vector2.Zero), cavernOpening.Length());
                GenRunners.VeinRunner(startValues.x, startValues.y, strength, startValues.direction, startValues.length);
                (Vector2 position, Vector2 velocity)[] arms = new (Vector2 position, Vector2 velocity)[4];
Beispiel #4
0
        public override void AI()
        {
            if (projectile.localAI[2] > 0f)
            {
                projectile.localAI[2]--;
                projectile.timeLeft--;
            }
            if (projectile.localAI[0] > 0f)
            {
                projectile.localAI[0]--;
            }
            if (projectile.localAI[0] == 0f && projectile.owner == Main.myPlayer)
            {
                projectile.localAI[0] = 5f;
                float currentTargetDist = projectile.ai[0] > 0?Main.npc[(int)projectile.ai[0] - 1].Distance(projectile.Center):0;
                for (int i = 0; i < Main.maxNPCs; i++)
                {
                    NPC targetOption = Main.npc[i];
                    if (targetOption.CanBeChasedBy())
                    {
                        float newTargetDist = targetOption.Distance(projectile.Center);
                        bool  selectNew     = projectile.ai[0] <= 0f || currentTargetDist > newTargetDist;
                        if (selectNew && (newTargetDist < 240f))
                        {
                            projectile.ai[0]  = i + 1;
                            currentTargetDist = newTargetDist;
                        }
                    }
                }
                if (projectile.ai[0] > 0f)
                {
                    projectile.timeLeft  = 300 - Main.rand.Next(120);
                    projectile.netUpdate = true;
                }
            }
            float scaleFactor = MathHelper.Clamp((30 - projectile.localAI[2]) * 0.04f, 0.1f, 1f);
            Dust  dust        = Dust.NewDustDirect(projectile.Center, 0, 0, 27, 0f, -2f);

            dust.noGravity = true;
            dust.velocity  = projectile.oldVelocity * 0.5f;
            dust.scale     = scaleFactor;
            dust.fadeIn    = 0.5f;
            dust.alpha     = 200;

            int target = (int)projectile.ai[0] - 1;

            if (target >= 0)
            {
                if (Main.npc[target].active)
                {
                    if (projectile.Distance(Main.npc[target].Center) > 1f)
                    {
                        Vector2 dir = projectile.DirectionTo(Main.npc[target].Center);
                        if (dir.HasNaNs())
                        {
                            dir = Vector2.UnitY;
                        }
                        float     angle     = dir.ToRotation();
                        PolarVec2 velocity  = (PolarVec2)projectile.velocity;
                        float     targetVel = projectile.ai[1];
                        bool      changed   = false;
                        if (velocity.R != targetVel)
                        {
                            OriginExtensions.LinearSmoothing(ref velocity.R, targetVel, (targetVel - 0.5f) * 0.1f);
                            changed = true;
                        }
                        if (velocity.Theta != angle)
                        {
                            OriginExtensions.AngularSmoothing(ref velocity.Theta, angle, 0.1f);
                            changed = true;
                        }
                        if (changed)
                        {
                            projectile.velocity = (Vector2)velocity;
                        }
                    }
                    return;
                }
                projectile.ai[0]     = 0f;
                projectile.netUpdate = true;
            }
            else
            {
                PolarVec2 velocity  = (PolarVec2)projectile.velocity;
                float     targetVel = projectile.ai[1];
                bool      changed   = false;
                if (velocity.R != targetVel)
                {
                    OriginExtensions.LinearSmoothing(ref velocity.R, targetVel / 3f, (targetVel - 0.5f) * 0.1f);
                    changed = true;
                }

                if (velocity.Theta != projectile.localAI[1])
                {
                    OriginExtensions.AngularSmoothing(ref velocity.Theta, projectile.localAI[1], (targetVel - 0.5f) * 0.03f);
                    changed = true;
                }
                else
                {
                    projectile.localAI[1] = Main.rand.NextFloat(-MathHelper.Pi, MathHelper.Pi);
                }

                if (changed)
                {
                    projectile.velocity = (Vector2)velocity;
                }
            }
        }
Beispiel #5
0
 internal Rock(PolarVec2 offset) : this()
 {
     this.offset = offset;
 }
Beispiel #6
0
        public override void AI()
        {
            float rotSpeed = projectile.spriteDirection * (0.05f + (0.01f * rocks.Where(r => r.attached).Count()));

            projectile.rotation += rotSpeed;
            if (!projectile.tileCollide)
            {
                Player owner = Main.player[projectile.owner];
                owner.GetModPlayer <OriginPlayer>().heldProjectile = owner.heldProj = projectile.whoAmI;
                projectile.velocity = Vector2.Zero;
                if (rocks.Count < 10)
                {
                    if (++projectile.localAI[0] >= projectile.ai[0] && owner.CheckMana(owner.HeldItem, pay: true))
                    {
                        projectile.localAI[0] = 0;
                        float[] laserScanResults = new float[3];
                        int     tries            = 15;
retry:
                        PolarVec2 spawnPosition = new PolarVec2(1, Main.rand.NextFloat(-MathHelper.Pi, MathHelper.Pi));
                        Collision.LaserScan(projectile.Center, (Vector2)spawnPosition, 1f, 481f, laserScanResults);
                        float dist = laserScanResults.Average();
                        if (dist >= 480f)
                        {
                            if (tries-- > 0)
                            {
                                goto retry;
                            }
                            dist          = 640;
                            spawnPosition = new PolarVec2(1, Main.rand.NextFloat(MathHelper.Pi - MathHelper.PiOver4, MathHelper.PiOver4));
                        }
                        spawnPosition.R = dist;
                        rocks.Add(new Rock(spawnPosition));
                        Vector2 soundPosition = projectile.Center + (Vector2)spawnPosition;
                        Main.PlaySound(SoundID.Item, (int)soundPosition.X, (int)soundPosition.Y, 28, 1, -0.3f);
                    }
                }
                Rock rock;
                for (int i = 0; i < rocks.Count; i++)
                {
                    rock = rocks[i];
                    if (!rock.attached)
                    {
                        rock.offset.R -= 162f / projectile.ai[0];
                        if (rock.offset.R <= rocks.Count)
                        {
                            rock.attached = true;
                        }
                    }
                    else
                    {
                        rock.offset.Theta += rotSpeed;
                    }
                    LightAndDust(projectile.Center + (Vector2)rock.offset);
                }
            }
            else if (projectile.ai[1] > 0)
            {
                projectile.ai[1] = 0;
                Rock rock;
                for (int i = 0; i < rocks.Count; i++)
                {
                    rock = rocks[i];
                    if (!rock.attached)
                    {
                        rocks.RemoveAt(i--);
                        PolarVec2 vel = rock.offset;
                        vel.R = -(162f / projectile.ai[0]);
                        Projectile.NewProjectile(projectile.Center + (Vector2)rock.offset, (Vector2)vel, Gravaulter_Rock1.ID + rock.type, projectile.damage / 2, projectile.knockBack, projectile.owner, ai1: rotSpeed * projectile.spriteDirection);
                    }
                    LightAndDust(projectile.Center + (Vector2)rock.offset);
                }
                if (rocks.Count == 0)
                {
                    projectile.timeLeft = 0;
                }
                else
                {
                    projectile.damage = (int)((rocks.Count + 5f) * 0.2f * projectile.damage);
                    Main.PlaySound(SoundID.Item88, projectile.Center);
                }
            }
            else
            {
                Rock rock;
                for (int i = 0; i < rocks.Count; i++)
                {
                    rock = rocks[i];
                    rock.offset.Theta += rotSpeed;
                    LightAndDust(projectile.Center + (Vector2)rock.offset);
                }
                projectile.velocity.Y += 0.06f;
            }
        }