void Start () {
		if(instance != null) {
			Destroy(gameObject, 0f);
			return;
		}

		instance = this;

		player = GameObject.FindGameObjectWithTag("Player");


		float time = 0 - Time.realtimeSinceStartup;

		Random.seed = seed = (int)(seed==0?Time.realtimeSinceStartup:seed);

		mineralOccurance = new SortedList<MineralType, float>();

		foreach (MineralType m in minerals)
			mineralOccurance.Add(m,0.5f);

		textureArray = new Texture2D[sizes,2,variants,2];

		for (int size = 0; size < sizes;size++) {
			for (int variant = 0; variant < variants;variant++) {
				int res = maxRes/(int)Mathf.Pow (2, sizes-size-1);
				textureArray[size,1,variant,0] = new Texture2D(res, res);
				textureArray[size,1,variant,1] = new Texture2D(res, res);
				
				GenerateMineraledTexture (textureArray[size,1,variant,0],
				                       	 textureArray[size,1,variant,1],
				                         Color.white,
				                         Color.white,
				                         Random.Range (int.MinValue,int.MaxValue));
			}
		}

		for (int size = 0;size < sizes;size++) {
			for (int variant = 0;variant < variants;variant++) {
				int res = maxRes/(int)Mathf.Pow (2, sizes-size-1);
				textureArray[size,0,variant,0] = new Texture2D(res, res);
				textureArray[size,0,variant,1] = new Texture2D(res, res);

				GenerateGenericTexture (textureArray[size,0,variant,0],
				                        textureArray[size,0,variant,1],
				                        Color.white,
				                        Random.Range (int.MinValue,int.MaxValue));
			}
		}

		time += Time.realtimeSinceStartup;
		print ("Generated Textures in: " + time);

		enabled = player;

		lnoise = new PerlinNoise(levelSeed);
	}
Exemple #2
0
	// Use this for initialization
	void Start () {
		if (flaggedAsteroids == null)
			flaggedAsteroids = new SortedList<int, AsteroidData>();

		asteroids = new SortedList<int, Asteroid>();
		asteroidIndex = -1;

		chunkx = Mathf.FloorToInt (transform.position.x/128);
		chunky = Mathf.FloorToInt (transform.position.y/128);

		gen = transform.parent.GetComponentInChildren<AsteroidGenerator>();
		eGen = transform.parent.GetComponentInChildren<EnemyGenerator>();

		chunkSeed = gen.levelSeed+chunkx+chunky*chunkSize;
	}
Exemple #3
0
    public void generateAsteroid(AsteroidGenerator generator)
    {
        //Randomly select asteroid
        int asteroidPos = Mathf.RoundToInt(Random.value * (asteroids.Length - 1));
        GameObject asteroidPrefab = asteroids[asteroidPos];

        //Instantiate asteroid and place in the generator's location
        GameObject asteroid = (GameObject) GameObject.Instantiate(asteroidPrefab, generator.transform.position, generator.transform.rotation);
        asteroid.transform.parent = transform;

        //Set reference to asteroid field
        ((Asteroid)asteroid.GetComponent ("Asteroid")).setAsteroidField(this);

        //Add to asteroid count
        numAsteroids++;
    }
Exemple #4
0
	// Use this for initialization
	void Start () {
		asteroidGen = gameObject.GetComponentInChildren<AsteroidGenerator>();
		enemyGen = gameObject.GetComponentInChildren<EnemyGenerator>();
		//enabled = player = GameObject.FindGameObjectWithTag("Player");
		
		float t = 0 - Time.realtimeSinceStartup;

		asteroidGen.levelSeed = levelSeed;
       

		initializedChunks = new Chunk[levelSize, levelSize];
		Load ();
		t += Time.realtimeSinceStartup;

		if(boss) {
			EnemyMotherShip eship = Instantiate(bossprefab, new Vector2(0, 200), Quaternion.identity) as EnemyMotherShip;
			//DontDestroyOnLoad(eship);
			//print (eship.name);
		}

        UnityEngine.Random.seed = levelSeed;
        float r, g, b;
        r = UnityEngine.Random.Range(0.2f, 0.3f);
        g = UnityEngine.Random.Range(0.2f, 0.3f);
        b = UnityEngine.Random.Range(0.2f, 0.3f);
        asteroidGen.baseColor = new Color(r,g,b);

        if (clouds)
        {
            clouds.material.SetColor("_MultColor", new Color(UnityEngine.Random.Range(0.7f, 1), 
                UnityEngine.Random.Range(0.7f, 1), UnityEngine.Random.Range(0.7f, 1), 
                UnityEngine.Random.Range(0.2f, 0.3f)));
            clouds.material.SetColor("_AddColor", new Color(UnityEngine.Random.Range(0.4f, 1), UnityEngine.Random.Range(0.4f, 1), UnityEngine.Random.Range(0.4f, 1),0));
        }

			//print ("Loaded Chunks in: " + t);

        ShipBuilder.instance.SpawnShip();
	}
Exemple #5
0
    void Start()
    {
        if (instance != null)
        {
            Destroy(gameObject, 0f);
            return;
        }

        instance = this;

        player = GameObject.FindGameObjectWithTag("Player");


        float time = 0 - Time.realtimeSinceStartup;

        Random.seed = seed = (int)(seed == 0?Time.realtimeSinceStartup:seed);

        mineralOccurance = new SortedList <MineralType, float>();

        foreach (MineralType m in minerals)
        {
            mineralOccurance.Add(m, 0.5f);
        }

        textureArray = new Texture2D[sizes, 2, variants, 2];

        for (int size = 0; size < sizes; size++)
        {
            for (int variant = 0; variant < variants; variant++)
            {
                int res = maxRes / (int)Mathf.Pow(2, sizes - size - 1);
                textureArray[size, 1, variant, 0] = new Texture2D(res, res);
                textureArray[size, 1, variant, 1] = new Texture2D(res, res);

                GenerateMineraledTexture(textureArray[size, 1, variant, 0],
                                         textureArray[size, 1, variant, 1],
                                         Color.white,
                                         Color.white,
                                         Random.Range(int.MinValue, int.MaxValue));
            }
        }

        for (int size = 0; size < sizes; size++)
        {
            for (int variant = 0; variant < variants; variant++)
            {
                int res = maxRes / (int)Mathf.Pow(2, sizes - size - 1);
                textureArray[size, 0, variant, 0] = new Texture2D(res, res);
                textureArray[size, 0, variant, 1] = new Texture2D(res, res);

                GenerateGenericTexture(textureArray[size, 0, variant, 0],
                                       textureArray[size, 0, variant, 1],
                                       Color.white,
                                       Random.Range(int.MinValue, int.MaxValue));
            }
        }

        time += Time.realtimeSinceStartup;
        print("Generated Textures in: " + time);

        enabled = player;

        lnoise = new PerlinNoise(levelSeed);
    }
        protected override void InternalLoad()
        {
            _isPaused = false;
            _isEnded = false;
            _alphaPauseDelta = 0f;
            _alphaPause = 0f;
            _elapsedTime = 0f;

            _level = LevelBuilder.CreateLevel();
            Level.CurrentLevel = _level; // Register the level as the current one for data

            SceneCamera.SetBounds(_level.Dimensions);
            SceneCamera.Zoom = 1.6f;

            _bgAsteroidGenerator = new AsteroidGenerator(Level.CurrentLevel.BackgroundLayer, true);
            _asteroidGenerator = new AsteroidGenerator(Level.CurrentLevel.MiddleGroundLayer, false);

            _skybox = new Skybox();
            _compass.Initialize();

            initScript();

            MusicPlayer.PlayGameMusic();

            SceneCamera.FadeOut(45, null);
        }
 public void BindToGenerator(AsteroidGenerator gen)
 {
     _gen = gen;
 }
Exemple #8
0
        public override void InitializeView( )
        {
            GameObject   newContainer = new GameObject("Asteroid");
            MeshFilter   filter       = newContainer.AddComponent <MeshFilter>();
            MeshRenderer renderer     = newContainer.AddComponent <MeshRenderer>();

//			collider = newContainer.AddComponent<PolygonCollider2D>();
            collider = newContainer.AddComponent <SphereCollider>();
//			Rigidbody2D rigid = newContainer.AddComponent<Rigidbody2D>();
            Rigidbody       rigid           = newContainer.AddComponent <Rigidbody>();
            ContainerView   view            = newContainer.AddComponent <ContainerView>();
            NavMeshObstacle navMeshObstacle = newContainer.AddComponent <NavMeshObstacle>();


            view.m_contain = this;
            this.View      = view;



            Volume = Containment.Amount;
            float size = Containment.Amount;

            if (vertices == null)
            {
                vertices = new List <Vector2>();
                AsteroidGenerator.GenerateCircular(size, 20f, 60f, out vertices);
            }


            int[] indices;
            Mesh  mesh = new Mesh();

            mesh.MarkDynamic();

            Triangulator tr = new Triangulator(vertices.ToArray());

            indices = tr.Triangulate();

            Vector3[] vertices3d = new Vector3[vertices.Count];
            for (int j = 0; j < vertices3d.Length; j++)
            {
                vertices3d[j].x = vertices[j].x;
                vertices3d[j].z = vertices[j].y;
            }

            mesh.vertices  = vertices3d;
            mesh.triangles = indices;
            mesh.RecalculateBounds();

            filter.sharedMesh = mesh;



//			collider.points = vertices.ToArray();
            collider.radius = size;

            rigid.mass = size * 100f;

            rigid.constraints = RigidbodyConstraints.FreezePositionY |
                                RigidbodyConstraints.FreezeRotationX |
                                RigidbodyConstraints.FreezeRotationZ;
            rigid.useGravity = false;

            renderer.sharedMaterial = new UnityEngine.Material(Shader.Find("Diffuse"));


            navMeshObstacle.shape               = NavMeshObstacleShape.Capsule;
            navMeshObstacle.carving             = true;
            navMeshObstacle.carveOnlyStationary = true;
            navMeshObstacle.radius              = size + 0.5f;
        }
 public void Init()
 {
     asteroidGen = GameObject.FindGameObjectWithTag("Asteroid Generator").GetComponent <AsteroidGenerator>();
 }