// The AI of the projectile public override void AI() { // capture the player instance so we can toss it around. Player player = Main.player[projectile.owner]; // handle mouse movement and DoControl(player); // handle charging (or not charging) DoCharge(player); // Handle Audio SoundUtil.UpdateTrackedSound(ChargeSoundSlotId, projectile.Center); }
public override void AI() { if (!player.channel || (ChargeLevel >= ChargeLimit)) { if (ChargeLevel >= 1) { float rot = (float)Math.Atan2((Main.mouseY + Main.screenPosition.Y) - projectile.Center.Y, (Main.mouseX + Main.screenPosition.X) - projectile.Center.X); Projectile.NewProjectileDirect(new Vector2(projectile.Center.X, projectile.Center.Y), new Vector2((float)((Math.Cos(rot) * 15)), (float)((Math.Sin(rot) * 15))), mod.ProjectileType("BigBangKamehamehaBlast"), projectile.damage + (ChargeLevel * 65), projectile.knockBack, projectile.owner); //ChargeLevel = 0; SoundUtil.PlayCustomSound("Sounds/BasicBeamFire", projectile.Center); projectile.Kill(); for (int i = 0; i < 100; i++) { float angle = Main.rand.NextFloat(360); float angleRad = MathHelper.ToRadians(angle); Vector2 position = new Vector2((float)Math.Cos(angleRad), (float)Math.Sin(angleRad)); Dust tDust = Dust.NewDustDirect(projectile.position + (position * (20 + 3.0f * projectile.scale)), projectile.width, projectile.height, DustType, 0f, 0f, 213, default(Color), 3.0f); tDust.velocity = -0.5f * Vector2.Normalize((projectile.position + (projectile.Size / 2)) - tDust.position) * 2; tDust.noGravity = true; } } chargeSoundSlotId = SoundUtil.KillTrackedSound(chargeSoundSlotId); } if (!startingCharge) { startingCharge = true; if (!Main.dedServ) { chargeSoundSlotId = SoundUtil.PlayCustomSound("Sounds/EnergyWaveCharge", projectile.Center); } } SoundUtil.UpdateTrackedSound(chargeSoundSlotId, projectile.Center); }
// The AI of the projectile public override void AI() { Player player = Main.player[projectile.owner]; ProcessKillRoutine(player); // stationary beams are instantaneously "detached", they behave weirdly. if (IsStationaryBeam && !IsDetached) { DetachmentTimer = 1; } // capture the current mouse vector, we're going to normalize movement prior to updating the charge ball location. if (projectile.owner == Main.myPlayer) { Vector2 mouseVector = Main.MouseWorld; if (OriginalMouseVector == Vector2.Zero) { OriginalMouseVector = mouseVector; } if (IsStationaryBeam && OriginalMouseVector != Vector2.Zero) { mouseVector = OriginalMouseVector; } Vector2 screenPosition = Main.screenPosition; if (OriginalScreenPosition == Vector2.Zero) { OriginalScreenPosition = screenPosition; } if (IsStationaryBeam && OriginalScreenPosition != Vector2.Zero) { screenPosition = OriginalScreenPosition; } if (OldMouseVector != Vector2.Zero && !IsStationaryBeam) { Vector2 mouseMovementVector = (mouseVector - OldMouseVector) / RotationSlowness; Vector2 screenChange = screenPosition - OldScreenPosition; mouseVector = OldMouseVector + mouseMovementVector + screenChange; } UpdateBeamTailLocationAndDirection(player, mouseVector); OldMouseVector = mouseVector; OldScreenPosition = screenPosition; } UpdateBeamPlayerItemUse(player); // handle whether the beam should be visible, and how visible. HandleBeamVisibility(); // handle the distance routine // the difference between distance and tracked distance is that distance is the actual travel. // tracked distance is with collision, and resets distance if it's too high. Distance += BeamSpeed; float TrackedDistance; for (TrackedDistance = 0f; TrackedDistance <= MaxBeamDistance; TrackedDistance += BEAM_TILE_DISTANCE_GRADIENT) { Vector2 origin = TailPositionStart() + projectile.velocity * (TrackedDistance + HeadSize.Y - StepLength()); if (!ProjectileUtil.CanHitLine(TailPositionStart(), origin)) { // changed to a while loop at a much finer gradient to smooth out beam transitions. Experimental. TrackedDistance -= BEAM_TILE_DISTANCE_GRADIENT; if (TrackedDistance <= 0) { TrackedDistance = 0; } break; } } // handle animation frames on animated beams if (IsBeamSegmentAnimated) { BeamSegmentAnimation += 8; if (BeamSegmentAnimation >= StepLength()) { BeamSegmentAnimation = 0; } } // if distance is about to be throttled, we're hitting something. Spawn some dust. if (Distance >= TrackedDistance) { var dustVector = TailPositionStart() + (TrackedDistance + HeadSize.Y - StepLength()) * projectile.velocity; ProjectileUtil.DoBeamCollisionDust(DustType, CollisionDustFrequency, projectile.velocity, dustVector); } // throttle distance by collision Distance = Math.Min(TrackedDistance, Distance); // shoot sweet sweet particles for (var i = 0; i < FireParticleDensity; i++) { ProjectileUtil.DoBeamDust(projectile.position, projectile.velocity, DustType, DustFrequency, Distance, TailHeldDistance, TailSize.ToVector2(), BeamSpeed); } // Handle the audio playing, note this positionally tracks at the head position end for effect. if (JustFired) { BeamSoundSlotId = SoundUtil.PlayCustomSound(BeamSoundKey, HeadPositionEnd()); } JustFired = false; // Update tracked audio SoundUtil.UpdateTrackedSound(BeamSoundSlotId, HeadPositionEnd()); //Add lights DelegateMethods.v3_1 = new Vector3(0.8f, 0.8f, 1f); Utils.PlotTileLine(projectile.Center, projectile.Center + projectile.velocity * (Distance - TailHeldDistance), BeamSize.Y, DelegateMethods.CastLight); }