public void DestroyWalls() { for (int i = 0; i < Walls.Count; ++i) { MonoBehaviour.Destroy(Walls[i].gameObject); } Walls.Clear(); }
public void NewEnemies(double PlayerAndWallSkin)//once the level has been completed, new opponents and walls are generated { if (Invaders.Count == 0) { SetInvaderRows(); Walls.Clear(); SetWalls(PlayerAndWallSkin); levelcounter++; score = score + 50 + 50 * difficultyIndex;//points for the completed level } }
public void ClearGame()//Removes all Gameobjects from the Gamedisplay and resets the Gamevalues { Player.HealthPoints = 3; score = 0; levelcounter = 1; PlayerProjectiles.Clear(); EnemyProjectiles.Clear(); Invaders.Clear(); Ufos.Clear(); Walls.Clear(); GameDisplay.Children.Clear(); }
public static void InitializeMap() { Walls.Clear(); Nodes.Clear(); EmptySquares.Clear(); Dots.Clear(); Powerups.Clear(); Ghosts.Clear(); Invaders.Clear(); //Initializes border of map string line = ""; int number = 0; using (StreamReader sr = new StreamReader("Maps/pacman" + PacmanGame.maps[PacmanGame.mapNumber].ToString() + ".txt")) { while (true) { line = sr.ReadLine(); if (line == null) { break; } for (int counter = 0; counter < line.Length; counter++) { wallMap[counter, number] = line[counter].ToString() == "0"; } number++; } } //Fills in rest of map using two dimensional bool array wallMap for (int x = 0; x < wallMap.GetLength(0); x++) { for (int y = 0; y < wallMap.GetLength(1); y++) { if (!wallMap[x, y]) { Walls.Add(new Wall(new Rectangle(x * PacmanGame.gridSize + PacmanGame.horizontalSpace, y * PacmanGame.gridSize + PacmanGame.verticalSpace, PacmanGame.gridSize, PacmanGame.gridSize))); } } } //Fills map with empty squares, dots and nodes in all places without walls //variable used to count nodes int variable = 0; for (int y = 1; y < PacmanGame.mapHeight / PacmanGame.gridSize - 1; y++) { for (int x = 1; x < PacmanGame.mapWidth / PacmanGame.gridSize - 1; x++) { Rectangle rectangle = new Rectangle(PacmanGame.gridSize * x + PacmanGame.horizontalSpace, PacmanGame.gridSize * y + PacmanGame.verticalSpace, PacmanGame.gridSize, PacmanGame.gridSize); bool value = true; foreach (Wall wall in Walls) { if (wall.Position == rectangle) { value = false; } } if (value) { EmptySquares.Add(new EmptySquare(rectangle)); Dots.Add(new Dot(rectangle)); Nodes.Add(new Node(variable, rectangle)); variable++; } } } //Remove the dot where the pacman starts Dots.Remove(new Dot(new Rectangle(PacmanGame.gridSize, PacmanGame.gridSize, PacmanGame.gridSize, PacmanGame.gridSize))); //Adds powerups Random random = new Random(); int[] values = Enumerable.Range(0, Map.Nodes.Count).OrderBy(x => random.Next()).ToArray(); for (int counter = 0; counter < 4; counter++) { int index = values[counter]; Rectangle rectangleValue = Map.Nodes.ElementAt(index).Position; Powerups.Add(new Powerup(rectangleValue)); //Remove the dot where the powerup is Dots.Remove(new Dot(rectangleValue)); } createAdjacencyList(); Paddles[0] = new Paddle(new Rectangle(PacmanGame.horizontalSpace / 2, PacmanGame.screenHeight / 2, PacmanGame.gridSize, PacmanGame.gridSize * 5), Player.Left); Paddles[1] = new Paddle(new Rectangle(PacmanGame.screenWidth - PacmanGame.horizontalSpace / 2, PacmanGame.screenHeight / 2, PacmanGame.gridSize, PacmanGame.gridSize * 5), Player.Right); }
public void ClearPool() { Walls.Clear(); Trees.Clear(); Loot.Clear(); }
private bool InitializePanel() { if (panel != null) { Walls.Clear(); StartPoints.Clear(); EndPoints.Clear(); renderedTetrisTextures.Clear(); PuzzleDimensions = new Point(panel.Width, panel.Height); // Calculation of puzzle sizes for current screen size int width = screenSize.X; int height = screenSize.Y; int maxPuzzleDimension = Math.Max(PuzzleDimensions.X, PuzzleDimensions.Y); int screenMinSize = Math.Min(width, height); int puzzleMaxSize = (int)(screenMinSize * PuzzleSpaceRatio(maxPuzzleDimension)); LineWidth = (int)(puzzleMaxSize * LineSizeRatio(maxPuzzleDimension)); BlockWidth = (int)(puzzleMaxSize * BlockSizeRatio(maxPuzzleDimension)); HalfLineWidthPoint = new Point(LineWidth / 2); LineWidthPoint = new Point(LineWidth); BlockSizePoint = new Point(BlockWidth); int endAppendixLength = (int)(BlockWidth * endPointLegth); int puzzleWidth = LineWidth * (PuzzleDimensions.X + 1) + BlockWidth * PuzzleDimensions.X; int puzzleHeight = LineWidth * (PuzzleDimensions.Y + 1) + BlockWidth * PuzzleDimensions.Y; int xMargin = (width - puzzleWidth) / 2; int yMargin = (height - puzzleHeight) / 2; Point margins = new Point(xMargin, yMargin); PuzzleConfig = new Rectangle(xMargin, yMargin, puzzleWidth, puzzleHeight); NodePadding = LineWidth + BlockWidth; // Creating walls hitboxes CreateHorizontalWalls(false); // Top walls CreateHorizontalWalls(true); // Bottom walls CreateVerticalWalls(false); // Left walls CreateVerticalWalls(true); // Right walls for (int i = 0; i < PuzzleDimensions.X; i++) { for (int j = 0; j < PuzzleDimensions.Y; j++) { Walls.Add(new Rectangle(xMargin + LineWidth * (i + 1) + BlockWidth * i, yMargin + LineWidth * (j + 1) + BlockWidth * j, BlockWidth, BlockWidth)); } } // Creating walls for broken edges var brokenEdges = panel.Edges.Where(x => x.State == EdgeState.Broken); foreach (Edge edge in brokenEdges) { Point nodeA = NodeIdToPoint(edge.Id % 100).Multiply(NodePadding) + margins; Point nodeB = NodeIdToPoint(edge.Id / 100).Multiply(NodePadding) + margins; Point middle = (nodeA + nodeB).Divide(2); Walls.Add(new Rectangle(middle, new Point(LineWidth))); } // Creating hitboxes for starting nodes foreach (Point start in GetStartNodes()) { StartPoints.Add(new Rectangle(xMargin + start.X * NodePadding - LineWidth, yMargin + start.Y * NodePadding - LineWidth, LineWidth * 3, LineWidth * 3)); } // Generate textures for tetris rules CreateTetrisRuleTextures(); #region === Inner methods region === // Returns a coef k: Total free space in pixels * k = puzzle size in pixels float PuzzleSpaceRatio(float puzzleDimension) => (float)(-0.0005 * Math.Pow(puzzleDimension, 4) + 0.0082 * Math.Pow(puzzleDimension, 3) - 0.0439 * Math.Pow(puzzleDimension, 2) + 0.1011 * puzzleDimension + 0.6875); // Returns a coef k: Puzzle size in pixels * k = block size in pixels float BlockSizeRatio(float puzzleDimension) => (float)(0.8563 * Math.Pow(puzzleDimension, -1.134)); // Returns a coef k: Puzzle size in pixels * k = line width in pixels float LineSizeRatio(float puzzleDimension) => - 0.0064f * puzzleDimension + 0.0859f; IEnumerable <Point> GetStartNodes() => panel.Nodes.Where(x => x.State == NodeState.Start).Select(x => NodeIdToPoint(x.Id)); IEnumerable <Point> GetEndNodesTop() { for (int i = 1; i < panel.Width; i++) { if (panel.Nodes[i].State == NodeState.Exit) { yield return(new Point(i, 0)); } } } IEnumerable <Point> GetEndNodesBot() { for (int i = 1; i < panel.Width; i++) { int index = panel.Height * (panel.Width + 1) + i; if (panel.Nodes[index].State == NodeState.Exit) { yield return(new Point(i, panel.Height)); } } } IEnumerable <Point> GetEndNodesLeft() { for (int j = 0; j < panel.Height + 1; j++) { int index = j * (panel.Width + 1); if (panel.Nodes[index].State == NodeState.Exit) { yield return(new Point(0, j)); } } } IEnumerable <Point> GetEndNodesRight() { for (int j = 0; j < panel.Height + 1; j++) { int index = j * (panel.Width + 1) + panel.Width; if (panel.Nodes[index].State == NodeState.Exit) { yield return(new Point(panel.Width, j)); } } } void CreateHorizontalWalls(bool isBottom) { int yStartPoint = isBottom ? yMargin + puzzleHeight : 0; var ends = isBottom ? GetEndNodesBot() : GetEndNodesTop(); if (ends.Count() == 0) { Walls.Add(new Rectangle(0, yStartPoint, width, yMargin)); } else { Walls.Add(new Rectangle(0, yStartPoint + (isBottom ? endAppendixLength : 0), width, yMargin - endAppendixLength)); int lastXPoint = 0; foreach (Point endPoint in ends) { int x = xMargin + endPoint.X * (NodePadding); Walls.Add(new Rectangle(lastXPoint, isBottom ? yStartPoint : (yMargin - endAppendixLength), x - lastXPoint, endAppendixLength)); EndPoints.Add(new EndPoint(new Rectangle(x, isBottom ? yStartPoint + endAppendixLength - LineWidth : (yMargin - endAppendixLength), LineWidth, LineWidth), isBottom ? Facing.Down : Facing.Up)); lastXPoint = x + LineWidth; } Walls.Add(new Rectangle(lastXPoint, isBottom ? yStartPoint : (yMargin - endAppendixLength), width - lastXPoint, endAppendixLength)); } } void CreateVerticalWalls(bool isRight) { int xStartPoint = isRight ? xMargin + puzzleWidth : 0; var ends = isRight ? GetEndNodesRight() : GetEndNodesLeft(); if (ends.Count() == 0) { Walls.Add(new Rectangle(xStartPoint, 0, xMargin, height)); } else { Walls.Add(new Rectangle(xStartPoint + (isRight ? endAppendixLength : 0), 0, xMargin - endAppendixLength, height)); int lastYPoint = 0; foreach (Point endPoint in ends) { int y = yMargin + endPoint.Y * (NodePadding); Walls.Add(new Rectangle(isRight ? xStartPoint : (xMargin - endAppendixLength), lastYPoint, endAppendixLength, y - lastYPoint)); EndPoints.Add(new EndPoint(new Rectangle(isRight ? xStartPoint + endAppendixLength - LineWidth : xMargin - endAppendixLength, y, LineWidth, LineWidth), isRight ? Facing.Right : Facing.Left)); lastYPoint = y + LineWidth; } Walls.Add(new Rectangle(isRight ? xStartPoint : (xMargin - endAppendixLength), lastYPoint, endAppendixLength, height - lastYPoint)); } } void CreateTetrisRuleTextures() { // Render shape into texture for each tetris rule var tetrisBlocks = panel.Blocks.Where(x => x.Rule is TetrisRule).ToList(); if (tetrisBlocks.Count > 0) { int maxDimension = tetrisBlocks.Select(x => x.Rule as TetrisRule).Select(x => Math.Max(x.Shape.GetLength(0), x.Shape.GetLength(1))).Max(); if (maxDimension < 3) { maxDimension++; } tetrisTextureSize = new Point((maxDimension + 1) * texTetris[0].Width); foreach (Block block in tetrisBlocks) { TetrisRule rule = block.Rule as TetrisRule; bool[,] shape = rule.Shape; // If shape is rotatable, then rotate it randomly before render if (rule is TetrisRotatableRule r) { shape = TetrisRotatableRule.RotateShapeCW(shape, rnd.Next(0, 4)); } // Draw shape on a texture RenderTarget2D texture = CreateTetrisTexture(shape, rule is TetrisRotatableRule, rule.IsSubtractive); // Save it to the dictionary renderedTetrisTextures.Add(block.Id, texture); } } } #endregion return(true); } return(false); }
public void Start(TanksForm fm) { UnSubscribe(); Apples.Clear(); Tanks.Clear(); Walls.Clear(); ShotsKolobok.Clear(); ShotsTanks.Clear(); kolobok = null; gameOver = false; Score = 0; Delta = 30; DeltaShots = 30; map = fm.map; backgroundMap = new Bitmap(map.Width, map.Height); mapGraphics = Graphics.FromImage(backgroundMap); mapGraphics.FillRectangle(Brushes.Black, 0, 0, map.Width, map.Height); for (int i = 0; i < example.Count(); i++) { for (int j = 0; j < example[i].Length; j++) { if (example[i][j] == 'X') { Walls.Add(new Wall(j, i)); mapGraphics.DrawImage(Walls.Last().Img, Walls.Last().X *TanksForm.sizeCell, Walls.Last().Y *TanksForm.sizeCell, TanksForm.sizeCell, TanksForm.sizeCell); } } } SpawnApples(); while (Tanks.Count < tanksCount) { Tanks.Add(new Tank()); foreach (var item in Walls) { if (Tanks.Last().CollidesWith(item)) { Tanks.RemoveAt(Tanks.Count - 1); break; } } } for (int i = 0; i < Apples.Count; i++) { mapGraphics.DrawImage(Apples[i].Img, Apples[i].X * TanksForm.sizeCell, Apples[i].Y * TanksForm.sizeCell, TanksForm.sizeCell, TanksForm.sizeCell); } for (int i = 0; i < Tanks.Count; i++) { mapGraphics.DrawImage(Tanks[i].Img, Tanks[i].X * TanksForm.sizeCell, Tanks[i].Y * TanksForm.sizeCell, TanksForm.sizeCell, TanksForm.sizeCell); } while (true) { kolobok = new Kolobok(); if (!kolobok.CollidesWithWalls(Walls)) { break; } } Subscribe(); mapGraphics.DrawImage(kolobok.Img, kolobok.X * TanksForm.sizeCell, kolobok.Y * TanksForm.sizeCell, TanksForm.sizeCell, TanksForm.sizeCell); map.Image = backgroundMap; }
public void LoadRoom(string roomName) { Enemies.Clear(); Blocks.Clear(); Items.Clear(); NPCs.Clear(); Doors.Clear(); Walls.Clear(); HiddenItems.Clear(); Dialogue = ""; CurrentRoom = roomName; //moves Link to the bottom of the map to avoid issues where blocks would spawn on top of him //mygame.player.Position = new Vector2(6 * XSCALE + XOFFSET, 7 * YSCALE + YOFFSET); addWalls(); XElement roomFile = XElement.Load("../../../../Content/Rooms/" + roomName + ".xml"); if (roomFile.Descendants("Background").Count() > 0) { Console.WriteLine(roomFile.Descendants("Background").Count()); if (roomFile.Element("Asset").Element("Background").Value == "RoomBowBackground") { Background = BlockSpriteFactory.Instance.RoomBowBackground; } else if (roomFile.Element("Asset").Element("Background").Value == "BlackWithWallBackground") { Background = BlockSpriteFactory.Instance.BlackWithWallBackground; } } else { Background = floorBaseWithWalls; } IEnumerable <XElement> loadedEnvironmentObjects = from item in roomFile.Descendants("Item") where (string)item.Element("ObjectType") == "Environment" select item; foreach (XElement environmentObject in loadedEnvironmentObjects) { AddEnvironmentObject(environmentObject); } IEnumerable <XElement> loadedEnemies = from item in roomFile.Descendants("Item") where (string)item.Element("ObjectType") == "Enemy" select item; foreach (XElement enemyObject in loadedEnemies) { AddEnemy(enemyObject); Thread.Sleep(20); //used so the random number generator for enemies don't have the same seed. It's time based and without this they have the same seed. } IEnumerable <XElement> loadedItems = from item in roomFile.Descendants("Item") where (string)item.Element("ObjectType") == "Item" select item; foreach (XElement itemObject in loadedItems) { AddItem(itemObject, Items); } IEnumerable <XElement> loadedHiddenItems = from item in roomFile.Descendants("Item") where (string)item.Element("ObjectType") == "HiddenItem" select item; foreach (XElement itemObject in loadedHiddenItems) { AddItem(itemObject, HiddenItems); } IEnumerable <XElement> loadedNPCs = from item in roomFile.Descendants("Item") where (string)item.Element("ObjectType") == "NPC" select item; foreach (XElement NPCObject in loadedNPCs) { AddNPC(NPCObject); } IEnumerable <XElement> loadedDoors = from item in roomFile.Descendants("Door") select item; foreach (XElement DoorObject in loadedDoors) { AddDoor(DoorObject); } }