Skip to content

Instantly share code, notes, and snippets.

@Doomfiva9
Created March 19, 2025 20:47
Show Gist options
  • Save Doomfiva9/e12fbec5c3fe10ee0dd09145db90a9ed to your computer and use it in GitHub Desktop.
Save Doomfiva9/e12fbec5c3fe10ee0dd09145db90a9ed to your computer and use it in GitHub Desktop.
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Microsoft.Xna.Framework;
using System;
using endgame.Content.Projectile;
using endgame.Content.Items; // Add this using statement for your custom projectiles
namespace endgame.Content.NPCs.Boss
{
public class DashingEyeBoss : ModNPC
{
private int dashCooldown = 0;
private bool isDashing = false;
private int animationTimer = 0;
private int currentFrame = 0;
private int beamCooldown = 0; // Cooldown for shooting beams
private int phaseTransitionTimer = 0; // Timer for phase transition
public override void SetStaticDefaults()
{
Main.npcFrameCount[NPC.type] = 6; // 6 total frames (3 frames for each phase)
}
public override void SetDefaults()
{
NPC.width = 100;
NPC.height = 100;
NPC.aiStyle = -1;
NPC.damage = 300;
NPC.defense = 600;
NPC.lifeMax = 900000;
NPC.knockBackResist = 0f;
NPC.noTileCollide = true;
NPC.noGravity = true;
NPC.boss = true;
NPC.lavaImmune = true;
NPC.value = Item.buyPrice(0, 5, 0, 0);
Music = MusicID.Boss1;
}
public override void AI()
{
Player player = Main.player[NPC.target];
if (!player.active || player.dead)
{
NPC.TargetClosest(false);
NPC.velocity.Y -= 1f;
if (NPC.timeLeft > 10)
{
NPC.timeLeft = 10;
}
return;
}
// **Calculate Direction Towards Player**
Vector2 targetPosition = player.Center;
Vector2 direction = targetPosition - NPC.Center;
direction.Normalize();
// **Flip Rotation to Make Red Side Face the Player**
NPC.rotation = (float)Math.Atan2(direction.Y, direction.X) + MathHelper.Pi; // 180-degree flip
// **Dashing Mechanic**
if (isDashing)
{
NPC.velocity = direction * 8f; // Dash speed
dashCooldown--;
if (dashCooldown <= 0)
{
isDashing = false;
}
}
else
{
// Random movement, slower than dashing
if (Main.rand.NextFloat() < 0.6f)
{
NPC.velocity *= 0.5f;
}
else
{
isDashing = true;
dashCooldown = 20; // Dash cooldown duration
}
}
// **Shooting Beams**
if (beamCooldown <= 0)
{
ShootBeamAtPlayer(player);
beamCooldown = 180; // Cooldown time between beams (adjust for difficulty)
}
else
{
beamCooldown--;
}
// **Health-Based Transformation (Red → Blue)**
float healthPercentage = (float)NPC.life / NPC.lifeMax;
if (healthPercentage > 0.5f)
{
// First Phase (Red)
currentFrame = (animationTimer / 10) % 3; // Cycle through frames 0-2 (first 3 frames)
}
else
{
// Second Phase (Blue, Open Eye)
currentFrame = 3 + (animationTimer / 10) % 3; // Cycle through frames 3-5 (next 3 frames)
}
// **Cycle Animation Timer**
animationTimer++;
if (animationTimer >= 30) // Adjust this for quicker or slower animation
{
animationTimer = 0;
}
// **Phase Transition Timer** (Optional: increase the speed or behavior in phase 2)
if (healthPercentage < 0.5f)
{
phaseTransitionTimer++;
if (phaseTransitionTimer > 180)
{
// Increase aggressiveness after phase transition (e.g., faster dashes, more frequent beams)
dashCooldown = 10;
NPC.velocity *= 1.5f;
}
}
}
private void ShootBeamAtPlayer(Player player)
{
Vector2 direction = player.Center - NPC.Center;
direction.Normalize();
float speed = 12f; // Speed of the beam
// Use your modded MagicMissile projectile here
Projectile.NewProjectile(NPC.GetSource_FromAI(), NPC.Center, direction * speed, ModContent.ProjectileType<MagicMissile>(), 150, 5f, Main.myPlayer);
}
public override void FindFrame(int frameHeight)
{
NPC.frame.Y = frameHeight * currentFrame; // Set the correct frame based on currentFrame
}
public override void BossLoot(ref string name, ref int potionType)
{
potionType = ItemID.LesserHealingPotion;
Item.NewItem(NPC.GetSource_Loot(), NPC.getRect(), ItemID.Acorn, Main.rand.Next(10, 20));
// Additional custom loot (optional)
if (Main.rand.NextBool(10)) // 10% chance for extra loot
{
Item.NewItem(NPC.GetSource_Loot(), NPC.getRect(), ModContent.ItemType<End_Ore>(), Main.rand.Next(1, 3));
}
}
}
}
this is all i have need help wiht the Projectile.NewProjectile it keep saying that it The type or namespace name 'NewProjectile' does not exist in the namespace 'endgame.Content.Projectile' (are you missing an assembly reference?)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment