private void ShootBolt(FInt rotation, int midX, int midY) { FInt r = FPRadians.Normalize(rotation); FInt velX = FInt.Create(Radians.GetXFromRotation((float)r.ToDouble(), (float)this.attSpeed.ToDouble())); FInt velY = FInt.Create(Radians.GetYFromRotation((float)r.ToDouble(), (float)this.attSpeed.ToDouble())); ProjectileEnemy projectile = ProjectileEnemy.Create(room, (byte)ProjectileEnemySubType.BoltBlue, FVector.Create(midX - 10, midY + 4), FVector.Create(velX, velY)); projectile.physics.SetGravity(FInt.Create(0)); projectile.rotation = (float)r.ToDouble(); }
public override void RunTick() { base.RunTick(); // Get Center Bounds int midX = this.posX + this.bounds.MidX; int midY = this.posY + this.bounds.MidY; // Only change behaviors every 16 frames. if (Systems.timer.frame16Modulus == 15) { this.WatchForCharacter(midX, midY); } // Check for any attack to make this round. if (this.charWatched is Character && this.attack.AttackThisFrame()) { // Get distance from Character, if applicable. int destX = this.charWatched is Character ? this.charWatched.posX + this.charWatched.bounds.MidX - 10 : midX; int destY = this.charWatched is Character ? this.charWatched.posY + this.charWatched.bounds.MidY - 10 : midY; int distance = FPTrigCalc.GetDistance(FVector.Create(midX, midY), FVector.Create(destX, destY)).RoundInt; if (distance < ViewDistance) { FInt rotation = FPRadians.GetRadiansBetweenCoords(midX, midY, destX, destY); this.rotation = (float)rotation.ToDouble(); if (this.attCount != 2) { this.ShootBolt(rotation, midX, midY); } if (this.attCount > 1) { this.ShootBolt(rotation + attSpread, midX, midY); this.ShootBolt(rotation - attSpread, midX, midY); } this.room.PlaySound(Systems.sounds.bolt, 0.6f, this.posX + 16, this.posY + 16); } } }
public override void RunTick() { // Update the rotation to move toward. int midX = this.actor.posX + this.actor.bounds.MidX; int midY = this.actor.posY + this.actor.bounds.MidY; // Only change behaviors every 16 frames. if (Systems.timer.frame16Modulus == 7) { this.TryUpdateBehavior(midX, midY); } // Get distance from Character, if applicable. int destX = this.charBeingChased is Character ? this.charBeingChased.posX + this.charBeingChased.bounds.MidX : midX; int destY = this.charBeingChased is Character ? this.charBeingChased.posY + this.charBeingChased.bounds.MidY : midY; int distance = FPTrigCalc.GetDistance(FVector.Create(midX, midY), FVector.Create(destX, destY)).RoundInt; // Stall if (this.stall > 0 && distance < this.stall) { if (this.physics.velocity.X != 0) { this.physics.velocity.X *= FInt.Create(0.85); } if (this.physics.velocity.Y != 0) { this.physics.velocity.Y *= FInt.Create(0.85); } return; } // Stop Chasing if (this.quickAct == ChaseAction.Standard || this.quickAct == ChaseAction.Wait) { if (this.physics.velocity.X != 0) { this.physics.velocity.X *= FInt.Create(0.9); } if (this.physics.velocity.Y != 0) { this.physics.velocity.Y *= FInt.Create(0.9); } return; } // Return to Starting Position if (this.quickAct == ChaseAction.Return) { destX = (int)this.startPos.X; destY = (int)this.startPos.Y; } FInt newVelX = FInt.Create(0); FInt newVelY = FInt.Create(0); // Chase or Flee if (this.axis == (byte)FlightChaseAxis.Both) { if (Math.Abs(midX - destX) < 2 && Math.Abs(midY - destY) <= 2) { this.physics.velocity.X *= FInt.Create(0.90); this.physics.velocity.Y *= FInt.Create(0.90); return; } FInt rotRadian = FPRadians.GetRadiansBetweenCoords(midX, midY, destX, destY); newVelX = FPRadians.GetXFromRotation(rotRadian, this.speed); newVelY = FPRadians.GetYFromRotation(rotRadian, this.speed); } // Vertical Movement Only else if (this.axis == (byte)FlightChaseAxis.Vertical) { if (Math.Abs(midY - destY) <= 2) { this.physics.velocity.Y *= FInt.Create(0.90); return; } FInt rotRadian = FPRadians.GetRadiansBetweenCoords(0, midY, 0, destY); newVelY = FPRadians.GetYFromRotation(rotRadian, this.speed); } // Horizontal Movement Only else { if (Math.Abs(midX - destX) <= 2) { this.physics.velocity.X *= FInt.Create(0.90); return; } FInt rotRadian = FPRadians.GetRadiansBetweenCoords(midX, 0, destX, 0); newVelX = FPRadians.GetXFromRotation(rotRadian, this.speed); } // Flee if (this.quickAct == ChaseAction.Flee) { newVelX = newVelX.Inverse; newVelY = newVelY.Inverse; } FInt accel = this.speed * FInt.Create(0.02); if (this.physics.velocity.X > newVelX) { this.physics.velocity.X -= accel; } else if (this.physics.velocity.X < newVelX) { this.physics.velocity.X += accel; } if (this.physics.velocity.Y > newVelY) { this.physics.velocity.Y -= accel; } else if (this.physics.velocity.Y < newVelY) { this.physics.velocity.Y += accel; } }