public void CreatePieces(Vector2 position, Texture2D texture) { for (int i = 0; i < Globals.Randomizer.Next(10, 15); i++) { ToAdd.Add(new Piece(new Vector2(position.X + Globals.Randomizer.Next(-20, 20), position.Y + Globals.Randomizer.Next(-20, 20)), texture, 60, 1)); } }
/// <summary> /// Adds a child to this element. /// </summary> /// <param name="child">The element to be parented.</param> public void AddChild(UIElement child) { if (child.Parent != null) { throw new Exception("Tried to add a child that already has a parent!"); } if (!Children.Contains(child)) { ToAdd.Add(child); } else { throw new Exception("Tried to add a child that already belongs to this element!"); } }
public void Update() { // Update tiles if (Started && !Player.Dead) { // Hull flash possible match timeSinceLastMatch++; if (Player.ShipHull.FlashPossibleTiles && timeSinceLastMatch > 240) { timeSinceLastMatch = 0; List <Tile> possibleMatches = CheckPossibleMatches(); possibleMatches[Globals.Randomizer.Next(0, possibleMatches.Count())].Flash = 145; } bool canSelect = true; for (int i = 0; i < Tiles.Count; i++) { for (int j = 0; j < Tiles[i].Count; j++) { Tiles[i][j].TilePosition = new Point(i, j); Tiles[i][j].UpdateLevel(this); if (!Tiles[i][j].Hidden) { // Above hidden if (j < BoardSize.Y - 1 && Tiles[i][j + 1].Hidden && Tiles[i][j + 1].Size < 0.1) { if (Tiles[i][j].Mine) { Tiles[i][j].Mine = false; } Tile temp = Tiles[i][j]; Tiles[i][j] = Tiles[i][j + 1]; Tiles[i][j + 1] = temp; } // Select if (canSelect && Globals.MState.LeftButton == ButtonState.Pressed && Globals.PrevMState.LeftButton == ButtonState.Released && Globals.MRectangle.Intersects(Tiles[i][j].Box) && !Tiles.Any(Column => Column.Any(item => item.Moving == true))) { canSelect = false; if (Selected == null) { Selected = Tiles[i][j]; } else if (Selected == Tiles[i][j]) { Selected = null; } else { // Check if pressed tile next to selected if (CheckAdjacent(i, j)) { Tile temp = Tiles[i][j]; Tiles[i][j] = Selected; Tiles[i][j].Moving = true; Tiles[i][j].ManuallyMoved = 180; Tiles[Selected.TilePosition.X][Selected.TilePosition.Y] = temp; Tiles[Selected.TilePosition.X][Selected.TilePosition.Y].Moving = true; Tiles[Selected.TilePosition.X][Selected.TilePosition.Y].ManuallyMoved = 180; // Check if swap is matching if (!CheckSingleMatch(i, j, Tiles) && !CheckSingleMatch(Selected.TilePosition.X, Selected.TilePosition.Y, Tiles)) { Tiles[i][j] = Tiles[Selected.TilePosition.X][Selected.TilePosition.Y]; Tiles[i][j].Moving = false; Tiles[Selected.TilePosition.X][Selected.TilePosition.Y] = Selected; Tiles[Selected.TilePosition.X][Selected.TilePosition.Y].Moving = false; GameObjects.Add(new Text(Tiles[i][j].Position - (Tiles[i][j].Position - Tiles[Selected.TilePosition.X][Selected.TilePosition.Y].Position), "Invalid Swap!", Color.Red, 60, 2, false, TextureManager.SpriteFont20)); } Selected = null; } else { Selected = Tiles[i][j]; } } } } else { if (Tiles[i][j].ManuallyMoved >= 0) { Tiles[i][j].ManuallyMoved = -1; } // "New" tile if hidden on top layer if (j == 0) { Player player = (Player)GameObjects.First(item => item is Player); Tiles[i][j].UnHide(player); } } } } CheckMatch(); // Modifiers if (HasModifier(Modifier.Asteroid)) { modifierTimer--; // spawn rock if possible to move if (modifierTimer < 0 && Globals.Randomizer.Next(0, 1001) < 3 && !(Player.ShipLocation == Location.left && !CheckPossibleMatches().Any(item => item.Type == TileType.right)) && !(Player.ShipLocation == Location.right && !CheckPossibleMatches().Any(item => item.Type == TileType.left)) && !(Player.ShipLocation == Location.middle && !CheckPossibleMatches().Any(item => item.Type == TileType.left) && !CheckPossibleMatches().Any(item => item.Type == TileType.right))) { modifierTimer = 120; ToAdd.Add(new Rock(Player, this)); } } if (HasModifier(Modifier.Sun)) { modifierTimer--; if (modifierTimer < 0 && Globals.Randomizer.Next(0, 1001) < 3) { modifierTimer = 120; CombatText("The sun is heating up!"); Player.SetDamageOverTime(3, 6, 0); if (GameObjects.Any(item => item is Enemy)) { Enemy enemy = (Enemy)GameObjects.First(item => item is Enemy); enemy.SetDamageOverTime(1, 6, 0); } } } if (HasModifier(Modifier.Satellite)) { Player.Energy.Change(0.04f); } if (HasModifier(Modifier.BlackHole)) { modifierTimer--; if (modifierTimer < 0 && Globals.Randomizer.Next(0, 1001) < 4) { modifierTimer = 300; CombatText("The tiles are heating up!"); for (int i = 0; i < Globals.Randomizer.Next(3, 7); i++) { while (true) { Point randomTile = new Point(Globals.Randomizer.Next(0, BoardSize.X), Globals.Randomizer.Next(0, BoardSize.Y)); Point randomTile2 = new Point(Globals.Randomizer.Next(0, BoardSize.X), Globals.Randomizer.Next(0, BoardSize.Y)); while (randomTile.X == randomTile2.X && randomTile.Y == randomTile2.Y) { randomTile2 = new Point(Globals.Randomizer.Next(0, BoardSize.X), Globals.Randomizer.Next(0, BoardSize.Y)); } Tile temp = Tiles[randomTile.X][randomTile.Y]; Tiles[randomTile.X][randomTile.Y] = Tiles[randomTile2.X][randomTile2.Y]; Tiles[randomTile2.X][randomTile2.Y] = temp; if (!CheckSingleMatch(randomTile.X, randomTile.Y, Tiles) && !CheckSingleMatch(randomTile2.X, randomTile2.Y, Tiles)) { break; } else { Tiles[randomTile2.X][randomTile2.Y] = Tiles[randomTile.X][randomTile.Y]; Tiles[randomTile.X][randomTile.Y] = temp; } } } } } } else if (Globals.KState.IsKeyDown(Keys.Enter)) { Started = true; } // Game objects foreach (GameObject go in GameObjects) { go.UpdateLevel(this); } // Add foreach (GameObject toAdd in ToAdd) { GameObjects.Add(toAdd); } ToAdd.Clear(); // Remove for (int i = GameObjects.Count - 1; i >= 0; i--) { if (GameObjects[i].Dead && !(GameObjects[i] is Player)) { if (GameObjects[i] is Enemy) { Player.GainExperience((int)EnemyDifficulty * 45 + 50 + Globals.Randomizer.Next(5, 10)); if (Rewards.Count() > 0) { foreach (Item reward in Rewards) { Player.AddItem(reward); } SceneManager.mapScene.NewItems.Flash = 10; } Player.Move = true; Player.Health.Change(1); } GameObjects.RemoveAt(i); } } // Infobuttons ModuleInfo.Update(); TileboardInfo.Update(); EnergyInfo.Update(); // Flee Flee.Update(); if (Flee.Press() && EnemyDifficulty != Difficulty.Boss) { if (Player.ItemInInventory("Flee")) { Player.GetItemInInventory("Flee").UseItem(Player, Player.GetItemInInventory("Flee")); } } if (Player.OutsideScreen()) { Player.Move = false; Player.Speed = 0; Player.Position = new Vector2(300, Globals.ScreenSize.Y - Player.Texture.Height); Player.Direction = Player.StandardDirection; LeaveLevel(GameObjects.Any(item => item is Enemy)); Player.BonusDamageOneFight = 0; } }
public void CombatText(string text) { ToAdd.Add(new Text(new Vector2(Globals.CombatScreenSize.X / 2, Globals.CombatScreenSize.Y / 2), text, Color.Red, 180, 1.5f, false, TextureManager.SpriteFont20)); }
public void SetUserRole(UserRole model) { ToAdd.Add(model.RoleId); }
public void AddShot(Shot shot) { ToAdd.Add(shot); }
public void Add(ComponentSystem system) { ToAdd.Add(system); }