Ejemplo n.º 1
0
    void Start()
    {
        Verse verse = GetComponent <MainController>().Verse;

        tacticalViewObject = new GameObject("Tactical view");

        Player = new Player(GetComponent <MainController>().Verse)
        {
            Funds = 1000
        };
        Player.Inventory.Add(new Inventory.Item()
        {
            part = verse.registry.partRegistry.Get("turret"), quantity = 1
        });

        Ship = new Ship(verse)
        {
            Name = "Serenity 2.0"
        };

        AddShip(Ship);
        Ship.AddPart(verse.registry.partRegistry.Get("root"), new Coordinate(0, 0));

        verse.NextShip();

        Ship Ship2 = new Ship(verse);

        Ship2.Name = "Serenity 1.0";

        AddShip(Ship2);
        Ship2.Position = new Vector2(10, 10);
        Ship2.AddPart(verse.registry.partRegistry.Get("root"), new Coordinate(0, 0));
        Ship2.AddPart(verse.registry.partRegistry.Get("basic_hull"), new Coordinate(0, 1));

        GUIController.Find("player_panel").SetParameters(new object[] { Player });
        GUIController.Find("ship_view").SetParameters(new object[] { Ship });

        // Test warp and merchant stuff
        Ship.WarpTo(Enumerable.ToList(verse.Galaxy.systems.Values)[0].planets[0]);
        Ship.Location.AddNpc(new Merchant("Jim"));
        (Ship.Location.GetNpc(0) as Merchant).Inventory.Funds = 2000;
        GUIController.Find("merchant_view").SetParameters(new object[] { Ship.Location.GetNpc(0) });
        (GUIController.Find("merchant_view") as GUI.Widget).Hide();
    }
Ejemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        Verse.Update();

        if (Input.GetKeyDown(KeyCode.Tab))
        {
            Verse.NextShip();
        }

        if (Input.GetButtonDown("map"))
        {
            switch (viewMode)
            {
            case ViewMode.Ship:
            case ViewMode.TacticalMap:
                SetMode(ViewMode.Map);
                break;

            case ViewMode.Map:
            case ViewMode.SolarMap:
                SetMode(ViewMode.Ship);
                break;
            }
        }
        else if (Input.GetButtonDown("TacticalMap"))
        {
            switch (viewMode)
            {
            case ViewMode.Ship:
            case ViewMode.Map:
            case ViewMode.SolarMap:
                SetMode(ViewMode.TacticalMap);
                break;

            case ViewMode.TacticalMap:
                SetMode(ViewMode.Ship);
                break;
            }
        }
        if (viewMode == ViewMode.Map || viewMode == ViewMode.SolarMap)
        {
            if (Input.GetMouseButtonDown(0))
            {
                Camera  camera = galaxy.GetComponent <GalaxyComponent>().Camera;
                Vector2 ray    = camera.ScreenToWorldPoint(Input.mousePosition);

                RaycastHit2D hitInfo = Physics2D.Raycast(ray, ray, 0.0f);

                if (viewMode == ViewMode.Map && hitInfo.transform != null && hitInfo.transform.GetComponent <SolarSystemComponent>() != null)
                {
                    if (hitInfo.transform.gameObject == oldHitObject && (Time.time - hitTime) < 0.5f)
                    {
                        SolarSystemComponent ssc = hitInfo.transform.GetComponent <SolarSystemComponent>();
                        solarMap = ssc.DisplaySystem();
                        SetMode(ViewMode.SolarMap, ssc.Emitter);

                        Debug.Log(ssc.Emitter.Name);
                    }

                    oldHitObject = hitInfo.transform.gameObject;
                    hitTime      = Time.time;
                    //GUIController.childs["star_menu"].Show();
                }
                else if (viewMode == ViewMode.SolarMap && hitInfo.transform != null && hitInfo.transform.GetComponentInParent <PlanetComponent>() != null)
                {
                    PlanetComponent pc = hitInfo.transform.GetComponentInParent <PlanetComponent>();
                    GUIController.childs["planet_menu"].Show();
                    GUIController.childs["planet_menu"].GameObject.transform.position = camera.WorldToScreenPoint(pc.transform.position);
                    GUIController.childs["planet_menu"].SetParameters(new object[] { pc.Emitter });
                }
                else if (hitInfo.transform == null || hitInfo.transform.GetComponent <WidgetComponent>() == null)
                {
                    if (GUIController.HoverObject == null)
                    {
                        //GUIController.childs["star_menu"].Hide();
                        GUIController.childs["planet_menu"].Hide();
                    }
                }
            }
        }

        Vector3 mousePos = cameraController.mainCamera.ScreenToViewportPoint(Input.mousePosition);

        if (cameraController.tacticalMapCamera.rect.Contains(mousePos))
        {
            //Debug.Log("Mouse is on tacmap.");
            if (Input.GetButtonDown("Fire1"))
            {
                shipController.Ship.AddWaypoint(
                    cameraController.tacticalMapCamera.ScreenToWorldPoint(Input.mousePosition)
                    );
                //Debug.Log(cameraController.tacticalMapCamera.ScreenToWorldPoint(Input.mousePosition));
            }
        }
    }