public void Generate() { if (GoblinCap <= 0 || sGlobalAllocation >= GoblinCap) { return; } Goblin character = inactiveGoblins [inactiveGoblins.Count - 1]; if (character == null) { return; } var offset = CollisionRadius * 0.75f; var rot = GraphicsUtilities.PalarAdjust(VirtualZRotation); var pos = new CGPoint((float)Math.Cos(rot) * offset, (float)Math.Sin(rot) * offset); character.Position = new CGPoint(pos.X + Position.X, pos.Y + Position.Y); MultiplayerLayeredCharacterScene scene = CharacterScene; character.AddToScene(CharacterScene); character.ZPosition = -1f; character.FadeIn(0.5f); inactiveGoblins.Remove(character); ActiveGoblins.Add(character); sGlobalAllocation++; }
public void UpdateAlphaWithScene(MultiplayerLayeredCharacterScene scene) { if (scene == null) throw new ArgumentNullException ("scene"); if (!FadeAlpha) return; nfloat closestHeroDistance = nfloat.MaxValue; // See if there are any heroes nearby. var ourPosition = Position; foreach (SKNode hero in scene.Heroes) { var theirPos = hero.Position; var distance = GraphicsUtilities.DistanceBetweenCGPoints(ourPosition, theirPos); closestHeroDistance = (nfloat)Math.Min (distance, closestHeroDistance); } if (closestHeroDistance > OpaqueDistance) { // No heroes nearby. Alpha = 1; } else { // Adjust the alpha based on how close the hero is. var ratio = closestHeroDistance / OpaqueDistance; Alpha = 0.1f + ratio * ratio * 0.9f; } }
void PickRandomFacingFor(CGPoint position) { MultiplayerLayeredCharacterScene scene = CharacterScene; var rnd = new Random(); // Pick best random facing from 8 test rays. nfloat maxDoorCanSee = 0; nfloat preferredZRotation = 0; for (int i = 0; i < 8; i++) { var testZ = rnd.NextDouble() * (2 * Math.PI); var x = -Math.Sin(testZ) * 1024 + position.X; var y = Math.Cos(testZ) * 1024 + position.Y; var pos2 = new CGPoint((int)x, (int)y); nfloat dist = 0; if (scene != null) { dist = scene.DistanceToWall(position, pos2); } if (dist > maxDoorCanSee) { maxDoorCanSee = dist; preferredZRotation = (float)testZ; } } ZRotation = preferredZRotation; }
public void AddToScene(MultiplayerLayeredCharacterScene scene) { if (scene == null) { throw new ArgumentNullException("scene"); } scene.AddNode(this, WorldLayer.Character); scene.AddNode(ShadowBlob, WorldLayer.BelowCharacter); }
public override void UpdateWithTimeSinceLastUpdate(double interval) { if (Character.Dying) { Target = null; return; } var position = Character.Position; MultiplayerLayeredCharacterScene scene = Character.CharacterScene; nfloat closestHeroDistance = float.MaxValue; // Find the closest living hero, if any, within our alert distance. foreach (HeroCharacter hero in scene.Heroes) { var heroPosition = hero.Position; var distance = GraphicsUtilities.DistanceBetweenCGPoints(position, heroPosition); if (distance < EnemyAlertRadius && distance < closestHeroDistance && !hero.Dying) { closestHeroDistance = distance; Target = hero; } } // If there's no target, don't do anything. if (Target == null) { return; } // Otherwise chase or attack the target, if it's near enough. var heroPos = Target.Position; float chaseRadius = ChaseRadius; if (closestHeroDistance > MaxAlertRadius) { Target = null; } else if (closestHeroDistance > ChaseRadius) { Character.MoveTowards(heroPos, interval); } else if (closestHeroDistance < ChaseRadius) { Character.FaceTo(heroPos); Character.PerformAttackAction(); } }
public override void UpdateWithTimeSinceLastUpdate(double interval) { Cave cave = (Cave)Character; if (cave.Health <= 0) { return; } MultiplayerLayeredCharacterScene scene = cave.CharacterScene; nfloat closestHeroDistance = MinimumHeroDistance; var closestHeroPosition = CGPoint.Empty; var cavePosition = cave.Position; foreach (SKNode hero in scene.Heroes) { var heroPosition = hero.Position; var distance = GraphicsUtilities.DistanceBetweenCGPoints(cavePosition, heroPosition); if (distance < closestHeroDistance) { closestHeroDistance = distance; closestHeroPosition = heroPosition; } } var distScale = closestHeroDistance / MinimumHeroDistance; // Generate goblins more quickly if the closest hero is getting closer. cave.TimeUntilNextGenerate -= (float)interval; // Either time to generate or the hero is so close we need to respond ASAP! int goblinCount = cave.ActiveGoblins.Count; if (goblinCount < 1 || cave.TimeUntilNextGenerate <= 0 || (distScale < 0.35f && cave.TimeUntilNextGenerate > 5)) { if (goblinCount < 1 || (goblinCount < 4 && closestHeroPosition != CGPoint.Empty) && scene.CanSee(closestHeroPosition, cave.Position)) { cave.Generate(); } cave.TimeUntilNextGenerate = 4 * distScale; } }
public override void PerformDeath() { base.PerformDeath(); var splort = (SKNode)DeathSplort.Copy(); splort.ZPosition = -1; splort.ZRotation = VirtualZRotation; splort.Position = Position; splort.Alpha = 0.1f; splort.RunAction(SKAction.FadeAlphaTo(1, 0.5)); MultiplayerLayeredCharacterScene scene = CharacterScene; scene.AddNode(splort, WorldLayer.BelowCharacter); RunAction(SKAction.Sequence(new [] { SKAction.FadeAlphaTo(0, 0.5f), SKAction.RemoveFromParent() })); smokeEmitter.RunAction(SKAction.Sequence(new [] { SKAction.WaitForDuration(2), SKAction.Run(() => { smokeEmitter.ParticleBirthRate = 2; }), SKAction.WaitForDuration(2), SKAction.Run(() => { smokeEmitter.ParticleBirthRate = 0; }), SKAction.WaitForDuration(10), SKAction.FadeAlphaTo(0, 0.5), SKAction.RemoveFromParent() })); inactiveGoblins.Clear(); }
public void UpdateAlphaWithScene(MultiplayerLayeredCharacterScene scene) { if (scene == null) { throw new ArgumentNullException("scene"); } if (!FadeAlpha) { return; } nfloat closestHeroDistance = nfloat.MaxValue; // See if there are any heroes nearby. var ourPosition = Position; foreach (SKNode hero in scene.Heroes) { var theirPos = hero.Position; var distance = GraphicsUtilities.DistanceBetweenCGPoints(ourPosition, theirPos); closestHeroDistance = (nfloat)Math.Min(distance, closestHeroDistance); } if (closestHeroDistance > OpaqueDistance) { // No heroes nearby. Alpha = 1; } else { // Adjust the alpha based on how close the hero is. var ratio = closestHeroDistance / OpaqueDistance; Alpha = 0.1f + ratio * ratio * 0.9f; } }
public void AddToScene(MultiplayerLayeredCharacterScene scene) { if (scene == null) throw new ArgumentNullException ("scene"); scene.AddNode (this, WorldLayer.Character); scene.AddNode (ShadowBlob, WorldLayer.BelowCharacter); }