示例#1
0
    public virtual void CreateHook(GameObject newHook, float distance, float snapDistance)
    {
        if (hook != null)
        {
            hook.SetActive(false);
            hook = null;
        }

        //Destroy old hook if there is any
        if (hook != null)
        {
            GameObject.Destroy(hook);
        }

        hookPrefab          = newHook;
        hook                = playerCopter.CreateGameObject(hookPrefab, Vector3.zero, Quaternion.identity);
        hookScript          = hook.GetComponent <HookScript>();
        hookScript.HookMass = hookMass;

        //hasHook = true;
        hookJoint        = playerRb.GetComponent <DistanceJoint2D>();
        hookJoint.anchor = hookAnchor.transform.localPosition;

        hookDistance      = distance;
        this.snapDistance = snapDistance;

        PushHookToCargo(true);
    }
示例#2
0
 // Start is called before the first frame update
 void Start()
 {
     audioSource      = GetComponent <AudioSource>();
     audioSource.clip = iceNoise;
     gun       = GetComponentInChildren <GunScript>();
     hook      = grappleHook.GetComponent <HookScript>();
     hook.ammo = 1f;
 }
示例#3
0
	public void Shoot(){
		isCasting = false;
		abilityReady = false;
		GameObject obj = (GameObject)Instantiate(ability_object, owner.transform.position + Vector3.up * 2, new Quaternion());
		hook = obj.GetComponent<HookScript>();
		hook.owner = this.owner.transform;
		hook.hookAbility = this;
		hook.maxLength = hookAimLength;
	}
示例#4
0
    public void Shoot()
    {
        isCasting    = false;
        abilityReady = false;
        GameObject obj = (GameObject)Instantiate(ability_object, owner.transform.position + Vector3.up * 2, new Quaternion());

        hook             = obj.GetComponent <HookScript>();
        hook.owner       = this.owner.transform;
        hook.hookAbility = this;
        hook.maxLength   = hookAimLength;
    }
示例#5
0
    public void Setup(Point gridPos, Vector3 worldPos, int type, Transform parent)
    {
        this.GridPosition  = gridPos;
        transform.position = worldPos;
        this.Type          = "";
        this.IsTower       = false;

        if (type == 0)
        {
            this.Type = "water";
            LevelManager.Instance.WaterTiles.Add(gridPos);
        }
        else if (type == 1)
        {
            this.Type = "wall";
        }
        else if (type == 2)
        {
            this.Type = "dock";
        }
        else if (type == 3)
        {
            this.Type = "path";
        }
        else if (type == 4)
        {
            this.Type = "room";
        }
        else if (type == 5)
        {
            this.Type = "hook";
            // Create a new hook object for the tile.
            HookScript hs = Instantiate(HookPrefab).GetComponentInChildren <HookScript>();
            hs.setup(hookCount, worldPos, this.transform);
            hookCount++;
        }
        else if (type == 6)
        {
            this.Type = "goal";
        }
        transform.SetParent(parent);
        LevelManager.Instance.Tiles.Add(gridPos, this);

        if (this.Type == "water")
        {
            LevelManager.Instance.WaterTiles.Add(gridPos);
        }
        else if (this.Type == "room")
        {
            LevelManager.Instance.roomTiles.Add(gridPos);
        }
    }
示例#6
0
    public void OnHook(NetworkMessage netMsg)
    {
        MObjects.Hook mObject = netMsg.ReadMessage <MObjects.Hook>();
        MobileAgent   from    = MobileAgent.list.Find(x => x.id == mObject.from);
        MobileAgent   to      = MobileAgent.list.Find(x => x.id == mObject.to);

        HookScript hs = Instantiate(hookEffect, to.transform.position, Quaternion.LookRotation(from.transform.position - to.transform.position)).GetComponent <HookScript>();

        hs.to   = to;
        hs.from = from;

        /*
         * MOVE FROM TO TO
         * */
    }
示例#7
0
//    protected virtual void OnEnable() {
//        EventManager.StartListening("HookDied", DetachHook);
//    }
//    protected virtual void OnDisable() {
//        EventManager.StopListening("HookDied", DetachHook);
//    }

    protected virtual void Start()
    {
        manager       = GameObject.Find("LevelManagerO").GetComponent <LevelManager>();
        copter        = GameObject.Find("Copter").GetComponent <Copter>();
        hookScript    = copter.HookScript;
        joint         = GetComponent <HingeJoint2D>();
        floating      = GetComponent <FloatingObject>();
        joint.enabled = false;

        timer = timeToLive;

        if (useTimer == true)
        {
            UpdateMethod += Timer;
        }
    }
示例#8
0
 public void StartRipping(HookScript _currentHook)
 {
     currentHook = _currentHook;
     moveSpeed   = currentHook.hookSpeed;
     originalPos = transform.position;
     lineRend.SetPosition(0, originalPos);
     lineRend.SetPosition(1, transform.position);
     lineRend.SetPosition(2, new Vector3(originalPos.x + 0.5f, originalPos.y - 0.3f));
     lineRend.enabled = true;
     beingRipped      = true;
     playerPos        = playerTransform.position;
     startedRipping   = true;
     if (FindObjectOfType <BossScript>() != null)
     {
         FindObjectOfType <BossScript>().StopVulnTimer();
     }
     ripTimer = Time.time;
 }
示例#9
0
    protected override void OnTriggerEnter2D(Collider2D other)
    {
        if (dead == true)
        {
            return;
        }
        if (other.tag.Equals("Hook") && hooked == false && other.gameObject != legs)
        {
            HookScript hs = GameObject.FindObjectOfType <HookScript>();
            if (hs == null)
            {
                return;                 //Check if the hook is out
            }
            hs.GrabHook(this);

            hookedTransform = other.transform;
            animator.Play("Hanging");


            GrabHook(other.GetComponent <Rigidbody2D>());
        }
    }
示例#10
0
        //Takes input from PlayerInput to handle all player actions
        public void Move(PlayerInput.Input input)
        {
            facing = input.lastDirection;
            TileScript currentTile = LevelManager.Instance.Tiles[location];

            //These are used to throttle their associated actions
            moveCounter += Time.deltaTime;
            fireCounter += Time.deltaTime;

            //These are used as a required channel time for their associated actions
            reloadCounter += Time.deltaTime;
            if (!input.sellHold)
            {
                sellCounter = 0;
            }
            if (!input.interactHold)
            {
                interactCounter = 0;
            }

            //Automatically reload weapon if not in use for a certain period or if clip is empty
            if (reloadCounter > reloadTime)
            {
                int missingAmmo = clipSize - ammoInClip;

                //If there's enough ammo left to reload the entire clip, do so
                if (ammo - missingAmmo > 0)
                {
                    ammo       -= missingAmmo;
                    ammoInClip += missingAmmo;
                }
                //Otherwise, just reload bullets equal to the remaining ammo
                else
                {
                    ammoInClip += ammo;
                    ammo        = 0;
                }
            }

            //If the player is selecting something from a menu
            if (selecting)
            {
                //If the player cancels the tower selection menu
                if (input.cancelDown)
                {
                    selecting = false;
                    LevelManager.Instance.TowerMenu [playerNumber - 1].SetActive(false);
                }
                //If the player releases the build button, begin building the last selected tower
                else if (input.buildUpgradeUp)
                {
                    working   = true;
                    selecting = false;
                    LevelManager.Instance.TowerMenu [playerNumber - 1].SetActive(false);
                }
                //Otherwise, the player can alter the selected tower with movement keys
                else
                {
                    if (input.upHold && !input.prevUpHold)
                    {
                        selectedOption -= optionsPerRow;
                    }                        //Move up one row
                    else if (input.downHold && !input.prevDownHold)
                    {
                        selectedOption += optionsPerRow;
                    }                        //Move down one row
                    else if (input.rightHold && !input.prevRightHold)
                    {
                        selectedOption++;
                    }                                       //Move right one space
                    else if (input.leftHold && !input.prevLeftHold)
                    {
                        selectedOption--;
                    }                                       //Move left one space
                    //All actions that can alter the selected option wrap back around
                    if (selectedOption >= towerPanel.numOptions())
                    {
                        selectedOption %= towerPanel.numOptions();
                    }
                    while (selectedOption < 0)
                    {
                        selectedOption += towerPanel.numOptions();
                    }
                    LevelManager.Instance.Tiles[location].setCurrentTile(playerNumber);
                    towerPanel.menuSelection(selectedOption);
                }
            }
            //If the player is in the process of building something
            else if (working)
            {
                int towerCost = towerPanel.Towers[selectedOption].Gold;
                if (towerCost <= gold)
                {
                    buildUpgradeCounter += Time.deltaTime;
                    transform.Rotate(new Vector3(0, 0, 90)); //temporary "working" animation

                    //If the player cancels the build command
                    if (input.cancelDown)
                    {
                        buildUpgradeCounter = 0;
                        working             = false;
                        moveSprite(location);//temporary to correct facing after random rotation
                    }
                    //If the build command completes
                    else if (buildUpgradeCounter >= buildUpgradeTime)
                    {
                        //build the selected tower on this line
                        buildUpgradeCounter = 0;
                        working             = false;
                        moveSprite(location);//temporary to correct facing after random rotation

                        towerPanel.handleSelection(playerNumber);
                        LevelManager.Instance.Tiles[location].PlaceTower(playerNumber);
                    }
                }
                else
                {
                    buildUpgradeCounter = 0;
                    working             = false;
                }
            }
            else if (operatingHook && !input.interactDown)
            {
                print("toggle operating hook");
                HookScript hs = currentTile.GetComponentInChildren <HookScript> ();
                hs.SetPilot(this);
                if (input.downHold)
                {
                    hs.MoveHookCounterClockwise();
                }
                else if (input.upHold)
                {
                    hs.MoveHookClockwise();
                }
                else if (input.leftHold)
                {
                    hs.LaunchHook();
                }
            }
            //If the player starts building something
            else if (input.buildUpgradeDown)
            {
                //Can only build on walls
                if (currentTile.Type == "wall")
                {
                    selecting = true;
                    //selectedOption = 0; //(uncomment this line if saving past selection is undesired)
                    //Build tower if there's no tower at location (open tower selection menu)
                    if (!currentTile.IsTower)
                    {
                        //Debug.Log(LevelManager.Instance.TowerMenu[playerNumber - 1]);
                        LevelManager.Instance.TowerMenu[playerNumber - 1].GetComponent <RectTransform>().transform.position = transform.position;
                        LevelManager.Instance.TowerMenu[playerNumber - 1].SetActive(true);

                        //currentTile.TowerMenu(transform.position);
                    }
                    //Upgrade tower if there is a tower at location (open tower upgrade selection menu)
                    else
                    {
                    }
                }
            }
            //If the player is selling something
            else if (input.sellHold)
            {
                //Sell tower if there is a tower at location
                if (currentTile.IsTower)
                {
                    transform.Rotate(new Vector3(0, 0, 90));//temporary "working" animation
                    sellCounter += Time.deltaTime;
                    if (sellCounter > sellTime)
                    {
                        sellCounter = 0;
                        //sell the tower on this line
                        moveSprite(location);//temporary to correct facing after random rotation
                    }
                }
            }
            //If the player is interacting with something
            else if (input.interactDown)
            {
                //TileScript next = LevelManager.Instance.Tiles[getNextPoint(facing)];
                //Interact with something if facing an object that can be interacted with
                if (currentTile.Type == "hook")
                {
                    operatingHook = operatingHook ? false : true;
                }
            }
            else
            {
                //If the player is firing their weapon (weapons are fully automatic)
                if (input.fireDown || input.fireHold)
                {
                    //Fire weapon in facing direction if there is ammo left in the clip
                    if (ammoInClip > 0 && fireCounter > fireCooldown)
                    {
                        ammoInClip--;
                        fireCounter   = 0;
                        reloadCounter = 0;
                        //fire bullet on this line
                        GameObject bullet = Instantiate(tower_projectile, transform.position, transform.rotation) as GameObject;
                        bullet.GetComponent <Rigidbody2D>().velocity = facing * projectileSpeed;
                        AudioSource.PlayClipAtPoint(pew, transform.position);
                    }
                }
                //If the player is moving (can move anywhere except water)
                if (moveCounter > moveCooldown)
                {
                    if (input.upHold || input.downHold || input.leftHold || input.rightHold)
                    {
                        moveInDirection(facing);
                        moveCounter = 0;
                    }
                }
            }

            /// Ammo reload section
            if (currentTile.Type == "room")
            {
                currentTile.updateUsables(playerNumber);
            }
        }