Inheritance: MonoBehaviour
Example #1
0
 // Use this for initialization
 void Start()
 {
     body = this.GetComponent <Rigidbody>();
     body.centerOfMass = MASS_CENTER;
     playerTransform   = GameObject.Find("Player").transform;
     player            = (GameObject)GameObject.Find("Player");
     cannon            = GetComponentInChildren <CannonScript> ();
 }
Example #2
0
 // Use this for initialization
 void Start()
 {
     audioSource     = GetComponent <AudioSource>();
     mapHandler      = GameObject.Find("MapHandler").GetComponent <MapHandler>();
     cannon          = GetComponentInChildren <CannonScript>(true);
     martiniList     = new bool[3];
     deathCount      = 0;
     playerRigidbody = GetComponent <Rigidbody>();
     anim            = GetComponent <Animator>();
 }
Example #3
0
    public void SimulateFlight(CannonScript theCannon)
    {
        Vector3     startPos         = new Vector3(0, 0, 0);
        Vector3     endPos           = new Vector3(0, 0, 0);
        Vector3     moveDelta        = new Vector3(0, 0, 0);
        Vector3     simVelocity      = new Vector3(0, 0, 0);
        Vector3     hitSurfaceNormal = new Vector3(0, 1, 0);
        const float deltaTime        = 1.0f / 10.0f;
        bool        hitTarget        = false;
        bool        hitGround        = false;


        int sanity = 0;

        if (theReticule == null)
        {
            return;
        }

        if (theCannon != null)
        {
            theCannon.GetSpawnBallPosition(out startPos);
            GetLaunchVelocity(theCannon.localElevationAngle, theCannon.localRotationAngle, out simVelocity);
            while (!hitGround && !hitTarget)
            {
                DoMotion(startPos, deltaTime, ref simVelocity, out moveDelta);
                DoCollisionDetection(startPos, moveDelta, out endPos, out hitSurfaceNormal, out hitTarget, out hitGround);
                startPos = endPos;
            }

            if (hitTarget)
            {
                theReticule.renderer.material = greenReticuleMaterial;
            }
            else
            {
                theReticule.renderer.material = redReticuleMaterial;
            }

            print("hitTarget - " + hitTarget + " endPos = " + endPos);

            //where should the reticule go, and what direction should it face?
            theReticule.newPos = endPos;
            theReticule.newOrientationInEulerAngles = Vector3.zero;
            float angleFromVertical = Vector3.Angle(hitSurfaceNormal, Vector3.up);
            if ((angleFromVertical > 1.0f) && (angleFromVertical < 45.0f))
            {
                //	bit of a hack... I know the orientation of the hill,
                //	so if the reticule is hitting anything other than flat ground,
                //	set it to the orientation of the hill
                theReticule.newOrientationInEulerAngles = theGameManager.theHill.transform.eulerAngles;
            }
        }
    }
Example #4
0
 // Use this for initialization
 void Awake()
 {
     audioSource     = GetComponent <AudioSource>();
     mapHandler      = GameObject.Find("MapHandler").GetComponent <MapHandler>();
     playerDisplay   = mapHandler.playerStats;
     cannon          = GetComponentInChildren <CannonScript>(true);
     martiniList     = new bool[3];
     playerRigidbody = GetComponent <Rigidbody>();
     anim            = GetComponent <Animator>();
     rayCastOffsetX  = GetComponent <BoxCollider>().bounds.size.x / 3;
 }
Example #5
0
    public void SimulateFlight(CannonScript theCannon)
    {
        Vector3 startPos = new Vector3(0,0,0);
        Vector3 endPos = new Vector3(0,0,0);
        Vector3 moveDelta = new Vector3(0,0,0);
        Vector3 simVelocity = new Vector3(0,0,0);
        Vector3 hitSurfaceNormal = new Vector3(0,1,0);
        const float deltaTime = 1.0f / 10.0f;
        bool hitTarget = false;
        bool hitGround = false;

        int sanity = 0;

        if (theReticule == null)
        {
            return;
        }

        if (theCannon != null)
        {
            theCannon.GetSpawnBallPosition(out startPos);
            GetLaunchVelocity(theCannon.localElevationAngle, theCannon.localRotationAngle, out simVelocity);
            while(!hitGround && !hitTarget)
            {
                DoMotion(startPos, deltaTime, ref simVelocity, out moveDelta);
                DoCollisionDetection(startPos, moveDelta, out endPos, out hitSurfaceNormal, out hitTarget, out hitGround);
                startPos = endPos;
        }

        if (hitTarget)
        {
            theReticule.renderer.material = greenReticuleMaterial;
        }
        else
        {
            theReticule.renderer.material = redReticuleMaterial;
        }

        print("hitTarget - " + hitTarget + " endPos = " + endPos);

        //where should the reticule go, and what direction should it face?
        theReticule.newPos = endPos;
        theReticule.newOrientationInEulerAngles = Vector3.zero;
        float angleFromVertical = Vector3.Angle(hitSurfaceNormal, Vector3.up);
        if ((angleFromVertical > 1.0f) && (angleFromVertical < 45.0f))
        {
            //	bit of a hack... I know the orientation of the hill,
            //	so if the reticule is hitting anything other than flat ground,
            //	set it to the orientation of the hill
            theReticule.newOrientationInEulerAngles = theGameManager.theHill.transform.eulerAngles;
        }
        }
    }
Example #6
0
    // Use this for initialization
    void Start()
    {
        cannonScript     = cannonObject.GetComponent <CannonScript>();
        source           = this.GetComponent <AudioSource>();
        ghostShip        = ghostShipObject.GetComponent <GhostShipScript>();
        ghost            = ghostObject.GetComponent <GhostScript>();
        difficultyScript = GameObject.FindGameObjectWithTag("Difficulty").GetComponent <DifficultyScript>();

        if (difficultyScript.isLegendaryMode == true)
        {
            ghost.GetComponentInChildren <SkinnedMeshRenderer>().material = legendaryGhost;
            ghost.LegendaryGhost();
        }
    }
Example #7
0
    // Use this for initialization
    void Awake()
    {
        myRB = GetComponent <Rigidbody2D> ();

        cannonProjectile = FindObjectOfType <CannonScript>();

        if (!cannonProjectile.facingRight)
        {
            myRB.AddForce(new Vector2(-1, 0) * rocketSpeed, ForceMode2D.Impulse);
        }
        else if (cannonProjectile.facingRight)
        {
            myRB.AddForce(new Vector2(1, 0) * rocketSpeed, ForceMode2D.Impulse);
        }
    }
Example #8
0
    // Update is called once per frame
    void Update()
    {
        CannonScript cannonScript = this.GetComponent <CannonScript>();

        ballVelocity = cannonScript.ballVelocity;

        myline   = this.GetComponent <LineRenderer>();
        cannon3D = this.GetComponent <Rigidbody>();

        velociiity = cannon3D.transform.forward * ballVelocity;

        plotline = Plot(cannon3D, cannon3D.position, velociiity, 1000);

        myline.positionCount = plotline.Length;

        myline.SetPositions(plotline);
    }
Example #9
0
    public override void Shoot(CannonScript cannon)
    {
        cannon.player.PlaySound(magnetSound);

        GameObject laser = (GameObject)Instantiate(Resources.Load("magnet")) as GameObject;

        laser.transform.position = cannon.transform.position + cannon.transform.right * 2;
        MagnetScript magnetScript = laser.GetComponent <MagnetScript>();

        magnetScript.Launch(cannon.transform.right);
        ammo--;
        if (ammo == 0)
        {
            gameObject.transform.parent.gameObject.SetActive(false);
            cannon.currentWeapon = null;
        }
    }
Example #10
0
    public void PlayerDied(PlayerController player)
    {
        player.deathCount++;
        playerDeaths[player.playerNumber - 1].text  = "Died: " + player.deathCount;
        playerPanels[player.playerNumber - 1].color = new Color(255, 255, 255, 1f);

        CannonScript cannon = players[player.playerNumber - 1].GetComponentInChildren <CannonScript>();

        //Dead player loses all his items!
        for (int i = 0; i < 3; i++)
        {
            player.martiniList[i] = false;
            UpdateItemDisplay(player);
        }
        //POSSIBLE BM TEXT
        player.gameObject.SetActive(false);
        StartCoroutine(RespawnTime(player));
    }
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            RaycastHit hit;
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            if (Physics.Raycast(ray, out hit, 3.0f))
            {
                if (hit.transform == transform)
                {
                    // If we click the button with the mouse
                    // Make the cannon shoot
                    CannonScript cs = hit.transform.parent.GetComponent <CannonScript>();
                    cs.Shoot();
                }
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (activated)
        {
            CannonScript cannonScript = GameObject.Find("launchlocation").GetComponent <CannonScript>();

            //ballVelocity = cannonScript.ballVelocity;

            var mouseMove = new Vector2(Input.GetAxisRaw("Mouse X"), Input.GetAxisRaw("Mouse Y"));
            mouseMove = Vector2.Scale(mouseMove, new Vector2(SENS_HOR, SENS_VER));
            // rotate the character horizontally
            character.transform.Rotate(0, mouseMove.x, 0);
            //transform.Rotate(-mouseMove.y, 0, 0); // rotate the camera vertically
            transform.localRotation = Quaternion.Euler(-ballVelocity, 0, 0);

            // enable the mouse cursor if Esc pressed
            if (Input.GetKeyDown("escape"))
            {
                Cursor.lockState = CursorLockMode.None;
            }
        }
    }
Example #13
0
    // Update is called once per frame
    void Update()
    {
        stateTimer += Time.deltaTime;

        if (transform.localScale.x < 0.85f)
        {
            transform.localScale = new Vector3(1f, 1f, 1f) * (transform.localScale.x + Time.deltaTime);
        }
        if (transform.localScale.x > 0.85f)
        {
            transform.localScale = new Vector3(1f, 1f, 1f) * 0.85f;
        }

        if (state == 0)
        {
            GetComponent <SpriteRenderer>().sprite = frames[0];
            GetComponent <Rigidbody2D>().velocity  = Vector3.right * Mathf.Cos(stateTimer * 1f) * 0.5f;
            Vector3 vel3         = new Vector3(GetComponent <Rigidbody2D>().velocity.normalized.x, GetComponent <Rigidbody2D>().velocity.normalized.y, 0f);
            float   angleBetween = Vector3.SignedAngle(transform.up, Vector3.up + vel3 * 0.75f, new Vector3(0f, 0f, 1f));
            transform.RotateAround(transform.position, new Vector3(0f, 0f, 1f), angleBetween * Time.deltaTime * 3f);
            if (stateTimer > 5f)
            {
                state      = 1;
                stateTimer = 0f;
                GameObject selectedPrefab = bombPrefab;
                spell = false;
                if (Random.Range(0f, 100f) < 25f)
                {
                    selectedPrefab = skullPrefab;
                    spell          = true;
                }
                createdSpell = Instantiate <GameObject>(selectedPrefab);
                createdSpell.transform.SetParent(this.transform);
                createdSpell.transform.position   = spellRef.transform.position;
                createdSpell.transform.rotation   = spellRef.transform.rotation;
                createdSpell.transform.localScale = spellRef.transform.localScale;
                createdSpell.GetComponent <PolygonCollider2D>().enabled = false;

                GameObject snd = Instantiate <GameObject>(soundPrefab);
                snd.GetComponent <SFXScript>().sfx = prepareSpell;
            }
        }
        else if (state == 1)
        {
            GetComponent <SpriteRenderer>().sprite = frames[1];
            GetComponent <Rigidbody2D>().velocity  = GetComponent <Rigidbody2D>().velocity.normalized;
            if (createdSpell != null)
            {
                createdSpell.transform.position   = spellRef.transform.position;
                createdSpell.transform.rotation   = spellRef.transform.rotation;
                createdSpell.transform.localScale = spellRef.transform.localScale;
                createdSpell.GetComponent <Rigidbody2D>().velocity = Vector2.zero;
            }
            Transform target = null;
            if (spell)
            {
                CannonScript cs = FindObjectOfType <CannonScript>();
                if (cs != null)
                {
                    target = cs.transform;
                }
            }
            else
            {
                float       minDist = 999999f;
                GemScript   gem     = null;
                GemScript[] allGems = FindObjectsOfType <GemScript>();
                foreach (GemScript gs in allGems)
                {
                    if (gs != null && (gs.transform.position - transform.position).magnitude < minDist)
                    {
                        minDist = (gs.transform.position - transform.position).magnitude;
                        gem     = gs;
                    }
                }
                if (gem != null)
                {
                    target = gem.transform;
                }
            }
            if (target != null)
            {
                float angleBetween = Vector3.SignedAngle(-transform.up, target.position - transform.position, new Vector3(0f, 0f, 1f));
                transform.RotateAround(transform.position, new Vector3(0f, 0f, 1f), angleBetween * Time.deltaTime * 6f);
            }
            if (stateTimer > 1.5f)
            {
                state      = 2;
                stateTimer = 0f;
                if (createdSpell != null)
                {
                    createdSpell.GetComponent <PolygonCollider2D>().enabled = true;
                    createdSpell.transform.SetParent(null);
                    if (target == null)
                    {
                        createdSpell.GetComponent <Rigidbody2D>().velocity = transform.up * -6f;
                    }
                    else
                    {
                        createdSpell.GetComponent <Rigidbody2D>().velocity = (target.position - createdSpell.transform.position) * 6f;
                    }
                    createdSpell = null;
                }

                GameObject snd = Instantiate <GameObject>(soundPrefab);
                snd.GetComponent <SFXScript>().sfx = castSpell;
            }
        }
        else
        {
            GetComponent <Rigidbody2D>().velocity  = Vector2.zero;
            GetComponent <SpriteRenderer>().sprite = frames[2];
            transform.position -= (transform.position * Time.deltaTime * 0.75f);
            if (stateTimer > 1.5f)
            {
                state      = 0;
                stateTimer = 0f;
            }
        }
    }
Example #14
0
 // Use this for initialization
 void Start()
 {
     cannonLeft  = GameObject.Find("CannonLeft").GetComponent <CannonScript>();
     cannonRight = GameObject.Find("CannonRight").GetComponent <CannonScript>();
 }
Example #15
0
 void Start()
 {
     PlayerInfo = GameObject.FindGameObjectWithTag ("Player").GetComponent<HealthScript>();
     BulletInfo = GameObject.FindGameObjectWithTag ("Cannon").GetComponent<CannonScript>();
 }
 private void Awake()
 {
     cannon = GetComponent <CannonScript>();
 }
Example #17
0
    IEnumerator WaitForHitPlayer(int indexPick, Vector3 vel)
    {
        yield return(new WaitForSeconds(1));

        if (_GameControler._Level == 1)
        {
            int ran = Random.Range(1, 4);
            if (ran == 1)
            {
                int ranDir = 1;
                vel *= (ranDir * 1.2f);
            }
        }
        switch (indexPick)
        {
        case 0:    //Lưu đạn
            Pick_GrenadeControler pick_grenade = gameObject.GetComponentInChildren <Pick_GrenadeControler>();
            pick_grenade.throwBallAIEnemy(vel);
            break;

        case 1:    //Slo
            ShotGunControler pick_shotGun = gameObject.GetComponentInChildren <ShotGunControler>();
            if (_Target == null)
            {
                IdentifyTarget();
            }
            pick_shotGun.throwBallAIEnemy(_Target.transform.position);
            StartCoroutine(WaitForTurn2ShotGun());
            break;

        case 2:    //Cối
            CannonScript pick_Bazoo = gameObject.GetComponentInChildren <CannonScript>();
            pick_Bazoo.ThrowBallEnemy(vel);
            break;

        case 3:     //Rocket
            AirCallControler pick_Bomp = gameObject.GetComponentInChildren <AirCallControler>();
            pick_Bomp.Pick_BombEnemy(_Target.transform.position);
            break;

        case 4:
            Pick_DrillerControler pick_driller = gameObject.GetComponentInChildren <Pick_DrillerControler>();
            pick_driller.throwBallEnemy(_Target.transform.position);
            break;

        case 5: break;

        case 6: break;    //Tự dùng

        case 7:
            Pick_LaserControler pick_laser = gameObject.GetComponentInChildren <Pick_LaserControler>();
            pick_laser.throwBallEnemy(_Target.transform.position);
            break;

        case 8:
            Pick_CarotControler pick_carrot = gameObject.GetComponentInChildren <Pick_CarotControler>();
            pick_carrot.throwBallEnemy(vel);
            break;

        case 9: break;

        case 10:
            Pick_PunchControler pick_punch = gameObject.GetComponentInChildren <Pick_PunchControler>();
            pick_punch.throwBallEnemy(_Target.transform.position);
            break;

        case 11:
            Pick_BowControler pick_bow = gameObject.GetComponentInChildren <Pick_BowControler>();
            pick_bow.throwBallEnemy(vel);
            break;

        case 12:
            Pick_MinigunControler pick_minigun = gameObject.GetComponentInChildren <Pick_MinigunControler>();
            pick_minigun.throwBallEnemy(_Target.transform.position);
            break;

        case 13:
            Pick_Grenade_PoisonControler pick_poison = gameObject.GetComponentInChildren <Pick_Grenade_PoisonControler>();
            pick_poison.throwBallAIEnemy(vel);
            break;

        case 14: break;

        case 15: break;

        case 16:
            Pick_FlamethrowerControler pick_flame = gameObject.GetComponentInChildren <Pick_FlamethrowerControler>();
            pick_flame.throwBallEnemy(_Target.transform.position);
            break;

        case 17: break;
        }
    }
Example #18
0
 public abstract void Shoot(CannonScript cannon);