示例#1
0
    // Use this for initialization
    void Start()
    {
        BuildingGrid = new GameObject[GridWidth, GridHeight];
        PosGrid      = new bool[GridWidth, GridHeight];
        obs_timer    = new Timer(5000);
        //loading map

        Vector2 map_pos = Vector2.zero;

        for (int m = 0; m < 4; m++)
        {
            map_pos = new Vector2((m % 2) * 5, (m / 2) * 5);

            int angle = Subs.GetRandom(new int[] { 0, 90, 180, 270 });

            var     map  = Subs.GetRandom(Maps);
            int     w    = map.map_data.GetLength(1);
            int     h    = map.map_data.GetLength(0);
            Vector2 size = new Vector2(w, h);
            for (int y = 0; y < h; y++)
            {
                for (int x = 0; x < w; x++)
                {
                    Vector2 pos = new Vector2(x, y);

                    pos = RotateArrayVector2(pos, size, angle);

                    pos.y = h - 1 - pos.y;

                    pos += map_pos;

                    if (map.map_data[y, x] == 1)
                    {
                        AddBuilding((int)pos.x, (int)pos.y);
                    }
                    if (map.map_data[y, x] == 2)
                    {
                        AddCheckPoint((int)pos.x, (int)pos.y);
                    }
                }
            }
        }

        var goal = raceController.CheckPoints[Subs.GetRandom(raceController.CheckPoints.Count)];

        goal.IsGoal             = true;
        raceController.StartPos = goal;

        raceController.CreateCars();

        CameraGo.transform.position =
            new Vector3(raceController.StartPos.transform.position.x,
                        CameraGo.transform.position.x,
                        raceController.StartPos.transform.position.z
                        );

        AStar.Scan();
    }
示例#2
0
    private void CreateRandomObstacle()
    {
        int rx = Subs.GetRandom(GridWidth);
        int ry = Subs.GetRandom(GridHeight);

        Vector3 rv = new Vector3(1, 0, 1) * 2.5f + new Vector3(Subs.GetRandom(5f), 0, Subs.GetRandom(5f));

        var go = Instantiate(Obstacle_prefab, new Vector3(rx * TileSize, 170, ry * TileSize) + rv, Quaternion.identity) as GameObject;

        if (obs_timer.Delay > 500)
        {
            obs_timer.Delay -= 100;
        }
    }
示例#3
0
    // Use this for initialization
    public WorldData()
    {
        Turn = 1;

        Ships = new List <ShipData>();

        //find and populate nodes
        var world = GameObject.FindGameObjectWithTag("World");

        int i = 0;

        foreach (Transform t in world.transform)
        {
            var Node = t.gameObject.GetComponent <NodeMain>();

            var data = new NodeData("Node " + i);
            Node.setData(data);
            data.setNode(Node);
            i++;
            Nodes.Add(data);
        }

        //player faction
        var pf = new FactionData("Player Faction", false, this);

        player_faction = pf;
        Factions.Add(pf);

        var pn = Nodes[Subs.GetRandom(Nodes.Count)];
        var pc = new ColonyData(this, pf, pn, true);

        pn.SetColony(pc);

        //other factions
        pf = new FactionData("Other Faction", true, this);
        Factions.Add(pf);

        while (pn.HasColony())
        {
            pn = Nodes[Subs.GetRandom(Nodes.Count)];
        }
        pc = new ColonyData(this, pf, pn, true);

        pn.SetColony(pc);
    }
示例#4
0
    // Update is called once per frame
    void Update()
    {
#if UNITY_EDITOR
        if (Input.GetKeyDown(KeyCode.B))
        {
            Vector2 pos = Vector3.zero;
            if (GetMouseTilePos(out pos))
            {
                int x = (int)pos.x, y = (int)pos.y;
                AddBuilding(x, y);
            }
        }

        if (Input.GetKeyDown(KeyCode.V))
        {
            ActionModeStarted = true;
        }

        if (Input.GetKeyDown(KeyCode.C))
        {
            for (int i = 0; i < 35; i++)
            {
                AddBuilding(Subs.GetRandom(GridWidth), Subs.GetRandom(GridHeight));
            }
            AStar.Scan();
        }

        if (Input.GetKeyDown(KeyCode.X))
        {
            AStar.Scan();
        }
#endif
        if (ActionModeStarted)
        {
            obs_timer.Update();

            if (obs_timer.Done)
            {
                CreateRandomObstacle();
                obs_timer.Reset();
            }
        }
    }
 public PathNodeMain GetNextNode()
 {
     return(forward_nodes[Subs.GetRandom(forward_nodes.Count)]);
 }
示例#6
0
 void OnPathDestroyed(List <PathNodeMain> nodes)
 {
     Move(nodes[Subs.GetRandom(nodes.Count)]);
 }
    // Update is called once per frame
    void Update()
    {
        if (_controlMode == ControlMode.CreatePaths)
        {
            if (GroundPosition(out temp_ground_pos))
            {
                selection_circle.transform.position = temp_ground_pos + Vector3.up * 0.1f;
            }
        }

        if (Input.GetKeyDown(KeyCode.Escape))
        {
            Application.LoadLevel("MenuScene");
        }

        if (GAMEOVER)
        {
            if (Input.GetKeyDown(KeyCode.R))
            {
                Application.LoadLevel("GameScene");
            }

            return;
        }
        //select
        if (Input.GetButtonUp("Select"))
        {
            if (moving_node)
            {
                moving_node = false;
                if (_controlMode == ControlMode.CreatePaths)
                {
                    selection_circle.gameObject.SetActive(true);
                }
            }
            if (node_pressed)
            {
                DeselectNode();
            }
            node_pressed = false;

            selection_rect_on = false;
            if (selection_rect_on_legit)
            {
                SelectUnits(selection_rect_start_pos, Input.mousePosition);
                selection_rect_on_legit = false;
                if (_controlMode == ControlMode.CreatePaths)
                {
                    selection_circle.gameObject.SetActive(true);
                }
            }
            else
            if (_controlMode == ControlMode.CreatePaths)
            {
                if (can_create_path)
                {
                    //CreateNodeInMousePos();
                }
            }
            can_create_path = false;
        }

        if (Input.GetButton("Select"))
        {
            if (moving_node)             //moving node
            {
                if (GroundPosition(out temp_ground_pos))
                {
                    if (node_pressed)
                    {
                        if (Vector3.Distance(
                                temp_ground_pos, selected_node.transform.position
                                - new Vector3(temp_selection_offset.x, 0, temp_selection_offset.z)
                                ) > 1)
                        {
                            selected_node.Reposition(temp_ground_pos + temp_selection_offset);
                            node_pressed = false;
                        }
                    }
                    else
                    {
                        selected_node.Reposition(temp_ground_pos + temp_selection_offset);
                    }
                }
            }
            else
            {
                //start selection rectangle
                if (!selection_rect_on_legit && selection_rect_on)
                {
                    if (Vector3.Distance(Input.mousePosition, selection_rect_start_pos) > 10)
                    {
                        selection_rect_on_legit = true;
                        selection_circle.gameObject.SetActive(false);
                    }
                }
            }
        }

        if (Input.GetButtonDown("Select"))
        {
            //check for units
            var unit = RaycastUnit();

            if (unit != null)
            {
                SelectUnit(unit);
#if UNITY_EDITOR
                unit.HP -= 10;
#endif
                return;
            }


            selection_rect_on        = true;
            selection_rect_start_pos = Input.mousePosition;

            if (_controlMode == ControlMode.None)
            {
                var node = RaycastPathNode();

                if (node != null)
                {
                    SetPathMode(true);
                    SetSelectedNode(node);
                    return;
                }
            }

            if (_controlMode == ControlMode.CreatePaths)
            {
                var node = RaycastPathNode();

                if (node != null)
                {
                    moving_node = true;
                    selection_circle.gameObject.SetActive(false);

                    if (selected_node == node)
                    {
                        node_pressed = true;
                    }
                    else
                    {
                        SetSelectedNode(node);
                        DeselectLine();
                    }

                    if (GroundPosition(out temp_ground_pos))
                    {
                        temp_selection_offset = node.transform.position - temp_ground_pos;
                    }
                    return;
                }

                var line = RaycastPathLine();

                if (line != null)
                {
                    SetSelectedLine(line);
                    DeselectNode();
                    return;
                }

                can_create_path = true;
            }

            DeselectUnits();

            DeselectLine();
        }

        //control actions
        if (Input.GetButtonDown("Command"))
        {
            if (_controlMode == ControlMode.None)
            {
                if (HasSelectedUnits())
                {
                    var node = RaycastPathNode();
                    if (node != null)
                    {
                        foreach (var s in selected_units)
                        {
                            s.Move(node);
                        }
                    }
                    else
                    {
                        if (GroundPosition(out temp_ground_pos))
                        {
                            foreach (var s in selected_units)
                            {
                                s.Move(temp_ground_pos);
                            }
                        }
                    }
                }
            }
            else
            if (_controlMode == ControlMode.CreatePaths)
            {
                CreateNodeInMousePos();
            }
        }

        //other
#if UNITY_EDITOR
        if (Input.GetKeyDown(KeyCode.Alpha1))
        {
            SetMode(ControlMode.None);
        }

        if (Input.GetKeyDown(KeyCode.Alpha3))
        {
            if (GroundPosition(out temp_ground_pos))
            {
                var go = Instantiate(Unit_prefab, temp_ground_pos + Vector3.up * 2, Quaternion.identity) as GameObject;
                AddCar(go.GetComponent <UnitMain>());
            }
        }

        if (Input.GetKeyDown(KeyCode.Alpha4))
        {
            SetGameover();
        }
#endif

        if (Input.GetButtonDown("PathMode"))
        {
            TogglePathMode();
        }

        if (Input.GetButtonDown("Remove"))
        {
            if (selected_node != null)
            {
                PathNodeMain node = null;
                if (selected_node.HasForwardNodes())
                {
                    node = Subs.GetRandom(selected_node.ForwardNodes);
                }
                else
                {
                    if (selected_node.HasBackwardNodes())
                    {
                        node = Subs.GetRandom(selected_node.BackwardNodes);
                    }
                }
                selected_node.Delete();
                if (node != null)
                {
                    SetSelectedNode(node);
                }
            }
            if (selected_line != null)
            {
                selected_line.Delete();
            }
        }

        if (Input.GetKeyDown(KeyCode.Space))
        {
            ToggleTimeState();
        }
    }