コード例 #1
0
 // Use this for initialization
 void Start()
 {
     cannonState = this.GetComponentInParent <CannonState>();
     cannonball.GetComponent <Image>().sprite = cannonballSprite;
     gunpowder.GetComponent <Image>().sprite  = gunpowderSprite;
     Reset();
 }
コード例 #2
0
    // Use this for initialization
    void Start()
    {
        Vector3 cannonBaseInitialRot   = cannonParent.transform.localEulerAngles;
        Vector3 cannonBarrelInitialRot = cannonBarrel.transform.localEulerAngles;

        cannonState = CannonState.WAITING;
        ReloadCannonBall();
    }
コード例 #3
0
 public void UpdatePreCooldownState()
 {
     preCoolDownPercent -= preCoolDownRate * Time.deltaTime;
     if (preCoolDownPercent <= 0)
     {
         cannonState = CannonState.COOLDOWN;
     }
 }
コード例 #4
0
 public void UpdateWaitingState()
 {
     //if the player clicks
     if (Input.GetMouseButton(0) == true)
     {
         //Debug.Log("Switching to charge State");
         cannonState = CannonState.CHARGING;
     }
 }
コード例 #5
0
    public void UpdateFiringState()
    {
        cannonAudioSource.Play();
        dustEmitter.Play();
        //Fire Cannon Ball (pass it the charge percent)
        ((CannonBallBehavior)loadedCannonBall.GetComponent(typeof(CannonBallBehavior))).Fire(chargePercent);

        preCoolDownPercent = 1f;
        cannonState        = CannonState.PRECOOLDOWN;
    }
コード例 #6
0
ファイル: Cannon.cs プロジェクト: DIS-game-project/HangryWolf
    // Use this for initialization
    void Start()
    {
        //set the sorting layer name for the line renderers
        //for the slingshot renderers this did not work so I
        //set the z on the background sprites to 10
        //hope there's a better way around that!
     
        TrajectoryLineRenderer.sortingLayerName = "Foreground";

        cannonState = CannonState.Idle;
      
        
    }
コード例 #7
0
ファイル: CannonBehaviour.cs プロジェクト: simple-ned/TD_Test
 public override void SetState(object state)
 {
     if (state is CannonState)
     {
         CannonState s = (CannonState)state;
         CannonPivot.position = s.PivotPosition;
         CannonPivot.rotation = s.PivotRotation;
         _isShooting          = s.IsShooting;
         _targetGlobalId      = s.CurrentTargetGlobalId;
         _enemiesGlobalId     = s.EnemiesGlobalIds;
     }
     else
     {
         Debug.LogError("Unable to restore object state! Something went deeply wrong.. " + gameObject.name);
     }
 }
コード例 #8
0
 private void Fire()
 {
     if (charging)
     {
         GameObject cannonBall = Instantiate(projectilePrefab, spawnPoint.transform.position, transform.rotation, transform.parent);
         cannonBall.GetComponent <Rigidbody>().AddForce(transform.forward * currMagnitude, ForceMode.Impulse);
         Vector3 torqueDirection = Random.insideUnitCircle.normalized;
         cannonBall.GetComponent <Rigidbody>().AddTorque(torqueDirection * projectileTorque);
         cannonBall.GetComponent <Cannonball>().player = player;
         cannonBall.GetComponent <Cannonball>().cannon = this;
         cannonState   = CannonState.INACTIVE;
         currMagnitude = 0;
         charging      = false;
         cam.GetComponent <CameraBehaviour>().TriggerShake();
     }
 }
コード例 #9
0
ファイル: CannonGroups.cs プロジェクト: BenMatase/RaginRovers
 public CannonGroups(int cannonKey,
                     int wheelKey,
                     int barKey,
                     int tabKey,
                     int boomKey,
                     bool isFlipped)
 {
     this.factory = GameObjectFactory.Instance;
     this.cannonKey = cannonKey;
     this.wheelKey = wheelKey;
     this.barKey = barKey;
     this.tabKey = tabKey;
     this.boomKey = boomKey;
     this.isFlipped = isFlipped;
     cannonState = CannonState.ROTATE;
 }
コード例 #10
0
 public CannonGroups(int cannonKey,
                     int wheelKey,
                     int barKey,
                     int tabKey,
                     int boomKey,
                     bool isFlipped)
 {
     this.factory   = GameObjectFactory.Instance;
     this.cannonKey = cannonKey;
     this.wheelKey  = wheelKey;
     this.barKey    = barKey;
     this.tabKey    = tabKey;
     this.boomKey   = boomKey;
     this.isFlipped = isFlipped;
     cannonState    = CannonState.ROTATE;
 }
コード例 #11
0
    public void UpdateChargingState()
    {
        if (chargePercent <= 1f)
        {
            //Debug.Log("Charging...");
            chargePercent += chargeRate * Time.deltaTime;
            //Update the meter
            metercontroller.setLengthFromRatio(chargePercent);
            //Update Cannon Height
            setBarrelRotationFromRatio(chargePercent);
        }

        if (Input.GetMouseButton(0) == false)
        {
            cannonState = CannonState.FIRING;
        }
    }
コード例 #12
0
    public void UpdateCooldownState()
    {
        chargePercent -= coolDownRate * Time.deltaTime;
        //Update the meter
        metercontroller.setLengthFromRatio(chargePercent);
        //Update Cannon Height
        setBarrelRotationFromRatio(chargePercent);

        if (chargePercent <= 0)
        {
            //Reload Cannonball
            ReloadCannonBall();

            //Switch to Waiting state
            cannonState = CannonState.WAITING;
        }
    }
コード例 #13
0
    private void FireCannon()
    {
        GameObject tempCannonBall = Instantiate(GameManager.CannonBallPrefab, transform.GetChild(0).position,
                                                Quaternion.identity);

        tempCannonBall.GetComponent <Rigidbody>().AddForce(transform.GetChild(0).forward * 30, ForceMode.Impulse);

        GameObject tempPs = Instantiate(GameManager.CannonBallSmokePSPrefab, transform.GetChild(0).position,
                                        Quaternion.identity);

        PlaySfx();

        Destroy(tempPs, 2f);

        State = CannonState.Empty;

        StartCoroutine(DelayedHit());
    }
コード例 #14
0
ファイル: CannonBehaviour.cs プロジェクト: simple-ned/TD_Test
    public override object GetState()
    {
        CannonState state = new CannonState
        {
            PivotPosition         = CannonPivot.position,
            PivotRotation         = CannonPivot.rotation,
            CurrentTargetGlobalId = _currentEnemyComponent != null ? _currentEnemyComponent.GlobalId : -1,
            IsShooting            = _isShooting
        };

        state.EnemiesGlobalIds = new List <int>();

        foreach (GoblinBehaviour e in _enemies)
        {
            state.EnemiesGlobalIds.Add(e.GlobalId);
        }

        return(state);
    }
コード例 #15
0
 void Start()
 {
     cannonState = GetComponent <CannonState>();
     cannonFire  = GetComponentInChildren <ParticleSystem>();
     animator    = GetComponent <Animator>();
 }
コード例 #16
0
 private void Awake()
 {
     cannonState = CannonState.INACTIVE;
     charging    = false;
     cam         = Camera.main;
 }
コード例 #17
0
 void Start()
 {
     clipRemaining = cannonData.clip;
     state         = CannonState.Firing;
 }
コード例 #18
0
 void ReloadEnd()
 {
     clipRemaining = cannonData.clip;
     state         = CannonState.Firing;
     timeToFire    = 0;
 }
コード例 #19
0
 void ReloadBegin()
 {
     state        = CannonState.Reloading;
     timeToReload = cannonData.reload;
 }
コード例 #20
0
    private void Awake()
    {
        State = CannonState.Empty;

        _squidController = FindObjectOfType <SquidController>();
    }
コード例 #21
0
ファイル: Cannon.cs プロジェクト: DIS-game-project/HangryWolf
    // Update is called once per frame
    void Update()
    {
       // print(WolfToThrow.transform.position);
        switch (cannonState)
        {
            case CannonState.Idle:
                //fix bird's position
                InitializeWolf();
               
                
                if (Input.GetMouseButtonDown(0))
                {
                    //get the point on screen user has tapped
                    Vector3 location = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                    //if user has tapped onto the bird
                    if (WolfToThrow.GetComponent<PolygonCollider2D>() == Physics2D.OverlapPoint(location))
                    {
                        cannonState = CannonState.UserAiming;
                    }
                }
                break;
            case CannonState.UserAiming:
                

                if (Input.GetMouseButton(0))
                {
                    //get where user is tapping
                    Vector3 location = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                    location.z = 0;
                    //we will let the user pull the bird up to a maximum distance
                    if (Vector3.Distance(location, CannonVector) > 1.5f)
                    {
                        //basic vector maths :)
                        var maxPosition = (location - CannonVector).normalized * 1.5f + CannonVector;
                        WolfToThrow.transform.position = maxPosition;
                    }
                    else
                    {
                        WolfToThrow.transform.position = location;
                    }
                    float distance = Vector3.Distance(CannonVector, WolfToThrow.transform.position);
                    //display projected trajectory based on the distance
                    DisplayTrajectoryLineRenderer2(distance);
                        var angle = Vector3.Angle( WolfWaitPosition.transform.position, Input.mousePosition);
                    //print(angle);
                        transform.eulerAngles = new Vector3(0, 0, angle);
                  
                }
                else//user has removed the tap 
                {
                    SetTrajectoryLineRenderesActive(false);
                    //throw the bird!!!
                    TimeSinceThrown = Time.time;
                    float distance = Vector3.Distance(CannonVector, WolfToThrow.transform.position);
                    if (distance > 1)
                    {
                       
                        cannonState = CannonState.WolfFlying;
                        ThrowWolf(distance);
                    }
                    else//not pulled long enough, so reinitiate it
                    {
                        //distance/10 was found with trial and error :)
                        //animate the bird to the wait position
                        WolfToThrow.transform.positionTo(distance / 10, //duration
                            WolfWaitPosition.transform.position). //final position
                            setOnCompleteHandler((x) =>
                        {
                            x.complete();
                            x.destroy();
                            InitializeWolf();
                        });

                    }
                }
                break;
            case CannonState.WolfFlying:
                break;
            default:
                break;
        }

    }
コード例 #22
0
ファイル: Cannon.cs プロジェクト: DIS-game-project/HangryWolf
 private void InitializeWolf()
 {
     //initialization of the ready to be thrown bird
     WolfToThrow.transform.position = WolfWaitPosition.position;
     cannonState = CannonState.Idle;
     
 }