コード例 #1
0
ファイル: Ship.cs プロジェクト: yishaiSilver/Starlit
    private void FixedUpdate()
    {
        // Rotate
        rb2d.MoveRotation(rotation - 90);

        // Unshrink if necessary
        if (shouldMaximize)
        {
            shouldMaximize = !Maximize();
        }

        // Set Target
        if (Input.GetMouseButtonDown(1) && isFullscale())
        {
            StopAutomatic();
            Vector3      mousePos   = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            Vector2      mousePos2D = new Vector2(mousePos.x, mousePos.y);
            RaycastHit2D hit        = Physics2D.Raycast(mousePos2D, Vector2.zero);
            if (hit.collider != null)
            {
                targetObject = hit.collider.gameObject.GetComponent <LandableObject>();
                landing      = true;
                SetLandingTargetText(hit.collider.gameObject);
            }
        }

        // Move with the planet if landed
        if (landed)
        {
            MoveTowards();
        }
    }
コード例 #2
0
ファイル: LandableMenu.cs プロジェクト: yishaiSilver/Starlit
    public void Enable(GameObject ship, LandableObject world)
    {
        theShip  = ship.GetComponent <Ship>();
        theWorld = world;

        title.text = world.name.ToUpper();

        panelCargo.text           = stringCargo + theShip.currentCargo + "/" + theShip.cargoSize;
        panelPlanetResources.text = stringPlanet + theWorld.resources;
    }
コード例 #3
0
ファイル: Ship.cs プロジェクト: yishaiSilver/Starlit
    public LandableObject FindClosestLandableObject()
    {
        landables = starSystem.GetLandables();

        if (landables.Length > 0)
        {
            LandableObject closest = landables[0];
            float          dist    = Vector2.Distance(transform.position, closest.transform.position);

            foreach (LandableObject obj in landables)
            {
                if (Vector2.Distance(transform.position, obj.transform.position) < dist)
                {
                    closest = obj;
                    dist    = Vector2.Distance(transform.position, obj.transform.position);
                }
            }

            return(closest);
        }
        return(null);
    }
コード例 #4
0
ファイル: HUDManager.cs プロジェクト: yishaiSilver/Starlit
 public void Land(GameObject ship, LandableObject target)
 {
     closeAll();
     worldMenu.SetActive(true);
     worldMenu.GetComponent <LandableMenu>().Enable(ship, target);
 }
コード例 #5
0
 public void notifyOfLand(GameObject ship, LandableObject target)
 {
     hudManager.Land(ship, target);
 }
コード例 #6
0
ファイル: Ship.cs プロジェクト: yishaiSilver/Starlit
    /*public bool Land(LandableObject target)
     * {
     *  //------Stopping
     *  if (!stoppedFirst && !StopLook(target.transform))
     *      return false;
     *  else
     *      stoppedFirst = true;
     *  //--------------------------
     *
     *  if (!distanceToStop && !ThrustToTarget(target.transform))
     *      return false;
     *  else
     *      distanceToStop = true;
     *
     *  //--------Stopping at target
     *  if (!Stop() && !stoppedAtTarget)
     *      return false;
     *  else
     *  {
     *      stoppedAtTarget = true;
     *      thrusting = false;
     *  }
     *
     *  //-------Aligning with Target and shrink
     *  bool moved = MoveTowards(target.transform);
     *  bool shrunk = Shrink();
     *
     *  if (!moved || !shrunk)
     *      return false;
     *  else // -------------------------------FINISHED
     *  {
     *      // reset landing bools
     *      landing = false;
     *      stoppedFirst = false;
     *      landingTargetTargeted = false;
     *      distanceToStop = false;
     *      thrustingForLand = false;
     *      stoppedAtTarget = false;
     *
     *      // the eagle has landed
     *      landed = true;
     *
     *      if (playerController != null)
     *          playerController.notifyOfLand(gameObject, target);
     *      //
     *      // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% OPEN WORLD MENU
     *      //
     *      return true;
     *  }
     * }*/

    public bool Land(LandableObject target)
    {
        //------Stopping
        if (!stoppedFirst && !Stop())
        {
            return(false);
        }
        else
        {
            stoppedFirst = true;
        }
        //--------------------------

        //-------Turning
        if (!landingTargetTargeted && !LookAt(target.transform))
        {
            return(false);
        }
        else
        {
            landingTargetTargeted = true;
        }
        //---------------------------

        //-------Thrusting to Target
        if (!distanceToStop && !ThrustToTarget(target.transform))
        {
            return(false);
        }
        else
        {
            distanceToStop = true;
        }
        //----------------------------

        //-------Aligning with Target
        if (!distanceToStop && !ThrustToTarget(target.transform))
        {
            return(false);
        }
        else
        {
            distanceToStop = true;
        }
        //----------------------------

        //--------Stopping at target
        if (!Stop() && !stoppedAtTarget)
        {
            return(false);
        }
        else
        {
            stoppedAtTarget = true;
            thrusting       = false;
        }

        //-------Aligning with Target and shrink
        bool moved  = MoveTowards(target.transform);
        bool shrunk = Shrink();

        if (!moved || !shrunk)
        {
            return(false);
        }
        else // -------------------------------FINISHED
        {
            // reset landing bools
            landing               = false;
            stoppedFirst          = false;
            landingTargetTargeted = false;
            distanceToStop        = false;
            thrustingForLand      = false;
            stoppedAtTarget       = false;

            // the eagle has landed
            landed = true;

            if (playerController != null)
            {
                playerController.notifyOfLand(gameObject, target);
            }
            //
            // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% OPEN WORLD MENU
            //
            return(true);
        }
    }
コード例 #7
0
ファイル: Ship.cs プロジェクト: yishaiSilver/Starlit
    public bool Manual()
    {
        if (inHyperSpace)
        {
            return(false);
        }

        bool ret = false;

        // Accelerate
        if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow))
        {
            thrusting = true;
            ret       = true;
        }

        // Stop
        if (Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow))
        {
            Stop();
            ret = true;
        }

        // Turn right
        if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow))
        {
            rotation -= rotSpeed * Time.deltaTime;
            ret       = true;
        }

        // Turn left
        if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow))
        {
            rotation += rotSpeed * Time.deltaTime;
            ret       = true;
        }

        // Land
        if (Input.GetKey(KeyCode.L))
        {
            targetObject = FindClosestLandableObject();
            SetLandingTargetText(targetObject.gameObject);
            landing = true;
        }

        if (Input.GetKey(KeyCode.T))
        {
            TakeOff();
        }

        if (Input.GetKey(KeyCode.U))
        {
            //script.shouldExecute = true;
        }
        else if (ret || Input.GetKey(KeyCode.I))
        {
            //script.shouldExecute = false;
            ret = true;
        }

        if (Input.GetKey(KeyCode.K))
        {
            //currentDirections = map.getStackTo(starSystem, targetStar);
        }

        if (!(currentDirections == null || currentDirections.Count == 0) && (jumping || Input.GetKey(KeyCode.J)))
        {
            jumping = true;
        }

        if (Input.GetKey(KeyCode.M))
        {
            playerController.toggleMap();
        }

        Thrust();
        return(ret);
    }