Inheritance: MonoBehaviour
Ejemplo n.º 1
0
 private void Start()
 {
     gm = GameMaster.instance;
     mg = MapGeneration.instance;
     _init_();
     StartCoroutine("wait");
 }
Ejemplo n.º 2
0
    void Start()
    {
        if (mapGeneration == null)
        {
            mapGeneration = this;
        }
        else
        {
            Destroy(this);
        }
        //// Use Object pooling for the wall generation. Start with 20 walls.
        //      for (int i = 0; i < 20; i++)
        //      {
        //          GameManager.instance.addWall(wall);
        //      }

        // Create the first one at the edge of screen
        LastPathPoint = new Vector2(10, UnityEngine.Random.Range(BOTTOM_PLAYER_POS, TOP_PLAYER_POS));

        // Generate first buffer, will always keep a buffer of 40 units
        Chunks.Add(GenerateChunk());

        List <Vector2> firstChunkPoints        = Chunks[0].getProceedingPathPoints();
        List <Vector2> firstChunkPointsOFFUP   = Chunks[0].getProceedingPathPointsUP();
        List <Vector2> firstChunkPointsOFFDOWN = Chunks[0].getProceedingPathPointsDOWN();

        for (int i = 0; i < firstChunkPoints.Count - 1; i++)
        {
            Debug.DrawLine(firstChunkPoints[i], firstChunkPoints[i + 1], Color.red, 10000f);
            Debug.DrawLine(firstChunkPointsOFFUP[i], firstChunkPointsOFFUP[i + 1], Color.red, 10000f);
            Debug.DrawLine(firstChunkPointsOFFDOWN[i], firstChunkPointsOFFDOWN[i + 1], Color.red, 10000f);
        }
    }
Ejemplo n.º 3
0
        public void update_neighbours()
        {
            //ARRANGE
            GameObject    hexGO         = new GameObject();
            GameObject    gameObject    = new GameObject();
            MapGeneration mapGeneration = gameObject.AddComponent <MapGeneration>();

            mapGeneration.HexagonPrefab = hexGO;
            mapGeneration.MapRadius     = 10;

            //generate map
            mapGeneration.HexDict = new Dictionary <Vector3Int, IHexagon>();
            mapGeneration.GenerateMap();
            mapGeneration.UpdateHexNeighbours();
            mapGeneration.ConnectContentsToHex();

            //get random hex
            Vector3Int coords = new Vector3Int(-3, 2, 1);
            IHexagon   hex    = (IHexagon)mapGeneration.HexDict[coords];

            //manually calculate its neighbours
            List <Vector3Int> directions = mapGeneration.GetDirections();
            List <IHexagon>   neighbours = new List <IHexagon>();

            foreach (Vector3Int direction in directions)
            {
                neighbours.Add(mapGeneration.HexDict[coords + direction]);
            }

            //ASSERT
            Assert.AreEqual(neighbours, hex.MyHexMap.Neighbours);
        }
Ejemplo n.º 4
0
    public void Start()
    {
        coordsCore[0] = -1;
        coordsCore[1] = -1;
        if (instance == null)
        {
            instance = this;
        }
        else if (instance != this)
        {
            Destroy(gameObject);
        }
        if (GameController.CurrentWaveDetails.terrainGenObject != null)
        {
            var terrainGenObject = GameController.CurrentWaveDetails.terrainGenObject;
            seed = terrainGenObject.seed;
            minX = terrainGenObject.minX;
            maxX = terrainGenObject.maxX;
            minY = terrainGenObject.minY;
            maxY = terrainGenObject.maxY;
        }
        else
        {
            // Generate seed
            seed = generateSeed();
        }


        // Generate map
        generateMap(this.seed);


        fortBase.GetComponentInChildren <Core>().gameObject.transform.position = new Vector3(coordsCore[0], coordsCore[1]);
    }
Ejemplo n.º 5
0
    /*
     * this is where all variables are initialized
     * */
    void init()
    {
        // a list of enemies
        enemy = new List <GameObject> ();

        mapCoordinates = new List <MapCoordinates> ();

        hitOrMiss = GameObject.Find("HitOrMiss").GetComponent <Text> ();
        enemyHit  = GameObject.Find("EnemyHit").GetComponent <Text> ();

        playerPanel.transform.position = new Vector3(Screen.width / 2, Screen.height / 2, 0);

        experienceCounter.text = "Experience: " + experience;

        numberOfEnemies = maxEnemies;

        // set all extra panels to off
        gameOver.SetActive(false);
        winScreen.SetActive(false);
        pauseMenu.SetActive(false);

        // the size of the map instantiated
        tiles = new int[mapSizeX, mapSizeY];

        // creates instance of a map generator
        mapGenerator = new MapGeneration(mapSizeX, mapSizeY, player);

        //inventory = GameObject.Find ("Inventory").GetComponent<Inventory> ();
    }
Ejemplo n.º 6
0
    public Grid(Setup_Render setup, Config_Map config, TerrainType[,] types)
    {
        gridUtils.InjectDependencies(this, setup.Mat_Terrain, setup.Mat_Border);
        _mapConfig = config;


        // GRID AND TILE INFORMATION
        Size          = config.GridSize;
        TileHeight    = config.TileSize;
        TileThickness = config.TileThickness;

        // for grid mesh
        Hexagons = new Hexagon[Size, Size];


        _terrainResource = new TerrainResource(setup);

        if (types == null)
        {
            _terrainTypes = MapGeneration.GenerateTerrainTypes(config);
        }
        else
        {
            _terrainTypes = types;
        }


        // Init Hexagons with Border
        InitHexagons();
        InitVertexData();
    }
Ejemplo n.º 7
0
        public void hexes_in_range()
        {
            GameObject    gameObject    = new GameObject();
            MapGeneration mapGeneration = gameObject.AddComponent <MapGeneration>();

            mapGeneration.HexagonPrefab = new GameObject();
            mapGeneration.MapRadius     = 10;

            mapGeneration.HexDict = new Dictionary <Vector3Int, IHexagon>();
            mapGeneration.GenerateMap();
            mapGeneration.UpdateHexNeighbours();
            mapGeneration.ConnectContentsToHex();

            IHexagon startHex = mapGeneration.HexDict[new Vector3Int(0, 0, 0)];

            MapPathfinding     mapPathfinding = new MapPathfinding();
            HashSet <IHexagon> hexesInRange   = mapPathfinding.GetHexesInRange(startHex, 1);

            HashSet <IHexagon> neighboursAndStart = startHex.MyHexMap.Neighbours;

            neighboursAndStart.Add(startHex);
            foreach (IHexagon neighbour in startHex.MyHexMap.Neighbours)
            {
                Assert.IsTrue(hexesInRange.Contains(neighbour));
            }
            foreach (IHexagon hex in hexesInRange)
            {
                Assert.IsTrue(neighboursAndStart.Contains(hex));
            }
        }
Ejemplo n.º 8
0
        public void pathfinding()
        {
            GameObject    gameObject    = new GameObject();
            MapGeneration mapGeneration = gameObject.AddComponent <MapGeneration>();

            mapGeneration.HexagonPrefab = new GameObject();
            mapGeneration.MapRadius     = 10;

            mapGeneration.HexDict = new Dictionary <Vector3Int, IHexagon>();
            mapGeneration.GenerateMap();
            mapGeneration.UpdateHexNeighbours();
            mapGeneration.ConnectContentsToHex();

            IHexagon start_hex = mapGeneration.HexDict[new Vector3Int(0, 0, 0)];
            IHexagon end_hex   = mapGeneration.HexDict[new Vector3Int(0, -4, 4)];

            MapPathfinding mapPathfinding = new MapPathfinding();
            MapPath        path           = mapPathfinding.GeneratePath(start_hex, end_hex);

            MapPath arbitrary_path = new MapPath();

            for (int i = 4; i >= 0; i--)
            {
                arbitrary_path.PathStack.Push(mapGeneration.HexDict[new Vector3Int(0, -i, i)]);
            }
            arbitrary_path.cost = 4;

            Assert.AreEqual(arbitrary_path.PathStack, path.PathStack);
            Assert.AreEqual(arbitrary_path.cost, path.cost);
        }
Ejemplo n.º 9
0
	public void Awake()
	{
		time = Time.time;
		Loaded = false;
		mGen = GetComponent<MapGeneration> (); //new MapGeneration();
		pFind = GetComponent<AStar> ();
		photonView = GetComponent<PhotonView> ();
		seed = 0;
		if (PhotonNetwork.isMasterClient) {
			seed = Random.seed;
			for (int i = -4; i <= 4; ++i) {
				for(int j = -4; j <= 4; ++j){
					mGen.GenerateBlock (i, j, seed, 0, 0);
				}
			}
			mGen.CreateGrid(0, 0);
			Loaded = true;	
			lastX = 0;
			lastY = 0;
		}
		
		// in case we started this demo with the wrong scene being active, simply load the menu scene
		if (!PhotonNetwork.connected)
		{
			Application.LoadLevel(Menu.SceneNameMenu);
			return;
		}
		// we're in a room. spawn a character for the local player. it gets synced by using PhotonNetwork.Instantiate
		playerObject = PhotonNetwork.Instantiate(this.playerPrefab.name, transform.position, Quaternion.identity, 0);
		playerController = playerObject.GetComponent<ThirdPersonController> ();
	}
Ejemplo n.º 10
0
    public IEnumerator Setup()
    {
        yield return(TestUtils.LaunchNewPoolBenchmarkAsync(true, true));

        ResetFrameTime();


        //Setup SpawnPositions
        var spawns = MapGeneration.GeneratePointsScattered(0, 0, TestUtils.MAX_SPAWNS);

        for (int i = 0; i < TestUtils.MAX_SPAWNS; i++)
        {
            _collectionSpawnpoints.Add(new Vector3(spawns[i].x, spawns[i].y, spawns[i].z));

            var go = GameObject.Instantiate(Resources.Load <GameObject>(_prefabPath));
            go.SetActive(false);
            _pool.Add(go);
        }

        RenderMaster.RenderTerrain = false;


        for (int i = 0; i < m_StabilizationFrames; i++)
        {
            yield return(0);
        }
    }
Ejemplo n.º 11
0
    private void Awake()
    {
        if (Instance != null)
        {
            throw new System.Exception();
        }

        Instance = this;
    }
Ejemplo n.º 12
0
 // Start is called before the first frame update
 void Start()
 {
     playerBody  = gameObject.GetComponent <Rigidbody2D>();
     animator    = gameObject.GetComponent <Animator>();
     spRenderer  = gameObject.GetComponent <SpriteRenderer>();
     map         = FindObjectOfType <MapGeneration>(); //there should only be one in a scene.
     menu        = FindObjectOfType <MenuScript>();
     playerStats = PlayerStats.getInstacne();
 }
Ejemplo n.º 13
0
    private void Start()
    {
        coins = PlayerPrefs.GetInt("coins");
        level = PlayerPrefs.GetInt("level");
        mg    = MapGeneration.instance;
        coinsTextField.text = coins.ToString();

        GoToMainMenu();
    }
Ejemplo n.º 14
0
 void OnEnable()
 {
     instance = this;
     playerCulling.cullMapsGrid = new Culling [mapTexture.width / tilemapChunkSize.x, mapTexture.height / tilemapChunkSize.y];
     foreach (var chunk in tileChunks)
     {
         playerCulling.NewMap(chunk.GetComponent <Culling>());
     }
 }
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();
        MapGeneration mapGeneration = (MapGeneration)target;

        if (GUILayout.Button("Generate Map"))
        {
            mapGeneration.Init();
        }
    }
Ejemplo n.º 16
0
    public Agent(int _x, int _y, int _direction, MapGeneration _parent)
    {
        parent = _parent;

        grid = parent.GetGrid();

        x         = _x;
        y         = _y;
        direction = _direction;
    }
Ejemplo n.º 17
0
        public static void SaveWorld(int seed, MapGeneration map, FactionHandler factions, SpellGeneration spells, LoreHandler lore)
        {
            BinaryFormatter formatter = new BinaryFormatter();
            string          path      = Application.persistentDataPath + "/" + seed.ToString() + "world.data";
            FileStream      stream    = new FileStream(path, FileMode.Create);

            WorldData worldData = new WorldData(factions, map, spells, lore);

            formatter.Serialize(stream, worldData);
            stream.Close();
        }
Ejemplo n.º 18
0
 void Awake()
 {
     if (instance != null)
     {
         Destroy(gameObject);
     }
     else
     {
         instance = this;
         GameObject.DontDestroyOnLoad(gameObject);
     }
 }
Ejemplo n.º 19
0
 private void UpdateMouseOverPlanetState()
 {
     isMouseOnAnyPlanet = false;
     foreach (GameObject planet in MapGeneration.GetRefrence().visiblePlanets)
     {
         if (Vector2.Distance(planet.transform.position, Camera.main.ScreenToWorldPoint(Input.mousePosition)) < PlanetTypes.GetPlanetRadius())
         {
             lastHoveredPlanet  = planet;
             isMouseOnAnyPlanet = true;
         }
     }
 }
Ejemplo n.º 20
0
    private void Start()
    {
        playerEntity = FindObjectOfType <Player>();
        playerT      = playerEntity.transform;

        nextCampCheckTime     = timeBetweenCampingChecks + Time.time;
        campPositionOld       = playerT.position;
        playerEntity.OnDeath += OnPlayerDeath;

        map = FindObjectOfType <MapGeneration>();
        NextWave();
    }
Ejemplo n.º 21
0
    private void Awake()
    {
        Instance = this;
        if (row % 2 == 0)
        {
            row++;
        }

        if (column % 2 == 0)
        {
            column++;
        }
    }
Ejemplo n.º 22
0
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();

        MapGeneration map = target as MapGeneration;

        map.GenerateMap();

        if (GUILayout.Button("Generate Map"))
        {
            map.GenerateMap();
        }
    }
Ejemplo n.º 23
0
    public override void OnInspectorGUI()
    {
        MapGeneration map = target as MapGeneration;

        if (DrawDefaultInspector())
        {
            map.GenerateMap();
        }

        if (GUILayout.Button("Generate Map"))
        {
            map.GenerateMap();
        }
    }
Ejemplo n.º 24
0
        public void get_directions()
        {
            List <Vector3Int> directions = new List <Vector3Int>();

            directions.Add(new Vector3Int(1, -1, 0));
            directions.Add(new Vector3Int(1, 0, -1));
            directions.Add(new Vector3Int(0, 1, -1));
            directions.Add(new Vector3Int(-1, 1, 0));
            directions.Add(new Vector3Int(-1, 0, 1));
            directions.Add(new Vector3Int(0, -1, 1));

            GameObject    gameObject      = new GameObject();
            MapGeneration myMapGeneration = gameObject.AddComponent <MapGeneration>();

            Assert.AreEqual(directions, myMapGeneration.GetDirections());
        }
Ejemplo n.º 25
0
        public GPUGrassModel(Config_Grass config)
        {
            Config        = config;
            VerticesCount = Config.Amount * config.Segments * 2;
            IndicesCount  = Config.Amount * (config.Segments - 1) * 6;

            VerticesKernelDimensions = new Vector2Int(Config.Amount, 1);
            IndicesKernelDimensions  = new Vector2Int(Config.Amount, config.Segments);
            Spawnpoints = MapGeneration.GeneratePointsScattered(config.Grasswidth, config.Grasswidth, (uint)Config.Amount, 0);               //todo: dependant on spawn config

            VerticesKernelStride = Marshal.SizeOf(typeof(GPUModelVertex));
            IndicesKernelStride  = Marshal.SizeOf(typeof(int));

            BuildDataComputeBufferType = ComputeBufferType.Append;
            UpdateType = UpdateType.None;
        }
Ejemplo n.º 26
0
    public override void OnInspectorGUI()
    {
        MapGeneration generationMaps = (MapGeneration)target;

        DrawDefaultInspector();

        if (GUILayout.Button("Generate") || generationMaps.GenerationAllTime)
        {
            GenerateMapAllTime = true;
            generationMaps.GenerateMap();
        }
        else
        {
            GenerateMapAllTime = false;
        }
    }
    public override void OnInspectorGUI()
    {
        MapGeneration mapGen = (MapGeneration)target;

        if (DrawDefaultInspector())
        {
            if (mapGen.autoUpdate)
            {
                mapGen.GenerateMap();
            }
        }

        if (GUILayout.Button("Generate"))
        {
            mapGen.GenerateMap();
        }
    }
Ejemplo n.º 28
0
    // Use this for initialization
    void Start()
    {
        manager = GameObject.FindGameObjectWithTag("GameManager").GetComponent <GameManagerScript>();

        mapGenerator = new MapGeneration();

        playerShip = manager.GetPlayer().Ship.ShipModel;

        if (manager.GetLevel() == 1)
        {
            print("loading 1");
            playerShip.transform.position = new Vector3(-7.9f, 0f, -17f);
        }

        // Call to set up the generation of the island objects
        islands = mapGenerator.GenerateMap(manager.GetLevel());
        SetIslands();
    }
Ejemplo n.º 29
0
        public override void LoadContent()
        {
            ContentManager content = ScreenManager.Game.Content;

            map = content.Load <Map>("map");
            MapGeneration.Generate(map);

            camera = new Camera(ScreenManager.Game.RenderWidth, ScreenManager.Game.RenderHeight, map);

            //camera.Zoom = 0.5f;

            text = content.Load <Texture2D>("titles");

            hud = new HUD(content.Load <Texture2D>("hud"));

            waterLevel           = ScreenManager.Game.RenderHeight;
            waterParallax        = new Parallax(content.Load <Texture2D>("abovewater-parallax"), 12, 0.5f, waterLevel, (map.TileWidth * map.Width), new Viewport(0, 0, ScreenManager.Game.RenderWidth, ScreenManager.Game.RenderHeight), false, true);
            underwaterBGParallax = new Parallax(content.Load <Texture2D>("underwater-bg"), 4, 1f, waterLevel + 20, (map.TileWidth * map.Width), new Viewport(0, 0, ScreenManager.Game.RenderWidth, ScreenManager.Game.RenderHeight), true, false);
            skyBGParallax        = new Parallax(content.Load <Texture2D>("sky-bg"), 72, 1f, 70, (map.TileWidth * map.Width), new Viewport(0, 0, ScreenManager.Game.RenderWidth, ScreenManager.Game.RenderHeight), false, false);
            rocksParallax        = new Parallax(content.Load <Texture2D>("seabed-rocks"), 16, 0.35f, (map.TileHeight * map.Height) - 15, (map.TileWidth * map.Width), new Viewport(0, 0, ScreenManager.Game.RenderWidth, ScreenManager.Game.RenderHeight), false, false);
            cloudsParallax       = new Parallax(content.Load <Texture2D>("clouds"), 16, 0.35f, 25, (map.TileWidth * map.Width), new Viewport(0, 0, ScreenManager.Game.RenderWidth, ScreenManager.Game.RenderHeight), false, false, true);

            playerShip          = new Ship(content.Load <Texture2D>("playership"), new Rectangle(0, 0, 10, 10), null, Vector2.Zero);
            playerShip.Position = new Vector2(64, 190);

            particleController.LoadContent(content);

            projectileController = new ProjectileController(1000, sheet => new Projectile(sheet, new Rectangle(0, 0, 4, 4), null, new Vector2(0, 0)), content.Load <Texture2D>("projectiles"));
            enemyController      = new EnemyController(content.Load <Texture2D>("enemies"), content.Load <Texture2D>("boss"));
            powerupController    = new PowerupController(1000, sheet => new Powerup(sheet, new Rectangle(0, 0, 6, 6), null, Vector2.Zero), content.Load <Texture2D>("powerup"));

            powerupController.BoxCollidesWith.Add(playerShip);
            projectileController.BoxCollidesWith.Add(playerShip);
            projectileController.BoxCollidesWith.Add(enemyController);
            projectileController.BoxCollidesWith.Add(projectileController);
            enemyController.BoxCollidesWith.Add(playerShip);
            enemyController.BoxCollidesWith.Add(projectileController);

            GameController.Reset();

            //enemyController.SpawnInitial(GameController.Wave, map);

            base.LoadContent();
        }
Ejemplo n.º 30
0
        public void initial_generation()
        {
            //ARRANGE
            GameObject    hexGO           = new GameObject();
            GameObject    gameObject      = new GameObject();
            MapGeneration myMapGeneration = gameObject.AddComponent <MapGeneration>();

            myMapGeneration.HexagonPrefab = hexGO;
            myMapGeneration.MapRadius     = 10;


            myMapGeneration.HexDict = new Dictionary <Vector3Int, IHexagon>();

            //ACT
            myMapGeneration.GenerateMap();

            //ASSERT
            Assert.AreEqual(331, myMapGeneration.HexDict.Count);
        }
Ejemplo n.º 31
0
        public void find_straight_distance()
        {
            GameObject    gameObject    = new GameObject();
            MapGeneration mapGeneration = gameObject.AddComponent <MapGeneration>();

            mapGeneration.HexagonPrefab = new GameObject();
            mapGeneration.MapRadius     = 10;

            mapGeneration.HexDict = new Dictionary <Vector3Int, IHexagon>();
            mapGeneration.GenerateMap();
            mapGeneration.UpdateHexNeighbours();

            IHexagon start_hex = mapGeneration.HexDict[new Vector3Int(0, 0, 0)];
            IHexagon end_hex   = mapGeneration.HexDict[new Vector3Int(0, -4, 4)];


            int distance = 4;

            Assert.AreEqual(distance, HexMath.FindDistance(start_hex, end_hex));
        }
Ejemplo n.º 32
0
	//GameObject player;
	
	void Start() {
		grid = GetComponent<MapGeneration>();
		ingame = GetComponent<InGame> ();
		seeker = Vector3.zero;//player.transform.position;
	}
 // Use this for initialization
 void Start()
 {
     mapGen = GameObject.FindGameObjectWithTag("GameManager").GetComponent<MapGeneration>();
 }
Ejemplo n.º 34
0
    void Awake()
    {
        if(_instance == null)
        {
            //If I am the first instance, make me the Singleton
            _instance = this;
            //DontDestroyOnLoad(this);
        }
        else
        {
            //If a Singleton already exists and you find
            //another reference in scene, destroy it!
            if(this != _instance)
                Destroy(this.gameObject);
        }

        //TODO: MAKE SURE THIS DOESNT DOUBLEFIRE
        Init ();
    }