public IEnumerable <Wait> RoutineStartLevel() { var tile = PlayerCurio.GetMainTile(); var movable = PlayerCurio.GetBehavior <BehaviorMovable>(); var orientation = PlayerCurio.GetBehavior <BehaviorOrientable>(); var start = tile.GetBehavior <BehaviorLevelStart>(); var player = PlayerCurio.GetBehavior <BehaviorPlayer>(); player.LevelTransition = true; orientation.OrientTo(Util.PointToAngle(start.Direction) + MathHelper.Pi); var pos = tile.VisualPosition; CameraCurio.TeleportVisual(GetOutsidePosition(pos, start.Direction, 150)); PlayerCurio.TeleportVisual(GetOutsidePosition(pos, start.Direction, 200)); player.Fade.Set(0); yield return(new WaitTime(100)); CameraCurio.MoveVisual(tile.VisualPosition, LerpHelper.QuadraticOut, new SliderScene(this, 150)); yield return(new WaitTime(100)); CurrentTheme?.Stop(); CurrentTheme = new MusicEffect(Theme); CurrentTheme.Volume.Set(0, 1, LerpHelper.QuadraticIn, 20); CurrentTheme.Play(); SoundIngress.Play(1f, 0f, 0f); player.Fade.Set(1, LerpHelper.QuarticOut, 70); PlayerCurio.MoveVisual(tile.VisualPosition, LerpHelper.QuarticOut, new SliderScene(this, 100)); yield return(new WaitTime(70)); player.LevelTransition = false; yield return(new WaitTime(30)); }
public IEnumerable <MapTile> GetImpactArea() { var tile = Curio.GetMainTile(); List <Point> offsets = new List <Point>(); for (int i = 0; i < 4; i++) { Vector2 offset = Util.AngleToVector(SwordAngle) * (i + 1) * 0.5f; offsets.Add(offset.ToTileOffset()); } return(offsets.Distinct().Select(o => tile.GetNeighborOrNull(o.X, o.Y)).NonNull()); }
public void Tick(SceneGame scene) { var tile = Curio.GetMainTile(); if (tile != null) { foreach (var target in tile.Contents.Where(x => x != Shooter && x.IsAlive())) { if (!AlreadyHit.IsInvincible(target, 1)) { var actions = new List <ActionWrapper>(); actions.Add(new ActionEnergyKnifeHit(Curio, target).InSlot(ActionSlot.Active)); actions.Apply(target); AlreadyHit.Add(target); } } } AlreadyHit.Tick(scene.TimeModCurrent); if (Lifetime.Done) { Curio.Destroy(); } Lifetime += scene.TimeModCurrent; }
public void Tick(SceneGame scene) { var tile = Curio.GetMainTile(); if (MoveFrame.Done) { MoveFrame = new Slider(MoveFrame.Time - MoveFrame.EndTime, MoveFrame.EndTime); var camera = Curio.GetCamera(); var offset = Direction.ToTileOffset(); var neighbor = tile.GetNeighborOrNull(offset.X, offset.Y); if (neighbor == null) { //Out of bounds Curio.Destroy(); } else { Curio.MoveTo(neighbor, MoveLerp, MoveFrame); camera?.MoveTo(neighbor, LerpHelper.Linear, MoveFrame); } } if (LifeTime.Done) { //Fizzle Curio.Destroy(); } LifeTime += scene.TimeModCurrent; MoveFrame += scene.TimeModCurrent; }
public void Draw(SceneGame scene, DrawPass pass) { var tile = Curio.GetMainTile(); var wall = SpriteLoader.Instance.AddSprite("content/terrain_chasm_wall"); var noise = Noise.GetValue(tile.X, tile.Y); int depth = (noise % 3) + 1; int ox = 0; int oy = 0; Color color = Color; switch (pass) { case DrawPass.Chasm1: if (depth < 3) { return; } ox = NoiseX.GetValue(tile.X, tile.Y); oy = NoiseY.GetValue(tile.X, tile.Y); color = Color.Lerp(color, Color.Black, 0.75f); break; case DrawPass.Chasm2: if (depth < 2) { return; } ox = NoiseX.GetValue(tile.X + 1000, tile.Y); oy = NoiseY.GetValue(tile.X, tile.Y); color = Color.Lerp(color, Color.Black, 0.50f); break; case DrawPass.Chasm3: if (depth < 1) { return; } ox = NoiseX.GetValue(tile.X + 2000, tile.Y); oy = NoiseY.GetValue(tile.X, tile.Y); color = Color.Lerp(color, Color.Black, 0.25f); break; } scene.SpriteBatch.Draw(wall.Texture, new Rectangle(tile.X * 16, tile.Y * 16, 16, 16), new Rectangle(tile.X * 16 + ox, tile.Y * 16 + oy, 16, 16), color); }
public void Tick(SceneGame scene) { var active = Curio.GetActionHolder(ActionSlot.Active); var lastSeen = Curio.GetBehavior <BehaviorLastSeen>(); var pathfinder = Curio.GetBehavior <BehaviorPathfinder>(); var orientable = Curio.GetBehavior <BehaviorOrientable>(); var tile = Curio.GetMainTile(); if (tile != null && active.Done && Curio.IsAlive()) { var map = tile.Map; var mace = Curio.GetBehavior <BehaviorMace>(); var delta = scene.PlayerCurio.GetVisualTarget() - Curio.GetVisualTarget(); if (mace != null && mace.IsInArea(scene.PlayerCurio) && map.CanSee(Curio.GetVisualTarget(), scene.PlayerCurio.GetVisualTarget())) { var angleCurrent = orientable.Angle; var angleTarget = Enumerable.Range(0, 8).Select(x => MathHelper.PiOver4 * x).GetClosestAngle(Util.VectorToAngle(delta)); var angleDelta = MathHelper.WrapAngle(angleTarget - angleCurrent); var attack = new List <ActionWrapper>() { //new ActionMaceAttack(Curio, scene.PlayerCurio, 20f, 5f).InSlot(ActionSlot.Active), new ActionMaceGoreAttack(Curio, scene.PlayerCurio, 40f, 20f, 5f).InSlot(ActionSlot.Active), new ActionTurn(Curio, angleDelta, 3).InSlot(ActionSlot.Active), }; attack.Apply(Curio); } else if (lastSeen.LastSeenTile != null) { var nextMove = pathfinder.GetNextMove(new Point(tile.X, tile.Y)); if (lastSeen.LastSeenTile != pathfinder.GetDestination() || !nextMove.HasValue) { pathfinder.FindPath(lastSeen.LastSeenTile); } if (nextMove.HasValue) { var angleCurrent = orientable.Angle; var angleTarget = Util.PointToAngle(nextMove.Value); var angleDelta = MathHelper.WrapAngle(angleTarget - angleCurrent); var movement = new List <ActionWrapper>(); if (Math.Abs(angleDelta) < 0.0001) { movement.Add(new ActionMoveForward(Curio, nextMove.Value.ToVector2(), 8).InSlot(ActionSlot.Active)); } else if (angleDelta < 0) { movement.Add(new ActionTurn(Curio, -MathHelper.PiOver4, 4).InSlot(ActionSlot.Active)); } else if (angleDelta > 0) { movement.Add(new ActionTurn(Curio, MathHelper.PiOver4, 4).InSlot(ActionSlot.Active)); } movement.Apply(Curio); } } } }
public static SceneGame GetWorld(this ICurio curio) { MapTile tile = curio.GetMainTile(); if (tile != null) { return(tile.Map.World); } return(null); //TODO: some curios might not be tilebound }
public void Tick(SceneGame scene) { var active = Curio.GetActionHolder(ActionSlot.Active); var lastSeen = Curio.GetBehavior <BehaviorLastSeen>(); var pathfinder = Curio.GetBehavior <BehaviorPathfinder>(); var orientable = Curio.GetBehavior <BehaviorOrientable>(); var tile = Curio.GetMainTile(); if (active.Done && Curio.IsAlive()) { var delta = scene.PlayerCurio.GetVisualTarget() - Curio.GetVisualTarget(); var distance = delta.Length(); if (distance < 24f) { var angleCurrent = orientable.Angle; var angleTarget = Enumerable.Range(0, 8).Select(x => MathHelper.PiOver4 * x).GetClosestAngle(Util.VectorToAngle(delta)); var angleDelta = MathHelper.WrapAngle(angleTarget - angleCurrent); var attack = new List <ActionWrapper>() { new ActionDaggerAttack(Curio, Util.ToTileOffset(Util.AngleToVector(angleTarget)), 5f, 2.5f).InSlot(ActionSlot.Active), new ActionTurn(Curio, angleDelta, 3).InSlot(ActionSlot.Active), }; attack.Apply(Curio); } else if (lastSeen.LastSeenTile != null) { var nextMove = pathfinder.GetNextMove(new Point(tile.X, tile.Y)); if (lastSeen.LastSeenTile != pathfinder.GetDestination() || !nextMove.HasValue) { pathfinder.FindPath(lastSeen.LastSeenTile); } if (nextMove.HasValue) { var angleCurrent = orientable.Angle; var angleTarget = Util.PointToAngle(nextMove.Value); var angleDelta = MathHelper.WrapAngle(angleTarget - angleCurrent); var movement = new List <ActionWrapper>(); if (Math.Abs(angleDelta) < 0.0001) { movement.Add(new ActionMoveForward(Curio, nextMove.Value.ToVector2(), 10).InSlot(ActionSlot.Active)); } else if (angleDelta < 0) { movement.Add(new ActionTurn(Curio, -MathHelper.PiOver4, 5).InSlot(ActionSlot.Active)); } else if (angleDelta > 0) { movement.Add(new ActionTurn(Curio, MathHelper.PiOver4, 5).InSlot(ActionSlot.Active)); } movement.Apply(Curio); } } } }
private void EmitWraith(ICurio target) { var emitTile = Curio.GetMainTile(); var targetTile = target.GetMainTile().GetNearby(5).ToList().Pick(Random); var wraith = new Curio(Template.Wraith); wraith.MoveTo(targetTile); Behavior.Apply(new BehaviorWraith(wraith, emitTile.VisualTarget, Random.NextFloat(30, 70))); SoundEmit.Play(1f, Random.NextFloat(-1, +1), Random.NextFloat(-1, +1)); }
public bool IsReady() { var tile = Curio.GetMainTile(); var levelEnd = tile.GetBehavior <BehaviorLevelEnd>(); if (levelEnd != null) { return(levelEnd.CanEscape()); } return(false); }
public void Draw(SceneGame scene, DrawPass pass) { var tile = Curio.GetMainTile(); if (pass == DrawPass.EffectLowAdditive) { SkillUtil.DrawArea(scene, GetImpactArea(), ColorStart, ColorEnd, Frame.Slide); SkillUtil.DrawImpact(scene, tile, ColorStart, ColorEnd, Frame.Slide); } DrawArcObject(scene, pass); }
public override void DrawIcon(ICurio curio, SceneGame scene, Vector2 pos) { var tile = curio.GetMainTile(); /*scene.PushSpriteBatch(shader: scene.Shader, shaderSetup: (matrix, projection) => * { * scene.SetupColorMatrix(curio.GetColor() * ColorMatrix.Identity, matrix, projection); * });*/ scene.DrawSprite(Icon, 0, pos - Icon.Middle, Microsoft.Xna.Framework.Graphics.SpriteEffects.None, GetColor(tile.X, tile.Y), 0); //scene.PopSpriteBatch(); }
public void Tick(SceneGame scene) { Fade.Update(); var tile = Curio.GetMainTile(); var passive = Curio.GetActionHolder(ActionSlot.Passive); var active = Curio.GetActionHolder(ActionSlot.Active); var levelEnd = tile?.GetBehavior <BehaviorLevelEnd>(); if (levelEnd != null && !scene.WaitForCutscene && passive.Done && active.Done && levelEnd.CanEscape() && Curio.IsAlive()) { EndLevel(scene); } UpdateFootstep(scene); bool faceForward = (Momentum.Amount > 0 || LevelTransition); if (ForwardBack.End > 0 && !faceForward) { ForwardBack.Set(0, LerpHelper.Quadratic, 30); } if (ForwardBack.End < 1 && faceForward) { ForwardBack.Set(1, LerpHelper.Quadratic, 30); } ForwardBack.Update(); HairFrame += LevelTransition ? 1 : scene.TimeModCurrent; if (Curio.IsDead() && !scene.IsGameOver) { scene.GameOver(GameOverType.Death); SoundDeath.Play(1, -0.5f, 0); } if (!scene.WaitForPlayer) { //MovePassive(); } else if (Momentum.Amount <= 0 && SwordReady) { SheatheSword(); } }
public static Vector2 GetVisualTarget(this ICurio curio) { var movable = curio.GetBehavior <BehaviorMovable>(); if (movable != null) { return(movable.VisualPosition() + new Vector2(8, 8)); } MapTile tile = curio.GetMainTile(); return(tile?.VisualTarget ?? Vector2.Zero); }
public override void Draw(ICurio curio, SceneGame scene, DrawPass pass) { var tile = curio.GetMainTile(); //var offset = curio.GetOffset(); if (pass != Pass) { //return; var wall = SpriteLoader.Instance.AddSprite("content/terrain_chasm_wall"); var noise = Noise.GetValue(tile.X, tile.Y); int ox = 0; int oy = 0; Color color = GetColor(tile.X, tile.Y); switch (pass) { case DrawPass.Chasm1: ox = NoiseX.GetValue(tile.X, tile.Y); oy = NoiseY.GetValue(tile.X, tile.Y); color = Color.Lerp(color, Color.Black, 0.75f); break; case DrawPass.Chasm2: ox = NoiseX.GetValue(tile.X + 1000, tile.Y); oy = NoiseY.GetValue(tile.X, tile.Y); color = Color.Lerp(color, Color.Black, 0.50f); break; case DrawPass.Chasm3: ox = NoiseX.GetValue(tile.X + 2000, tile.Y); oy = NoiseY.GetValue(tile.X, tile.Y); color = Color.Lerp(color, Color.Black, 0.25f); break; } scene.SpriteBatch.Draw(wall.Texture, new Rectangle(tile.X * 16, tile.Y * 16, 16, 16), new Rectangle(tile.X * 16 + ox, tile.Y * 16 + oy, 16, 16), color); return; } /*scene.PushSpriteBatch(shader: scene.Shader, shaderSetup: (matrix, projection) => * { * scene.SetupColorMatrix(curio.GetColor() * ColorMatrix.Identity, matrix, projection); * });*/ var floor = Sprite; var debris = SpriteLoader.Instance.AddSprite("content/terrain_debris"); if (Noise.GetValue(tile.X, tile.Y) % 100 < 3) { floor = debris; } scene.SpriteBatch.Draw(floor.Texture, new Rectangle(tile.X * 16, tile.Y * 16, 16, 16), new Rectangle(tile.X * 16, tile.Y * 16, 16, 16), GetColor(tile.X, tile.Y)); //scene.PopSpriteBatch(); }
public void Tick(SceneGame scene) { var tile = Curio.GetMainTile(); if (tile != null) { if (tile.IsSolid()) { Curio.Destroy(); } } }
private void Retarget() { var origin = Origin.GetMainTile(); var target = Target.GetMainTile(); var mace = Origin.GetBehavior <BehaviorMace>(); var map = origin.Map; if (origin != null && target != null && mace != null && mace.IsInArea(Target) && map.CanSee(Origin.GetVisualTarget(), Target.GetVisualTarget())) { Offset = new Point(target.X - origin.X, target.Y - origin.Y); } }
public void FindPath(MapTile destination) { if (!Cooldown.Done) { return; } MapTile source = Curio.GetMainTile(); if (source != null) { Setup(); var path = WeightedPathfinder.Search(Graph, new Point(source.X, source.Y), new Point(destination.X, destination.Y)); if (path != null) { Path = path; } else { Cooldown.Time = 0; } } }
public override void Draw(ICurio curio, SceneGame scene, DrawPass pass) { var tile = curio.GetMainTile(); var offset = curio.GetOffset(); /*scene.PushSpriteBatch(shader: scene.Shader, shaderSetup: (matrix, projection) => * { * scene.SetupColorMatrix(curio.GetColor() * ColorMatrix.Identity, matrix, projection); * });*/ var floor = Sprite; scene.SpriteBatch.Draw(floor.Texture, new Rectangle(tile.X * 16, tile.Y * 16, 16, 16), new Rectangle(tile.X * 16, tile.Y * 16, 16, 16), GetColor(tile.X, tile.Y)); //scene.PopSpriteBatch(); }
public override void Draw(ICurio curio, SceneGame scene, DrawPass pass) { var spikes = SpriteLoader.Instance.AddSprite("content/terrain_spikes"); var tile = curio.GetMainTile(); var offset = curio.GetOffset(); if (pass == DrawPass.WallBottom) { scene.DrawSprite(spikes, 0, new Vector2(tile.X * 16 + 8, tile.Y * 16 + 8) - spikes.Middle, SpriteEffects.None, 0); } if (pass == DrawPass.WallTop) { scene.SpriteBatch.Draw(Sprite.Texture, new Rectangle(tile.X * 16, tile.Y * 16, 16, 16), new Rectangle(tile.X * 16, tile.Y * 16, 16, 16), GetColor(tile.X, tile.Y)); } }
public void MoveTick(Vector2 direction) { SparkFrame += Curio.GetWorld().TimeModCurrent; if (SparkFrame.Done) { SparkFrame.Reset(); if (Position == 0) { return; } var tile = Curio.GetMainTile(); var angle = Curio.GetAngle() + Position * MathHelper.PiOver4; var offset = Util.AngleToVector(angle).ToTileOffset(); var neighbor = tile.GetNeighborOrNull(offset.X, offset.Y); if (neighbor != null && neighbor.IsSolid()) { Vector2 sparkDirection = direction; if (Position < 0) { sparkDirection = sparkDirection.TurnLeft(); } if (Position > 0) { sparkDirection = sparkDirection.TurnRight(); } Vector2 tip = GetBlade(8); for (int i = 0; i < 3; i++) { Vector2 randomOffset = Util.AngleToVector(Random.NextAngle()) * 20; new SparkParticle(Curio.GetWorld(), SpriteLoader.Instance.AddSprite("content/effect_cinder"), tip, 10) { Velocity = sparkDirection * Random.Next(24, 48) + randomOffset, Color = Color.White, Size = Random.NextFloat(), VelocityLerp = LerpHelper.QuadraticIn, DrawPass = DrawPass.EffectCreatureAdditive, }; } } } }
public static ICurio GetGrappleTarget(this ICurio origin, Vector2 direction) { var tile = origin.GetMainTile(); var offset = Util.ToTileOffset(direction); var neighbor = tile; for (int i = 0; i < 10; i++) { neighbor = neighbor.GetNeighborOrNull(offset.X, offset.Y); if (neighbor == null) { break; } var grappleTarget = neighbor.GetGrappleTarget(); if (grappleTarget != null) { return(grappleTarget); } } return(null); }
public void Tick(SceneGame scene) { var tile = Curio.GetMainTile(); if (tile != null) { if (tile.IsSolid()) { Curio.Destroy(); } var targets = tile.Contents.Where(x => x.IsAlive() && x != Projectile.Shooter); if (targets.Any()) { var target = targets.First(); var actions = new List <ActionWrapper>(); actions.Add(new ActionEnergyKnifeHit(Curio, target).InSlot(ActionSlot.Active)); actions.Apply(target); Curio.Destroy(); } } }
bool PerformMovement(BehaviorLastSeen lastSeen) { var pathfinder = Curio.GetBehavior <BehaviorPathfinder>(); var orientable = Curio.GetBehavior <BehaviorOrientable>(); var tile = Curio.GetMainTile(); var nextMove = pathfinder.GetNextMove(new Point(tile.X, tile.Y)); if (lastSeen.LastSeenTile != pathfinder.GetDestination() || !nextMove.HasValue) { pathfinder.FindPath(lastSeen.LastSeenTile); } if (nextMove.HasValue) { var angleCurrent = orientable.Angle; var angleTarget = Util.PointToAngle(nextMove.Value); var angleDelta = MathHelper.WrapAngle(angleTarget - angleCurrent); var movement = new List <ActionWrapper>(); if (Math.Abs(angleDelta) < 0.0001) { movement.Add(new ActionMoveForward(Curio, nextMove.Value.ToVector2(), MoveTime).InSlot(ActionSlot.Active)); } else if (angleDelta < 0) { movement.Add(new ActionTurn(Curio, -MathHelper.PiOver4, TurnTime).InSlot(ActionSlot.Active)); } else if (angleDelta > 0) { movement.Add(new ActionTurn(Curio, MathHelper.PiOver4, TurnTime).InSlot(ActionSlot.Active)); } movement.Apply(Curio); return(true); } return(false); }
public void Tick(SceneGame scene) { var active = Curio.GetActionHolder(ActionSlot.Active); var lastSeen = Curio.GetBehavior <BehaviorLastSeen>(); var pathfinder = Curio.GetBehavior <BehaviorPathfinder>(); var orientable = Curio.GetBehavior <BehaviorOrientable>(); var alive = Curio.GetBehavior <BehaviorAlive>(); var tile = Curio.GetMainTile(); var enemyDistance = Vector2.Distance(scene.PlayerCurio.GetVisualTarget(), Curio.GetVisualTarget()); var isEnemyFar = enemyDistance > 200; var isEnemyClose = enemyDistance < 100; var isEnemyArmed = scene.PlayerCurio.HasBehaviors <BehaviorSword>(); WingsOpen.Update(); ForwardBack.Update(); if (active.Done && alive.CurrentDead) { var actions = new List <ActionWrapper>(); actions.Add(new ActionNemesisRevive(Curio, 120).InSlot(ActionSlot.Active)); actions.Apply(Curio); if (!actions.Any(x => x.Action is ActionNemesisRevive)) { scene.GameOver(GameOverType.NemesisKill); } } if (active.Done && Curio.IsAlive()) { if (ForwardBack.End > 0 && State != NemesisState.Forward) { ForwardBack.Set(0, LerpHelper.Quadratic, 30); } if (ForwardBack.End < 1 && State == NemesisState.Forward) { ForwardBack.Set(1, LerpHelper.Quadratic, 30); } if (State == NemesisState.Back) { if (isEnemyArmed) { ParryTimer += scene.TimeModCurrent; if (ParryTimer.Done) { State = NemesisState.Parry; ParryTimer.Time = 0; } } if (isEnemyFar) { ChaseTimer += scene.TimeModCurrent; if (ChaseTimer.Done) { State = NemesisState.Forward; ChaseTimer.Time = 0; } } } if (State == NemesisState.Parry) { if (!isEnemyArmed || isEnemyFar) { ParryTimer += scene.TimeModCurrent; if (ParryTimer.Done) { State = NemesisState.Back; ParryTimer.Time = 0; } } } if (State == NemesisState.Forward) { if (isEnemyClose) { State = NemesisState.Back; } ChaseTimer += 1; if (lastSeen.LastSeenTile != null) { var nextMove = pathfinder.GetNextMove(new Point(tile.X, tile.Y)); if (lastSeen.LastSeenTile != pathfinder.GetDestination() || !nextMove.HasValue) { pathfinder.FindPath(lastSeen.LastSeenTile); } if (nextMove.HasValue) { var angleCurrent = orientable.Angle; var angleTarget = Util.PointToAngle(nextMove.Value); var angleDelta = MathHelper.WrapAngle(angleTarget - angleCurrent); var movement = new List <ActionWrapper>(); if (ChaseTimer.Done) { var randomPath = pathfinder.Path.Pick(Random); var randomPathTile = Curio.GetMap().GetTileOrNull(randomPath.X, randomPath.Y); if (randomPathTile != tile) { var dist = Vector2.Distance(randomPathTile.VisualTarget, Curio.GetVisualTarget()); movement.Add(new ActionMoveNemesis(Curio, scene.PlayerCurio, randomPathTile, dist / 8f + 10).InSlot(ActionSlot.Active)); ChaseTimer.Time = 0; } } else if (Math.Abs(angleDelta) < 0.0001) { movement.Add(new ActionMoveForward(Curio, nextMove.Value.ToVector2(), 5).InSlot(ActionSlot.Active)); } else if (angleDelta < 0) { movement.Add(new ActionTurn(Curio, -MathHelper.PiOver4, 3).InSlot(ActionSlot.Active)); } else if (angleDelta > 0) { movement.Add(new ActionTurn(Curio, MathHelper.PiOver4, 3).InSlot(ActionSlot.Active)); } movement.Apply(Curio); } } } } }
public void Tick(SceneGame scene) { var active = Curio.GetActionHolder(ActionSlot.Active); var lastSeen = Curio.GetBehavior <BehaviorLastSeen>(); var pathfinder = Curio.GetBehavior <BehaviorPathfinder>(); var orientable = Curio.GetBehavior <BehaviorOrientable>(); var tile = Curio.GetMainTile(); var map = Curio.GetMap(); if (Curio.IsDead()) { Decay += scene.TimeModCurrent; } if (Decay.Done) { var actions = new List <ActionWrapper>(); actions.Add(new ActionRatGib(scene.PlayerCurio, Curio, 2000, SoundLoader.AddSound("content/sound/splat.wav")).InSlot(ActionSlot.Active)); actions.Apply(Curio); } if (active.Done && Curio.IsAlive()) { if (lastSeen.LastSeenTile != null) { var nextMove = pathfinder.GetNextMove(new Point(tile.X, tile.Y)); if (!pathfinder.HasPath) { var positions = map.EnumerateTiles().Shuffle(Random); foreach (var escapeTile in positions) { if (Vector2.Distance(escapeTile.VisualTarget, tile.VisualTarget) < 300) { continue; } if (escapeTile.IsChasm() || escapeTile.IsSolid()) { continue; } pathfinder.FindPath(escapeTile); SoundRat.Play(1, Random.NextFloat(-0.5f, +0.5f), 0); break; } } else if (nextMove.HasValue) { var angleCurrent = orientable.Angle; var angleTarget = Util.PointToAngle(nextMove.Value); var angleDelta = MathHelper.WrapAngle(angleTarget - angleCurrent); var movement = new List <ActionWrapper>(); if (Math.Abs(angleDelta) < 0.0001) { movement.Add(new ActionMoveForward(Curio, nextMove.Value.ToVector2(), 4).InSlot(ActionSlot.Active)); } else if (angleDelta < 0) { movement.Add(new ActionTurn(Curio, -MathHelper.PiOver4, 5).InSlot(ActionSlot.Active)); } else if (angleDelta > 0) { movement.Add(new ActionTurn(Curio, MathHelper.PiOver4, 5).InSlot(ActionSlot.Active)); } movement.Apply(Curio); } else { var actions = new List <ActionWrapper>(); actions.Add(new ActionRatGib(scene.PlayerCurio, Curio, 2000, SoundLoader.AddSound("content/sound/splat.wav")).InSlot(ActionSlot.Active)); actions.Apply(Curio); } } } }
public bool ShouldDraw(SceneGame scene, Vector2 cameraPosition) { var tile = Curio.GetMainTile(); return(tile.GetMap() == scene.Map && scene.IsWithinCamera(cameraPosition, tile.VisualTarget)); }
public override void Draw(GameTime gameTime) { CameraTarget.Setup(this, Viewport.Width, Viewport.Height); Util.SetupRenderTarget(this, ref DistortionMap, Viewport.Width, Viewport.Height); Util.SetupRenderTarget(this, ref BloodMapAdditive, Viewport.Width, Viewport.Height); Util.SetupRenderTarget(this, ref BloodMapMultiply, Viewport.Width, Viewport.Height); Projection = Matrix.CreateOrthographicOffCenter(0, Viewport.Width, Viewport.Height, 0, 0, -1); WorldTransform = CreateViewMatrix(); ApplyScreenShake(ref WorldTransform); DrawTextures(); SetRenderTarget(null); var cameraTile = CameraCurio.GetMainTile(); //var tiles = cameraTile?.GetNearby(15) ?? Enumerable.Empty<MapTile>(); //var curios = Manager.GetCurios().Where(x => !(x is MapTile)).Concat(tiles); //var gameObjects = curios.SelectMany(curio => curio.GetDrawables()); var globalDrawables = Manager.Drawable.GetDrawables(); var cameraPos = CameraCurio.GetVisualTarget(); var drawPasses = globalDrawables .Concat(VisualEffects) .Concat(Menu.GetAllMenus().OfType <IDrawable>()) .Where(x => x.ShouldDraw(this, cameraPos)) .ToMultiLookup(x => x.GetDrawPasses()); SetRenderTarget(CameraTarget.A); int width = 19 * 32; int height = 19 * 32; GraphicsDevice.ScissorRectangle = new Rectangle((Viewport.Width - width) / 2, (Viewport.Height - height) / 2, width, height); PushSpriteBatch(samplerState: SamplerState.PointWrap, blendState: NonPremultiplied, transform: WorldTransform, projection: Projection); PushSpriteBatch(transform: WorldTransform *Matrix.CreateTranslation(new Vector3(-CameraSize, 0)) * Matrix.CreateScale(0.80f) * Matrix.CreateTranslation(new Vector3(CameraSize, 0))); drawPasses.DrawPass(this, DrawPass.ChasmBottom); PopSpriteBatch(); PushSpriteBatch(transform: WorldTransform *Matrix.CreateTranslation(new Vector3(-CameraSize, 0)) * Matrix.CreateScale(0.85f) * Matrix.CreateTranslation(new Vector3(CameraSize, 0))); drawPasses.DrawPass(this, DrawPass.Chasm1); PopSpriteBatch(); PushSpriteBatch(transform: WorldTransform *Matrix.CreateTranslation(new Vector3(-CameraSize, 0)) * Matrix.CreateScale(0.90f) * Matrix.CreateTranslation(new Vector3(CameraSize, 0))); drawPasses.DrawPass(this, DrawPass.Chasm2); PopSpriteBatch(); PushSpriteBatch(transform: WorldTransform *Matrix.CreateTranslation(new Vector3(-CameraSize, 0)) * Matrix.CreateScale(0.95f) * Matrix.CreateTranslation(new Vector3(CameraSize, 0))); drawPasses.DrawPass(this, DrawPass.Chasm3); PopSpriteBatch(); drawPasses.DrawPass(this, DrawPass.Tile); drawPasses.DrawPass(this, DrawPass.Item); drawPasses.DrawPass(this, DrawPass.EffectLow); PushSpriteBatch(blendState: BlendState.Additive); drawPasses.DrawPass(this, DrawPass.EffectLowAdditive); PopSpriteBatch(); drawPasses.DrawPass(this, DrawPass.WallBottom); drawPasses.DrawPass(this, DrawPass.Creature); PushSpriteBatch(blendState: BlendState.Additive); drawPasses.DrawPass(this, DrawPass.EffectCreatureAdditive); PopSpriteBatch(); drawPasses.DrawPass(this, DrawPass.WallTop); drawPasses.DrawPass(this, DrawPass.Effect); PushSpriteBatch(blendState: BlendState.Additive); drawPasses.DrawPass(this, DrawPass.EffectAdditive); PopSpriteBatch(); PopSpriteBatch(); SetRenderTarget(CameraTarget.B); CameraTarget.Swap(); //Draw screenflashes ColorMatrix color = ColorMatrix.Identity; ApplyScreenFlash(ref color); PushSpriteBatch(samplerState: SamplerState.PointWrap, blendState: NonPremultiplied, shader: Shader, shaderSetup: (transform, projection) => { SetupColorMatrix(color, Matrix.Identity, Projection); }); SpriteBatch.Draw(CameraTarget.B, CameraTarget.B.Bounds, Color.White); PopSpriteBatch(); SetRenderTarget(CameraTarget.B); CameraTarget.Swap(); //Draw glitches RenderGlitches(CameraTarget); //Draw to screen SetRenderTarget(null); PushSpriteBatch(samplerState: SamplerState.PointWrap, blendState: NonPremultiplied, shader: Shader, shaderSetup: (transform, projection) => { SetupColorMatrix(ColorMatrix.Identity, Matrix.Identity, Projection); }); SpriteBatch.Draw(CameraTarget.B, CameraTarget.B.Bounds, Color.White); PopSpriteBatch(); PushSpriteBatch(samplerState: SamplerState.PointWrap, blendState: BlendState.Additive, shader: Shader, shaderSetup: (transform, projection) => { SetupColorMatrix(ColorMatrix.Identity, Matrix.Identity, Projection); }); SpriteBatch.Draw(BloodMapAdditive, BloodMapAdditive.Bounds, Color.White); PopSpriteBatch(); PushSpriteBatch(samplerState: SamplerState.PointWrap, blendState: MultiplyBoth, shader: Shader, shaderSetup: (transform, projection) => { SetupColorMatrix(ColorMatrix.Identity, Matrix.Identity, Projection); }); SpriteBatch.Draw(BloodMapMultiply, BloodMapMultiply.Bounds, Color.White); PopSpriteBatch(); //Draw cursor and tooltip SpriteReference cursor_tile = SpriteLoader.Instance.AddSprite("content/cursor_tile"); SetupNormal(Matrix.Identity, Projection); //SpriteBatch.Begin(blendState: NonPremultiplied, rasterizerState: RasterizerState.CullNone, samplerState: SamplerState.PointWrap, transformMatrix: WorldTransform); PushSpriteBatch(blendState: NonPremultiplied, samplerState: SamplerState.PointWrap, transform: WorldTransform, projection: Projection); if (TileCursor.HasValue) { DrawSprite(cursor_tile, Frame / 8, new Vector2(TileCursor.Value.X * 16, TileCursor.Value.Y * 16), SpriteEffects.None, 0); } drawPasses.DrawPass(this, DrawPass.UIWorld); //SpriteBatch.End(); PopSpriteBatch(); //SetupNormal(Matrix.Identity); //SpriteBatch.Begin(blendState: NonPremultiplied, rasterizerState: RasterizerState.CullNone, samplerState: SamplerState.PointWrap); PushSpriteBatch(blendState: NonPremultiplied, samplerState: SamplerState.PointWrap, projection: Projection); drawPasses.DrawPass(this, DrawPass.UI); Menu.Draw(this); var mousePos = new Vector2(InputState.MouseX, InputState.MouseY); var mouseCursor = SpriteLoader.Instance.AddSprite("content/ui_mouse_cursor"); DrawSprite(mouseCursor, 0, mousePos, SpriteEffects.None, 0); DrawTooltip(); PopSpriteBatch(); }