Ejemplo n.º 1
0
        public override void AI()
        {
            if (npc.realLife < 0)
            {
                npc.active = false;
                return;
            }
            NPC head = Main.npc[npc.realLife];

            npc.life   = head.active ? npc.lifeMax : 0;
            npc.immune = head.immune;
            if (Main.netMode != NetmodeID.MultiplayerClient)
            {
                NPC next = Main.npc[ai[1]];
                if (Math.Abs(AngleDif(npc.rotation, next.oldRot[1])) > MathHelper.PiOver2)
                {
                    npc.rotation = next.oldRot[1];
                }
                else
                {
                    LinearSmoothing(ref npc.rotation, next.oldRot[1], npc.collideY?0.1f:0.3f);
                }
                //Vector2 targetPos = next.oldPosition + new Vector2(next.width/2, next.height/2) - new Vector2(24, 0).RotatedBy(npc.rotation);;
                //npc.velocity = targetPos - npc.Center;

                Vector2 targetPos = next.oldPosition - new Vector2(24, 0).RotatedBy(npc.rotation);
                Vector2 unit      = new Vector2(1, 0).RotatedBy(npc.rotation);

                /*Vector2? validPos = null;
                 * for(int i = -2; i <= 2; i++) {
                 *  if(Collision.CanHit(targetPos,32,28,targetPos+unit-new Vector2(0,8*i),32,28)) {
                 *      validPos = targetPos-new Vector2(0, 8*i);
                 *  }
                 * }
                 * if(validPos.HasValue) {
                 *  npc.Center = targetPos + new Vector2(next.width/2, next.height/2);
                 * } else if((targetPos-npc.Center).Length()>16){
                 *  npc.Center = targetPos;
                 * }*/
                Vector2 offset = Collision.AdvancedTileCollision(new bool[TileLoader.TileCount], targetPos - new Vector2(0, 8), new Vector2(0, 16), 32, 30);
                npc.position = targetPos + offset - new Vector2(0, 8);
                //LerpSmoothing(ref npc.position, targetPos + offset - new Vector2(0,8), 0.9f, 4);
                //Vector2 center = npc.Center;
                //float dist = Math.Max((targetPos-center).Length()-8, 0);
                //LinearSmoothing(ref center.X, targetPos.X, 1+dist);
                //LinearSmoothing(ref center.Y, targetPos.Y, 1+dist);
                //npc.Center = center;
                //npc.Center = next.oldPosition + new Vector2(next.width/2, next.height/2) - new Vector2(24, 0).RotatedBy(npc.rotation);
            }
        }
Ejemplo n.º 2
0
        public override void UpdateEffects(Player player)
        {
            Rectangle rect = new Rectangle((int)(player.position.X - 6), (int)(player.position.Y - 6), player.width + 12, player.height + mountData.heightBoost + 12);

            if (player.controlLeft)
            {
                rect.X -= 16;
            }
            if (player.controlRight)
            {
                rect.Width += 16;
            }
            if (player.controlJump)
            {
                rect.Y -= 16;
            }
            if (player.controlDown)
            {
                rect.Height += 16;
            }
            bool sand = false;

            for (int x = rect.X / 16; x <= (rect.X + rect.Width) / 16 && !sand; x++)
            {
                for (int y = rect.Y / 16; y <= (rect.Y + rect.Height) / 16 && !sand; y++)
                {
                    int type = Main.tile[x, y].type;
                    if (Main.tile[x, y].nactive() && (type == TileID.Sand || type == TileID.Pearlsand || type == TileID.Ebonsand || type == TileID.Crimsand || type == TileID.Sandstone || type == TileID.HardenedSand || type == TileID.HallowHardenedSand || type == TileID.CorruptHardenedSand || type == TileID.CrimsonHardenedSand || type == TileID.HallowSandstone || type == TileID.CorruptSandstone || type == TileID.CrimsonSandstone || type == TileID.DesertFossil))
                    {
                        sand = true;
                    }
                }
            }
            float moveSpeed = mountData.dashSpeed * 2.5f * player.GetModPlayer <JoostPlayer>().accRunSpeedMult;
            float jumpSpeed = mountData.jumpSpeed * 2;
            float accel     = mountData.acceleration;

            if (player.controlRight && player.GetModPlayer <JoostPlayer>().sandSharkVel.X < moveSpeed)
            {
                if (player.velocity.X < 0)
                {
                    player.GetModPlayer <JoostPlayer>().sandSharkVel.X = 0;
                }
                else
                {
                    player.GetModPlayer <JoostPlayer>().sandSharkVel.X = (player.GetModPlayer <JoostPlayer>().sandSharkVel.X + accel > moveSpeed) ? moveSpeed : player.GetModPlayer <JoostPlayer>().sandSharkVel.X + accel;
                }
            }
            if (player.controlLeft && player.GetModPlayer <JoostPlayer>().sandSharkVel.X > -moveSpeed)
            {
                if (player.velocity.X > 0)
                {
                    player.GetModPlayer <JoostPlayer>().sandSharkVel.X = 0;
                }
                else
                {
                    player.GetModPlayer <JoostPlayer>().sandSharkVel.X = (player.GetModPlayer <JoostPlayer>().sandSharkVel.X - accel < -moveSpeed) ? -moveSpeed : player.GetModPlayer <JoostPlayer>().sandSharkVel.X - accel;
                }
            }
            if (player.controlJump && player.GetModPlayer <JoostPlayer>().sandSharkVel.Y > -jumpSpeed)
            {
                if (player.velocity.Y >= 0)
                {
                    if (player.velocity.Y == 0)
                    {
                        player.GetModPlayer <JoostPlayer>().sandSharkVel.Y = -jumpSpeed;
                    }
                    else
                    {
                        player.GetModPlayer <JoostPlayer>().sandSharkVel.Y = 0;
                    }
                }
                else
                {
                    player.GetModPlayer <JoostPlayer>().sandSharkVel.Y = (player.GetModPlayer <JoostPlayer>().sandSharkVel.Y - accel < -jumpSpeed) ? -jumpSpeed : player.GetModPlayer <JoostPlayer>().sandSharkVel.Y - accel;
                }
            }
            if (player.controlDown)
            {
                if (player.velocity.Y <= 0)
                {
                    player.GetModPlayer <JoostPlayer>().sandSharkVel.Y = 0;
                }
                else if (player.GetModPlayer <JoostPlayer>().sandSharkVel.Y < jumpSpeed)
                {
                    player.GetModPlayer <JoostPlayer>().sandSharkVel.Y = (player.GetModPlayer <JoostPlayer>().sandSharkVel.Y + accel > jumpSpeed) ? jumpSpeed : player.GetModPlayer <JoostPlayer>().sandSharkVel.Y + accel;
                }
            }
            if (sand)
            {
                player.buffImmune[BuffID.Suffocation] = true;
                player.suffocating = false;
                player.noFallDmg   = true;
                player.velocity    = Collision.AdvancedTileCollision(TileID.Sets.ForAdvancedCollision.ForSandshark, rect.TopLeft(), player.velocity, rect.Width, rect.Height, player.controlDown, player.controlDown, (int)player.gravDir);
                if (player.gravDir > 0)
                {
                    if (player.controlJump && player.velocity.Y > -jumpSpeed)
                    {
                        if (player.velocity.Y <= 0)
                        {
                            player.velocity.Y = player.GetModPlayer <JoostPlayer>().sandSharkVel.Y;
                        }
                        player.velocity.Y -= 1f;
                        player.position.Y += player.velocity.Y / 4;
                    }
                    if (player.controlDown && player.velocity.Y < jumpSpeed)
                    {
                        if (player.velocity.Y >= 0)
                        {
                            player.velocity.Y = player.GetModPlayer <JoostPlayer>().sandSharkVel.Y;
                        }
                        player.velocity.Y += 1f;
                        player.position.Y += player.velocity.Y / 4;
                    }
                }
                else
                {
                    if (player.controlJump && player.velocity.Y < jumpSpeed)
                    {
                        if (player.velocity.Y >= 0)
                        {
                            player.velocity.Y = player.GetModPlayer <JoostPlayer>().sandSharkVel.Y;
                        }
                        player.velocity.Y += 1f;
                        player.position.Y += player.velocity.Y / 4;
                    }
                    if (player.controlDown && player.velocity.Y > -jumpSpeed)
                    {
                        if (player.velocity.Y <= 0)
                        {
                            player.velocity.Y = player.GetModPlayer <JoostPlayer>().sandSharkVel.Y;
                        }
                        player.velocity.Y -= 1f;
                        player.position.Y += player.velocity.Y / 4;
                    }
                }
                if (player.controlRight)
                {
                    if (player.velocity.X < moveSpeed)
                    {
                        if (player.velocity.X >= 0)
                        {
                            player.velocity.X = player.GetModPlayer <JoostPlayer>().sandSharkVel.X;
                        }
                        player.velocity.X++;
                    }
                    player.position.X += player.velocity.X / 4;
                    player.direction   = 1;
                }
                if (player.controlLeft)
                {
                    if (player.velocity.X > -moveSpeed)
                    {
                        if (player.velocity.X <= 0)
                        {
                            player.velocity.X = player.GetModPlayer <JoostPlayer>().sandSharkVel.X;
                        }
                        player.velocity.X--;
                    }
                    player.position.X += player.velocity.X / 4;
                    player.direction   = -1;
                }
                if (Collision.SlopeCollision(player.position, player.velocity, player.width, player.height + 2, player.gravity, player.stairFall) != new Vector4(player.position, player.velocity.X, player.velocity.Y))
                {
                    if (player.controlDown)
                    {
                        player.position.Y += player.height;
                    }
                    if (player.controlJump)
                    {
                        player.position.Y -= player.height;
                    }
                }
                player.runSoundDelay += (int)player.velocity.Length();
                if (player.runSoundDelay > 40)
                {
                    player.runSoundDelay = 0;
                    Main.PlaySound(15, (int)player.Center.X, (int)player.Center.Y, 1, 0.8f);
                }
            }
            else if (player.wet)
            {
                if (!player.controlJump)
                {
                    if (player.GetModPlayer <JoostPlayer>().sandSharkVel.Y < 0)
                    {
                        player.GetModPlayer <JoostPlayer>().sandSharkVel.Y = 0;
                    }
                    else
                    {
                        player.GetModPlayer <JoostPlayer>().sandSharkVel.Y += 0.1f;
                    }
                }
                player.velocity = player.GetModPlayer <JoostPlayer>().sandSharkVel;
                player.GetModPlayer <JoostPlayer>().sandSharkVel *= 0.99f;
            }
            if (player.velocity.Y != 0)
            {
                player.fullRotation       = (float)(Math.Atan2(player.velocity.Y * 0.25f, (Math.Abs(player.velocity.X) + 2) * player.direction)) + (player.direction == 1 ? 0 : (float)Math.PI);
                player.fullRotationOrigin = player.Center - player.position + new Vector2(0, player.height / 2);
            }
            else
            {
                player.fullRotation = 0;
            }
        }