public int[,] TrackPlayer(CaveTile center, Cave map) { int[,] trackedValues = new int[range, range]; int startingRow = center.X - range / 2; int startingCol = center.Y - range / 2; //TextureCreator.print("Center tile [" + center.X.ToString() + "," + center.Y.ToString() +"]"); //TextureCreator.print("Starting value [" + startingRow.ToString() + "," + startingCol.ToString()); for (int row = 0; row < range; row++) { startingCol = center.Y - range / 2; for (int col = 0; col < range; col++) { if (startingRow == center.X && startingCol == center.Y) { trackedValues[row, col] = PlayerValue; //TextureCreator.print("En player value"); } else { trackedValues[row, col] = map.GetValueAt(startingRow, startingCol); // TextureCreator.print("Tile [" + startingRow.ToString() + "," +startingCol.ToString() + "] = " + map.GetValueAt(startingRow, startingCol).ToString()); } startingCol++; } // end if startingRow++; } // end if return(trackedValues); }
public void UpdateMiniMap() { CaveTile playerTile = level.GetTileAtPosition(player.position); int[,] miniMapData = tracker.TrackPlayer(playerTile, level); uiRenderer.SetMiniMap(miniMapData); }
private static void CreateIslandTile() { CaveTile myAT = new CaveTile(); Sprite[] myTextures = myAT.GetSprite(); if (myTextures != null) { Debug.Log(myTextures.GetType() + "Length: " + myTextures.Length); Debug.Log(myTextures[0].name); } else { Debug.Log("Texture not loaded"); } string fName2 = "CaveTile"; myAT.name = fName2 + ".asset"; //Has to be placed before Create of Asset data will be lost after saving myAT.InitiateSlots(myTextures); AssetDatabase.CreateAsset(myAT, "Assets/Tiles/" + myAT.name + ""); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); }
private void SpawnCollectables() { List <CaveTile> collectableTiles = level.GetTilesWithValue(3); for (int i = 0; i < collectableTiles.Count; i++) { CaveTile tile = collectableTiles[i]; Vector3 position = level.GetPositionAtTile(tile.X, tile.Y); position.y += 0.25f; InstantiateGameObject(CollectablePrefab, position, CollectablesContainer); } // end if }
public static List <CaveTile> MatrixToTileList(int[,] data) { List <CaveTile> tiles = new List <CaveTile>(); for (int row = 0; row < data.GetLength(0); row++) { for (int col = 0; col < data.GetLength(0); col++) { CaveTile tile = new CaveTile(row, col, data[row, col]); tiles.Add(tile); } // end for } // end for return(tiles); }
//public Vector3 GetPositionAtTile() public Vector3 GetPositionAtTile(int x, int y) { Vector3 position = Vector3.zero; CaveTile tile = new CaveTile(x, y, -1); foreach (KeyValuePair <Vector3, CaveTile> keyValue in tilesPosition) { if (keyValue.Value.Equals(tile)) { position = keyValue.Key; break; } // end if } // end for return(position); }
public int GetValueAt(int x, int y) { CaveTile tile = new CaveTile(x, y, -1); if (!IsOutOfBounds(tile.X, tile.Y)) { for (int i = 0; i < Data.Count; i++) { if (Data[i].Equals(tile)) { tile.Value = Data[i].Value; } } // end for } return(tile.Value); }
public CaveTile GetTileAtPosition(Vector3 pos) { float shortestDistance = 0; bool isPosibleTileFound = false; CaveTile tile = new CaveTile(-1, -1, -1); foreach (KeyValuePair <Vector3, CaveTile> keyValue in tilesPosition) { float currentDistance = Vector3.Distance(keyValue.Key, pos); if (currentDistance < shortestDistance || !isPosibleTileFound) { CaveTile currentTile = keyValue.Value; if (currentTile.Value == CaveGeneratorUtilities.DataConstants.Ground) { shortestDistance = currentDistance; isPosibleTileFound = true; tile = new CaveTile(currentTile.X, currentTile.Y, currentTile.Value); } // end if } // end for } return(tile); }
public void Update(CaveTile[][][] map) { if (moving) { if (Util.Distance(position.X, position.Y, target.X, target.Y) > 5) { if (target.X > position.X) position.X += speed; if (target.X < position.X) position.X -= speed; if (target.Y < position.Y) position.Y -= speed; if (target.Y > position.Y) position.Y += speed; } else moving = false; } /* if (Keyboard.GetState().IsKeyDown(Keys.W)) { velocity.Y -= speed; } else if (Keyboard.GetState().IsKeyDown(Keys.S)) { velocity.Y += speed; } if (Keyboard.GetState().IsKeyDown(Keys.A)) { velocity.X -= speed; } else if (Keyboard.GetState().IsKeyDown(Keys.D)) { velocity.X += speed; } */ rotation = (float)Math.Atan(Math.Sqrt(Math.Pow(Mouse.GetState().X - position.X, 2) + Math.Pow(Mouse.GetState().Y - position.Y, 2))); //Does lazer fire like a gun or like a water gun (constant stream as long as button is held down) if (Mouse.GetState().LeftButton == ButtonState.Pressed) { //Fire lazer until power out if (lazerPower > 0) { //Fire lazer lazerPower--; } } else { lazerPower += lazerRechargeTime; } if (Mouse.GetState().LeftButton == ButtonState.Released && previousMouseState.LeftButton == ButtonState.Pressed) { //Fire Lazer } //Set speed limit if (velocity.X > maxVelocity) { velocity.X = maxVelocity; } if (velocity.Y > maxVelocity) { velocity.Y = maxVelocity; } if (!drawingTweet) { if (currentTime >= twitterTime) { currentTime = 0; DrawTweet(); } } else { if (currentTime >= 800) { drawingTweet = false; currentTime = 0; } } currentTime++; position += velocity; previousMouseState = Mouse.GetState(); }
public ControlNode(Vector2 _pos, CaveTile _caveTile, float squareSize) : base(_pos) { caveTile = _caveTile; above = new Node(position + Vector2.up * squareSize / 2f); right = new Node(position + Vector2.right * squareSize / 2f); }
/// <summary> /// Runs the logic around the game loop /// </summary> /// <param name="difficulty">Difficulty of the game</param> /// <param name="newPlayer">The current player</param> /// <returns>Whether or not the game will continue</returns> public void RunMapGame() { EncounterProg encounter = new EncounterProg(); encounter.RunCharacterCreation(); Random randomNumberSeed = new Random(); bool newMap = true; int height = 8, width = 20; while (newMap) { PlayerToken player = new PlayerToken(encounter); Console.WriteLine("Loading New Map..."); Console.WriteLine("This may take up to 60 seconds..."); Map map = new Map(width, height); TownMap townMap = new TownMap(width, height); Dictionary <int, CaveMap> caveMapStorage = new Dictionary <int, CaveMap>(); List <Tile> specialTilePile = new List <Tile>(); int randomSeed = randomNumberSeed.Next(_currentLevel - 1, _currentLevel + 2); if (_currentLevel == 1) { randomSeed = randomNumberSeed.Next(0, 3); } else if (_currentLevel == 2) { randomSeed = randomNumberSeed.Next(1, 3); } for (int i = 0; i < randomSeed; i++) { double randomWidthSeed = randomNumberSeed.Next(2, 4); double randomHeightSeed = randomNumberSeed.Next(1, 1); CaveMap caveMap = new CaveMap((int)(width / (randomWidthSeed)), (int)(height / (randomHeightSeed))); CaveTile caveTile = new CaveTile(); caveTile.AssociationNum = i + 1; specialTilePile.Add(caveTile); caveMapStorage.Add(i + 1, caveMap); } TownMapTile currentTownMapTile = new TownMapTile(); ExitTile endTile = new ExitTile(); endTile.Position = new int[2]; currentTownMapTile.Position = FindTileOrEntitySpawn.StartingPostion(map, currentTownMapTile); specialTilePile.Add(currentTownMapTile); specialTilePile.Add(endTile); List <ICharacter> entityPile = new List <ICharacter>(); randomSeed = randomNumberSeed.Next(_currentLevel, _currentLevel * 5); bool isTownMap = true; bool isCaveMap = true; while ((isTownMap || isCaveMap) && newMap) { newMap = RunWorldMap(encounter, player, map, specialTilePile, randomSeed, endTile, entityPile); isTownMap = false; isCaveMap = false; foreach (Tile tile in specialTilePile) { if (tile.GetType() == typeof(CaveTile) && IsColliding.IsCurrentlyColliding(tile, player)) { newMap = RunCaveMap(encounter, player, caveMapStorage, endTile, tile); isCaveMap = true; } else if (tile.GetType() == typeof(TownMapTile) && IsColliding.IsCurrentlyColliding(currentTownMapTile, player)) { encounter.TownReplenish(); newMap = RunTownMap(encounter, player, townMap, currentTownMapTile, endTile); isTownMap = true; } } } width += 10; height += 2; if (width == 100) { newMap = false; } _currentLevel++; } Console.WriteLine("Game Over"); }