public TreeNode RecursiveFind(int val, TreeNode node, ParentLevel pl) { pl.level++; if (node == null) { pl.level--; return(null); } if (node.val == val) { return(node); } TreeNode findL = RecursiveFind(val, node.left, pl); if (findL != null) { pl.parentValues.Add(node.val); return(findL); } TreeNode findR = RecursiveFind(val, node.right, pl); if (findR != null) { pl.parentValues.Add(node.val); return(findR); } pl.level--; return(null); }
public override GameObject Add(GameObject o) { if (!o.Created) { o.TagsReady = ParentLevel.LevelForEditing; Level.ObjectCreate(o, this, ParentLevel); #if EDITOR && WINDOWS if (ParentLevel.LevelForEditing) { o.IdNumber = ParentLevel.FindUniqueID(); } #endif o.SetParents(ParentLevel, this); o.Create(); if (!o.TagsReady) { ObjectsToReadyTags.AddFirst(o); } } AddHierarchyObject(o); Children.AddFirst(o); ReferenceGameObject = null; if (CanLoad) { o.Load(); } return(o); }
public override void PlayerJoinedEvent(PlayerProfile profile) { List <MineralRock> AllRocks = new List <MineralRock>(); foreach (MineralRock r in Enumerate(typeof(MineralRock))) { if (r.IsStartingZone.get() == 1 && r.miningPlatform == null) { AllRocks.Add(r); } } if (AllRocks.Count == 0) { return; } PlayerShip p = (PlayerShip)ParentLevel.AddObject(new PlayerShip(-1, profile)); ChooseStartState.AddPlayer(); MineralRock SelectedRock = AllRocks[Rand.r.Next(AllRocks.Count)]; p.Position.set(SelectedRock.Position.get()); SelectedRock.Interact(p); }
public override void UpdateEditor(GameTime gameTime) { if (WorldViewer.self.ContainsMouse && !WorldViewer.self.MouseOverForm) { RayCast(gameTime); } if (MyCamera.get() == null) { MyCamera.set(FindObject(typeof(Camera3DObject))); if (MyCamera.get() != null) { if (EditorSelected) { UpdateSelected(); } } else { Camera3DObject camera = new Camera3DObject(); ParentLevel.AddObject(camera, this); MyCamera.set(camera); camera.Name.set("EditorCamera"); } } if (ParentLevel.LevelForEditing) { base.UpdateEditor(gameTime); } }
public override bool RayCast(GameTime gameTime) { foreach (GameObject o in Children) { if (o.RayCast(gameTime)) { return(true); } } if (!KeyboardManager.AltPressed()) { return(objectControls.RayCast(gameTime)); } else { if (MouseManager.MouseClicked && CreatorBasic.LastCreator != null) { GameObject o = CreatorBasic.LastCreator.ReturnObject(); ParentLevel.AddObject(o); if (o.GetType().IsSubclassOf(typeof(Basic2DObject))) { Basic2DObject b = (Basic2DObject)o; b.Position.set(Vector2.Transform(WorldViewer.self.RelativeMousePosition, Matrix.Invert(DrawCamera.ViewMatrix))); ClearSelected(); AddSelected(b); if (UseGrid.get()) { SnapSelected(); } } } return(true); } }
public void MakeFadeManager() { if (FadeManager == null) { ParentLevel.AddObject(FadeManager = new FadeManager()); } FadeManager.self = FadeManager; }
public override void CreateInGame() { PlasmaTurret p = new PlasmaTurret(FactionNumber.get()); ParentLevel.AddObject(p); p.SetPosition(Position.get()); base.CreateInGame(); }
public override void CreateInGame() { for (int i = 0; i < FlareCount.get(); i++) { ParentLevel.AddObject(new WorldFlare(Distance.get(), SpawnPosition.get(), Color.getAsColor(), Speed.get())); } base.CreateInGame(); }
public override void LeftClick(GameTime gameTime) { if (gameTime.TotalGameTime.TotalMilliseconds < DoubleClickTime + 300) { ParentLevel.SetScene(this); } base.LeftClick(gameTime); }
public override void Update(GameTime gameTime) { frame.WorldMatrix = WorldMatrix; if (UnitCount > 0 && !Dead && WaveFSM.WaveStepState.WeaponsFree) { UnitDelay += gameTime.ElapsedGameTime.Milliseconds; if (UnitDelay > MaxUnitDelay) { UnitCount--; UnitDelay -= MaxUnitDelay; UnitShip s = (UnitShip)SpawnCard.GetUnit(FactionNumber); ParentLevel.AddObject(s); s.SetLevel((IsUpdgraded ? 3 : 2) * WaveManager.DifficultyMult, 1); if (GetTeam() == WaveManager.ActiveTeam) { float Theta = 0; float Offset = 0; Vector3 Position3 = new Vector3(Position.X(), Y, Position.Y()); while (!TestFree(Position.get(), Theta, Offset, Size.X())) { Theta += (float)Math.PI / 10f; if (Theta > Math.PI * 2) { Theta -= (float)Math.PI * 2; Offset += Size.X() / 2; } } Vector2 BestPosition = Position.get() + Logic.ToVector2(Theta) * Offset; s.Position.set(BestPosition); Position3 = new Vector3(BestPosition.X, 0, BestPosition.Y); for (int j = 0; j < 30; j++) { ParticleManager.CreateParticle(Position3, Rand.V3() * 200, new Color(1, 0.75f, 0.5f), 20, 5); } Position3 = new Vector3(Position.X(), 0, Position.Y()); ParticleManager.CreateParticle(Position3, Vector3.Zero, new Color(1, 0.75f, 0.5f), Size.X() * 5, 4); for (int i = 0; i < 30; i++) { ParticleManager.CreateParticle(Position3, Rand.V3() * 200, new Color(1, 0.75f, 0.5f), 20, 5); } } else { s.Position.set(NeutralManager.GetSpawnPosition()); } } } base.Update(gameTime); }
public override bool TriggerEvent(EventType Event, string[] args) { switch (Event) { case EventType.AddObject: GameObject o = ParentLevel.FindObject(args[0]); if (o != null && o.GetType().IsSubclassOf(typeof(Basic3DObject))) { Basic3DObject b = (Basic3DObject)o; if (ObjectCount == 0) { AddTag(GameObjectTag.Update); } if (arySize == ObjectCount) { if (arySize == 0) { PathObjects = new GameObject[4]; PathSpeed = new float[4]; PathPosition = new float[4]; } else { arySize *= 2; GameObject[] NewPathObjects = new GameObject[arySize]; float[] NewPathSpeed = new float[arySize]; float[] NewPathPosition = new float[arySize]; for (int i = 0; i < ObjectCount; i++) { NewPathObjects[i] = PathObjects[i]; NewPathSpeed[i] = PathSpeed[i]; NewPathPosition[i] = PathPosition[i]; } PathObjects = NewPathObjects; PathPosition = NewPathPosition; NewPathSpeed = PathSpeed; } } PathObjects[ObjectCount] = b; PathPosition[ObjectCount] = Logic.ParseF(args[1]); float f = Logic.ParseF(args[2]); PathSpeed[ObjectCount] = f != 0 ? f : TravelSpeed.get(); ObjectCount++; } return(true); } return(base.TriggerEvent(Event, args)); }
public override void Destroy() { #if EDITOR && WINDOWS DisposeRenderTarget(); #endif GameObject[] sc = Children.ToArray(); foreach (GameObject g in sc) { g.Destroy(); } ParentLevel.RemoveScene(this); }
public override void Destroy() { if (HasSpeedField && BasicField.TestFieldClear(Position.get())) { HasSpeedField = false; SpeedBoostField s = new SpeedBoostField(); ParentLevel.AddObject(s); s.Position.set(Position.get()); } base.Destroy(); }
public override void Destroy() { if (HasCloakField && BasicField.TestFieldClear(Position.get())) { HasCloakField = false; CloakingField c = new CloakingField(); ParentLevel.AddObject(c); c.SetPosition(Position.get()); } base.Destroy(); }
public override void Damage(float damage, float pushTime, Vector2 pushSpeed, BasicShipGameObject Damager, AttackType attackType) { if (attackType != AttackType.White && HasDamageField && BasicField.TestFieldClear(Position.get())) { HasDamageField = false; DamageBoostField c = new DamageBoostField(); ParentLevel.AddObject(c); c.SetPosition(Position.get()); } base.Damage(damage, pushTime, pushSpeed, Damager, attackType); }
private void SpawnUnit(UnitShip s) { ParentLevel.AddObject(s); s.SetLevel(1, 1); PlaceRotationMult += PlaceRotationMultChange; if (PlaceRotationMult > 1) { PlaceRotationMult -= 1; } s.Position.set(Position.get() + Logic.ToVector2(PlaceRotationMult * PlaceRotation) * (Size.X() + s.Size.X()) / 1.95f); }
private void SummonUnits() { if (!CanSummon) { return; } Vector3 Position3 = new Vector3(Position.X(), 0, Position.Y()); CanSummon = false; HasSummoned = true; float Theta = 0; float Offset = Size.X() * 2; for (int i = 0; i < SummonCard.GhostCount; i++) { UnitShip u = (UnitShip)SummonCard.GetUnit(FactionNumber); ParentLevel.AddObject(u); while (!TestFree(Position.get(), Theta, Offset, Size.X())) { Theta += (float)Math.PI / 10f; if (Theta > Math.PI * 2) { Theta -= (float)Math.PI * 2; Offset += Size.X(); } } Vector2 BestPosition = Logic.ToVector2(Theta) * Offset + Position.get(); u.SetForGhost(); u.SetLevel(UnitLevel, 1); u.Position.set(BestPosition); Position3 = new Vector3(BestPosition.X, 0, BestPosition.Y); for (int j = 0; j < 30; j++) { ParticleManager.CreateParticle(Position3, Rand.V3() * 200, new Color(1, 0.75f, 0.5f), 20, 5); } } Position3 = new Vector3(Position.X(), 0, Position.Y()); ParticleManager.CreateParticle(Position3, Vector3.Zero, new Color(1, 0.75f, 0.5f), Size.X() * 5, 4); for (int i = 0; i < 30; i++) { ParticleManager.CreateParticle(Position3, Rand.V3() * 200, new Color(1, 0.75f, 0.5f), 20, 5); } }
public override bool RayCast(GameTime gameTime) { if (MouseManager.MouseClicked && !EditorSelected) { if (Logic.Rect(Position.get(), Size.get(), Parent2DScene.DrawCamera.ViewMatrix).Contains(WorldViewer.self.RelativeMousePoint)) { if (!KeyboardManager.ControlPressed()) { if (!KeyboardManager.ShiftPressed()) { ParentScene.ClearSelected(); } ParentScene.AddSelected(this); } else { if (EditorSelected) { ParentScene.RemoveSelected(this); } else { ParentScene.AddSelected(this); } } ParentLevel.ModifyWindows(); return(true); } } else if (MouseManager.RMouseClicked) { if (Logic.Rect(Position.get(), Size.get(), Parent2DScene.DrawCamera.ViewMatrix).Contains(WorldViewer.self.RelativeMousePoint)) { if (!KeyboardManager.AltPressed()) { ParentScene.ClearSelected(); ParentScene.AddSelected(this); RightClick(gameTime); ParentLevel.ModifyWindows(); } else { Destroy(); } return(true); } } return(false); }
public override void Damage(float damage, float pushTime, Vector2 pushSpeed, BasicShipGameObject Damager, AttackType attackType) { if (attackType != AttackType.White && HasSpeedField && BasicField.TestFieldClear(Position.get())) { HasSpeedField = false; SpeedBoostField s = new SpeedBoostField(); ParentLevel.AddObject(s); s.Position.set(Position.get()); } if (attackType != Weakness && attackType != AttackType.Explosion && attackType != AttackType.Melee) { attackType = Resistence; } base.Damage(damage, pushTime, pushSpeed, Damager, attackType); }
public override GroundableEntity CreateEntity() { GroundableEntity result; GeometryEntity groundingEntity; float mass; lock (instanceMutationLock) { result = CreateEntityObject(out mass); if (EntryPoint.InEditor) { mass = 0f; } groundingEntity = GroundingGeometryEntity != null? ParentLevel.GetEntityRepresentation(GroundingGeometryEntity) : null; } if (!EditorOnly || EntryPoint.InEditor) { if (PhysicsShape != PhysicsShapeHandle.NULL) { result.SetPhysicsShape( PhysicsShape, Vector3.ZERO, mass, disablePerformanceDeactivation: true, restitution: GameplayConstants.EGG_RESTITUTION, linearDamping: GameplayConstants.EGG_DAMPING_LINEAR, angularDamping: GameplayConstants.EGG_DAMPING_ANGULAR, friction: GameplayConstants.EGG_FRICTION, rollingFriction: GameplayConstants.EGG_FRICTION_ROLLING ); result.EnableContinuousCollisionDetection(GameplayConstants.MIN_SPEED_FOR_EGG_CCD, GameplayConstants.EGG_COLLISION_RADIUS * 0.01f); } result.SetModelInstance(AssetLocator.GameLayer, Model, Material); } if (groundingEntity != null) { result.Ground(groundingEntity); } return(result); }
public void Advance(int steps = 1, bool advanceParent = true, bool advanceChild = true) { for (int i = 0; i < steps; i++) { // save next and current layouts var nextLayout = GetNextLayout(); string tiles = GetTileString(); string nextTiles = GetTileStringFor(nextLayout); // handle recursive levels if (advanceParent) { // add parent level if layout will change if (nextTiles != tiles && ParentLevel == null) { ParentLevel = new RecursiveEris(childLevel: this); } // advance parent level, if any if (ParentLevel != null) { ParentLevel.Advance(advanceChild: false); } } if (advanceChild) { // add child level if layout will change if (nextTiles != tiles && ChildLevel == null) { ChildLevel = new RecursiveEris(parentLevel: this); } // advance child level, if any if (ChildLevel != null) { ChildLevel.Advance(advanceParent: false); } } // update tiles Cells = nextLayout; } }
public override void Update(GameTime gameTime) { /* * SparkTimer += gameTime.ElapsedGameTime.Milliseconds; * if (SparkTimer > MaxSparkTimer.get()) * { * SparkTimer -= MaxSparkTimer.get(); * ParentLevel.AddObject(new PathfindingFlare(PathFindingManager.self, Rand.r.Next(PathFindingManager.self.CellsX.get()), * Rand.r.Next(PathFindingManager.self.CellsX.get()), 0, 0, Color.getAsColor())); * }*/ if (!WaveFSM.WaveStepState.WeaponsFree) { Basic2DScene Parent2DScene = (Basic2DScene)ParentScene; Vector2 p = NeutralManager.GetSpawnPosition(); ParentLevel.AddObject(new PathfindingFlare(PathFindingManager.self, (int)((p.X - Parent2DScene.MinBoundary.X()) / PathFindingManager.self.Divisor.X), (int)((p.Y - Parent2DScene.MinBoundary.Y()) / PathFindingManager.self.Divisor.Y), 0, 0, Color.getAsColor())); } base.Update(gameTime); }
public override void PlayerJoinedEvent(PlayerProfile p) { SpyPlayer player = new SpyPlayer(p); ParentLevel.AddObject(player, this); foreach (GameObject o in Children) { if (o.GetType().Equals(typeof(SpyPlayerSpawn))) { SpyPlayerSpawn spawn = (SpyPlayerSpawn)o; if (spawn.PlayerNumber.get() == p.PlayerNumber) { player.Position.set(spawn.Position.get()); } return; } } base.PlayerJoinedEvent(p); }
public bool IsCousins(TreeNode root, int x, int y) { ParentLevel pl = new ParentLevel() { level = 0 }; TreeNode rx = RecursiveFind(x, root, pl); ParentLevel pl2 = new ParentLevel() { level = 0 }; TreeNode ry = RecursiveFind(y, root, pl2); int?parent1 = pl.parentValues.Any() ? (int?)pl.parentValues[0] : null; int?parent2 = pl2.parentValues.Any() ? (int?)pl2.parentValues[0] : null; Console.WriteLine(pl.level + " " + parent1); Console.WriteLine(pl2.level + " " + parent2); return(pl.level == pl2.level && parent1 != parent2); }
public override void Interact(PlayerShip p) { if (miningPlatform == null && FactionManager.CanBuildMiningPlatform(p.FactionNumber)) { Vector3 P3 = new Vector3(Position.X(), 0, Position.Y()); for (int i = 0; i < 40; i++) { LineParticleSystem.AddParticle(P3, P3 + Rand.V3() * 1000, TeamInfo.GetColor(p.GetTeam())); } MiningPlatform m = FactionManager.GetMiningPlatform(p.FactionNumber); ParentLevel.AddObject(m); m.Position.set(Position.get()); setPlatform(m); SoundManager.Play3DSound("PlayerBuildMiningRing", new Vector3(m.Position.X(), Y, m.Position.Y()), 0.25f, 500, 1); if (p.PlacedStartingMineralRock) { FactionManager.AddCells(p.FactionNumber, -FactionManager.GetMiningPlatformCost(p.FactionNumber)); FactionManager.SetBuildingPlatform(p.FactionNumber, m); } else { FactionManager.GetFaction(p.FactionNumber).MiningPlatformCounter = 0; m.HullToughness *= 2; m.SetAsStarting(); p.PlacedStartingMineralRock = true; p.StartingMineralRock = this; } p.LastPlacedPlatform.AddFirst(m); PathFindingManager.AddMineralRock(m); } base.Interact(p); }
public override bool TriggerEvent(EventType Event, string[] args) { switch (Event) { case EventType.GotoLevel: MakeFadeManager(); FadeManager.SetFadingTarget(args[0]); return(true); case EventType.GotoScene: MakeFadeManager(); FadeManager.SetFadingTarget(ParentLevel.FindScene(args[0])); return(true); case EventType.SwapViews: LinkedList <GameObject> tempSidelined = new LinkedList <GameObject>(SidelinedViewers); SidelinedViewers.Clear(); LinkedList <GameObject> temp = new LinkedList <GameObject>(WorldViewerChildren); foreach (GameObject o in temp) { o.RemoveTag(GameObjectTag.WorldViewer); SidelinedViewers.AddLast(o); } foreach (GameObject o in tempSidelined) { o.AddTag(GameObjectTag.WorldViewer); } return(true); } return(base.TriggerEvent(Event, args)); }
public override void Update(GameTime gameTime) { if (Fading) { FadingAlpha += gameTime.ElapsedGameTime.Milliseconds * 1 / 1000f; if (FadingAlpha > 1) { FadingAlpha = 1; Fading = false; if (TargetScene != null) { ParentLevel.SetScene(TargetScene); TargetScene = null; } else { GameManager.LoadTitleLevel(TargetLevel); } } SetFadeColor(new Vector4(0, 0, 0, FadingAlpha)); } else if (FadingAlpha > 0) { FadingAlpha -= gameTime.ElapsedGameTime.Milliseconds * 1 / 1000f; if (FadingAlpha < 0) { FadingAlpha = 0; } SetFadeColor(new Vector4(0, 0, 0, FadingAlpha)); } base.Update(gameTime); }
public IList <TNode> MyList(TNode node) { var parent = GetParent(node); return(ParentLevel.GetChilds(parent)); }
public override void BlowUp() { if (Dead || Lives < 1) { return; } Vector3 P3 = new Vector3(Position.X(), 0, Position.Y()); for (int i = 0; i < 10; i++) { LineParticleSystem.AddParticle(P3, P3 + Rand.V3() * MaxEngagementDistance, TeamInfo.GetColor(GetTeam())); } foreach (Faction f in FactionManager.Factions) { if (MyCard == null) { MyCard = (TurretCard)FactionCard.FactionTurretDeck[0]; } if (f.Team != GetTeam()) { f.roundReport.TurretsKilled++; f.AddEvent(MyCard.Name + " Destroyed", new Color(1, 0.5f, 0.5f), FactionEvent.KillTexture); } else { f.roundReport.TurretsLost++; f.AddEvent(MyCard.Name + " Lost", new Color(1, 0.5f, 0.5f), FactionEvent.LossTexture); } } if (ShouldDeathSound) { SoundManager.Play3DSound(DeathSound, new Vector3(Position.X(), Y, Position.Y()), DeathVolume, 1000, 1); ShouldDeathSound = false; } FreezeMult = 0; VirusTime = 0; DeathParticles(); Lives--; Dead = true; if (MyBustedTurret == null) { MyBustedTurret = new BustedTurret(this); ParentLevel.AddObject(MyBustedTurret); MyBustedTurret.SetPosition(getPosition()); } MyBustedTurret.WorldMatrix = WorldMatrix; MyBustedTurret.Activate(); InstanceManager.RemoveChild(this); RemoveTag(GameObjectTag._2DSolid); RemoveTag(GameObjectTag._2DForward); LinkedList <GameObject> GList = Parent2DScene.GetList(GameObjectTag._2DSolid); if (GList.Contains(this)) { GList.Remove(this); } BuildTimer = 0; float BulletExplosionDistance = 200; float BulletExplosionDamage = 1f; QuadGrid grid = Parent2DScene.quadGrids.First.Value; for (int i = 0; i < 2; i++) { bool ActivateDeathSound = true; foreach (Basic2DObject o in grid.Enumerate(Position.get(), new Vector2(BulletExplosionDistance * 2))) { if (o.GetType().IsSubclassOf(typeof(UnitShip))) { BasicShipGameObject s = (BasicShipGameObject)o; float dist = Vector2.Distance(s.Position.get(), Position.get()) - o.Size.X() / 2; if (dist < BulletExplosionDistance && GetTeam() != s.GetTeam() && s.CanBeTargeted()) { float DistMult = 1; if (dist > 0) { DistMult = (BulletExplosionDistance - dist) / BulletExplosionDistance; } if (s.GetType().IsSubclassOf(typeof(UnitShip))) { UnitShip ship = (UnitShip)s; ship.CanDeathSound = ActivateDeathSound; } s.Damage(DistMult * BulletExplosionDamage, DistMult, Vector2.Normalize(s.Position.get() - Position.get()), this, AttackType.Explosion); if (s.Dead) { ActivateDeathSound = false; } else if (s.GetType().IsSubclassOf(typeof(UnitShip))) { UnitShip ship = (UnitShip)s; ship.CanDeathSound = true; } } } } } if (ShieldAlpha > 0) { ShieldInstancer.Remove(this); ShieldAlpha = -1; } }
private void SetAsStart(Button b) { ParentLevel.SetStartingScene(this); }