public static void SetLaserLength(Scene scene, Laserbeam beam) { Level level = scene as Level; beam.Length = MaxBeamLength(level, beam); float shortestWidth = MaxBeamLength(level, beam); foreach (Solid s in scene.Tracker.GetEntities <Solid>()) { if (beam.CollideCheck(s)) { if (s.Collider is Grid) { shortestWidth = Math.Min(shortestWidth, GetLaserLengthDACOnGrid(beam, s.Collider as Grid, shortestWidth)); } else { shortestWidth = Math.Min(shortestWidth, LengthCalculatingFunctions[beam.Direction](beam, s.Collider)); } } } foreach (LaserDetectorActor entity in scene.Tracker.GetEntities <LaserDetectorActor>()) { Collider origCollider = entity.Collider; Collider collider = entity.GetLaserBlockingCollider(beam); ColliderList colliderList = collider as ColliderList; if (colliderList == null) { entity.Collider = collider; if (beam.CollideCheck(entity)) { shortestWidth = Math.Min(shortestWidth, LengthCalculatingFunctions[beam.Direction](beam, collider)); } } else { foreach (Collider c in colliderList.colliders) { entity.Collider = c; if (beam.CollideCheck(entity)) { shortestWidth = Math.Min(shortestWidth, LengthCalculatingFunctions[beam.Direction](beam, c)); } } } entity.Collider = origCollider; } beam.Length = shortestWidth; }
public override void OnNewLaserbeam(Laserbeam laserbeams) { Player player = base.Scene.Tracker.GetEntity <Player>(); Vector2 position = player != null && atPlayer ? player.Position : Position; float pitch = NoteHelper.relativeA4ToFreq(this.pitch - 69) / 440f; FMOD.Studio.EventInstance instance = Audio.Play(SFX.EventnameByHandle(sound), position); instance?.setVolume(volume); instance?.setPitch(pitch); }
public virtual bool LaserBlockingCheck(Laserbeam beam) { Collider origCollider = Collider; Collider = GetLaserBlockingCollider(beam); bool colliding = Collide.Check(beam, this); Collider = origCollider; return(colliding); }
private void reflect(Laserbeam beam) { if (!reflections.ContainsKey(beam)) { Level level = Scene as Level; string newDirection = LaserHelper.GetReflection(opening, beam); if (newDirection != null) { reflections[beam] = new Laserbeam(Position, newDirection, beam.Color, beam.TTL); level.Add(reflections[beam]); reflections[beam].Depth = beam.Depth + 1; reflections[beam].Position += reflectionOffsets[newDirection]; } } }
public override void OnLaserbeams(List <Laserbeam> laserbeams) { HashSet <Laserbeam> needsUpdate = new HashSet <Laserbeam>(reflections.Keys); foreach (Laserbeam beam in laserbeams) { reflect(beam); needsUpdate.Remove(beam); } foreach (Laserbeam beam in needsUpdate) { Laserbeam target = reflections[beam]; target.RemoveSelf(); reflections.Remove(beam); } }
private void onLastFrame(string s) { if (isActive() && laserbeam == null) { Level level = Scene as Level; laserbeam = new Laserbeam(Position - laserOffset, direction, color, beamDuration, this); level.Add(laserbeam); idleSprite.Play("idle", true); idleSprite.Rate = 1; idleSprite.Visible = true; startupSprite.Visible = false; bloom.Visible = light.Visible = true; } inStartupAnimation = false; startupSprite.Stop(); }
public static void SetLaserLengthDAQ(Scene scene, Laserbeam beam) { Level level = scene as Level; float maxLength = LaserHelper.MaxBeamLength(level, beam); float offset = maxLength / 2f; beam.Length = offset; while (offset >= 1f) { bool colliding = beam.CollideCheck <Solid>() || LaserHelper.LaserBlockingCheck(scene, beam); int sign = colliding ? -1 : 1; offset /= 2f; beam.Length += sign * offset; } beam.Length = (float)Math.Round(beam.Length); }
public static float GetLaserLengthDACOnGrid(Laserbeam beam, Grid grid, float checking) { float origLength = beam.Length; float offset = checking / 2f; beam.Length = offset; while (offset >= 1f) { bool colliding = grid.Collide(beam); int sign = colliding ? -1 : 1; offset /= 2f; beam.Length += sign * offset; } float res = beam.Length; beam.Length = origLength; return(res); }
public override void Update() { if (isActive()) { if (laserbeam == null && !inStartupAnimation) { startupSprite.Play("start", true); startupSprite.Rate = 1; startupSprite.Visible = true; idleSprite.Visible = false; inStartupAnimation = true; bloom.Visible = light.Visible = true; } } else { if (laserbeam != null && !inStartupAnimation) { startupSprite.Play("start", true); startupSprite.Rate = -1; startupSprite.SetAnimationFrame(startupSprite.CurrentAnimationTotalFrames - 1); startupSprite.Visible = true; idleSprite.Visible = false; inStartupAnimation = true; laserbeam.RemoveSelf(); laserbeam = null; bloom.Visible = light.Visible = false; } } base.Update(); }
public virtual Collider GetLaserBlockingCollider(Laserbeam beam) { return(LaserBlockingCollider); }
public virtual void OnDeadLaserbeam(Laserbeam beam) { }
public virtual void OnNewLaserbeam(Laserbeam beam) { }
public static bool LaserBlockingCheck(Scene scene, Laserbeam beam) { var res = scene.Tracker.GetEntities <LaserDetectorActor>().Cast <LaserDetectorActor>().Any(entity => entity.LaserBlockingCheck(beam)); return(res); }
public static string GetReflection(string opening, Laserbeam beam) { return(GetReflection(opening, beam.Direction)); }
public static float MaxBeamLength(Level level, Laserbeam beam) { return(MaxLengthFunction[beam.Direction](level, beam)); }
public override Collider GetLaserBlockingCollider(Laserbeam beam) { bool notBlocking = knownBeams != null && knownBeams.Contains(beam); return(notBlocking ? direcitonKnownBlockingColliders[direction] : direcitonBlockingColliders[direction]); }