Exemplo n.º 1
0
    private void Awake()
    {
        instance = this;
        GameObject gameObject = new GameObject("topBar", typeof(Image));

        gameObject.transform.SetParent(transform, false);
        gameObject.GetComponent <Image>().color = Color.black;
        topBar           = gameObject.GetComponent <RectTransform>();
        topBar.anchorMin = new Vector2(0, 1);
        topBar.anchorMax = new Vector2(1, 1);
        topBar.sizeDelta = new Vector2(0, 0);

        gameObject = new GameObject("bottomBar", typeof(Image));
        gameObject.transform.SetParent(transform, false);
        gameObject.GetComponent <Image>().color = Color.black;
        bottomBar           = gameObject.GetComponent <RectTransform>();
        bottomBar.anchorMin = new Vector2(0, 0);
        bottomBar.anchorMax = new Vector2(1, 0);
        bottomBar.sizeDelta = new Vector2(0, 0);

        CMDebug.ButtonUI(new Vector2(-200, 0), "Show", () => {
            Show(300, .3f);
        });
        CMDebug.ButtonUI(new Vector2(200, 0), "Hide", () => {
            Hide(.3f);
        });
    }
Exemplo n.º 2
0
 public void Save()
 {
     PlayerData.scenename = SceneManager.GetActiveScene().name;
     PlayerData.position  = detective.position;
     CMDebug.TextPopupMouse("Saved!");
     data.Save();
 }
Exemplo 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;
            }
        }
    }
Exemplo n.º 4
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));
        }
    }
Exemplo n.º 5
0
 private void OnTriggerEnter2D(Collider2D collider)
 {
     if (collider.gameObject.name == "Trophy")
     {
         CMDebug.TextPopup("Win!", transform.position);
     }
 }
Exemplo n.º 6
0
 private void ExecuteTask_Victory(Task.Victory task)
 {
     CMDebug.TextPopup("ExecuteTask_Victory", transform.position);
     worker.PlayVictoryAnimation(() =>
     {
         state = State.WaitingForNextTask;
     });
 }
Exemplo n.º 7
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;
     });
 }
Exemplo n.º 8
0
 private void ExecuteTask_Victory(CM_GameHandler.Task.Victory victoryTask)
 {
     // Play Victory animation
     CMDebug.TextPopup("ExecuteTask_Victory", worker.GetPosition());
     worker.PlayVictoryAnimation(() => {
         state = State.WaitingForNextTask;
     });
 }
Exemplo n.º 9
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>());
     });
 }
Exemplo n.º 10
0
    // Start is called before the first frame update
    void Start()
    {
        Debug.Log("console: GameHandler.Start");
        int i = 0;

        FunctionPeriodic.Create(() => {
            CMDebug.TextPopupMouse("Ding " + i + "!");
            i++;
        }, .5f);
    }
Exemplo n.º 11
0
 private void Update()
 {
     if (Input.GetMouseButtonDown(0))
     {
         // Spawn a pistol and queue the task to take it to a slot when possible
         GameObject pistolGameObject = SpawnPistolSprite(UtilsClass.GetMouseWorldPosition());
         taskSystem.EnqueueTask(() => {
             foreach (WeaponSlot weaponSlot in weaponSlotList)
             {
                 if (weaponSlot.IsEmpty())
                 {
                     // If the weapon slot is empty lets create the task to take it there
                     weaponSlot.SetHasWeaponIncoming(true);
                     Task task = new Task.TakeWeaponToWeaponSlot {
                         weaponPosition     = pistolGameObject.transform.position,
                         weaponSlotPosition = weaponSlot.GetPosition(),
                         grabWeapon         = (CM_WorkerTaskAI weaponWorkerTaskAI) => {
                             // Grab weapon, parent the weapon to the worker
                             pistolGameObject.transform.SetParent(weaponWorkerTaskAI.transform);
                         },
                         dropWeapon = () => {
                             // Drop weapon, set parent back to null
                             pistolGameObject.transform.SetParent(null);
                             // Notify the weapon slot that the weapon has arrived
                             weaponSlot.SetWeaponTransform(pistolGameObject.transform);
                         },
                     };
                     return(task);
                 }
                 // Weapon slot not empty, keep looking
             }
             // No weapon slot is empty, try again later
             return(null);
         });
         //CMDebug.TextPopupMouse("Add Task: ShellFloorCleanUp, 5s delay");
         //SpawnFloorShellsWithTask(UtilsClass.GetMouseWorldPosition());
     }
     if (Input.GetMouseButtonDown(1))
     {
         CMDebug.TextPopupMouse("Add Task: MoveToPosition");
         //CM_TaskSystem.Task task = new CM_TaskSystem.Task.Victory { };
         //taskSystem.AddTask(task);
         Task task = new Task.MoveToPosition {
             targetPosition = UtilsClass.GetMouseWorldPosition()
         };
         taskSystem.AddTask(task);
     }
     if (Input.GetKeyDown(KeyCode.Alpha1))
     {
         CMDebug.TextPopupMouse("Add Task: Victory");
         Task task = new Task.Victory {
         };
         taskSystem.AddTask(task);
     }
 }
Exemplo n.º 12
0
    private void Start()
    {
        healthSystem = new HealthSystem(100);
        damagedBarImage.fillAmount = barImage.fillAmount;
        healthSystem.OnDamaged    += HealthSystem_OnDamaged;
        healthSystem.OnHealed     += HealthSystem_OnHealed;
        SetHealth(healthSystem.GetHealthNormalized());


        CMDebug.ButtonUI(new Vector2(-100, -50), "Damage", () => healthSystem.Damage(10));
        CMDebug.ButtonUI(new Vector2(+100, -50), "Heal", () => healthSystem.Heal(10));
    }
Exemplo n.º 13
0
    private void Start()
    {
        Minimap.Minimap.Init();

        CMDebug.ButtonUI(new Vector2(300, 200), "Show Minimap", Minimap.Minimap.ShowWindow);
        CMDebug.ButtonUI(new Vector2(300, 160), "Hide Minimap", Minimap.Minimap.HideWindow);

        CMDebug.ButtonUI(new Vector2(300, 120), "Player Icon Show", playerMinimapIcon.Show);
        CMDebug.ButtonUI(new Vector2(300, 80), "Player Icon Hide", playerMinimapIcon.Hide);

        CMDebug.ButtonUI(new Vector2(300, 20), "Zoom In", Minimap.Minimap.ZoomIn);
        CMDebug.ButtonUI(new Vector2(300, -20), "Zoom Out", Minimap.Minimap.ZoomOut);
    }
Exemplo n.º 14
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyUp(KeyCode.Space))
        {
            //LowSpeedEffect();
            timeManager.DoSlowMotion();
        }

        if (Input.GetMouseButtonUp(1))
        {
            CMDebug.TextPopupMouse("Disparando");
            //Shoot();
        }
    }
Exemplo n.º 15
0
    private void Awake()
    {
        barMaskRectTransform = transform.Find("barMask").GetComponent <RectTransform>();
        barRawImage          = transform.Find("barMask").Find("bar").GetComponent <RawImage>();
        edgeRectTransform    = transform.Find("edge").GetComponent <RectTransform>();

        barMaskWidth = barMaskRectTransform.sizeDelta.x;

        mana = new Mana();

        CMDebug.ButtonUI(new Vector2(0, -100), "Spend Mana", () => {
            mana.TrySpendMana(30);
        });
    }
Exemplo n.º 16
0
 public void DequeueTask()
 {
     for (int i = 0; i < queuedTaskList.Count; i++)
     {
         QueuedTask <T> queuedTask = queuedTaskList[i];
         T task = queuedTask.DequeueTask();
         if (task != null)
         {
             AddTask(task);
             queuedTaskList.RemoveAt(i);
             i--;
             CMDebug.TextPopupMouse("Task Dequeue");
         }
     }
 }
Exemplo n.º 17
0
    private void Start()
    {
        Debug.Log("GameHandler.Start");
        int number = 0;

        FunctionPeriodic.Create(() =>
        {
            CMDebug.TextPopupMouse("Don't work with this lady! She a ssssnake");
            number++;
        }, .5f);

        levelGrid = new LevelGrid(20, 20);
        snake.SetUp(levelGrid);
        levelGrid.SetUp(snake);
    }
Exemplo n.º 18
0
 // Update is called once per frame
 void Update()
 {
     if (GameData.gameState == GUIManager.States.InGame || GameData.gameState == GUIManager.States.Pause)
     {
         //实现点击移动
         if (Input.GetMouseButtonDown(0))
         {
             //CMDebug.TextPopupMouse(GameData.save.Progress.ToString()+","+level);
         }
         if (Input.GetKeyUp(KeyCode.Escape))
         {
             if (Time.timeScale > 0.0f)
             {
                 moveObject.PauseGame();
             }
             else
             {
                 moveObject.m.ResumeGame();
             }
         }
         GameData.UpdateShipStatus();
         FlushGameLists(shells);
     }
     if (GameData.gameState == GUIManager.States.Outfit)
     {
         if (GUIManager.outfitTurrets != null)
         {
             GUIManager.outfitTurrets = GUIManager.FlushNullInArray(GUIManager.outfitTurrets);
         }
         //有泄漏就明显报错
         foreach (GameObject i in GUIManager.outfitTurrets)
         {
             if (i == null)
             {
                 CMDebug.TextPopupMouse("!!");
             }
         }
         if (Input.GetKeyUp(KeyCode.Escape))
         {
             GameObject.Find("EventSystem").GetComponent <GUIManager>().CleanOutfitScreen();
             GUIManager.ShowGUI(GUIManager.States.SelectLevels);
         }
     }
     //if (Input.GetMouseButtonDown(0))
     //{
     //    CMDebug.TextPopupMouse(GameData.gameState.ToString());
     //}
 }
Exemplo n.º 19
0
    private void Start()
    {
        FunctionPeriodic.Create(HealingAnimatedPeriodic, .05f);
        HeartsHealthSystem heartsHealthSystem = new HeartsHealthSystem(5);

        SetHeartsHealthSystem(heartsHealthSystem);


        //Testing buttons
        CMDebug.ButtonUI(new Vector2(-50, -100), "Damage 1", () => heartsHealthSystem.Damage(1));
        CMDebug.ButtonUI(new Vector2(50, -100), "Damage 4", () => heartsHealthSystem.Damage(4));

        CMDebug.ButtonUI(new Vector2(-50, -200), "Heal 1", () => heartsHealthSystem.Heal(1));
        CMDebug.ButtonUI(new Vector2(50, -200), "Heal 4", () => heartsHealthSystem.Heal(4));
        CMDebug.ButtonUI(new Vector2(150, -200), "Heal 50", () => heartsHealthSystem.Heal(50));
    }
Exemplo n.º 20
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);
        }
    }
Exemplo n.º 21
0
 public static bool TrySpendResourcesCost()
 {
     if (GameResources.GetResourceAmount(GameResources.ResourceType.Wood) >= 10 &&
         GameResources.GetResourceAmount(GameResources.ResourceType.Gold) >= 5)
     {
         // We do have resources
         GameResources.RemoveResourceAmount(GameResources.ResourceType.Wood, 10);
         GameResources.RemoveResourceAmount(GameResources.ResourceType.Gold, 5);
         // Spawn Tower
         return(true);
     }
     else
     {
         // Not enough resources
         CMDebug.TextPopupMouse("Not enough resources!\nWood: 10; Gold: 5");
         return(false);
     }
 }
Exemplo n.º 22
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()));
        }
    }
Exemplo n.º 23
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;
            }
        }
    }
Exemplo n.º 24
0
 private void Start()
 {
     _highscoretable = GameObject.Find("HighscoreTable").GetComponent <highscoretable>();
     inputWindow.Show("Enter name", "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", 3,
                      () =>
     {
         CMDebug.TextPopupMouse("Cancel!");
     }, (inputText) =>
     {
         CMDebug.TextPopupMouse("Ok: " + inputText);
         if (GameObject.Find("scoreman") == null)
         {
         }
         else
         {
             _highscoretable.AddHighscore(m_score, inputText);
         }
     });
 }
    private void Awake()
    {
        guestSpritesheetData = GuestSpritesheetData.GenerateRandom();
        SetGuestSpritesheetData(guestSpritesheetData);

        CMDebug.ButtonUI(new Vector2(100, -170), "Randomize", () => {
            guestSpritesheetData = GuestSpritesheetData.GenerateRandom();
            SetGuestSpritesheetData(guestSpritesheetData);
        });
        CMDebug.ButtonUI(new Vector2(250, -170), "Save", () => {
            guestSpritesheetData.Save();
            CMDebug.TextPopupMouse("Saved!");
        });
        CMDebug.ButtonUI(new Vector2(400, -170), "Load", () => {
            guestSpritesheetData = GuestSpritesheetData.Load_Static();
            SetGuestSpritesheetData(guestSpritesheetData);
            CMDebug.TextPopupMouse("Loaded!");
        });
    }
Exemplo n.º 26
0
    private void Start()
    {
        cameraFollow.Setup(() => playerTransform.position);

        CMDebug.ButtonUI(new Vector2(570, 330), "Player", () =>
        {
            cameraFollow.SetGetCameraFollowPositionFunc(() => playerTransform.position);
        });
        //CMDebug.ButtonUI(new Vector2(570, 330), "Character1", () =>
        //{
        //    cameraFollow.SetGetCameraFollowPositionFunc(() => character1Transform.position);
        //}); CMDebug.ButtonUI(new Vector2(570, 330), "Character2", () =>
        //{
        //    cameraFollow.SetGetCameraFollowPositionFunc(() => character2Transform.position);
        //});
        CMDebug.ButtonUI(new Vector2(570, 270), "Manual", () =>
        {
            cameraFollow.SetGetCameraFollowPositionFunc(() => manualMovementTransform.position);
        });
    }
Exemplo n.º 27
0
    // Start is called before the first frame update
    private void Start()
    {
        HealthSystem healthSystem = new HealthSystem(100);

        Transform healthBarTransform = Instantiate(HealthBarPrefab, new Vector3(transform.position.x, (transform.position.y + 1f)), Quaternion.identity);

        HealthBar healthBar = healthBarTransform.GetComponent <HealthBar>();

        healthBar.Setup(healthSystem);

        CMDebug.ButtonUI(new Vector2(100, 100), "damage", () => {
            healthSystem.Damage(10);
            Debug.Log("Damaged: " + healthSystem.GetHealth());
        });

        CMDebug.ButtonUI(new Vector2(-100, 100), "heal", () => {
            healthSystem.Heal(10);
            Debug.Log("Healed: " + healthSystem.GetHealth());
        });
    }
Exemplo n.º 28
0
 private void DequeueTasks()
 {
     for (int i = 0; i < queuedTaskList.Count; i++)
     {
         QueuedTask <TTask> queuedTask = queuedTaskList[i];
         TTask task = queuedTask.TryDequeueTask();
         if (task != null)
         {
             // Task dequeued! Add to normal list
             AddTask(task);
             queuedTaskList.RemoveAt(i);
             i--;
             CMDebug.TextPopupMouse("Task Dequeued");
         }
         else
         {
             // Returned task is null, keep it queued
         }
     }
 }
Exemplo n.º 29
0
    private void Update()
    {
        if (Input.GetMouseButton(0))
        {
            Vector3 mouseWorldPosition = UtilsClass.GetMouseWorldPosition();
            tilemap.SetTilemapSprite(mouseWorldPosition, tilemapSprite);
        }

        if (Input.GetKeyDown(KeyCode.T))
        {
            tilemapSprite = Tilemap.TilemapObject.TilemapSprite.None;
            CMDebug.TextPopupMouse(tilemapSprite.ToString());
        }
        if (Input.GetKeyDown(KeyCode.Y))
        {
            tilemapSprite = Tilemap.TilemapObject.TilemapSprite.Ground;
            CMDebug.TextPopupMouse(tilemapSprite.ToString());
        }
        if (Input.GetKeyDown(KeyCode.U))
        {
            tilemapSprite = Tilemap.TilemapObject.TilemapSprite.Path;
            CMDebug.TextPopupMouse(tilemapSprite.ToString());
        }
        if (Input.GetKeyDown(KeyCode.I))
        {
            tilemapSprite = Tilemap.TilemapObject.TilemapSprite.Dirt;
            CMDebug.TextPopupMouse(tilemapSprite.ToString());
        }


        if (Input.GetKeyDown(KeyCode.P))
        {
            tilemap.Save();
            CMDebug.TextPopupMouse("Saved!");
        }
        if (Input.GetKeyDown(KeyCode.L))
        {
            tilemap.Load();
            CMDebug.TextPopupMouse("Loaded!");
        }
    }
Exemplo n.º 30
0
    private void Start()
    {
        Stats stats = new Stats(10, 2, 5, 10, 3);

        uiStatsRadarChart.SetStats(stats);

        CMDebug.ButtonUI(new Vector2(100, 20), "ATK++", () => stats.IncreaseStatAmount(Stats.Type.Attack));
        CMDebug.ButtonUI(new Vector2(100, -20), "ATK--", () => stats.DecreaseStatAmount(Stats.Type.Attack));

        CMDebug.ButtonUI(new Vector2(200, 20), "DEF++", () => stats.IncreaseStatAmount(Stats.Type.Defence));
        CMDebug.ButtonUI(new Vector2(200, -20), "DEF--", () => stats.DecreaseStatAmount(Stats.Type.Defence));

        CMDebug.ButtonUI(new Vector2(300, 20), "SPD++", () => stats.IncreaseStatAmount(Stats.Type.Speed));
        CMDebug.ButtonUI(new Vector2(300, -20), "SPD--", () => stats.DecreaseStatAmount(Stats.Type.Speed));

        CMDebug.ButtonUI(new Vector2(400, 20), "MAN++", () => stats.IncreaseStatAmount(Stats.Type.Mana));
        CMDebug.ButtonUI(new Vector2(400, -20), "MAN--", () => stats.DecreaseStatAmount(Stats.Type.Mana));

        CMDebug.ButtonUI(new Vector2(500, 20), "HEL++", () => stats.IncreaseStatAmount(Stats.Type.Health));
        CMDebug.ButtonUI(new Vector2(500, -20), "HEL--", () => stats.DecreaseStatAmount(Stats.Type.Health));
    }