Ejemplo n.º 1
0
    private void HandleGridMovement()
    {
        gridMoveTimer += Time.deltaTime;
        if (gridMoveTimer >= gridMoveTimerMax)
        {
            gridMoveTimer -= gridMoveTimerMax;

            SnakeMovePosition previousSnakeMovePosition = null;
            if (snakeMovePositionList.Count > 0)
            {
                previousSnakeMovePosition = snakeMovePositionList[0];
            }
            SnakeMovePosition snakeMovePosition = new SnakeMovePosition(previousSnakeMovePosition, gridPosition, gridMoveDirection);
            snakeMovePositionList.Insert(0, snakeMovePosition);

            Vector2Int gridMoveDirectionVector;
            switch (gridMoveDirection)
            {
            default:
            case Direction.Left: gridMoveDirectionVector = new Vector2Int(-1, 0); break;

            case Direction.Right: gridMoveDirectionVector = new Vector2Int(1, 0); break;

            case Direction.Up: gridMoveDirectionVector = new Vector2Int(0, 1); break;

            case Direction.Down: gridMoveDirectionVector = new Vector2Int(0, -1); break;
            }

            gridPosition += gridMoveDirectionVector;

            gridPosition = levelGrid.ValidateGridPosition(gridPosition);

            bool snakeAteFood = levelGrid.TrySnakeEatFood(gridPosition);
            if (snakeAteFood)
            {
                snakeBodySize++;
                CreateSnakeBody();
            }

            if (snakeMovePositionList.Count >= snakeBodySize + 1)
            {
                snakeMovePositionList.RemoveAt(snakeMovePositionList.Count - 1);
            }

            UpdateSnakeBodyParts();

            foreach (SnakeBodyPart snakeBodyPart in snakeBodyPartList)
            {
                Vector2Int snakeBodyPartGridPosition = snakeBodyPart.GetGridPosition();
                if (gridPosition == snakeBodyPartGridPosition)
                {
                    CMDebug.TextPopup("Dead", transform.position);
                    state = State.Dead;
                }
            }

            transform.position    = new Vector3(gridPosition.x, gridPosition.y);
            transform.eulerAngles = new Vector3(0, 0, GetAnglefromVector(gridMoveDirectionVector));
        }
    }
Ejemplo n.º 2
0
 private void OnTriggerEnter2D(Collider2D collider)
 {
     if (collider.gameObject.name == "Trophy")
     {
         CMDebug.TextPopup("Win!", transform.position);
     }
 }
Ejemplo n.º 3
0
    /// <summary>
    /// 请求下一个任务
    /// </summary>
    private void RequestNextTask()
    {
        CMDebug.TextPopup("请求下一个任务", transform.position);
        TaskBase task = taskSystem.RequestNextTask();

        if (task == null)
        {
            state = State.WaitingForNextTask;
        }
        else
        {
            state = State.ExecutingTask;
            if (task is Task.MoveToPosition)
            {
                ExecuteTask_MoveToPosition(task as Task.MoveToPosition);
                return;
            }
            if (task is Task.Victory)
            {
                ExecuteTask_Victory(task as Task.Victory);
                return;
            }
            if (task is Task.ShellFloorCleanUp)
            {
                ExecuteTask_ShellFloorCleanUp(task as Task.ShellFloorCleanUp);
                return;
            }
            if (task is Task.TaskWeaponToWeaponSlot)
            {
                ExecuteTask_TaskWeaponToWeaponSlot(task as Task.TaskWeaponToWeaponSlot);
                return;
            }
        }
    }
Ejemplo n.º 4
0
 private void ExecuteTask_MoveToPosition(CM_GameHandler.Task.MoveToPosition moveToPositionTask)
 {
     // Move Worker to target position
     CMDebug.TextPopup("ExecuteTask_MoveToPosition", worker.GetPosition());
     worker.MoveTo(moveToPositionTask.targetPosition, () => {
         state = State.WaitingForNextTask;
     });
 }
Ejemplo n.º 5
0
 private void ExecuteTask_Victory(CM_GameHandler.Task.Victory victoryTask)
 {
     // Play Victory animation
     CMDebug.TextPopup("ExecuteTask_Victory", worker.GetPosition());
     worker.PlayVictoryAnimation(() => {
         state = State.WaitingForNextTask;
     });
 }
Ejemplo n.º 6
0
 private void ExecuteTask_Victory(Task.Victory task)
 {
     CMDebug.TextPopup("ExecuteTask_Victory", transform.position);
     worker.PlayVictoryAnimation(() =>
     {
         state = State.WaitingForNextTask;
     });
 }
Ejemplo n.º 7
0
 /// <summary>
 /// 执行任务_移动到指定位置
 /// </summary>
 /// <param name="task">The task.</param>
 /// <exception cref="System.NotImplementedException"></exception>
 private void ExecuteTask_MoveToPosition(Task.MoveToPosition task)
 {
     CMDebug.TextPopup("ExecuteTask_MoveToPosition", transform.position);
     worker.MoveTo(task.targetPosition, () =>
     {
         state = State.WaitingForNextTask;
         // Destroy(gameObject.GetComponent<MoveHandler>());
     });
 }
Ejemplo n.º 8
0
    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.LeftControl))
        {
            spell = Spell.TP;
        }

        if (state == State.Alive)
        {
            HandleInput();
            HandleMovement();
        }
        else
        {
            CMDebug.TextPopup("game over!", transform.position);
        }
    }
Ejemplo n.º 9
0
    private void HandleGridMovement()
    {
        gridMoveTimer += Time.deltaTime;
        if (gridMoveTimer >= gridMoveTimerMax)
        {
            gridMoveTimer -= gridMoveTimerMax;

            SnakeMovePosition previousSnakeMovePosition = null;
            if (snakeMovePositionList.Count > 0)
            {
                previousSnakeMovePosition = snakeMovePositionList[0];
            }
            snakeMovePositionList.Insert(0, new SnakeMovePosition(previousSnakeMovePosition, gridPosition, gridMoveDirection));

            gridPosition += getDirectionAsVector2Int();
            gridPosition  = levelGrid.ValidateGridPosition(gridPosition);

            if (levelGrid.TrySnakeEatFood(gridPosition))
            {
                CreateSnakeBody();
            }
            UpdateSnakeBodyParts();

            if (snakeMovePositionList.Count > snakeBodyPartList.Count + 1)
            {
                snakeMovePositionList.RemoveAt(snakeMovePositionList.Count - 1);
            }

            foreach (SnakeBodyPart bodyPart in snakeBodyPartList)
            {
                Vector2Int bodyPartGridPosition = bodyPart.GetGridPosition();
                if (gridPosition == bodyPartGridPosition)
                {
                    CMDebug.TextPopup("DEAD!", transform.position);
                    state = State.Dead;
                    GameHandler.SnakeDied();
                    return;
                }
            }

            transform.position    = new Vector3(gridPosition.x, gridPosition.y);
            transform.eulerAngles = new Vector3(0, 0, GetAngleFromVector(getDirectionAsVector2Int()));
        }
    }
Ejemplo n.º 10
0
    /// <summary>
    /// 请求下一个任务
    /// </summary>
    private void RequestNextTask()
    {
        CMDebug.TextPopup("请求下一个任务", transform.position);
        TransporterTask task = taskSystem.RequestNextTask();

        if (task == null)
        {
            state = State.WaitingForNextTask;
        }
        else
        {
            state = State.ExecutingTask;
            if (task is TransporterTask.TakeWeaponFromSlotToPosition)
            {
                ExecuteTask_TaskWeaponToWeaponSlot(task as TransporterTask.TakeWeaponFromSlotToPosition);
                return;
            }
        }
    }
Ejemplo n.º 11
0
    private void HandleMovement()
    {
        gridMoveTimer += Time.deltaTime;
        if (spell == Spell.TP)
        {
            gridPosition += gridMoveDirection;
            spell         = Spell.Nothing;
        }

        if (gridMoveTimer > gridMoveTimerMax)
        {
            movePositionGridList.Insert(0, gridPosition);

            gridPosition  += gridMoveDirection;
            gridMoveTimer -= gridMoveTimerMax;

            for (int i = 0; i < movePositionGridList.Count; i++)
            {
                Vector2Int   movePosition = movePositionGridList[i];
                World_Sprite worldSprite  = World_Sprite.Create(new Vector3(movePosition.x, movePosition.y), Vector3.one * .5f, Color.white);
            }

            foreach (Vector2Int movePosition in movePositionGridList)
            {
                if (gridPosition == movePosition)
                {
                    CMDebug.TextPopup("DEAD!", transform.position);
                    state = State.Dead;
                }
            }
            transform.position = new Vector3(gridPosition.x, gridPosition.y);
            if (!levelGrid.validateGridPosition(gridPosition))
            {
                CMDebug.TextPopup("DEAD", transform.position);
                state = State.Dead;
            }
            Debug.Log("removal tp");
            transform.eulerAngles = new Vector3(0, 0, getAngleFromVector(gridMoveDirection) - 90);
        }
    }
Ejemplo n.º 12
0
 private void RequestNextTask()
 {
     CMDebug.TextPopup("RequestNextTask", worker.GetPosition());
     CM_GameHandler.TransporterTask task = taskSystem.RequestNextTask();
     if (task == null)
     {
         // No tasks available, wait before asking again
         state = State.WaitingForNextTask;
     }
     else
     {
         // There is a task available, execute it depending on type
         state = State.ExecutingTask;
         if (task is CM_GameHandler.TransporterTask.TakeWeaponFromSlotToPosition)
         {
             ExecuteTask_TakeWeaponFromSlotToPosition(task as CM_GameHandler.TransporterTask.TakeWeaponFromSlotToPosition);
             return;
         }
         // Task type unknown, error!
         Debug.LogError("Task type unknown!");
     }
 }
Ejemplo n.º 13
0
 private void RequestNextTask()
 {
     CMDebug.TextPopup("RequestNextTask", worker.GetPosition());
     CM_GameHandler.Task task = taskSystem.RequestNextTask();
     if (task == null)
     {
         // No tasks available, wait before asking again
         state = State.WaitingForNextTask;
     }
     else
     {
         // There is a task available, execute it depending on type
         state = State.ExecutingTask;
         if (task is CM_GameHandler.Task.MoveToPosition)
         {
             ExecuteTask_MoveToPosition(task as CM_GameHandler.Task.MoveToPosition);
             return;
         }
         if (task is CM_GameHandler.Task.Victory)
         {
             ExecuteTask_Victory(task as CM_GameHandler.Task.Victory);
             return;
         }
         if (task is CM_GameHandler.Task.ShellFloorCleanUp)
         {
             ExecuteTask_ShellFloorCleanUp(task as CM_GameHandler.Task.ShellFloorCleanUp);
             return;
         }
         if (task is CM_GameHandler.Task.TakeWeaponToWeaponSlot)
         {
             ExecuteTask_TakeWeaponToWeaponSlot(task as CM_GameHandler.Task.TakeWeaponToWeaponSlot);
             return;
         }
         // Task type unknown, error!
         Debug.LogError("Task type unknown!");
     }
 }
Ejemplo n.º 14
0
    private void HandleGridMovement()
    {
        gridMoveTimer += Time.deltaTime;
        if (gridMoveTimer >= gridMoveTimerMax)
        {
            gridMoveTimer -= gridMoveTimerMax;

            SnakeMovePosition previousSnakeMovePosition = null;
            if (snakeMovePositionList.Count > 0)
            {
                previousSnakeMovePosition = snakeMovePositionList[0];
            }
            SnakeMovePosition snakeMovePosition = new SnakeMovePosition(previousSnakeMovePosition, gridPosition, gridMoveDirection);
            snakeMovePositionList.Insert(0, snakeMovePosition);

            Vector2Int gridMoveDirectionVector = new Vector2Int();
            switch (gridMoveDirection)
            {
            case Direction.Right:
                gridMoveDirectionVector = new Vector2Int(+1, 0); break;

            case Direction.Left:
                gridMoveDirectionVector = new Vector2Int(-1, 0); break;

            case Direction.Up:
                gridMoveDirectionVector = new Vector2Int(0, +1); break;

            case Direction.Down:
                gridMoveDirectionVector = new Vector2Int(0, -1); break;
            }

            gridPosition += gridMoveDirectionVector;

            gridPosition = levelGrid.ValidateGridPosition(gridPosition);

            bool snakeAteFood = levelGrid.TrySnakeEatFood(gridPosition);
            if (snakeAteFood)
            {
                gridMoveTimerMax -= .01f;
                // Snake Ate food, grow body
                snakeBodySize++;
                CreateSnakeBodyPart();
            }

            if (snakeMovePositionList.Count >= snakeBodySize + 1)
            {
                snakeMovePositionList.RemoveAt(snakeMovePositionList.Count - 1);
            }

            UpdateSnakeBodyParts();

            foreach (SnakeBodyPart snakeBodyPart in snakeBodyPartList)
            {
                Vector2Int snakeBodyPartGridPosition = snakeBodyPart.GetGridPosition();
                if (gridPosition == snakeBodyPartGridPosition)
                {
                    // Game Over!
                    state = State.Dead;
                    GameHandler.SnakeDied();
                    CMDebug.TextPopup("Dead!", transform.position);
                }
            }

            transform.position    = new Vector3(gridPosition.x, gridPosition.y);
            transform.eulerAngles = new Vector3(0, 0, GetAngleFromVector(gridMoveDirectionVector) - 90); // - 90 as unity thinks of up as 90deg.
        }
    }
Ejemplo n.º 15
0
    private void HandleGridMovement()
    {
        gridMoveTimer += Time.deltaTime;
        if (gridMoveTimer >= gridMoveTimerMax)
        {
            gridMoveTimer -= gridMoveTimerMax;

            SoundManager.PlaySound(SoundManager.Sound.SnakeMove);

            SnakeMovePosition prevoiusSnakeMovePosition = null;
            if (snakeMovePositionList.Count > 0)
            {
                prevoiusSnakeMovePosition = snakeMovePositionList [0];
            }

            SnakeMovePosition snakeMovePosition = new SnakeMovePosition(prevoiusSnakeMovePosition, gridPosition, gridNextDirection);
            snakeMovePositionList.Insert(0, snakeMovePosition);

            Vector2Int gridMoveDirectionVector;
            switch (gridNextDirection)
            {
            default:
            case Direction.Up: gridMoveDirectionVector = new Vector2Int(0, 1); break;

            case Direction.Right: gridMoveDirectionVector = new Vector2Int(1, 0); break;

            case Direction.Down: gridMoveDirectionVector = new Vector2Int(0, -1); break;

            case Direction.Left: gridMoveDirectionVector = new Vector2Int(-1, 0); break;
            }

            gridPosition += gridMoveDirectionVector;
            gridPosition  = levelGrid.ValidateGridPosition(gridPosition);

            bool snakeAteFood = levelGrid.TrySnakeEatFood(gridPosition);
            if (snakeAteFood)
            {
                snakeBodySize++;
                CreateSnakeBodyPart();
                gridMoveTimerMax -= .01f;
                SoundManager.PlaySound(SoundManager.Sound.SnakeEat);
                Score.AddScore();
            }
            ;

            if (snakeMovePositionList.Count >= snakeBodySize + 1)
            {
                snakeMovePositionList.RemoveAt(snakeMovePositionList.Count - 1);
            }

            foreach (SnakeBodyParts snakeBodyPart in snakeBodyPartsList)
            {
                Vector2Int snakeBodyPartGridPosition = snakeBodyPart.GetGridPosition();
                if (gridPosition == snakeBodyPartGridPosition)
                {
                    // Game Ever
                    CMDebug.TextPopup("DEAD!", transform.position);
                    state = State.Dead;
                    GameHandler.SnakeDied();
                    SoundManager.PlaySound(SoundManager.Sound.SnakeDie);
                }
            }

            transform.position    = new Vector3(gridPosition.x + .5f, gridPosition.y + .5f);
            transform.eulerAngles = new Vector3(0, 0, GetAngleFromVector(gridMoveDirectionVector) - 90);

            UpdateSnakeBodyParts();

            gridMoveDirection = gridNextDirection;
        }
    }
Ejemplo n.º 16
0
 private void TestingDOTSEvents_OnRacingEnemyPassed(object sender, System.EventArgs e)
 {
     CMDebug.TextPopup("Ding!", new Vector3(.5f, .2f));
 }