Example #1
0
    void Awake()
    {
        _mousePos = new Vector2();
        //// TEMPORARY
        PlayerName      = "Drewon";
        PlayerMaxHealth = 100;
        PlayerMaxMana   = 20;
        Softcore        = false;

        // References
        _animator   = GetComponent <PlayerAnimator>();
        sRB         = gameObject.GetComponent <SandboxRB>();
        _mainCamera = GameObject.FindGameObjectWithTag("MainCamera");
        meshObject  = transform.GetChild(1).gameObject;
        MeshControl.playerMeshObject = meshObject;
        playerMaterial = Resources.Load <Material>("Textures/Materials/PlayerMaterial");
        _chunkControl  = GameObject.FindGameObjectWithTag("GameController");
        _chunkControl.GetComponent <ChunkControl>().playerCharacter = this.gameObject;
        _cC = _chunkControl.GetComponent <ChunkControl>();
        MapData.chunkControl = _chunkControl; // change
        Inventory.SetPlayerObject(this.gameObject);


        IsFacingRight  = true;
        facingSnapShot = true;
        cameraVector   = new Vector3(0, 0, -25);

        itemUseMethods = GetMethodsList(typeof(ItemScripts));


        MiningDistance = 5;
        _playerLight   = new LightSource(15, playerPosition, Color.clear);
        LightControl.dynamicLights.Add(_playerLight);
    }
Example #2
0
 void Start()
 {
     control   = worldGeometry.GetComponent("ChunkControl") as ChunkControl;
     chunkSize = control.chunkSize;
     voxelSize = control.voxelSize;
     mesh      = GetComponent <MeshFilter> ().mesh;
     render    = GetComponent <MeshRenderer>();
     generateMesh();
 }
Example #3
0
 void Start()
 {
     control = controlObject.GetComponent("ChunkControl") as ChunkControl;
 }
Example #4
0
    public void GenerateMap(int sizeX, int sizeY)
    {
        //var random = new System.Random(seed);

        ChunkInfo.Init();
        ChunkControls = new ChunkControl[sizeX][];

        //generate map, change chance with distance from center point
        for (int i = 0; i < sizeX; i++)
        {
            ChunkControls[i] = new ChunkControl[sizeY];
            for (int j = 0; j < sizeY; j++)
            {
                Chunk      newChunk   = ChunkInfo.GetChunk(Random.Range(0, ChunkInfo.Chunks.Count));
                GameObject newChunkGO = GameObject.Instantiate(Resources.Load("Prefabs/Chunks/" + newChunk.ID) as GameObject);
                newChunkGO.transform.SetParent(transform);
                WidthX  = sizeX * ChunkInfo.ChunkSize.x;
                HeightY = sizeY * ChunkInfo.ChunkSize.y;
                float posX = -(WidthX / 2) + (ChunkInfo.ChunkSize.x / 2) + ChunkInfo.ChunkSize.x * i;
                float posY = -(HeightY / 2) + (ChunkInfo.ChunkSize.y / 2) + ChunkInfo.ChunkSize.y * j;
                newChunkGO.transform.localPosition = new Vector3(posX, posY, 30f);
                var newChunkControl = newChunkGO.AddComponent <ChunkControl>();
                ChunkControls[i][j] = newChunkControl;

                NetworkServer.Spawn(newChunkGO);

                float distX = i - sizeX / 2f;
                float distY = j - sizeY / 2f;
                float distanceFromCenter = Mathf.Sqrt(distX * distX + distY * distY);

                int   numOfObstacles = 0;
                float tempNumber     = Random.Range(0, distanceFromCenter + 5);
                if (tempNumber > 3)
                {
                    numOfObstacles = 1;
                }
                if (tempNumber > 5)
                {
                    numOfObstacles = 2;
                }

                //Use script from darwin to generate random items (bombs)
                for (int k = 0; k < numOfObstacles; k++)
                {
                    //int dice = Random.Range(0, 100);
                    //string itemName = null;
                    //if (dice < 45) {
                    //    itemName = "CollectableLightning";
                    //}
                    //else if (dice < 75) {
                    //    itemName = "CollectableBomb";
                    //}
                    //else {
                    //    itemName = "CollectableShuriken";
                    //}
                    //GenerateItem(itemName);

                    int  itemPosX = 0, itemPosY = 0;
                    bool placeable = false;
                    while (!placeable)
                    {
                        int childIndex = Random.Range(0, 36);
                        if (!newChunkGO.transform.GetChild(childIndex).GetComponent <BoxCollider>())
                        {
                            placeable = true;
                            itemPosX  = childIndex % 6;
                            itemPosY  = childIndex / 6;
                        }
                    }
                    Vector3 pos = new Vector3(-0.4f + itemPosX * 0.16f, -0.4f + itemPosY * 0.16f, -1);
                    //Lucas was here
                    //Create different collectables based on chance
                    GameObject newCollectable;
                    int        dice = Random.Range(0, 100);
                    if (dice < 45)
                    {
                        newCollectable = GameObject.Instantiate(Resources.Load("Prefabs/CollectableLightning") as GameObject);
                    }
                    else if (dice < 75)
                    {
                        newCollectable = GameObject.Instantiate(Resources.Load("Prefabs/CollectableBomb") as GameObject);
                    }
                    else
                    {
                        newCollectable = GameObject.Instantiate(Resources.Load("Prefabs/CollectableShuriken") as GameObject);
                    }
                    newCollectable.transform.position = newChunkGO.transform.position + pos * 5f;
                    NetworkServer.Spawn(newCollectable);
                }
            }
        }

        CmdGenerateItem("CollectableBomb");
    }
 public void RemoveChunk(ChunkControl chunkControl)
 {
     ChunkControls.Remove(chunkControl);
 }