public MarioClearPipe(EntityData data, Vector2 offset) : base(data.Position + offset) { Depth = -5; nodes = data.NodesWithPosition(offset); removeRedundantNodes(); texturePath = data.Attr("texture", "glass"); surfaceSound = data.Int("surfaceSound", -1); HasPipeSolids = data.Bool("hasPipeSolids", true); TransportSpeed = data.Float("transportSpeed", 175f); pipeWidth = data.Int("pipeWidth", 32); pipeColliderWidth = pipeWidth - pipeWidthColliderValue; startDirection = GetPipeExitDirection(nodes[0], nodes[1]); endDirection = GetPipeExitDirection(nodes[nodes.Length - 1], nodes[nodes.Length - 2]); startDirectionVector = GetPipeExitDirectionVector(nodes[0], nodes[1]); endDirectionVector = GetPipeExitDirectionVector(nodes[nodes.Length - 1], nodes[nodes.Length - 2]); startCollider = getPipeCollider(Vector2.Zero, startDirection, pipeWidth, pipeColliderWidth, pipeColliderDepth); endCollider = getPipeCollider(new Vector2(nodes.Last().X - nodes.First().X, nodes.Last().Y - nodes.First().Y), endDirection, pipeWidth, pipeColliderWidth, pipeColliderDepth); Collider = new ColliderList(startCollider, endCollider); pipeSolids = new List <MarioClearPipeSolid>(); }
public static ColliderList GenerateSemiEfficientColliderGrid(VirtualMap <char> tileMap, int cellWidth, int cellHeight) { ColliderList colliders = new ColliderList(); for (int x = 0; x < tileMap.Columns; x++) { for (int y = 0; y < tileMap.Rows; y++) { if (tileMap.AnyInSegmentAtTile(x, y) && tileMap[x, y] != '0') { int width = 1; int height = 1; Hitbox h = new Hitbox(cellWidth, cellHeight, x, y); while (tileMap.AnyInSegmentAtTile(x, y) && tileMap[x, y] != '0') { width++; height++; x++; y++; } h.Width *= width; h.Height *= height; colliders.Add(h); } } } return(colliders.colliders.Length > 0 ? colliders : null); }
public void Remove(Collider collider) { if (!ColliderList.Contains(collider)) { return; } /* * foreach (Cell cell in GetCells(collider.WorldTransform)) * { * if (cell.Colliders.Contains(collider)) * { * cell.Colliders.Remove(collider); * } * } */ // OR ForEach((cell) => { if (cell.Colliders.Contains(collider)) { cell.Colliders.Remove(collider); } }); ComputedCollision.Remove(collider); ColliderList.Remove(collider); }
public override void start(BehaviourContext context) { base.start(context); Debug.Log(FindColliderWithLayer(context._settings._hideLayer)); _colliders = FindColliderWithLayer(context._settings._hideLayer); }
public static void AddLightOcclude(Entity entity, ColliderList colliders, float alpha = 1f) { foreach (Hitbox hitbox in colliders.colliders) { entity.Add(new LightOcclude(new Rectangle((int)hitbox.Position.X, (int)hitbox.Position.Y, (int)hitbox.Width, (int)hitbox.Height), alpha)); } }
public RetractSpinner(EntityData data, Vector2 offset) : base(data.Position + offset) { // pulled straight from vanilla spinners. this.offset = Calc.Random.NextFloat(); Tag = Tags.TransitionUpdate; Collider = new ColliderList(new Circle(6f), new Hitbox(16f, 4f, -8f, -3f)); Visible = false; Add(new PlayerCollider(OnPlayer)); Add(new HoldableCollider(OnHoldable)); Add(new LedgeBlocker()); Depth = 1; // just below Madeline, since the default state is retracted if (data.Bool("attachToSolid")) { Add(new StaticMover { OnShake = OnShake, SolidChecker = IsRiding, OnDestroy = RemoveSelf }); } int randomSeed = Calc.Random.Next(); // load the retracted and expanded sprites. Calc.PushRandom(randomSeed); List <MTexture> expandedVariations = GFX.Game.GetAtlasSubtextures("danger/SpringCollab2020/retractspinner/urchin_harm"); List <MTexture> retractedVariations = GFX.Game.GetAtlasSubtextures("danger/SpringCollab2020/retractspinner/urchin_safe"); MTexture expandedTexture = Calc.Random.Choose(expandedVariations); MTexture retractedTexture = Calc.Random.Choose(retractedVariations); expandedSprite = new Image(expandedTexture).SetOrigin(12f, 12f); retractedSprite = new Image(retractedTexture).SetOrigin(12f, 12f); Calc.PopRandom(); // the default state is "retracted". add the matching sprite Add(retractedSprite); }
public FancyFallingBlock(EntityData data, Vector2 offset) : base(data.Position + offset, '3', data.Width, data.Height, data.Bool("finalBoss", false), data.Bool("behind", false), data.Bool("climbFall", true)) { baseData = new DynData <FallingBlock>(this); Remove(baseData.Get <TileGrid>("tiles")); Remove(Get <TileInterceptor>()); badLightOcclude = Get <LightOcclude>(); int newSeed = Calc.Random.Next(); Calc.PushRandom(newSeed); tileMap = GenerateTileMap(data.Attr("tileData", "")); Autotiler.Generated generated = GFX.FGAutotiler.GenerateMap(tileMap, default(Autotiler.Behaviour)); baseData["tiles"] = generated.TileGrid; Add(baseData.Get <TileGrid>("tiles")); Add(animatedTiles = generated.SpriteOverlay); Calc.PopRandom(); if (data.Bool("finalBoss", false)) { VirtualMap <char> tileMapHighlighted = GenerateTileMap(data.Attr("tileDataHighlight", "")); Calc.PushRandom(newSeed); TileGrid highlight = GFX.FGAutotiler.GenerateMap(tileMapHighlighted, default(Autotiler.Behaviour)).TileGrid; highlight.Alpha = 0f; baseData["highlight"] = highlight; Add(baseData.Get <TileGrid>("highlight")); Calc.PopRandom(); } ColliderList colliders = GenerateBetterColliderGrid(tileMap, 8, 8); AddLightOcclude(this, colliders); Collider = colliders; Add(new TileInterceptor(baseData.Get <TileGrid>("tiles"), false)); }
public FancyFinalBossMovingBlock(EntityData data, Vector2 offset) : base(data.NodesWithPosition(offset), data.Width, data.Height, data.Int("nodeIndex", 0)) { baseData = new DynData <FinalBossMovingBlock>(this); Remove(baseData.Get <TileGrid>("sprite")); Remove(baseData.Get <TileGrid>("highlight")); Remove(Get <TileInterceptor>()); badLightOcclude = Get <LightOcclude>(); tileMap = GenerateTileMap(data.Attr("tileData", "")); tileMapHighlighted = GenerateTileMap(data.Attr("tileDataHighlight", "")); int newSeed = Calc.Random.Next(); Calc.PushRandom(newSeed); baseData["sprite"] = GFX.FGAutotiler.GenerateMap(tileMap, default(Autotiler.Behaviour)).TileGrid; Add(baseData.Get <TileGrid>("sprite")); Calc.PopRandom(); Calc.PushRandom(newSeed); TileGrid highlight = GFX.FGAutotiler.GenerateMap(tileMapHighlighted, default(Autotiler.Behaviour)).TileGrid; highlight.Alpha = 0f; baseData["highlight"] = highlight; Add(baseData.Get <TileGrid>("highlight")); Calc.PopRandom(); Add(new TileInterceptor(baseData.Get <TileGrid>("sprite"), false)); highlightCollider = GenerateBetterColliderGrid(tileMapHighlighted, 8, 8); collider = GenerateBetterColliderGrid(tileMap, 8, 8); AddLightOcclude(this, collider); Collider = collider; }
public static ColliderList GenerateBetterColliderGrid(VirtualMap <char> tileMap, int cellWidth, int cellHeight) { ColliderList colliders = new ColliderList(); List <Hitbox> prevCollidersOnX = new List <Hitbox>(); Hitbox prevCollider = null; void ExtendOrAdd() { bool extendedOnX = false; foreach (Hitbox hitbox in prevCollidersOnX) { if (hitbox.Position.X + hitbox.Width == prevCollider.Position.X && hitbox.Position.Y == prevCollider.Position.Y && hitbox.Height == prevCollider.Height) { // Weird check, but hey. extendedOnX = true; hitbox.Width += cellWidth; prevCollider = null; break; } } if (!extendedOnX) { colliders.Add(prevCollider); prevCollidersOnX.Add(prevCollider); prevCollider = null; } } for (int x = 0; x < tileMap.Columns; x++) { for (int y = 0; y < tileMap.Rows; y++) { if (tileMap.AnyInSegmentAtTile(x, y) && tileMap[x, y] != '0') { if (prevCollider == null) { prevCollider = new Hitbox(cellWidth, cellHeight, x * cellWidth, y * cellHeight); } else { prevCollider.Height += cellHeight; } } else if (prevCollider != null) { ExtendOrAdd(); } } if (prevCollider != null) { ExtendOrAdd(); } } return(colliders.colliders.Length > 0 ? colliders : null); }
public void Reset() { ForEach((cell) => cell.Colliders.Clear()); ComputedCollision.Clear(); ColliderList.Clear(); }
public override void Awake(Scene scene) { List <SolidExtension> extensions = new List <SolidExtension>(); FindExtensions(extensions); GroupOffset = new Vector2(GroupBoundsMin.X, GroupBoundsMin.Y) - Position; Colliders = new Hitbox[extensions.Count(ext => ext.HasHitbox) + 1]; AllColliders = new Hitbox[extensions.Count + 1]; int j = 0; for (int i = 0; i < extensions.Count; i++) { SolidExtension e = extensions[i]; Vector2 offset = e.Position - Position; Hitbox hitbox = new Hitbox(e.Width, e.Height, offset.X, offset.Y); if (e.HasHitbox) { Colliders[j] = hitbox; j++; } AllColliders[i] = hitbox; e.RemoveSelf(); // You don't want disabled Solids hanging around in the level, so you remove them. } int tWidth = (int)((GroupBoundsMax.X - GroupBoundsMin.X) / 8); int tHeight = (int)((GroupBoundsMax.Y - GroupBoundsMin.Y) / 8); GroupTiles = new bool[tWidth + 2, tHeight + 2]; AllGroupTiles = new bool[tWidth + 2, tHeight + 2]; Colliders[Colliders.Length - 1] = (Hitbox)Collider; AllColliders[AllColliders.Length - 1] = (Hitbox)Collider; Collider = new ColliderList(AllColliders); for (int x = 0; x < tWidth + 2; x++) { for (int y = 0; y < tHeight + 2; y++) { AllGroupTiles[x, y] = TileCollideWithGroup(x - 1, y - 1); } } Collider = new ColliderList(Colliders); for (int x = 0; x < tWidth + 2; x++) { for (int y = 0; y < tHeight + 2; y++) { GroupTiles[x, y] = TileCollideWithGroup(x - 1, y - 1); } } scene.Add(BGRenderer = new BGTilesRenderer(this)); base.Awake(scene); }
public FancyCrumbleWallOnRumble(EntityData data, Vector2 offset, EntityID id) : base(data.Position + offset, data.Char("tiletype", 'm'), data.Width, data.Height, data.Bool("blendin", false), data.Bool("persistent", false), id) { tileMap = GenerateTileMap(data.Attr("tileData", "")); ColliderList colliders = GenerateBetterColliderGrid(tileMap, 8, 8); AddLightOcclude(this, colliders); Collider = colliders; }
public FancyFloatySpaceBlock(EntityData data, Vector2 offset) : base(data.Position + offset, data.Width, data.Height, data.Char("connectsTo", '3'), data.Bool("disableSpawnOffset", false)) { badLightOcclude = Get <LightOcclude>(); tileMap = GenerateTileMap(data.Attr("tileData", "")); ColliderList colliders = GenerateBetterColliderGrid(tileMap, 8, 8); Collider = colliders; AddLightOcclude(this, colliders); }
public void PickUpFellow() { FellowRobot.transform.parent = transform; FellowRobot.transform.localPosition = new Vector3(0, 1.25f, 0); FellowRobot.transform.localRotation = Quaternion.identity; FellowRobot.PickedUp = true; PickedUpObject = FellowRobot; ColliderList.Remove(FellowRobot.gameObject); }
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 void PickUpHeavyTrash() { Debug.Log(name + ": PickUpHeavyTrash"); formation = new FormationBehaviour(CurrentTrash, this); CurrentTrash.PickedUp = true; PickedUpObject = CurrentTrash; ColliderList.Remove(CurrentTrash.gameObject); }
public OutroCar(EntityData data, Vector2 offset) : base(data, offset) { origData = new DynData <IntroCar>(this); Image bodySprite = origData.Get <Image>("bodySprite"); bodySprite.FlipX = true; Hitbox hitbox = new Hitbox(25f, 4f, -7f, -17f); Hitbox hitbox2 = new Hitbox(19f, 4f, -24f, -11f); Collider = new ColliderList(hitbox, hitbox2); }
// pickable-up objects stuff public void PickUpLightTrash() { Debug.Log(name + ": PickUpLightTrash"); CurrentTrash.transform.parent = transform; CurrentTrash.transform.localPosition = new Vector3(0, 1.25f, 0); CurrentTrash.transform.localRotation = Quaternion.identity; CurrentTrash.PickedUp = true; PickedUpObject = CurrentTrash; ColliderList.Remove(CurrentTrash.gameObject); }
public void Add(Collider collider) { if (ColliderList.Contains(collider)) { return; } foreach (Cell cell in GetCells(collider.WorldTransform)) { cell.Colliders.Add(collider); } ComputedCollision[collider] = new HashSet <Collider>(); ColliderList.Add(collider); }
public static ColliderList GenerateInefficientColliderGrid(VirtualMap <char> tileMap, int cellWidth, int cellHeight) { ColliderList colliders = new ColliderList(); for (int x = 0; x < tileMap.Columns; x++) { for (int y = 0; y < tileMap.Rows; y++) { if (tileMap.AnyInSegmentAtTile(x, y) && tileMap[x, y] != '0') { colliders.Add(new Hitbox(cellWidth, cellHeight, x * cellWidth, y * cellHeight)); } } } return(colliders.colliders.Length > 0 ? colliders : null); }
public KillerDebris(Vector2 position, bool attachToSolid, string color) : base(position) { Enum.TryParse(color, out _color); Tag = Tags.TransitionUpdate; Collider = new ColliderList(new Circle(6f), new Hitbox(16f, 4f, -8f, -3f)); Visible = false; Add(new PlayerCollider(OnPlayer)); Add(new HoldableCollider(OnHoldable)); Add(new LedgeBlocker()); Depth = -8500; AttachToSolid = attachToSolid; if (attachToSolid) { Add(new StaticMover { OnShake = OnShake, SolidChecker = IsRiding, OnDestroy = RemoveSelf }); } _randomSeed = Calc.Random.Next(); }
public CustomSandwichLava(EntityData data, Vector2 offset) { startX = data.Position.X + offset.X; Direction = data.Enum("direction", DirectionMode.CoreModeBased); Speed = data.Float("speed", 20f); // vanilla is 160. so, setting sandwichGap to 120 requires each side to be shifted by 20 pixels towards the other ((160 - 120) / 2). sandwichDisplacement = (160f - data.Float("sandwichGap", 160f)) / 2; Depth = -1000000; Collider = new ColliderList(new Hitbox(340f, 120f, 0f, -sandwichDisplacement), new Hitbox(340f, 120f, 0f, -280f + sandwichDisplacement)); Visible = false; Add(loopSfx = new SoundSource()); Add(new PlayerCollider(OnPlayer)); Add(new CoreModeListener(OnChangeMode)); Add(bottomRect = new LavaRect(400f, 200f, 4)); bottomRect.Position = new Vector2(-40f, 0f); bottomRect.OnlyMode = LavaRect.OnlyModes.OnlyTop; bottomRect.SmallWaveAmplitude = 2f; Add(topRect = new LavaRect(400f, 200f, 4)); topRect.Position = new Vector2(-40f, -360f); topRect.OnlyMode = LavaRect.OnlyModes.OnlyBottom; topRect.SmallWaveAmplitude = 2f; topRect.BigWaveAmplitude = (bottomRect.BigWaveAmplitude = 2f); topRect.CurveAmplitude = (bottomRect.CurveAmplitude = 4f); Add(new TransitionListener { OnOutBegin = () => { // save the Y positions transitionStartY = Y; transitionStartTopRectY = topRect.Position.Y; transitionStartBottomRectY = bottomRect.Position.Y; if (persistent && Scene != null && Scene.Entities.FindAll <CustomSandwichLava>().Count <= 1) { // no lava in the next room: leave Leave(); } else { // look up for all lava blocker triggers in the next room. lavaBlockerTriggers = Scene.Entities.OfType <LavaBlockerTrigger>().ToList(); } }, OnOut = progress => { if (Scene != null) { X = (Scene as Level).Camera.X; if (!leaving) { // make the lava elements transition smoothly to their expected positions. Y = MathHelper.Lerp(transitionStartY, centerY, progress); topRect.Position.Y = MathHelper.Lerp(transitionStartTopRectY, TopOffset - topRect.Height + sandwichDisplacement, progress); bottomRect.Position.Y = MathHelper.Lerp(transitionStartBottomRectY, -sandwichDisplacement, progress); } } if ((progress > 0.95f) && leaving) { // lava is leaving, transition is over soon => remove it RemoveSelf(); } }, OnInEnd = () => { if (entering) { // transition is over. grab the camera position now since it's done moving. Y = centerY; entering = false; } } }); }
/** * @brief 衝突(すり抜けあり)を検出する * @param other 衝突したオブジェクト */ void OnTriggerStay(Collider other) { // 衝突リストがnullでないとき if (colliders != null) { // 4方向の壁に衝突したとき if (other.gameObject.CompareTag("Wall_Left") || other.gameObject.CompareTag("Wall_Foreground") || other.gameObject.CompareTag("Wall_Right") || other.gameObject.CompareTag("Wall_Back")) { ColliderList list = new ColliderList(); list.colliderObj = other; list.direct = inputDirect; list.priority = 1; // 優先度中に設定 list.rotated = false; // 4方向の壁は回転後でもステージ内に移動したいのでfalseとする foreach (ColliderList colliderList in colliders) { if (colliderList.colliderObj) { // 同じ方向の壁と衝突済みの時 if (list.colliderObj.gameObject.CompareTag(colliderList.colliderObj.gameObject.tag)) { return;// 衝突リストに追加しない } // 同じ方向の入力でブロックに衝突済みの時 else if (colliderList.colliderObj.gameObject.CompareTag("Block") && colliderList.direct == list.direct) { return;// 衝突リストに追加しない } } } colliders.Add(list); // 新しい衝突として検出する isCollide = true; // 衝突した状態にする } // ステージの床に衝突したとき else if (other.gameObject.CompareTag("Stage")) { ColliderList list = new ColliderList(); list.colliderObj = other; list.direct = InputDirection.no; // 床と衝突するので入力なしを格納 list.priority = 0; // 優先度低に設定 list.rotated = false; // 床は回転後でもステージ内に移動したいのでfalseとする foreach (ColliderList colliderList in colliders) { if (colliderList.colliderObj != null) { // ステージの床と衝突済みの時 if (colliderList.colliderObj.gameObject.CompareTag("Stage")) { return;// 衝突リストに追加しない } // 入力なしでブロックと衝突済みの時 else if (colliderList.colliderObj.gameObject.CompareTag("Block") && colliderList.direct == InputDirection.no) { return;// 衝突リストに追加しない } } } colliders.Add(list); // 新しい衝突として検出する isCollide = true; // 衝突した状態にする } // ブロックと衝突したとき else if (other.gameObject.CompareTag("Block")) { ColliderList list = new ColliderList(); list.colliderObj = other; list.direct = inputDirect; list.rotated = false; // 回転をして衝突したとき if (!beforeQuaternion.Equals(blockQuaternion)) { canRotate = false; // 回転不可能にする list.rotated = true; // 衝突リストに回転して衝突 list.priority = 2; // 優先度高に設定 } // 入力なしでブロックと衝突したとき else if (list.direct == InputDirection.no) { list.priority = 0;// 優先度低に設定 } // 入力ありでブロックと衝突したとき else { list.priority = 1;// 優先度中に設定 } // 同じものと衝突していないかのチェック foreach (ColliderList colliderList in colliders) { if (colliderList.colliderObj != null) { // ステージの床と衝突済みのとき if (colliderList.colliderObj.gameObject.CompareTag("Stage") && colliderList.direct == list.direct) { return;// 衝突リストに追加しない } // 左側の壁と衝突済みのとき else if (colliderList.colliderObj.gameObject.CompareTag("Wall_Left") && colliderList.direct == list.direct) { return;// 衝突リストに追加しない } // 手前側の壁と衝突済みのとき else if (colliderList.colliderObj.gameObject.CompareTag("Wall_Foreground") && colliderList.direct == list.direct) { return;// 衝突リストに追加しない } // 右側の壁と衝突済みのとき else if (colliderList.colliderObj.gameObject.CompareTag("Wall_Right") && colliderList.direct == list.direct) { return;// 衝突リストに追加しない } // 奥側の壁と衝突済みのとき else if (colliderList.colliderObj.gameObject.CompareTag("Wall_Back") && colliderList.direct == list.direct) { return;// 衝突リストに追加しない } // ブロックと衝突済みのとき else { // 回転して衝突したとき if (list.rotated) { // 別のブロックと回転して衝突済みのとき if (colliderList.rotated == list.rotated) { return;// 衝突リストに追加しない } // 別のブロックと回転なし(落下して)衝突済みのとき else if (colliderList.direct == InputDirection.no) { return;// 衝突リストに追加しない } } // 回転なしで同じ入力方向でブロックと衝突済みのとき else if (colliderList.direct == list.direct) { // 入力なしで衝突したとき if (list.direct == InputDirection.no) { // 回転して衝突済みのとき if (colliderList.rotated) { return;// 衝突リストに追加しない } } // 入力ありで衝突したとき else { return;// 衝突リストに追加しない } } else if (colliderList.colliderObj.gameObject.transform.parent != null) { // 同じブロックと落下して衝突済みのとき if (!list.rotated && list.colliderObj.gameObject.transform.parent.name.Equals(colliderList.colliderObj.gameObject.transform.parent.name)) { return;// 衝突リストに追加しない } } } } } colliders.Add(list); // 新しい衝突として検出する isCollide = true; // 衝突した状態にする canSet = false; // 設置未完了 } } }
public CustomSpinner(EntityData data, Vector2 position, bool attachToSolid, string directory, string destroyColor, bool isCore, string tint) : base(data.Position + position) { ID = data.ID; DashThrough = data.Bool("dashThrough", false); this.tint = tint; Tint = ColorHelper.GetColor(tint); this.directory = directory; // for VivHelper compatibility SpritePathSuffix = data.Attr("spritePathSuffix", ""); UpdateDirectoryFields(false); moveWithWind = data.Bool("moveWithWind", false); // funny story time: this used to exist in older versions of Frost Helper as a leftover. // I tried removing it in 1.20.3, but this broke some TASes due to spinner cycles. // So now this needs to stay here forever D: // List<MTexture> atlasSubtextures = GFX.Game.GetAtlasSubtextures(this.bgDirectory); // MTexture mtexture = Calc.Random.Choose(atlasSubtextures); // Actually, just calling Random.Next() is enough, so that's nice Calc.Random.Next(); coldDirectory = directory; this.destroyColor = destroyColor; this.isCore = isCore; offset = Calc.Random.NextFloat(); Tag = Tags.TransitionUpdate; Collider = new ColliderList(new Collider[] { new Circle(6f, 0f, 0f), new Hitbox(16f, 4f, -8f, -3f) }); Visible = false; Add(new PlayerCollider(new Action <Player>(OnPlayer), null, null)); Add(new HoldableCollider(new Action <Holdable>(OnHoldable), null)); Add(new LedgeBlocker(null)); Depth = -8500; AttachToSolid = attachToSolid; if (AttachToSolid) { Add(new StaticMover { OnShake = new Action <Vector2>(OnShake), SolidChecker = new Func <Solid, bool>(IsRiding), OnDestroy = new Action(RemoveSelf) }); } randomSeed = Calc.Random.Next(); if (isCore) { Add(new CoreModeListener(new Action <Session.CoreModes>(OnChangeMode))); } float bloomAlpha = data.Float("bloomAlpha", 0.0f); if (bloomAlpha != 0.0f) { Add(new BloomPoint(Collider.Center, bloomAlpha, data.Float("bloomRadius", 0f))); } }
public ComponentCollision() : base("collision") { _boundingBox = new RectangleF(0.0f, 0.0f, 0.0f, 0.0f); ColliderList.Add(this); }
public SidewaysLava(EntityData data, Vector2 offset) { intro = data.Bool("intro", false); lavaMode = data.Enum("lavaMode", LavaMode.LeftToRight); speedMultiplier = data.Float("speedMultiplier", 1f); Depth = -1000000; if (lavaMode == LavaMode.LeftToRight) { // one hitbox on the left. Collider = new Hitbox(340f, 200f, -340f); } else if (lavaMode == LavaMode.RightToLeft) { // one hitbox on the right. Collider = new Hitbox(340f, 200f, 320f); } else { // hitboxes on both sides, 280px apart. Collider = new ColliderList(new Hitbox(340f, 200f, -340f), new Hitbox(340f, 200f, 280f)); } Visible = false; Add(new PlayerCollider(OnPlayer)); Add(new CoreModeListener(OnChangeMode)); Add(loopSfx = new SoundSource()); if (lavaMode != LavaMode.RightToLeft) { // add the left lava rect, just off-screen (it is 340px wide) Add(leftRect = new SidewaysLavaRect(340f, 200f, 4, SidewaysLavaRect.OnlyModes.OnlyLeft)); leftRect.Position = new Vector2(-340f, 0f); leftRect.SmallWaveAmplitude = 2f; } if (lavaMode != LavaMode.LeftToRight) { // add the right lava rect, just off-screen (the screen is 320px wide) Add(rightRect = new SidewaysLavaRect(340f, 200f, 4, SidewaysLavaRect.OnlyModes.OnlyRight)); rightRect.Position = new Vector2(lavaMode == LavaMode.Sandwich ? 280f : 320f, 0f); rightRect.SmallWaveAmplitude = 2f; } if (lavaMode == LavaMode.Sandwich) { // listen to transitions since we need the sandwich lava to deal smoothly with them. Add(new TransitionListener { OnOutBegin = () => { sandwichTransitionStartX = X; if (!sandwichTransferred) { // the next screen has no sideways sandwich lava. so, just leave. AddTag(Tags.TransitionUpdate); sandwichLeaving = true; Collidable = false; Alarm.Set(this, 2f, () => RemoveSelf()); } else { sandwichTransferred = false; // look up for all lava blocker triggers in the next room. lavaBlockerTriggers = Scene.Entities.OfType <LavaBlockerTrigger>().ToList(); } }, OnOut = progress => { if (Scene != null) { Level level = Scene as Level; // make sure the sandwich lava is following the transition. Y = level.Camera.Y - 10f; if (!sandwichLeaving) { // make the lava smoothly go back to 20px on each side. X = MathHelper.Lerp(sandwichTransitionStartX, level.Camera.Left + 20f, progress); } } if (progress > 0.95f && sandwichLeaving) { // destroy the lava, since transition is almost done. RemoveSelf(); } } }); } }