MapMaker.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using UnityEngine;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. public class MapMaker : MonoBehaviour
  5. {
  6. [Header("Map Settings")]
  7. public int initialMapSize = 150;
  8. public int expansionSize = 50;
  9. public float playerDistanceThreshold = 20f;
  10. [Header("Generation Settings")]
  11. public int seed = 12345;
  12. private MapData mapData;
  13. private TerrainGenerator terrainGenerator;
  14. private FeatureGenerator featureGenerator;
  15. private ExpansionManager expansionManager;
  16. private Transform player;
  17. // Start is called once before the first execution of Update after the MonoBehaviour is created
  18. void Start()
  19. {
  20. InitializeMap();
  21. GenerateInitialMap();
  22. }
  23. // Update is called once per frame
  24. void Update()
  25. {
  26. if (player != null)
  27. {
  28. CheckForExpansion();
  29. }
  30. }
  31. private void InitializeMap()
  32. {
  33. Random.InitState(seed);
  34. mapData = new MapData(initialMapSize, initialMapSize);
  35. terrainGenerator = new TerrainGenerator();
  36. featureGenerator = new FeatureGenerator();
  37. //expansionManager = new ExpansionManager(this);
  38. // Find player object (assuming it has a "Player" tag)
  39. GameObject playerObj = GameObject.FindGameObjectWithTag("Player");
  40. if (playerObj != null)
  41. player = playerObj.transform;
  42. }
  43. private void GenerateInitialMap()
  44. {
  45. // Generate base terrain
  46. terrainGenerator.GenerateTerrain(mapData);
  47. // Generate features
  48. featureGenerator.GenerateFeatures(mapData);
  49. // Visualize the map (you'll need to implement this based on your rendering system)
  50. VisualizeMap();
  51. }
  52. private void CheckForExpansion()
  53. {
  54. Vector2 playerPos = new Vector2(player.position.x, player.position.z);
  55. if (expansionManager.ShouldExpand(playerPos, mapData))
  56. {
  57. ExpandMap(playerPos);
  58. }
  59. }
  60. private void ExpandMap(Vector2 playerPos)
  61. {
  62. expansionManager.ExpandMap(mapData, playerPos, expansionSize);
  63. VisualizeMap(); // Update visualization
  64. }
  65. private void VisualizeMap()
  66. {
  67. // This is where you'd implement your map visualization
  68. // For now, we'll just log the map data
  69. Debug.Log($"Map generated with size: {mapData.Width}x{mapData.Height}");
  70. Debug.Log($"Towns: {mapData.GetTowns().Count}, Villages: {mapData.GetVillages().Count}");
  71. }
  72. public MapData GetMapData() => mapData;
  73. }