Example #1
0
 void Start()
 {
     cannon       = GetComponent <CannonController>();
     motor        = GetComponent <ShipMotor>();
     ship         = GetComponent <Ship>();
     ship.OnDead += OnDead;
 }
    void Start()
    {
        motor = GetComponent <ShipMotor>();
        motor.OnStartBoost += OnStartBoost;

        initialTrailColor = thrusterTrail.startColor;
    }
Example #3
0
        private void ChaseTarget(ShipStateController controller)
        {
            ShipMotor shipMotor = controller.GetMotor();
            Rigidbody ship      = controller.GetRigidbody();
            Rigidbody target    = controller.GetTarget();

            if (target == null)
            {
                return;
            }

            Steer(shipMotor, ship, target);

            AdjustThrottle();

            Vector3 toTarget = target.position - ship.position;

            float angle = Vector3.Angle(ship.transform.forward, toTarget);



            Vector3 velocityDifference = ship.velocity - target.velocity;

            //Check throttle
            //Check angle from player
            //Check velocity differences
            //Adjust throttle

            //steer based on stats/throttle
        }
Example #4
0
    private void Start()
    {
        motor = GetComponent<ShipMotor>();
        cannon = GetComponent<CannonController>();

        lockCursor();
    }
Example #5
0
    private void Start()
    {
        motor  = GetComponent <ShipMotor>();
        cannon = GetComponent <CannonController>();

        lockCursor();
    }
    void Start()
    {
        motor = GetComponent<ShipMotor>();
        motor.OnStartBoost += OnStartBoost;

        initialTrailColor = thrusterTrail.startColor;
    }
Example #7
0
    void Awake()
    {
        motor = GetComponent <ShipMotor>();

        //*
        motor.MaxSpeed = motor.baseMaxSpeed;

        //bullets = new List<PlayerBullet>();

        if (!gameCamera && GameObject.FindGameObjectWithTag("MainCamera").GetComponent <Camera>())
        {
            gameCamera = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <Camera>();
        }

        if (!collider && GetComponent <CircleCollider2D>())
        {
            collider = GetComponent <CircleCollider2D>();
        }

        if (!bmManager && GetComponent <BulletModifierManager>())
        {
            bmManager = GetComponent <BulletModifierManager>();
        }

        if (!safeZoneOnRespawn && GetComponent <SafeZoneOnRespawn>())
        {
            safeZoneOnRespawn = GetComponent <SafeZoneOnRespawn>();
        }

        initalPosition = transform.position;
    }
Example #8
0
 void Start()
 {
     cannon = GetComponent<CannonController>();
     motor = GetComponent<ShipMotor>();
     ship = GetComponent<Ship>();
     ship.OnDead += OnDead;
 }
Example #9
0
    void Update()
    {
        transform.position += direction.ToVector3() * Speed * Time.deltaTime;

        Ray ray = new Ray(transform.position, (transform.rotation * Vector3.up));

        Debug.DrawRay(ray.origin, ray.direction, Color.red);
        RaycastHit2D[] hits = Physics2D.RaycastAll(ray.origin.ToVector2(), ray.direction.ToVector2(), 0.0f);
        foreach (RaycastHit2D hit in hits)
        {
            if (hit.collider.gameObject == this.gameObject)
            {
                continue;
            }

            Ship ship = hit.collider.gameObject.GetComponent <Ship>();

            if (ship != null && ship.Team != Team)
            {
                ShipMotor motor = hit.collider.gameObject.GetComponent <ShipMotor>();
                if (motor.Destroyed)
                {
                    break;
                }
                motor.Damage(Team, Damage);
                if (!Piercing)
                {
                    Destroy(this.gameObject);
                }
            }
        }
    }
Example #10
0
 protected override void Interact(ShipMotor shipMotor)
 {
     foreach (var asteroid in GameObject.FindObjectsOfType <Asteroid>())
     {
         asteroid.StopForXTime(slow);
     }
     Destroy(gameObject);
 }
Example #11
0
    // Use this for initialization
    void Start()
    {
        ship_input = ship_settings.UseAi ?
                     new AIInput() as IShipInput :
                     new ControllerInput();

        ship_motor = new ShipMotor(ship_input, transform, ship_settings);
    }
Example #12
0
    void OnTriggerEnter2D(Collider2D other)
    {
        ShipMotor shipMotor = other.gameObject.GetComponent <ShipMotor>();

        if (shipMotor != null)
        {
            Interact(shipMotor);
        }
    }
Example #13
0
 void Start()
 {
     motor = GetComponent <ShipMotor>();
     cam   = Camera.main;
     if (cam == null)
     {
         Debug.Log("No Camera Found");
     }
 }
Example #14
0
 void Start()
 {
     health = maxHealth;
     motor  = GetComponent <ShipMotor>();
     if (OnHealthChange != null)
     {
         OnHealthChange(health, 0);
     }
 }
Example #15
0
    void Start()
    {
        motor                = ship.GetComponent <ShipMotor>();
        canvas               = GetComponent <Canvas>();
        rectTransform        = GetComponent <RectTransform>();
        ship.OnHealthChange += OnHealthChange;
        ship.OnScoreChange  += OnScoreChange;
        motor.OnBoostChange += OnBoostChange;

        SetScoreVisible(ship.GetScore());
    }
Example #16
0
    void Start()
    {
        if (soundSystem == null) {
            this.enabled = false;
            return;
        }

        cannon = GetComponent<CannonController>();
        motor = GetComponent<ShipMotor>();
        ship = GetComponent<Ship>();

        Bind();

        shootSoundPriority = soundSystem.MinPriority();
        boostSoundPriority = soundSystem.MaxPriority();
    }
Example #17
0
    void Start()
    {
        if (soundSystem == null)
        {
            this.enabled = false;
            return;
        }

        cannon = GetComponent <CannonController>();
        motor  = GetComponent <ShipMotor>();
        ship   = GetComponent <Ship>();

        Bind();

        shootSoundPriority = soundSystem.MinPriority();
        boostSoundPriority = soundSystem.MaxPriority();
    }
Example #18
0
 void OnTriggerEnter2D(Collider2D hitInfo)
 {
     Debug.Log(hitInfo.name);
     if (armed)
     {
         ShipMotor ship = hitInfo.GetComponent <ShipMotor>();
         if (ship != null)
         {
             ship.TakeDamage(damage);
             Instantiate(smokePrefab, transform.position, transform.rotation);
             Destroy(gameObject);
         }
         else
         {
             Instantiate(smokePrefab, transform.position, transform.rotation);
             Destroy(gameObject);
         }
     }
 }
Example #19
0
    void Start()
    {
        camera         = GetComponent <Camera>();
        curRollDamping = rollDamping;

        motor = ship.GetComponent <ShipMotor>();
        motor.OnStartManeuver += OnStartManeuver;
        motor.OnStopManeuver  += OnStopManeuver;
        motor.OnStartBoost    += OnStartBoost;
        motor.OnStopBoost     += OnStopBoost;

        ship.OnRespawn      += OnRespawn;
        ship.OnHealthChange += OnHealthChange;

        normalFov = camera.fieldOfView;
        boostFov  = normalFov * boostFovFactor;
        fovTarget = normalFov;

        shakeTimer = shakeTime;
    }
Example #20
0
    void Start()
    {
        camera = GetComponent<Camera>();
        curRollDamping = rollDamping;

        motor = ship.GetComponent<ShipMotor>();
        motor.OnStartManeuver += OnStartManeuver;
        motor.OnStopManeuver += OnStopManeuver;
        motor.OnStartBoost += OnStartBoost;
        motor.OnStopBoost += OnStopBoost;

        ship.OnRespawn += OnRespawn;
        ship.OnHealthChange += OnHealthChange;

        normalFov = camera.fieldOfView;
        boostFov = normalFov * boostFovFactor;
        fovTarget = normalFov;

        shakeTimer = shakeTime;
    }
Example #21
0
 void Start()
 {
     motor = GetComponent<ShipMotor>();
     initialRotation = new Vector3(270.0f, 0.0f, 0.0f);
 }
Example #22
0
    void Awake()
    {
        shipMotor = GetComponent<ShipMotor>();

        tiltJoystick = GetComponent<TiltJoystick>();
    }
Example #23
0
    void Awake()
    {
        shipMotor = GetComponent <ShipMotor>();

        tiltJoystick = GetComponent <TiltJoystick>();
    }
Example #24
0
    void Start()
    {
        motor = ship.GetComponent<ShipMotor>();
        canvas = GetComponent<Canvas>();
        rectTransform = GetComponent<RectTransform>();
        ship.OnHealthChange += OnHealthChange;
        ship.OnScoreChange += OnScoreChange;
        motor.OnBoostChange += OnBoostChange;

        SetScoreVisible(ship.GetScore());
    }
Example #25
0
 void Start()
 {
     motor           = GetComponent <ShipMotor>();
     initialRotation = new Vector3(270.0f, 0.0f, 0.0f);
 }
Example #26
0
    void Update()
    {
        //Calculate Total Engine Force (Break down into engines later)
        float _xMov = Input.GetAxisRaw("Horizontal");
        float _zMov = Input.GetAxisRaw("Vertical");

        Vector2 _movVerticle = transform.up * _zMov;
        Vector2 _velocity    = (_movVerticle).normalized * speed;

        // Debug.Log("Velocity : [" + _velocity[0] + ", " + _velocity[1] + "]");

        //Apply movment
        motor.Move(_velocity);
        motor.Rot(-turnForce * _xMov);
        // gameObject.GetComponent<Rigidbody2D>().AddTorque(1.0f*Time.deltaTime);


        if (Input.GetButtonDown("Fire1"))
        {
            ShootMissile();
        }
        if (Input.GetButtonDown("Fire2"))
        {
            StartCoroutine(ShootMachineGun());
        }
        void ShootMissile()
        {
            if (whichBay)
            {
                whichBay = false;
                GameObject _missile = Instantiate(missilePrefab, firePointRight.position, firePointRight.rotation);
                _missile.GetComponent <Rigidbody2D>().velocity        = gameObject.GetComponent <Rigidbody2D>().velocity;
                _missile.GetComponent <Rigidbody2D>().angularVelocity = gameObject.GetComponent <Rigidbody2D>().angularVelocity;
                _missile.GetComponent <Rigidbody2D>().AddForce(transform.right * MissileForce);
            }
            else
            {
                whichBay = true;
                GameObject _missile = Instantiate(missilePrefab, firePointLeft.position, firePointLeft.rotation);
                _missile.GetComponent <Rigidbody2D>().velocity        = gameObject.GetComponent <Rigidbody2D>().velocity;
                _missile.GetComponent <Rigidbody2D>().angularVelocity = gameObject.GetComponent <Rigidbody2D>().angularVelocity;
                _missile.GetComponent <Rigidbody2D>().AddForce(-1.0f * transform.right * MissileForce);
            }
        }

        IEnumerator ShootMachineGun()
        {
            RaycastHit2D hitInfoL = Physics2D.Raycast(machinegunLeft.position + machinegunLeft.up, machinegunLeft.up);
            RaycastHit2D hitInfoR = Physics2D.Raycast(machinegunRight.position + machinegunRight.up, machinegunRight.up);

            if (hitInfoL)
            {
                ShipMotor ship = hitInfoL.transform.GetComponent <ShipMotor>();
                if (ship != null)
                {
                    ship.TakeDamage(damage);
                    Instantiate(impactEffect, hitInfoL.point, Quaternion.identity);
                    lineRendererL.SetPosition(0, machinegunLeft.position);
                    lineRendererL.SetPosition(1, hitInfoL.point);
                }
            }
            else
            {
                lineRendererL.SetPosition(0, machinegunLeft.position);
                lineRendererL.SetPosition(1, machinegunLeft.position + machinegunLeft.up * 100);
            }
            if (hitInfoR)
            {
                ShipMotor ship = hitInfoR.transform.GetComponent <ShipMotor>();
                if (ship != null)
                {
                    ship.TakeDamage(damage);
                    Instantiate(impactEffect, hitInfoR.point, Quaternion.identity);
                    lineRendererR.SetPosition(0, machinegunRight.position);
                    lineRendererR.SetPosition(1, hitInfoR.point);
                }
            }
            else
            {
                lineRendererR.SetPosition(0, machinegunRight.position);
                lineRendererR.SetPosition(1, machinegunRight.position + machinegunRight.up * 100);
            }
            lineRendererL.enabled = true;
            lineRendererR.enabled = true;
            yield return(0);

            lineRendererL.enabled = false;
            lineRendererR.enabled = false;
        }
    }
Example #27
0
 void Start()
 {
     colliders = player.GetComponents <Collider>();
     motor     = GetComponent <ShipMotor>();
     ship      = GetComponent <Ship>();
 }
Example #28
0
 protected abstract void Interact(ShipMotor shipMotor);
Example #29
0
    void Update()
    {
        // If you want to disable input while you are using menues... no thanks
        // if (EventSystem.current.IsPointerOverGameObject())
        //     return;
        //Calculate Total Engine Force (Break down into engines later)
        float _xMov = Input.GetAxisRaw("Horizontal");
        float _zMov = Input.GetAxisRaw("Vertical");

        Vector2 _movVerticle = transform.up * _zMov;
        Vector2 _velocity    = (_movVerticle).normalized * speed;

        // Debug.Log("Velocity : [" + _velocity[0] + ", " + _velocity[1] + "]");

        //Apply movment
        motor.Move(_velocity);
        motor.Rot(-turnForce * _xMov);
        // gameObject.GetComponent<Rigidbody2D>().AddTorque(1.0f*Time.deltaTime);

        if (Input.GetMouseButtonDown(0))
        {
            ShootMissile();

            Vector3      mousePos   = GetWorldPositionOnPlane(Input.mousePosition, 0f);
            Vector2      mousePos2D = new Vector2(mousePos.x, mousePos.y);
            RaycastHit2D hit        = Physics2D.Raycast(mousePos2D, Vector2.zero);
            // Debug.Log("MousePosition" + Input.mousePosition);
            // Debug.Log("MousePositionWorldPoint" + mousePos);
            if (hit.collider != null)
            {
                Debug.Log("We Hit" + hit.collider.name + " " + hit.point);
            }
            RemoveFocus();
        }
        if (Input.GetMouseButtonDown(1))
        {
            StartCoroutine(ShootMachineGun());
            Vector3      mousePos   = GetWorldPositionOnPlane(Input.mousePosition, 0f);
            Vector2      mousePos2D = new Vector2(mousePos.x, mousePos.y);
            RaycastHit2D hit        = Physics2D.Raycast(mousePos2D, Vector2.zero);
            // Debug.Log("MousePosition" + Input.mousePosition);
            // Debug.Log("MousePositionWorldPoint" + mousePos);
            if (hit.collider != null)
            {
                Interactable interactable = hit.collider.GetComponent <Interactable>();
                if (interactable != null)
                {
                    SetFocus(interactable);
                }
            }
        }

        // if(Input.GetButtonDown("Fire1"))
        // {
        //     ShootMissile();
        // }
        // if(Input.GetButtonDown("Fire2"))
        // {
        //     StartCoroutine(ShootMachineGun());
        // }
        void ShootMissile()
        {
            if (whichBay)
            {
                whichBay = false;
                GameObject _missile = Instantiate(missilePrefab, firePointRight.position, firePointRight.rotation);
                _missile.GetComponent <Rigidbody2D>().velocity        = gameObject.GetComponent <Rigidbody2D>().velocity;
                _missile.GetComponent <Rigidbody2D>().angularVelocity = gameObject.GetComponent <Rigidbody2D>().angularVelocity;
                _missile.GetComponent <Rigidbody2D>().AddForce(transform.right * 20f);
            }
            else
            {
                whichBay = true;
                GameObject _missile = Instantiate(missilePrefab, firePointLeft.position, firePointLeft.rotation);
                _missile.GetComponent <Rigidbody2D>().velocity        = gameObject.GetComponent <Rigidbody2D>().velocity;
                _missile.GetComponent <Rigidbody2D>().angularVelocity = gameObject.GetComponent <Rigidbody2D>().angularVelocity;
                _missile.GetComponent <Rigidbody2D>().AddForce(-1.0f * transform.right * 20f);
            }
        }

        IEnumerator ShootMachineGun()
        {
            RaycastHit2D hitInfoL = Physics2D.Raycast(machinegunLeft.position + machinegunLeft.up, machinegunLeft.up);
            RaycastHit2D hitInfoR = Physics2D.Raycast(machinegunRight.position + machinegunRight.up, machinegunRight.up);

            if (hitInfoL)
            {
                ShipMotor ship = hitInfoL.transform.GetComponent <ShipMotor>();
                if (ship != null)
                {
                    ship.TakeDamage(damage);
                    Instantiate(impactEffect, hitInfoL.point, Quaternion.identity);
                    lineRendererL.SetPosition(0, machinegunLeft.position);
                    lineRendererL.SetPosition(1, hitInfoL.point);
                }
            }
            else
            {
                lineRendererL.SetPosition(0, machinegunLeft.position);
                lineRendererL.SetPosition(1, machinegunLeft.position + machinegunLeft.up * 100);
            }
            if (hitInfoR)
            {
                ShipMotor ship = hitInfoR.transform.GetComponent <ShipMotor>();
                if (ship != null)
                {
                    ship.TakeDamage(damage);
                    Instantiate(impactEffect, hitInfoR.point, Quaternion.identity);
                    lineRendererR.SetPosition(0, machinegunRight.position);
                    lineRendererR.SetPosition(1, hitInfoR.point);
                }
            }
            else
            {
                lineRendererR.SetPosition(0, machinegunRight.position);
                lineRendererR.SetPosition(1, machinegunRight.position + machinegunRight.up * 100);
            }
            lineRendererL.enabled = true;
            lineRendererR.enabled = true;
            yield return(0);

            lineRendererL.enabled = false;
            lineRendererR.enabled = false;
        }
    }
Example #30
0
 protected override void Interact(ShipMotor shipMotor)
 {
     shipMotor.UpdateLife(healAmount);
     Destroy(gameObject);
 }
Example #31
0
 void Start()
 {
     motor = gameObject.GetComponent<ShipMotor>();
 }
Example #32
0
 public ShipController(ShipMotor shipMotorInstance)
 {
     _shipMotorInstance = shipMotorInstance;
 }
Example #33
0
        public override void Update()
        {
            UpdateLight();

            motor = getChunk().getVoxelObject().component.GetComponent <ShipMotor>();
        }
Example #34
0
 void Start()
 {
     colliders = player.GetComponents<Collider>();
     motor = GetComponent<ShipMotor>();
     ship = GetComponent<Ship>();
 }
Example #35
0
        private void Steer(ShipMotor shipMotor, Rigidbody ship, Rigidbody target)
        {
            Vector3 toTarget = target.position - ship.position;

            Vector3 targetAngle = Quaternion.LookRotation(toTarget).eulerAngles;
            Vector3 shipAngles  = ship.rotation.eulerAngles;

            //Yaw (Left/Right)
            float shipXAngle   = shipAngles.x;
            float targetXAngle = targetAngle.x;

            if (shipXAngle > targetXAngle)
            {
                shipXAngle -= 360;
            }
            float clockwise = targetXAngle - shipXAngle;

            shipXAngle = shipAngles.x;
            if (targetXAngle > shipXAngle)
            {
                targetXAngle -= 360;
            }
            float counterClockwise = shipXAngle - targetXAngle;

            bool useClockwise = (clockwise <= counterClockwise);

            if (useClockwise)
            {
                shipMotor.Pitch(-1f * Time.fixedDeltaTime);
            }
            else
            {
                shipMotor.Pitch(1f * Time.fixedDeltaTime);
            }

            //Pitch (Up/Down)
            float shipYAngle   = shipAngles.y;
            float targetYAngle = targetAngle.y;

            if (shipYAngle > targetYAngle)
            {
                shipYAngle -= 360;
            }
            clockwise = targetYAngle - shipYAngle;

            shipYAngle = shipAngles.y;
            if (targetYAngle > shipYAngle)
            {
                targetYAngle -= 360;
            }
            counterClockwise = shipYAngle - targetYAngle;

            useClockwise = (clockwise <= counterClockwise);

            if (useClockwise)
            {
                shipMotor.Yaw(-1f * Time.fixedDeltaTime);
            }
            else
            {
                shipMotor.Yaw(1f * Time.fixedDeltaTime);
            }
        }
 void Start()
 {
     motor = GetComponent <ShipMotor>();
 }