예제 #1
0
    private void Update()
    {
        if (currentTurretPlacementCooldown > 0f)
        {
            currentTurretPlacementCooldown -= Time.deltaTime;
        }

        if (CurTurret != null)
        {
            Vector3 mouseWorldPos = cam.ScreenToWorldPoint(Input.mousePosition);
            mouseWorldPos.z = 0f;
            CurTurret.transform.position = mouseWorldPos;

            bool canBePlaced = CurTurret.SetPlacementValidity(
                !gm.IsMouseCollidingWithTilemap(CurTurret.Stats.TrackCollisionRadius));

            if ((Input.GetMouseButtonDown(0) || Input.GetMouseButtonUp(0)) && canBePlaced)
            {
                gm.Gold -= CurTurret.Stats.TurretPrice;
                CurTurret.SetPlacementValidity(true);
                CurTurret.Activate();
                CurTurret = null;

                currentTurretPlacementCooldown = turretPlacementCooldown;
                AudioManager.PlayMoneySound();
            }
            else if (Input.GetMouseButtonDown(1))
            {
                Destroy(CurTurret.gameObject);
                CurTurret = null;
            }
        }
    }
        public MainWindow()
        {
            InitializeComponent();

            turret = new Turret("COM4", 115200);
            turret.Activate();

            ControlArea.MouseMove += RecieveMouseMove;

            this.Closed += (sender, e) => turret.Deactivate();
            watch        = Stopwatch.StartNew();

            xBox.PreviewTextInput += validateCoordInput;
            xBox.PreviewKeyDown   += filterSpace;

            yBox.PreviewTextInput += validateCoordInput;
            yBox.PreviewKeyDown   += filterSpace;
            MoveBtn.Click         += (sender, args) => MoveToCoordinates();
            ControlArea.MouseDown += (sender, args) => turret.Fire();

            this.KeyUp += HandleKeyUp;
        }