Esempio n. 1
0
 protected override int SetReciverAsDpm()
 {
     return(CmdStation.Register(GodPower
                                .GetSetIceBoxCommand())
            .To(OutputPrinter)
            .Execute()
            .ExitCode);
 }
Esempio n. 2
0
    // ======================================================================================
    void FixedUpdate()
    {
        if (GameMgr.IsPaused || SceneMgr.IsGameOver)
        {
            return;
        }

        UpdatePowersGUI();

        IsInGodRegion();

        if (MaySwitchPowers)
        {
            if (Input.GetButtonDown("Create Bomb"))
            {
                CurrentPower = GodPower.Bomb;
            }
            else if (Input.GetButtonDown("Create Turret"))
            {
                CurrentPower = GodPower.Turret;
            }
            else if (Input.GetButtonDown("Create Trap"))
            {
                CurrentPower = GodPower.Trap;
            }
        }

        if (CurrentPower == GodPower.Bomb)
        {
            if (!IsDraggingBomb && GameMgr.Timer > LastBomb + BombPowerCooldown && IsInGodRegion() && Input.GetButton("Fire1"))
            {
                MaySwitchPowers = false;
                IsDraggingBomb  = true;

                DraggedBomb = Instantiate(
                    PrefabBomb,
                    GetMouseWorldPos(),
                    Quaternion.identity
                    ) as GameObject;
            }

            if (!Input.GetButton("Fire1") || !IsInGodRegion())
            {
                if (IsDraggingBomb)
                {
                    IsDraggingBomb  = false;
                    MaySwitchPowers = true;

                    LastBomb = GameMgr.Timer;

                    if (DraggedBomb)
                    {
                        Rigidbody BombPhysics = DraggedBomb.GetComponent <Rigidbody>();
                        BombPhysics.useGravity  = true;
                        BombPhysics.isKinematic = false;

                        Vector3[] PositionVector = LastMousePositions.ToArray() as Vector3[];
                        float[]   TimeArray      = LastStepsTime.ToArray() as float[];

                        Vector3 ThrowVector = (
                            (PositionVector[PositionVector.Length - 1] - PositionVector[0]) /
                            (TimeArray[TimeArray.Length - 1] - TimeArray[0])
                            );

                        BombPhysics.velocity = ThrowVector.normalized * Mathf.Clamp(ThrowVector.magnitude, 0, BombMaximumSpeed);
                    }
                }
            }

            if (IsDraggingBomb)
            {
                Rigidbody BombPhysics = DraggedBomb.GetComponent <Rigidbody>();
                BombPhysics.position = GetMouseWorldPos();

                /*
                 *  Vector3 GoalVector = (GetMouseWorldPos() - BombPhysics.position);
                 *  BombPhysics.velocity = (
                 *  BombPhysics.velocity +
                 *  GoalVector.normalized * Time.fixedDeltaTime * BombAcceleration
                 * );*/
            }
        }
        else if (CurrentPower == GodPower.Turret)
        {
            if (Input.GetButton("Fire1"))
            {
                if (!IsPlacingTurret)
                {
                    if (GameMgr.Timer > LastTurret + TurretPowerCooldown)
                    {
                        MaySwitchPowers = false;
                        IsPlacingTurret = true;

                        PlacedTurret = Instantiate(
                            PrefabTurret,
                            GetMouseWorldPos(),
                            Quaternion.identity
                            ) as GameObject;

                        AngleIndicator = Instantiate(
                            PrefabAngleIndicator,
                            PlacedTurret.transform.position,
                            Quaternion.identity
                            ) as GameObject;
                    }
                }

                if (IsPlacingTurret)
                {
                    if (GetMouseWorldPos() == PlacedTurret.transform.position)
                    {
                        AngleIndicator.transform.rotation = Quaternion.Euler(0.0f, 0.0f, 0.0f);
                    }
                    else
                    {
                        float WinningAngle = 0.0f;
                        float MouseAngle   = Vector3.Angle(Vector3.right, GetMouseWorldPos() - PlacedTurret.transform.position);

                        for (float angle = 0.0f; angle < 360.0f; angle += TurretAngleSteps)
                        {
                            if (Mathf.Abs(angle - MouseAngle) < Mathf.Abs(WinningAngle - MouseAngle))
                            {
                                WinningAngle = angle;
                            }
                        }

                        AngleIndicator.transform.rotation = Quaternion.Euler(0.0f, 0.0f, -WinningAngle);
                    }
                }
            }
            else
            {
                if (IsPlacingTurret)
                {
                    LastTurret = GameMgr.Timer;

                    if (AngleIndicator)
                    {
                        Destroy(AngleIndicator);
                    }

                    float WinningAngle = 0.0f;
                    float MouseAngle   = Vector3.Angle(Vector3.right, GetMouseWorldPos() - PlacedTurret.transform.position);

                    for (float angle = 0.0f; angle < 360.0f; angle += TurretAngleSteps)
                    {
                        if (Mathf.Abs(angle - MouseAngle) < Mathf.Abs(WinningAngle - MouseAngle))
                        {
                            WinningAngle = angle;
                        }
                    }

                    PlacedTurret.GetComponent <LaserTurret>().Activate(WinningAngle);

                    IsPlacingTurret = false;
                    MaySwitchPowers = true;
                    PlacedTurret    = null;
                }
            }
        }
        else if (CurrentPower == GodPower.Trap)
        {
            if (Input.GetButtonDown("Fire1") && GameMgr.Timer > LastTrap + TrapPowerCooldown)
            {
                Instantiate(
                    PrefabTrap,
                    GetMouseWorldPos(),
                    Quaternion.identity
                    );

                LastTrap = GameMgr.Timer;
            }
        }

        LastStepsTime.Enqueue(GameMgr.Timer);
        LastMousePositions.Enqueue(GetMouseWorldPos());
        if (LastMousePositions.Count > 5)
        {
            LastMousePositions.Dequeue();
            LastStepsTime.Dequeue();
        }
    }