Inheritance: MonoBehaviour
Ejemplo n.º 1
0
    // Start is called before the first frame update
    void Awake()
    {
        levelBlocks = new LevelBlock[row * col];

        for (int i = 0; i < row; i++)
        {
            for (int t = 0; t < col; t++)
            {
                int idx = i * col + t;

                Vector3 pos = new Vector3(t * 2, 0, i * 2);
                levelBlocks[idx] = new LevelBlock(i, t, pos);

                NavMeshHit hit;

                if (NavMesh.SamplePosition(pos, out hit, 0.2f, NavMesh.AllAreas))
                {
                    //levelBlocks[idx].pos = hit.position;
                    levelBlocks[idx].isOnNavMesh = true;
                    blocksOnMesh.Add(levelBlocks[idx]);
                }
                else
                {
                    levelBlocks[idx].isOnNavMesh = false;
                }
            }
        }

        InitThreatScore();
        SpawnHealth();

        playerHealth = GetComponent <CompleteProject.PlayerHealth>();
    }
Ejemplo n.º 2
0
    int CaculateMoveCost(LevelBlock startBlock, LevelBlock endBlock)
    {
        int distance_x = startBlock.col - endBlock.col;
        int distance_y = startBlock.row - endBlock.row;

        return(distance_x * distance_x + distance_y * distance_y);
    }
Ejemplo n.º 3
0
    int EvaluateOcculsion(int row, int col)
    {
        if (row >= 0 && col >= 0)
        {
            int idx = row * this.col + col;

            if (idx < levelBlocks.Length)
            {
                int occulsion = 0;

                LevelBlock centerBlock = GetBlock(row, col);

                if (centerBlock != null)
                {
                    List <LevelBlock> blocksInRange = GetBlocksInRange(centerBlock.pos, 1);

                    occulsion = 9 - blocksInRange.Count;
                }

                return(occulsion);
            }
            else
            {
                return(-1);
            }
        }
        else
        {
            return(-1);
        }
    }
Ejemplo n.º 4
0
    public LevelBlock[] GetSafePath(Vector3 center, int pathNodeCount, int radius, float agreesion)
    {
        ResetDebugHighlight();

        LevelBlock[]      results       = new LevelBlock[pathNodeCount];
        List <LevelBlock> blocksInRange = new List <LevelBlock>();

        for (int i = 0; i < levelBlocks.Length; i++)
        {
            blocksInRange = GetBlocksInRange(levelBlocks[i].pos, 5);
            levelBlocks[i].EvaluateThreat(blocksInRange, factors);
            //levelBlocks[i].threatScore = EvaluateThreatScore(levelBlocks[i], 5);
        }

        for (int i = 0; i < pathNodeCount; i++)
        {
            if (i == 0)
            {
                blocksInRange = GetBlocksInRange(center, radius);
                blocksInRange.Sort();
            }
            else
            {
                blocksInRange = GetBlocksInRange(results[i - 1].pos, radius);
                blocksInRange.Sort();
            }

            results[i] = blocksInRange[0];
            results[i].debugHighlight = true;
        }

        return(results);
    }
Ejemplo n.º 5
0
    public void AddLevelBlock()
    {
        // Random.Range => Un numero aleatorio entre los datos que le das
        int randomIndex = Random.Range(0, allTheLevelBlocks.Count);

        LevelBlock currentBlock = (LevelBlock)Instantiate(allTheLevelBlocks[randomIndex]);

        currentBlock.transform.SetParent(this.transform, false);

        Vector3 spawnPosition = Vector3.zero;

        if (currentBlocks.Count == 0)
        {
            spawnPosition = levelStartPoint.position;
        }
        else
        {
            spawnPosition = currentBlocks[currentBlocks.Count - 1].exitPoint.position;
        }

        Vector3 correction = new Vector3(spawnPosition.x - currentBlock.startPoint.position.x,
                                         spawnPosition.y - currentBlock.startPoint.position.y, 0);

        currentBlock.transform.position = correction;
        currentBlocks.Add(currentBlock);
    }
Ejemplo n.º 6
0
    public void AddNewBlock()
    {
        // Seleccionar un bloque aleatorio entre los que tenemos disponibles
        int randomIndex = Random.Range(0, allTheLevelBlocks.Count);

        LevelBlock block = (LevelBlock)Instantiate(allTheLevelBlocks [randomIndex]);          //Vamos a coger cualquier bloque que ya se ha cargado en el nivel (randomIndex) y tendra como variable block

        block.transform.SetParent(this.transform, false);


        //Posicion del bloque
        Vector3 blockPosition = Vector3.zero;

        if (currentLevelBlocks.Count == 0)
        {
            //Vamos a colocar el primer bloque en pantalla
            blockPosition = levelInitialPosition.position;
        }
        else
        {
            //Ya tengo bloques en pantalla lo empalmo al ultimo disponible
            blockPosition = currentLevelBlocks [currentLevelBlocks.Count - 1].exitPoint.position;             // De todos los bloques que hay en pantalla se coge el ultimo, tambien hace que el nuevo bloque(blockPosition)
                                                                                                              //se coloque justo en el punto de salida del bloque anterior
        }

        block.transform.position = blockPosition;
        currentLevelBlocks.Add(block);
    }
Ejemplo n.º 7
0
    public void DrawOrbs()
    {
        InformOrbs("ResetOrb", null);
        if (Active)
        {
            GameObject selectedObject = Selection.activeGameObject;
            if (selectedObject == null)
            {
                return;
            }
            while (selectedObject.transform.parent != null &&
                   selectedObject.transform.parent.name != "LevelBlocks" &&
                   !selectedObject.name.Contains("LevelEditor"))
            {
                selectedObject = selectedObject.transform.parent.gameObject;
            }
            if (selectedObject.name.Contains("LevelEditor"))
            {
                return;
            }
            if (!selectedObject.CompareTag("LevelBlock"))
            {
                return;
            }
            LevelBlock blockScript = selectedObject.GetComponent <LevelBlock>();
            blockSize = blockScript == null ? defaultBlockSize : blockScript.BlockSize;

            SetOrbPosition(selectedObject);
            InformOrbs("SetObject", selectedObject);
            InformOrbs("Look", null);
        }
    }
Ejemplo n.º 8
0
    // Update is called once per frame
    void Update()
    {
        if (evaluateThreat)
        {
            evaluateTimer += Time.deltaTime;

            if (evaluateTimer > 0.25f)
            {
                for (int i = 0; i < levelBlocks.Length; i++)
                {
                    levelBlocks[i].enemyCount = CheckEnemyCount(levelBlocks[i].pos, 1.25f);
                }

                evaluateTimer = 0;
            }
        }

        aggression = EvaluateAggression(0, 0.5f);

        if (Input.GetKeyDown(KeyCode.T))
        {
            startBlock = GetPlayerBlock();

            for (int i = 0; i < levelBlocks.Length; i++)
            {
                List <LevelBlock> blocksInRange = GetBlocksInRange(levelBlocks[i].pos, 5);
                levelBlocks[i].EvaluateThreat(blocksInRange, factors);
            }

            pathBlocks = AStarPathfinding(startBlock, GetBlock(18, 18));
        }
    }
Ejemplo n.º 9
0
        public void UpdateTargetAmount(LevelBlock lvBlock)
        {
            if (levelBlock is LevelBoosterType)
            {
                return;
            }
            bool isChange = false;

            if (levelBlock is LevelBlockType && lvBlock is LevelBlockType)
            {   // block
                if ((levelBlock as LevelBlockType).type == (lvBlock as LevelBlockType).type)
                {
                    ++targetAmount;
                    isChange = true;
                }
            }
            else if (levelBlock is LevelBlock && lvBlock is LevelBlock)
            {   // blocker
                if ((levelBlock as LevelBlock).blockerType == (lvBlock as LevelBlock).blockerType)
                {
                    ++targetAmount;
                    isChange = true;
                }
            }
            if (isChange)
            {
                amountText.text = (targetAmount - currentAmount).ToString();
            }
        }
Ejemplo n.º 10
0
    public void RemoveLevelBlock()
    {
        LevelBlock oldBlok = currentLevelBlock[0];

        currentLevelBlock.Remove(oldBlok);
        Destroy(oldBlok.gameObject);
    }
Ejemplo n.º 11
0
    public void AddNewBlock()
    {
        //Seleccionar un bloque aleatorio entre los disponibles
        int randomIndex = Random.Range(0, allTheLevelBlocks.Count);

        if (isGenerateinitialBlock)
        {
            randomIndex = 0;
        }
        LevelBlock block = (LevelBlock)Instantiate(allTheLevelBlocks [randomIndex]);

        block.transform.SetParent(this.transform, false);

        //Posición del bloque
        Vector3 BlockPosition = Vector3.zero;

        if (currentLevelBlocks.Count == 0)
        {
            // Colocar el primer Bloque en Pantalla
            BlockPosition = levelInitialPoint.position;
        }
        else
        {
            // Ya hay bloques y lo empalmo con el ultimo disponible
            BlockPosition = currentLevelBlocks [currentLevelBlocks.Count - 1].exitPoint.position;
        }
        block.transform.position = BlockPosition;
        currentLevelBlocks.Add(block);
    }
Ejemplo n.º 12
0
    public void RemoveLevelBlock()                   //remover bloques cuando ya el personaje pase por ellos
    {
        LevelBlock oldBlock = currentLevelBlocks[0]; //el bloque viejo que queremos destruir

        currentLevelBlocks.Remove(oldBlock);         //invocamos el metodo remove para eliminar
        Destroy(oldBlock.gameObject);                //y al eliminarlos los destruimos
    }
Ejemplo n.º 13
0
    public void AddNewBlock()
    {
        // Seleccionar un bloque aleatorio entre los que tenemos disponibles
        int randomIndex = Random.Range(0, allLevelBlocks.Count);

        if (isGeneratingInitialBlocks)
        {
            randomIndex = 0;
        }
        LevelBlock block = (LevelBlock)Instantiate(allLevelBlocks[randomIndex]);

        block.transform.SetParent(this.transform, false);

        // Posición del bloque
        Vector3 blockPosition = Vector3.zero;

        if (currentLevelBlocks.Count == 0)
        {
            // Vamos a colocar el primer bloque en pantalla
            blockPosition = levelInitialPoint.position;
        }
        else
        {
            // Ya tengo bloques en pantalla, lo empalmo al ultimo disponible
            blockPosition = currentLevelBlocks[currentLevelBlocks.Count - 1].exitPoint.position;
        }
        block.transform.position = blockPosition;
        currentLevelBlocks.Add(block);
    }
Ejemplo n.º 14
0
    public void RemoveOldBlock()
    {
        LevelBlock block = currentLevelBlocks[0];         // El bloque más antiguo es siempre el primero de la lista

        currentLevelBlocks.Remove(block);
        Destroy(block.gameObject);
    }
Ejemplo n.º 15
0
    public void RemoveBlock()
    {
        LevelBlock block = current[0];

        current.Remove(block);
        Destroy(block.gameObject);
    }
Ejemplo n.º 16
0
    public void AddNewBlock()
    {
        // Seleccionar un bloque aleatorio entre los que tenemos disponibles
        int randomIndex = Random.Range(0, allLevelBlocks.Count);

        if (isGeneratingInitialBlocks)
        {
            randomIndex = 0;
        }
        // Se crea una copia de uno de los niveles que ya existen y se asigna a la variable 'block'.
        LevelBlock block = (LevelBlock)Instantiate(allLevelBlocks[randomIndex]);

        block.transform.SetParent(this.transform, false);         // El padre del bloque siempre es él mismo

        // Posicion del bloque
        Vector3 blockPosition = Vector3.zero;

        if (currentLevelBlocks.Count == 0)
        {
            // Vamos a colocar el primer bloque en pantalla
            blockPosition = levelInitialPosition.position;
        }
        else
        {
            // Ya tengo bloques en pantalla y lo empalmo al último disponible.
            blockPosition = currentLevelBlocks[currentLevelBlocks.Count - 1].exitPoint.position;
        }

        block.transform.position = blockPosition;
        currentLevelBlocks.Add(block);         // Se añade a la lista de bloques
    }
Ejemplo n.º 17
0
    public void RemoveLevelBlock()                   //Remover bloque de nivel
    {
        LevelBlock oldBlock = currentLevelBlocks[0]; //Variable que se refiere al bloque de nivel de los actuales, en la posicion 0. La varianle es de tipo Level Block porque se refiere a un objeto de la lista currentLevelBlocks la cual es de ese tipo

        currentLevelBlocks.Remove(oldBlock);         //Se usa el metodo Remove() de currentLevelBlocks(por ser una List<>), para eliminar oldBlock de la lista
        Destroy(oldBlock.gameObject);                //Y con Destroy() se elimina graficamente del juego
    }
Ejemplo n.º 18
0
    public void GenerateLevel()
    {
        for (int i = 0; i < 8; i++)
        {
            LevelBlock _newBlock = null;
            if (i < 3)
            {
                _newBlock = levelBlockPooler.GetLevelBlock(BlockDifficulty.None);
            }
            else
            {
                _newBlock = levelBlockPooler.GetLevelBlock(BlockDifficulty.Easy);
            }
            levelBlocks.Add(_newBlock);
            if (i == 0)
            {
                _newBlock.gameObject.SetActive(true);
                _newBlock.InitializeBlock(CollectableCallback, numBlocksGenerated, coinSpinTime);
                _newBlock.SetPosition(Vector3.zero);
                _newBlock.SetSpeed(currentBlockSpeed);
                numBlocksGenerated++;
            }
            else
            {
                _newBlock.gameObject.SetActive(true);
                _newBlock.InitializeBlock(CollectableCallback, numBlocksGenerated, coinSpinTime);
                _newBlock.SetPosition(levelBlocks[i - 1].GetPosition() + (Vector3.forward * levelBlockSize));
                _newBlock.SetSpeed(currentBlockSpeed);
                numBlocksGenerated++;
            }
        }

        rhinoDetection.SetSpeed(currentBlockSpeed);
    }
Ejemplo n.º 19
0
    public void RemoveOldBlock()
    {
        LevelBlock block = currentLevelBlocks[0];

        currentLevelBlocks.Remove(block);
        Destroy(block.gameObject);
    }
Ejemplo n.º 20
0
 public void UpdateTargetAmount(LevelBlock lvBlock)
 {
     foreach (var element in group.GetComponentsInChildren <GoalUIElement>())
     {
         element.UpdateTargetAmount(lvBlock);
     }
 }
Ejemplo n.º 21
0
    public void RemoveOldestLevelBlock()
    {
        LevelBlock oldestBlock = currentBlocks[0];

        currentBlocks.Remove(oldestBlock);
        Destroy(oldestBlock.gameObject);
    }
Ejemplo n.º 22
0
    public void AddLevelBlock()
    {
        //Generamos un número aleatorio entero entre a<= y b<
        int randomIndex = Random.Range(0, allTheLevelBlocks.Count);

        LevelBlock currentBlock = (LevelBlock)Instantiate(allTheLevelBlocks[randomIndex]);

        currentBlock.transform.SetParent(this.transform, false); //Pone el nuevo bloque de nivel como hijo del LevelGenerator

        Vector3 spawnPosition = Vector3.zero;

        if (currentBlocks.Count == 0)
        {
            spawnPosition = levelStartPoint.position;
        }
        else
        {
            spawnPosition = currentBlocks[currentBlocks.Count - 1].exitPoint.position;
        }

        Vector3 correction = new Vector3(spawnPosition.x - currentBlock.startPoint.position.x, spawnPosition.y - currentBlock.startPoint.position.y, 0);

        currentBlock.transform.position = correction;
        currentBlocks.Add(currentBlock);
    }
    public void RemoveLevelBlock()
    {
        LevelBlock oldBlock = CurrentLevelBlocks[0];

        CurrentLevelBlocks.Remove(oldBlock);
        Destroy(oldBlock.gameObject);
    }
Ejemplo n.º 24
0
    public void AddLevelBlock()
    {
        CheckDistance();
        // Random.Range => Un numero aleatorio entre los datos que le das
        int        randomIndex  = Random.Range(0, MaxIndex);
        LevelBlock currentBlock = (LevelBlock)Instantiate(SelectBlock(randomIndex));            //Funcion que devuelve el bloque

        //LevelBlock currentBlock = (LevelBlock)Instantiate(basicLevelBlocks[randomIndex]);
        currentBlock.transform.SetParent(this.transform, false);

        Vector3 spawnPosition = Vector3.zero;

        if (currentBlocks.Count == 0)
        {
            spawnPosition = levelStartPoint.position;
        }
        else
        {
            spawnPosition = currentBlocks[currentBlocks.Count - 1].exitPoint.position;
        }

        Vector3 correction = new Vector3(spawnPosition.x - currentBlock.startPoint.position.x,
                                         spawnPosition.y - currentBlock.startPoint.position.y, 0);

        currentBlock.transform.position = correction;
        currentBlocks.Add(currentBlock);
    }
Ejemplo n.º 25
0
    public void RemoveLevelBlock()                   //ocurre cada vez que cruzamos una exitZone
    {
        LevelBlock oldBlock = currentLevelBlocks[0]; //inicializamos el bloque a destruir

        currentLevelBlocks.Remove(oldBlock);         //lo eliminamos del listado
        Destroy(oldBlock.gameObject);                //destruimos ese gameObject
    }
Ejemplo n.º 26
0
    private void Start()
    {
        //Camera.main.transparencySortMode = TransparencySortMode.Orthographic;
        levelParser = GetComponent <LevelParser>();
        levelData   = levelParser.LoadLevelFromFile();
        currBlock   = 0;

        currScrollSpeed = normalScrollSpeed;

        bottomBlock = GenLoadedLevelBlock(currBlock, new Vector2(0f, 0f), currScrollSpeed, 0.5f, 20f);
        topBlock    = GenLoadedLevelBlock(currBlock + 1, new Vector2(0f, 10f), currScrollSpeed, 0f, 20f);
        currBlock++;
        //bottomBlock = CreateLevelBlock(new Vector2(0f, 0f), currScrollSpeed, 0.5f, 20f,
        //    new List<Vector2>() { new Vector2(3.5f, 0) },
        //    new List<Vector2>() { new Vector2(-9f, 3) },
        //    new List<Vector2>() { new Vector2(3.5f, -2f), new Vector2(-3.5f, -2f) },
        //                                backgroundTex[0]);

        //topBlock = CreateLevelBlock(new Vector2(0f, 10f), currScrollSpeed, 0f, 20f,
        //    new List<Vector2>() { new Vector2(3.5f, 0) },
        //    new List<Vector2>() { new Vector2(-9f, 3) },
        //    new List<Vector2>() { new Vector2(3.5f, -2f), new Vector2(-3.5f, -2f) },
        //                                backgroundTex[0]);


        character.boundary      = screenBoundary;
        character.PeakTouched  += OnCenteringBegin;
        character.CenteringEnd += OnCenteringEnd;
        //OnPhaseChange

        centering = false;
        StartCoroutine(CheckLevelEndCoroutine());
    }
Ejemplo n.º 27
0
    public override void OnInspectorGUI()
    {
        LevelBlock _target = target as LevelBlock;

        base.OnInspectorGUI();

        if (GUILayout.Button("Realign"))
        {
            normalForTarget = Vector3.Cross((_target.endPoint1.position - _target.endCenter.position),
                                            (_target.endPoint2.position - _target.endCenter.position)).normalized;
            normalForNextBlock = Vector3.Cross((_target.nextBlockPoint1.position - _target.nextBlockCenter.position),
                                               (_target.nextBlockPoint2.position - _target.nextBlockCenter.position)).normalized;
            float angle = Vector3.Angle(normalForTarget, normalForNextBlock);
            Debug.Log(angle);
            if (Math.Abs(angle - 180f) > 0.01)
            {
                //_target.nextBlock.transform.rotation = Quaternion.FromToRotation(normalForNextBlock, -normalForTarget);
            }

            float distance = Vector3.Distance(_target.nextBlockCenter.position, _target.endCenter.position);
            if (distance > 0.003)
            {
                _target.nextBlock.transform.position = _target.nextBlock.transform.position + (_target.endCenter.position - _target.nextBlockCenter.position);
            }
        }
        Debug.DrawRay(_target.endCenter.position, normalForTarget, Color.red);
        //Debug.DrawRay(_target.nextBlockCenter.position, _target.nextBlockCenter.up, Color.magenta);
        //Debug.DrawRay(_target.nextBlockCenter.position, normalForNextBlock, Color.green);
    }
Ejemplo n.º 28
0
    private void Option_Pitch(GameObject selectedObject)
    {
        bool pitch = true; //only do pitch change if all children can change

        foreach (Transform child in selectedObject.transform)
        {
            LevelBlock script = child.GetComponent <LevelBlock>();
            if (script == null || !script.Pitch)
            {
                pitch = false;
            }
        }
        if (pitch)
        {
            GUILayout.Space(10);
            EditorGUILayout.LabelField("Change Pitch");
            GUILayout.BeginHorizontal();
            increasePitch = GUILayout.TextField(increasePitch, GUILayout.Width(100));
            float increaseInt = 0;
            if (increasePitch.Contains("%"))
            {
                float.TryParse(increasePitch.Replace("%", ""), out increaseInt);
            }
            else
            {
                float.TryParse(increasePitch, out increaseInt);
            }

            if (GUILayout.Button("Change Pitch") && increaseInt != 0)
            {
                EditorUtility.DisplayDialog("SORRY",
                                            "This feature is still a work in progress. I will update you when it is complete",
                                            "OK");
                ////rotate
                //Vector3 byAngle = new Vector3(increaseInt, 0, 0);

                //foreach (Transform child in selectedObject.transform)
                //{
                //    if (increaseInt + child.eulerAngles.x > 45)
                //        increaseInt = 45 - child.eulerAngles.x;
                //    Vector3 scale = child.localScale;
                //    Vector3 pos = child.position;
                //    float cTheta = Mathf.Cos(increaseInt * Mathf.PI / 180);
                //    float h = Mathf.Abs(child.eulerAngles.x) < Mathf.Abs(byAngle.x) ? scale.z / cTheta : scale.z * cTheta;
                //    float o = Mathf.Tan(increaseInt * Mathf.PI / 180) * 60;

                //    scale.z = h;
                //    pos.y += o/2;

                //    child.localScale = scale;
                //    child.position = pos;
                //    Quaternion toAngle = Quaternion.Euler(child.eulerAngles + byAngle);
                //    child.rotation = toAngle;
                //}
                increasePitch = "";
            }
            GUILayout.EndHorizontal();
        }
    }
 protected override void OnStop()
 {
     if (lastRequest != null && agent.gameObject.activeSelf)
     {
         agent.ResetPath();
     }
     lastRequest = null;
 }
Ejemplo n.º 30
0
    protected override void OnUpdate()
    {
        base.OnUpdate();

        LevelBlock healthBlock = levelScanner.GetHealthBlock();

        this.healthBlock.value = healthBlock;
    }
Ejemplo n.º 31
0
    public void AddBlock()
    {
        currentBlock = //Instantiate(
            blockSources[blockIndex];
            //) as LevelBlock;

        currentBlock.transform.parent = blockParent;

        blockIndex++;
        blockIndex %= blockSources.Length;
    }
Ejemplo n.º 32
0
    public int[] GetTileCoords(LevelBlock l)
    {
        int[] coords = null;

        for (int y = 0; y < 12; y++)
            for (int x = 0; x < 12; x++)
                if (levelBlocks[x][y] == l)
                    coords = new int[] { x, y };

        return coords;
    }
Ejemplo n.º 33
0
    // Update is called once per frame
    void Update()
    {
        //movement

        //adjust if colliding with multiple blocks
        if (blocksColliding.Count > 1)
        {
            float distance = 100.0f;
            LevelBlock closestBlock = null;
            Vector3 playerPos = new Vector3(transform.position.x - 0.08f, transform.position.y + 0.08f, 0);

            foreach (LevelBlock l in blocksColliding)
                if (Vector3.Distance(playerPos, l.transform.position) < distance)
                {
                    distance = Vector3.Distance(playerPos, l.transform.position);
                    closestBlock = l;
                }

            inBlock = closestBlock;

            if (facing == Direction.left || facing == Direction.right)
                transform.position = new Vector3(transform.position.x, inBlock.transform.position.y - 0.08f, 0);
            else
                transform.position = new Vector3(inBlock.transform.position.x + 0.08f, transform.position.y, 0);
        }
        else
            if (blocksColliding.Count == 1)
                inBlock = blocksColliding[0];

        if (!isDieing)
        {
            if (!isFiring)
            {
                if (Input.GetKey(KeyCode.RightArrow))
                {
                    if (!isAdjusting)
                    {
                        move(Direction.right);

                        isMoving = true;
                        isAdjusting = false;
                        facing = Direction.right;
                    }
                }
                else if (Input.GetKey(KeyCode.LeftArrow))
                {
                    if (!isAdjusting)
                    {
                        move(Direction.left);

                        isMoving = true;
                        isAdjusting = false;
                        facing = Direction.left;
                    }
                }
                else if (Input.GetKey(KeyCode.UpArrow))
                {
                    if (!isAdjusting)
                    {
                        move(Direction.up);

                        isMoving = true;
                        isAdjusting = false;
                        facing = Direction.up;
                    }
                }
                else if (Input.GetKey(KeyCode.DownArrow))
                {
                    if (!isAdjusting)
                    {
                        move(Direction.down);

                        isMoving = true;
                        facing = Direction.down;
                    }
                }
                else
                {
                    if (isMoving)
                    {
                        isAdjusting = true;
                    }
                    else
                        isAdjusting = false;
                }
            }

            //keep moving if not in center of tile
            if (isAdjusting)
            {
                //keep moving until fully in block
                switch (facing)
                {
                    case Direction.right:
                        transform.Translate(Vector2.right * movementSpeed * Time.deltaTime);
                        if (transform.position.x - 0.08f >= inBlock.transform.position.x)
                        {
                            isMoving = false;
                            isAdjusting = false;
                        }
                        break;
                    case Direction.left:
                        transform.Translate(-Vector2.right * movementSpeed * Time.deltaTime);
                        if (transform.position.x + 0.08f <= inBlock.transform.position.x + 0.16f)
                        {
                            isMoving = false;
                            isAdjusting = false;
                        }
                        break;
                    case Direction.up:
                        if (transform.localScale.x > 0)
                            transform.Translate(Vector2.right * movementSpeed * Time.deltaTime);
                        else
                            transform.Translate(-Vector2.right * movementSpeed * Time.deltaTime);

                        if (transform.position.y + 0.08f > inBlock.transform.position.y)
                        {
                            isMoving = false;
                            isAdjusting = false;
                        }

                        break;
                    case Direction.down:
                        if (transform.localScale.x > 0)
                            transform.Translate(Vector2.right * movementSpeed * Time.deltaTime);
                        else
                            transform.Translate(-Vector2.right * movementSpeed * Time.deltaTime);

                        if (transform.position.y + 0.08f < inBlock.transform.position.y)
                        {
                            isMoving = false;
                            isAdjusting = false;
                        }
                        break;
                }
            }

            //fire
            if (Input.GetKey(KeyCode.Space) && !isMoving)
            {
                isFiring = true;
                shootSound.Play();
            }

            if (isFiring)
            {
                currentFiringTime += Time.deltaTime;
                if (currentFiringTime >= firingTotalTime)
                {
                    isFiring = false;
                    currentFiringTime = 0;
                }
            }
        }
        else
        {
            //currently dieing
            currentDeathStateTime += Time.deltaTime;
            if(currentDeathStateTime >= deathStateWaitTime)
            {
                deathState++;
                currentDeathStateTime = 0;
                if (deathState == 3)
                    deathSound.Play();
            }

            if (deathState == 4)
            {
                Destroy(gameObject);
            }
        }

        updateAnimator();

        blocksColliding.Clear();
    }
Ejemplo n.º 34
0
    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.GetComponent<LevelBlock>() != null)
        {
            Level l = GameObject.Find("Level").GetComponent<Level>();
            inBlock = other.GetComponent<LevelBlock>();
            int[] myPos = l.GetTileCoords(inBlock);

            bool dugRight, dugLeft, dugUp, dugDown;
            dugRight = dugLeft = dugUp = dugDown = false;

            if (myPos[0] != 0)
                dugLeft = l.levelBlocks[myPos[0] - 1][myPos[1]].dug;

            if (myPos[0] != 11)
                dugRight = l.levelBlocks[myPos[0] + 1][myPos[1]].dug;

            if (myPos[1] != 0)
                dugUp = l.levelBlocks[myPos[0]][myPos[1] - 1].dug;

            if (myPos[1] != 11)
                dugDown = l.levelBlocks[myPos[0]][myPos[1] + 1].dug;

            Player.Direction prevFacing = facing;

            switch (facing)
            {
                case Player.Direction.right:
                    if (!dugRight && !dugUp && !dugDown)//turn around
                        facing = Player.Direction.left;

                    if (!dugRight && dugUp && !dugDown)// turn up
                        facing = Player.Direction.up;

                    if (!dugRight && !dugUp && dugDown)// turn down
                        facing = Player.Direction.down;

                    if(!dugRight && dugUp && dugDown)// turn up or down
                    {
                        int rand = Random.Range(0,2);
                        facing = (rand == 0? Player.Direction.up: Player.Direction.down);
                    }

                    break;

                case Player.Direction.left:
                    if (!dugLeft && !dugUp && !dugDown)// turn around
                        facing = Player.Direction.right;

                    if (!dugLeft && dugUp && !dugDown)// turn up
                        facing = Player.Direction.up;

                    if (!dugLeft && !dugUp && dugDown) //turn down
                        facing = Player.Direction.down;

                    if (!dugLeft && dugUp && dugDown) //turn up or down
                    {
                        int rand = Random.Range(0, 2);
                        facing = (rand == 0 ? Player.Direction.up : Player.Direction.down);
                    }

                    break;

                case Player.Direction.up:
                    if (!dugUp && !dugLeft && !dugRight)// turn around
                        facing = Player.Direction.down;

                    if (!dugUp && dugLeft && !dugRight) //turn left
                        facing = Player.Direction.left;

                    if (!dugUp && !dugLeft && dugLeft) // turn right
                        facing = Player.Direction.right;

                    if(!dugUp && dugLeft && dugLeft) // turn right or left
                    {
                        int rand = Random.Range(0, 2);
                        facing = (rand == 0 ? Player.Direction.left : Player.Direction.right);
                    }

                    break;

                case Player.Direction.down:
                    if (!dugDown && !dugLeft && !dugRight) //turn around
                        facing = Player.Direction.up;

                    if (!dugDown && dugLeft && !dugRight)
                    //turn left
                        facing = Player.Direction.left;

                    if (!dugDown && !dugLeft && dugRight) // turn right
                        facing = Player.Direction.right;

                    if (!dugDown && dugLeft && dugRight) //turn right or left
                    {
                        int rand = Random.Range(0, 2);
                        facing = (rand == 0 ? Player.Direction.left : Player.Direction.right);
                    }

                    break;
            }

            if (prevFacing != facing)
            {
                Vector3 blockPos = other.gameObject.transform.position;
                transform.position = new Vector3(blockPos.x + 0.08f, blockPos.y - 0.08f, 0);
            }
        }
    }
Ejemplo n.º 35
0
    // Use this for initialization
    void Start()
    {
        //get level sprites
        Sprite[] dirtTiles = new Sprite[4];
        Sprite[] sprites = Resources.LoadAll<Sprite>("sprites/background");
        int j = 0;
        for (int i = 0; i < sprites.Length; i++)
        {
            if(sprites[i].name.StartsWith("dirtTile"))
            {
                dirtTiles[j] = sprites[i];
                j++;
            }
        }

        //create level
        levelBlocks = new LevelBlock[12][];
        for (int i = 0; i < levelBlocks.Length; i++)
            levelBlocks[i] = new LevelBlock[12];

        //create level blocks
        for (int y = 0; y < 12; y++)
        {

            for (int x = 0; x < 12; x++)
            {
                float xOffset = 0 + (x * 0.16f);
                float yOffset = 0 - (y * 0.16f);
                Vector3 pos = transform.position;
                pos.x = pos.x + xOffset;
                pos.y = pos.y + yOffset;
                pos.z = 0;

                levelBlocks[x][y] = Instantiate<LevelBlock>(blockPrefab);
                levelBlocks[x][y].transform.position = pos;
                levelBlocks[x][y].GetComponent<SpriteRenderer>().sprite = dirtTiles[(y/3)];
            }

        }

        //put in dug blocks and monsters depending on level
        switch(currentLevel)
        {
            case 1:
                //dug blocks
                for(int i = 2; i<=5; i++)
                    levelBlocks[1][i].SetOverlay(11);

                for(int i = 8; i<=10; i++)
                    levelBlocks[i][2].SetOverlay(11);

                for(int i = 6; i<=7; i++)
                    levelBlocks[10][i].SetOverlay(11);

                for(int i = 2; i<= 5; i++)
                    levelBlocks[i][9].SetOverlay(11);

                levelBlocks[6][5].SetOverlay(11);

                //monsters
                TomatoThing t = Instantiate<TomatoThing>(tomatoPrefab);
                t.transform.position = new Vector3(levelBlocks[2][9].transform.position.x + 0.08f, levelBlocks[2][9].transform.position.y - 0.08f, 0);

                t = Instantiate<TomatoThing>(tomatoPrefab);
                t.transform.position = new Vector3(levelBlocks[8][2].transform.position.x + 0.08f, levelBlocks[8][2].transform.position.y - 0.08f, 0);

                t = Instantiate<TomatoThing>(tomatoPrefab);
                t.transform.position = new Vector3(levelBlocks[1][2].transform.position.x + 0.08f, levelBlocks[1][2].transform.position.y - 0.08f, 0);

                Dino d = Instantiate<Dino>(dinoPrefab);
                d.transform.position = new Vector3(levelBlocks[10][6].transform.position.x + 0.08f, levelBlocks[10][6].transform.position.y - 0.08f, 0);

                //player
                Player p = Instantiate<Player>(playerPrefab);
                p.transform.position = new Vector3(levelBlocks[6][5].transform.position.x + 0.08f, levelBlocks[6][5].transform.position.y - 0.08f, 0);

                break;

            case 2:
                //dug blocks
                for (int i = 2; i <= 5; i++)
                    levelBlocks[1][i].SetOverlay(11);

                for (int i = 8; i <= 10; i++)
                    levelBlocks[i][2].SetOverlay(11);

                for (int i = 6; i <= 7; i++)
                    levelBlocks[10][i].SetOverlay(11);

                for (int i = 2; i <= 5; i++)
                    levelBlocks[i][9].SetOverlay(11);

                levelBlocks[6][5].SetOverlay(11);

                for (int i = 3; i <= 7; i++)
                    levelBlocks[i][7].SetOverlay(11);

                //monsters
                t = Instantiate<TomatoThing>(tomatoPrefab);
                t.transform.position = new Vector3(levelBlocks[2][9].transform.position.x + 0.08f, levelBlocks[2][9].transform.position.y - 0.08f, 0);
                t.movementSpeed = 0.5f;

                t = Instantiate<TomatoThing>(tomatoPrefab);
                t.transform.position = new Vector3(levelBlocks[8][2].transform.position.x + 0.08f, levelBlocks[8][2].transform.position.y - 0.08f, 0);
                t.movementSpeed = 0.5f;

                t = Instantiate<TomatoThing>(tomatoPrefab);
                t.transform.position = new Vector3(levelBlocks[1][2].transform.position.x + 0.08f, levelBlocks[1][2].transform.position.y - 0.08f, 0);
                t.movementSpeed = 0.5f;

                d = Instantiate<Dino>(dinoPrefab);
                d.transform.position = new Vector3(levelBlocks[10][6].transform.position.x + 0.08f, levelBlocks[10][6].transform.position.y - 0.08f, 0);
                d.movementSpeed = 0.5f;

                d = Instantiate<Dino>(dinoPrefab);
                d.transform.position = new Vector3(levelBlocks[3][7].transform.position.x + 0.08f, levelBlocks[7][7].transform.position.y - 0.08f, 0);
                d.movementSpeed = 0.5f;

                d = Instantiate<Dino>(dinoPrefab);
                d.transform.position = new Vector3(levelBlocks[7][7].transform.position.x + 0.08f, levelBlocks[7][7].transform.position.y - 0.08f, 0);
                d.movementSpeed = 0.5f;

                //player
                p = Instantiate<Player>(playerPrefab);
                p.transform.position = new Vector3(levelBlocks[6][5].transform.position.x + 0.08f, levelBlocks[6][5].transform.position.y - 0.08f, 0);

                break;
        }
    }
Ejemplo n.º 36
0
        public void HandleLevelCollisions(LevelBlock levelBlock, AnimatedObject moveableObject)
        {
            if (levelBlock.IntersectRectangle.Intersects(moveableObject.IntersectRectangle))
            {
                if(moveableObject.PrevPosition.Y > levelBlock.IntersectRectangle.Bottom)
                {
                    moveableObject.Position = moveableObject.PrevPosition;
                    if(moveableObject is Player)
                    {
                        Player.AbortJump();
                    }

                }
                else if (levelBlock.IsAboveLevelObject(moveableObject))
                {
                    //moveableObject.Position.Y = levelBlock.Position.Y - moveableObject.ImageSize.Y;
                    moveableObject.Position = new Vector2(moveableObject.Position.X,
                                                          levelBlock.Position.Y - moveableObject.ImageSize.Y);
                }
                else if(levelBlock.Position.X > moveableObject.Position.X)
                {
                    //moveableObject.Position.X = moveableObject.PrevPosition.X;
                    moveableObject.Position = new Vector2(moveableObject.PrevPosition.X, moveableObject.Position.Y);
                }
                else if (levelBlock.Position.X < moveableObject.Position.X)
                {
                    //moveableObject.position.X = moveableObject.PrevPosition.X;
                    moveableObject.Position = new Vector2(moveableObject.PrevPosition.X, moveableObject.Position.Y);
                }
            }
        }