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)); } }
private void OnTriggerEnter2D(Collider2D collider) { if (collider.gameObject.name == "Trophy") { CMDebug.TextPopup("Win!", transform.position); } }
/// <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; } } }
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; }); }
private void ExecuteTask_Victory(CM_GameHandler.Task.Victory victoryTask) { // Play Victory animation CMDebug.TextPopup("ExecuteTask_Victory", worker.GetPosition()); worker.PlayVictoryAnimation(() => { state = State.WaitingForNextTask; }); }
private void ExecuteTask_Victory(Task.Victory task) { CMDebug.TextPopup("ExecuteTask_Victory", transform.position); worker.PlayVictoryAnimation(() => { state = State.WaitingForNextTask; }); }
/// <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>()); }); }
private void Update() { if (Input.GetKeyDown(KeyCode.LeftControl)) { spell = Spell.TP; } if (state == State.Alive) { HandleInput(); HandleMovement(); } else { CMDebug.TextPopup("game over!", transform.position); } }
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())); } }
/// <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; } } }
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); } }
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!"); } }
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!"); } }
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. } }
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; } }
private void TestingDOTSEvents_OnRacingEnemyPassed(object sender, System.EventArgs e) { CMDebug.TextPopup("Ding!", new Vector3(.5f, .2f)); }