private static List<Entity> LoadZone1_2() { List<Entity> zone = new List<Entity>(); Random r = new Random(); Random r2 = new Random(53); for (int i = 0; i < 55; i++) { Tree tree = new Tree() { WorldPosition = new Vector2(r.Next(-1200, 1200), r2.Next(-1200, 1200)) }; tree.LoadContent(); zone.Add(tree); } for (int i = 0; i < 4; i++) { Rock rock = new Rock() { WorldPosition = new Vector2(r.Next(-600, 600), r2.Next(-600, 600)) }; rock.LoadContent(); zone.Add(rock); } // Background Tiles for (int i = -15; i < 15; i++) { for (int j = -15; j < 15; j++) { if (i < -10 || i > 10 || j < -10 || j > 10) { CementBlock block = new CementBlock() { WorldPosition = new Vector2(i * 150, j * 150) }; block.LoadContent(); zone.Add(block); } else { GroundTile tile = new GroundTile(GroundTile.GroundTileType.Grass) { WorldPosition = new Vector2(i * 150, j * 150) }; tile.LoadContent(); zone.Add(tile); } } } House house = new House() { WorldPosition = new Vector2(0, 0) }; house.LoadContent(); zone.Add(house); return zone; }
public override bool Update(GameTime gameTime) { camera.UpdateBegin(); if (!gameState.Update(gameTime)) { return(false); } if (!pauseGame) { for (int i = 0; i < Entities.Count; i++) { Entities[i].Update(gameTime); } } #if DEBUG else { player.Update(gameTime); } #endif #if DEBUG #region Editor if (Input.e.pressed) { editorTool++; if ((int)editorTool >= Enum.GetNames(editorTool.GetType()).Length) { editorTool = 0; } } else if (Input.q.pressed) { editorTool--; if ((int)editorTool < 0) { editorTool = (EditorTool)(Enum.GetNames(editorTool.GetType()).Length - 1); } } //if (editorTool != EditorTool.None) { if (Input.mbLeft.pressed || Input.mbRight.pressed) { pressedX = (int)Math.Floor(camera.mousePos.X / Tile.size); pressedY = (int)Math.Floor(camera.mousePos.Y / Tile.size); mouseDown = Input.mbLeft.pressed ? Input.mbLeft : Input.mbRight; } if (mouseDown != null && mouseDown.released) { switch (editorTool) { #region Tile case EditorTool.Tile: case EditorTool.Goal: int x = (int)Math.Floor(camera.mousePos.X / Tile.size); int y = (int)Math.Floor(camera.mousePos.Y / Tile.size); int xStart = Math.Min(x, pressedX); int xEnd = Math.Max(x, pressedX); int yStart = Math.Min(y, pressedY); int yEnd = Math.Max(y, pressedY); bool setStreet = mouseDown == Input.mbLeft; if (xStart < 0) { xStart = 0; } if (yStart < 0) { yStart = 0; } if (xStart >= width) { xStart = width - 1; } if (yStart >= height) { yStart = height - 1; } if (editorTool == EditorTool.Tile) { for (int y1 = yStart; y1 <= yEnd; y1++) { for (int x1 = xStart; x1 <= xEnd; x1++) { street[x1, y1] = setStreet; } } UpdateTiles(xStart - 1, xEnd + 1, yStart - 1, yEnd + 1); } else if (editorTool == EditorTool.Goal) { for (int y1 = yStart; y1 <= yEnd; y1++) { for (int x1 = xStart; x1 <= xEnd; x1++) { AddEntity(new Goal(new Vector2(x1, y1) * Tile.size)); } } } break; #endregion case EditorTool.House: if (mouseDown == Input.mbLeft) { House house = new House(GetDragRectangle()); AddEntity(house); } break; } mouseDown = null; } if (mouseDown == Input.mbRight) { if (editorTool != EditorTool.Tile) { for (int i = Entities.Count - 1; i >= 0; i--) { if (Entities[i] is E_Mask m && m.Mask.ColVector(camera.mousePos)) { RemoveEntity(Entities[i]); } } } } else { switch (editorTool) { case EditorTool.Tile: break; case EditorTool.House: break; case EditorTool.Car: if (Input.mbLeft.pressed) { if (carIndex == 0) { carBuild = new PlayerCar(camera.mousePos, 0f); } else { carBuild = new Car(camera.mousePos, 0f); } AddEntity(carBuild); } if (Input.mbLeft.down) { Vector2 dir = camera.mousePos - carBuild.Pos; carBuild.orientation = (float)Math.Atan2(dir.Y, dir.X); } break; case EditorTool.Bot: if (Input.mbLeft.pressed) { Bot bot = Entities.Find(f => f is Bot b && b.botID == carIndex) as Bot; if (bot == null) { PathTrack path = new PathTrack(new List <Vector2>() { camera.mousePos }); if (carIndex == 0) { bot = new Friend(path); } else { bot = new Bot(carIndex, path); } AddEntity(bot); } else { bot.path.nodes.Add(camera.mousePos); } } break; } } if (Input.plusNum.pressed) { carIndex++; } else if (Input.minusNum.pressed) { carIndex--; } } #endregion #endif camera.targetPos = player.Pos; camera.UpdateEnd(G.ResX, G.ResY); #if DEBUG if (Input.f.pressed) { Win(); } #endif return(true); }
private static List<Entity> LoadZone1_1() { List<Entity> zone = new List<Entity>(); Random r = new Random(); Random r2 = new Random(53); List<Vector2> treePositions = new List<Vector2>(); // Left upper treePositions.Add(new Vector2(-500, -100)); treePositions.Add(new Vector2(-450, -440)); treePositions.Add(new Vector2(-250, -255)); treePositions.Add(new Vector2(-750, -791)); // Left lower treePositions.Add(new Vector2(-200, 55)); treePositions.Add(new Vector2(-810, 515)); treePositions.Add(new Vector2(-700, 815)); // Right upper treePositions.Add(new Vector2(500, -800)); treePositions.Add(new Vector2(850, -510)); // Right lower treePositions.Add(new Vector2(850, 50)); foreach(Vector2 treePos in treePositions) { Tree tree = new Tree() { WorldPosition = treePos }; tree.LoadContent(); zone.Add(tree); } for (int i = 0; i < 4; i++) { Rock rock = new Rock() { WorldPosition = new Vector2(r.Next(-600, 600), r2.Next(-600, 600)) }; rock.LoadContent(); zone.Add(rock); } // Background Tiles for (int i = -15; i < 15; i++) { for (int j = -15; j < 15; j++) { if (i < -10 || i > 10 || j < -10 || j > 10) { CementBlock block = new CementBlock() { WorldPosition = new Vector2(i * 150, j * 150) }; block.LoadContent(); zone.Add(block); } else { GroundTile tile = new GroundTile(GroundTile.GroundTileType.Grass) { WorldPosition = new Vector2(i * 150, j * 150) }; tile.LoadContent(); zone.Add(tile); } } } House house = new House() { WorldPosition = new Vector2(0, 0) }; house.LoadContent(); zone.Add(house); return zone; }