Example #1
0
    private void Awake()
    {
        #region Singleton

        if (Instance == null)
        {
            Instance = this;
        }
        else
        {
            Destroy(gameObject);
        }
        #endregion

        if (isHub)
        {
            CombinedGrid = new GridClass(5, 16, 1, "GameGrid");
        }
        else
        {
            CombinedGrid = new GridClass(5, 30, 1, "GameGrid");
        }


        PopulatePrefabs();


        designer = FindObjectOfType <Designer>();
        designer?.ClearLevel();
    }
Example #2
0
 public Cell(int xPos, int yPos, bool isEmpty, GridClass grid)
 {
     GridClass = grid;
     XPos      = xPos;
     YPos      = yPos;
     IsEmpty   = isEmpty;
 }
Example #3
0
    private void InitializeLocalValues()
    {
        //Properties

        Ready         = false;
        Online        = false;
        RemoteControl = "";
        Favorites     = "";

        //Navigation Values

        Canal     = 0;
        Nivel     = 0;
        EmpresaID = -1;
        GranjaID  = -1;
        NucleoID  = -1;
        GalponID  = -1;
        SiloID    = -1;

        ActiveElem  = -1;
        Zoom        = 1;
        CurrentPage = 1;
        TotalPages  = 0;
        Flag        = 0;

        //Get Scripts

        AppController = gameObject.GetComponent <AppControllerScript>();
        GridScript    = gameObject.GetComponent <GridClass>();

        //UI Values

        onlineView      = GameObject.Find("Online").transform.Find("Text").GetComponent <Text>();
        onlineView.text = "Offline";
    }
    private IEnumerator InitializeControlScript()
    {
        // Set Inherit Scripts
        gameObject.AddComponent <WindowManager>();
        gameObject.AddComponent <GridClass>();

        // Get Inherit Scripts
        basicScript = GetComponent <WindowManager>();
        gridScript  = GetComponent <GridClass>();

        //START CONTROLLER IDENTITY
        gridScript.type = "centro";
        gridScript.itemsOnServerPath = "https://commendable-rigs.000webhostapp.com/initarjetas.php";
        //gridScript.serverPath = "http://localhost/indicadores/initarjetas.php";
        //Prefab MUST have children called Titulo
        gridScript.prefabLocalPath = "Prefabs/CentroPrefab/CentroPrefab";
        StartCoroutine(gridScript.Initialize());
        //END CONTROLLER IDENTITY

        basicScript.InstanceAndShowPopUp("temporal", "BasicPopUpPrefab", "CentrosViewCanvas", "Cargando", 8.0f, 0.5f);
        yield return(new WaitUntil(() => gridScript.Ready));

        //Begin Editable Zone
        //ActivateDataChecking();
    }
    public void InitializeLocalValues()
    {
        //Navigation Values

        Canal     = 0;
        Nivel     = 0;
        EmpresaID = -1;
        GranjaID  = -1;
        NucleoID  = -1;
        GalponID  = -1;
        SiloID    = -1;

        //Get Scripts

        ServerScript     = gameObject.GetComponent <ServerClass>();
        GridScript       = gameObject.GetComponent <GridClass>();
        ThemeScript      = gameObject.GetComponent <ThemeClass>();
        WinManagerScript = gameObject.GetComponent <WindowManager>();

        //Initialize Grids

        GridName     = "Grid";
        GridLocation = GameObject.Find("Grid");
        GridCanales  = GameObject.Find("GridCanales");
        GridLocation.SetActive(false);

        //Channels Buttons

        GameObject.Find("Temas").transform.Find("Fondo").GetComponent <Button>().onClick.AddListener(() => GoToChannel("temas"));
        GameObject.Find("Indicadores").transform.Find("Fondo").GetComponent <Button>().onClick.AddListener(() => GoToChannel("indicadores"));
        GameObject.Find("Resumen").transform.Find("Fondo").GetComponent <Button>().onClick.AddListener(() => GoToChannel("resumen"));
        GameObject.Find("Temperatura").transform.Find("Fondo").GetComponent <Button>().onClick.AddListener(() => GoToChannel("temperatura"));

        //Debugging and navigation

        backBtn = GameObject.Find("back-btn").GetComponent <Button>();
        backBtn.onClick.AddListener(() => JumpToComponent("menu"));
        empresaBtn       = GameObject.Find("empresas-btn").GetComponent <Button>();
        granjaBtn        = GameObject.Find("granjas-btn").GetComponent <Button>();
        nucleoBtn        = GameObject.Find("nucleos-btn").GetComponent <Button>();
        galponBtn        = GameObject.Find("galpones-btn").GetComponent <Button>();
        empresaImg       = GameObject.Find("empresas-btn").GetComponent <Image>();
        granjaImg        = GameObject.Find("granjas-btn").GetComponent <Image>();
        nucleoImg        = GameObject.Find("nucleos-btn").GetComponent <Image>();
        galponImg        = GameObject.Find("galpones-btn").GetComponent <Image>();
        enabledColor     = AuxFunctions.ConvertColorRGBA(107.0f, 171.0f, 129.0f, 1.0f);
        disabledColor    = AuxFunctions.ConvertColorRGBA(143.0f, 168.0f, 185.0f, 1.0f);
        empresaImg.color = disabledColor;
        granjaImg.color  = disabledColor;
        nucleoImg.color  = disabledColor;
        galponImg.color  = disabledColor;
        empresaBtn.onClick.AddListener(() => JumpToComponent("empresa"));
        granjaBtn.onClick.AddListener(() => JumpToComponent("granja"));
        nucleoBtn.onClick.AddListener(() => JumpToComponent("nucleo"));
    }
Example #6
0
        public void GetXNorthWestCornerTest()
        {
            // Arrange
            var g = new GridClass();

            // Act
            var result = g.GetX("1");

            // Assert
            Assert.AreEqual(1, result);
        }
Example #7
0
        public void GetGridRefNorthEastCornerTest()
        {
            // Arrange
            var g = new GridClass();

            // Act
            var result = g.GetGridRef(100, 1);

            // Assert
            Assert.AreEqual("100", result);
        }
Example #8
0
        public void GetXMidPointTest()
        {
            // Arrange
            var g = new GridClass();

            // Act
            var result = g.GetX("304");

            // Assert
            Assert.AreEqual(4, result);
        }
Example #9
0
        public void GetXSouthEastCornerTest()
        {
            // Arrange
            var g = new GridClass();

            // Act
            var result = g.GetX("10000");

            // Assert
            Assert.AreEqual(100, result);
        }
Example #10
0
        public void GetYSouthWestCornerTest()
        {
            // Arrange
            var g = new GridClass();

            // Act
            var result = g.GetY("9901");

            // Assert
            Assert.AreEqual(100, result);
        }
Example #11
0
        public void StartingPositionTest()
        {
            // Arrange
            var g = new GridClass();

            // Act
            var result = g.GetGridRef(1, 1);

            // Assert
            Assert.AreEqual("1", result);
        }
Example #12
0
        public void GetGridRefSouthWestCornerTest()
        {
            // Arrange
            var g = new GridClass();

            // Act
            var result = g.GetGridRef(1, 100);

            // Assert
            Assert.AreEqual("9901", result);
        }
Example #13
0
        private void button5_Click(object sender, EventArgs e)
        {
            const string filename = @"D:\dev\MapwinGIS\GitHub\unittests\MapWinGISTests\Testdata\HDF5\test.h5";
            var          subset   = $"HDF5:\"{filename}\"://image1/image_data";
            // Open subdataset as grid:
            var grd = new GridClass();

            if (grd.Open(subset))
            {
                axMap1.AddLayer(grd, true);
            }
        }
Example #14
0
 void Awake()
 {
     // Singleton pattern
     if (instance == null)
     {
         instance = this;
     }
     else
     {
         Destroy(this.gameObject);
     }
 }
Example #15
0
    /// <summary>
    /// Valid attack cells
    /// </summary>
    /// <returns>List of cells in attack range</returns>
    public static List <CellClass> FindPath(CellClass startCell, GridClass grid, int attackRange, UnitClass currentUnit)
    {
        List <CellClass> openList;
        List <CellClass> closedList;

        openList   = new List <CellClass>();
        closedList = new List <CellClass>();
        Debug.Log("hello?");

        startCell.Distance   = 0;
        startCell.ParentCell = null;
        CellClass curCell = startCell;

        openList.Add(curCell);

        while (curCell.Distance <= attackRange)
        {
            closedList.Add(curCell);
            openList.Remove(curCell);

            foreach (CellClass cell in curCell.adjacentCells)
            {
                cell.Distance = curCell.Distance + cell.Cost;

                if (cell.Cost != 0 && cell.Distance <= attackRange &&
                    !openList.Contains(cell) && !closedList.Contains(cell))
                {
//					UnitClass unit = UnitManager.instance.units.Find( (UnitClass u) => u.Cell == cell);
//
//					if ( unit != null){
//						if ( unit.playerSide != currentUnit.playerSide ) {
//							cell.ParentCell = curCell;
//							openList.Add( cell );
//						}
//					}
//					else {
                    cell.ParentCell = curCell;
                    openList.Add(cell);
//					}
                }
            }
            if (openList.Count == 0)
            {
                break;
            }
            openList.Sort(SortByDistance);
            curCell = openList[0];
        }
        Debug.Log(closedList.Count);
        closedList.TrimExcess();
        return(closedList);
    }
Example #16
0
    /// <summary>
    /// Returns a list containing one CellPosition for every cell on the specified side.
    /// </summary>
    public List <CellPosition> ListAllCellsOnSide(GridClass side)
    {
        List <CellPosition> result = new List <CellPosition>();

        for (uint x = 0; x < width; x++)
        {
            for (uint z = 0; z < length; z++)
            {
                result.Add(new CellPosition(x, z, side));
            }
        }
        return(result);
    }
Example #17
0
    /// <summary>
    /// If one can be found, returns the position of a cell on the specified side which does not
    /// contain the specified type of dweller. If none can be found, null is returned instead.
    /// </summary>
    public CellPosition FindRandomCellWithout(DwellerType type, GridClass side)
    {
        List <CellPosition> allCells = ListAllCellsOnSide(side);

        allCells.Shuffle();
        foreach (CellPosition position in allCells)
        {
            if (!IsTypeInCell(position, type))
            {
                return(position);
            }
        }
        return(null);
    }
Example #18
0
        private void btnGdalInfo_Click(object sender, EventArgs e)
        {
            GlobalSettings settings = new GlobalSettings();

            settings.ResetGdalError();
            UtilsClass utils = new MapWinGIS.UtilsClass();

            var filename = @"D:\dev\GIS-Data\HDF5\RAD_NL25_RAC_03H_201612040000.h5";
            var result   = utils.GDALInfo(filename, "");

            if (!string.IsNullOrEmpty(result))
            {
                txtResults.Text = result;
                var hndle = axMap1.AddLayerFromFilename(filename, tkFileOpenStrategy.fosAutoDetect, true);
                if (hndle >= 1)
                {
                    return;
                }

                txtResults.Text += @" GDAL Error: " + settings.GdalLastErrorMsg
                                   + axMap1.get_ErrorMsg(axMap1.LastErrorCode);
                var grd    = new GridClass();
                var opened = grd.Open(filename);
                if (!opened)
                {
                    txtResults.Text += @" Could not open grid: " + grd.ErrorMsg[grd.LastErrorCode];
                    return;
                }

                if (!grd.OpenBand(0))
                {
                    txtResults.Text += @" Could not open grid band: " + grd.ErrorMsg[grd.LastErrorCode];
                    return;
                }

                hndle = axMap1.AddLayer(grd, true);
                if (hndle >= 1)
                {
                    return;
                }

                txtResults.Text += @" Could not add grid: " + grd.ErrorMsg[grd.LastErrorCode];

                return;
            }

            txtResults.Text = @" GDAL Error: " + settings.GdalLastErrorMsg
                              + @" GdalPluginPath: " + settings.GdalPluginPath;
        }
Example #19
0
    /// <summary>
    /// Find valid unit move cells
    /// </summary>
    /// <returns>List of cells in move range</returns>
    /// <param name="moveRange">How far the unit can move</param>
    public static List <CellClass> FindPath(CellClass startCell, GridClass grid, int moveRange)
    {
        List <CellClass> openList;
        List <CellClass> closedList;

        openList   = new List <CellClass>();
        closedList = new List <CellClass>();

        startCell.Distance   = 0;
        startCell.ParentCell = null;
        CellClass curCell = startCell;

        openList.Add(curCell);

        while (curCell.Distance <= moveRange)
        {
            closedList.Add(curCell);
            openList.Remove(curCell);

            if (curCell.adjacentCells.Count == 0)
            {
                Debug.Log("Uh.. no adjacent cells. Whee!");
            }
            else
            {
                foreach (CellClass cell in curCell.adjacentCells)
                {
//				System.Predicate<CellClass> listPredicate = c => c == cell;
                    cell.Distance = curCell.Distance + cell.Cost;
                    if (cell.Cost != 0 && cell.Occupied == false && cell.Distance <= moveRange &&
                        !openList.Contains(cell) && !closedList.Contains(cell))
                    {
                        cell.ParentCell = curCell;
                        openList.Add(cell);
                    }
                }
            }
            if (openList.Count == 0)
            {
                break;
            }
            openList.Sort(SortByDistance);
            curCell = openList[0];
        }
//		Debug.Log( closedList.Count);
        closedList.TrimExcess();
        return(closedList);
    }
Example #20
0
        public frmZJ_Find_GD(ZSL_BCST024_PO[] model)
        {
            InitializeComponent();
            DirdArr = new List <GridClass>();
            List    = model;
            string[] cols  = { q(Msg_Type.fieldgd), q(Msg_Type.fieldgdxx) };//"工单", "工单信息"
            string[] colss = { "gd", "gdxx" };
            string[] vcols = { };

            DataGridBuild(cols, colss, dataGridView1, vcols);
            //DvList = new List<DataGridclass>();
            for (int i = 0; i < List.Length; i++)
            {
                GridClass node = new GridClass();
                node.Gd   = List[i].AUFNR;
                node.Gdxx = List[i].MATNR + "/" + List[i].MAKTX;
                DirdArr.Add(node);
            }
            dataGridView1.DataSource = DirdArr;
        }
Example #21
0
    public LevelData CreateNewLevel()
    {
        CreatorGrid = new GridClass(Game.Instance.CombinedGrid.width, Game.Instance.CombinedGrid.height, Game.Instance.CombinedGrid.step, "CreatorGrid");

        ClearGrid(CreatorGrid);
        if (Game.Instance.isHub)
        {
            HubLevelCreator();
        }
        else
        {
            RandomLevelCreator();
        }

        LevelData levelData = new LevelData();

        levelData.items = levelDataItems.ToArray();

        levelDataItems.Clear();
        return(levelData);
    }
Example #22
0
    public void UncoverTile()
    {
        if (!isCovered() || flag || GridClass.isFinished())
        {
            return;
        }

        if (mine)
        {
            clickedMine = true;
            GridClass.UncoverMines();
            ChangeTexture(0);
        }
        else
        {
            int x = (int)transform.localPosition.x;
            int y = (int)transform.localPosition.y;
            ChangeTexture(GridClass.AdjecentMines(x, y));

            GridClass.FloodFill(x, y, new bool[GridClass.Width, GridClass.Height]);
        }
    }
Example #23
0
    private void Start()
    {
        grid = Game.Instance.CombinedGrid;

        markers = new GameObject[grid.width, grid.height];

        markers[0, 0] = firstMarker;

        RectTransform fmrt = firstMarker.GetComponent <RectTransform>();

        for (int i = 0; i < grid.width; i++)
        {
            for (int j = 0; j < grid.height; j++)
            {
                if (i == 0 && j == 0)
                {
                    continue;
                }
                GameObject nextMarker = Instantiate(firstMarker, this.transform);
                nextMarker.GetComponent <RectTransform>().localPosition = new Vector3(fmrt.localPosition.x + i * step, fmrt.localPosition.y + j * step);
                markers[i, j] = nextMarker;
            }
        }
    }
Example #24
0
    public void InitializeValues()
    {
        NumberCanales = 4;
        // Control & Navigation Values
        remoteControlFromBD       = "";
        storedRemoteControlFromBD = "";

        Canal             = 0;
        CanalFromBD       = 0;
        storedCanalFromBD = 0;

        Nivel             = 0;
        NivelFromBD       = 0;
        storedNivelFromBD = 0;

        EmpresaID           = "-1";
        EmpresaIdFromBD     = "-1";
        storedEmpresaFromBD = "-1";

        GranjaID           = "-1";
        GranjaIdFromBD     = "-1";
        storedGranjaFromBD = "-1";

        NucleoID           = "-1";
        NucleoIdFromBD     = "-1";
        storedNucleoFromBD = "-1";

        GalponID                 = "-1";
        galponesDataFromBD       = "-1";
        storedGalponesDataFromBD = "-1";

        SiloID           = "-1";
        storedSiloFromBD = "-1";

        activeElem        = -1;
        zoomFromBD        = 1;
        currentPageFromBD = 1;
        totalPagesFromBD  = 0;
        themeFromBD       = 0;
        flagFromBD        = 0;

        //Initialize Grids
        gridName    = "Grid";
        grid        = GameObject.Find("Grid");
        gridCanales = GameObject.Find("GridCanales");
        grid.SetActive(false);

        // Add Scripts from Namespace
        if (gameObject.GetComponent <GridClass>() == null)
        {
            gameObject.AddComponent <GridClass>();
        }

        if (gameObject.GetComponent <ThemeClass>() == null)
        {
            gameObject.AddComponent <ThemeClass>();
        }

        // Get Scripts
        gridScript  = GetComponent <GridClass>();
        themeScript = GetComponent <ThemeClass>();

        //UI Interface

        //Channels Buttons
        GameObject.Find("Temas").transform.Find("Fondo").GetComponent <Button>().onClick.AddListener(() => TemasChannel());
        GameObject.Find("Indicadores").transform.Find("Fondo").GetComponent <Button>().onClick.AddListener(() => IndicadoresChannel());
        GameObject.Find("Resumen").transform.Find("Fondo").GetComponent <Button>().onClick.AddListener(() => ResumenChannel());
        GameObject.Find("Temperatura").transform.Find("Fondo").GetComponent <Button>().onClick.AddListener(() => TemperaturaChannel());

        //Debugging an navigation
        //navigationPath = new List<string>();
        backBtn = GameObject.Find("back-btn").GetComponent <Button>();
        backBtn.onClick.AddListener(() => JumpToComponent("back"));
        empresaBtn       = GameObject.Find("empresas-btn").GetComponent <Button>();
        granjaBtn        = GameObject.Find("granjas-btn").GetComponent <Button>();
        nucleoBtn        = GameObject.Find("nucleos-btn").GetComponent <Button>();
        galponBtn        = GameObject.Find("galpones-btn").GetComponent <Button>();
        empresaImg       = GameObject.Find("empresas-btn").GetComponent <Image>();
        granjaImg        = GameObject.Find("granjas-btn").GetComponent <Image>();
        nucleoImg        = GameObject.Find("nucleos-btn").GetComponent <Image>();
        galponImg        = GameObject.Find("galpones-btn").GetComponent <Image>();
        enabledColor     = AuxFunctions.ConvertColorRGBA(107.0f, 171.0f, 129.0f, 1.0f);
        disabledColor    = AuxFunctions.ConvertColorRGBA(143.0f, 168.0f, 185.0f, 1.0f);
        empresaImg.color = disabledColor;
        granjaImg.color  = disabledColor;
        nucleoImg.color  = disabledColor;
        galponImg.color  = disabledColor;
        empresaBtn.onClick.AddListener(() => JumpToComponent("empresa"));
        granjaBtn.onClick.AddListener(() => JumpToComponent("granja"));
        nucleoBtn.onClick.AddListener(() => JumpToComponent("nucleo"));
    }
Example #25
0
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            if (Source.IsNullOrWhiteSpace())
            {
                Source = Url.Action(DefaultSourceAction);
            }
            if (GridClass.IsNullOrWhiteSpace())
            {
                GridClass = DefaultClass;
            }
            if (ModelType == null)
            {
                ModelType = ViewContext.ViewData.ModelMetadata.ModelType;
            }
            var           viewConfig         = ViewConfigureAttribute.GetAttribute(ModelType);
            StringBuilder tableHeaderBuilder = new StringBuilder();
            StringBuilder tableSearchBuilder = new StringBuilder();

            if (viewConfig != null)
            {
                var primaryKey = viewConfig.MetaData.Properties.Select(m => m.Value).FirstOrDefault(m => m.CustomAttributes.Any(attr => attr.AttributeType == typeof(KeyAttribute)));
                viewConfig.InitDisplayName();
                if ((EditAble ?? true) && primaryKey != null)
                {
                    string name = primaryKey.Name.FirstCharToLowerCase();
                    if (name.Length == 2)
                    {
                        name = name.ToLower();
                    }

                    if (Edit.IsNullOrWhiteSpace())
                    {
                        Edit = Url.Action(DefaultEditAction) + "/{" + name + "}";
                    }
                    tableHeaderBuilder.AppendFormat(TableHeadStructure,
                                                    string.Empty,
                                                    WebUtility.HtmlEncode(EditLinkTemplate.FormatWith(Edit)),
                                                    string.Empty,
                                                    "操作",
                                                    string.Empty,
                                                    Query.Operators.None,
                                                    string.Empty,
                                                    string.Empty);
                    tableSearchBuilder.Append(TableSearchStructure);
                }

                var columns = viewConfig.GetViewPortDescriptors(true)
                              .Where(m => m.IsShowInGrid)
                              .Each(m =>
                {
                    var dropDown = m as DropDownListDescriptor;
                    StringBuilder optionBuilder = new StringBuilder();
                    if (dropDown != null)
                    {
                        foreach (var item in dropDown.OptionItems)
                        {
                            optionBuilder.AppendFormat("{{\"name\":\"{0}\",\"value\":\"{1}\"}},", item.Value, item.Key);
                        }
                    }
                    else if (m.DataType == typeof(bool) || m.DataType == typeof(bool?))
                    {
                        optionBuilder.AppendFormat("{{\"name\":\"{0}\",\"value\":\"{1}\"}},", "是", "true");
                        optionBuilder.AppendFormat("{{\"name\":\"{0}\",\"value\":\"{1}\"}},", "否", "false");
                    }
                    tableHeaderBuilder.AppendFormat(TableHeadStructure,
                                                    m.Name.FirstCharToLowerCase(),
                                                    WebUtility.HtmlEncode(m.GridColumnTemplate),
                                                    OrderAsc == m.Name ? "asc" : OrderDesc == m.Name ? "desc" : "",
                                                    m.DisplayName,
                                                    optionBuilder.Length == 0 ? string.Empty : WebUtility.HtmlEncode($"[{optionBuilder.ToString().Trim(',')}]"),
                                                    m.SearchOperator,
                                                    m.DataType.Name,
                                                    (m as TextBoxDescriptor)?.JavaScriptDateFormat);
                    tableSearchBuilder.Append(TableSearchStructure);
                });
            }
            output.TagName = "div";
            output.Attributes.Add("class", "container-fluid");
            output.Content.SetHtmlContent(TableStructure.FormatWith(GridClass, Source, tableHeaderBuilder, tableSearchBuilder));
        }
Example #26
0
 private void Start()
 {
     grid = new GridClass(4, 2, 10f);
 }
Example #27
0
 void ClearGrid(GridClass grid)
 {
     grid.ResetGrid();
 }
Example #28
0
    public override void _Process(float Delta)     //NOTE: Only runs on server
    {
        Assert.ActualAssert(Net.Work.IsNetworkServer());

        TimeSinceUpdate += Delta;

        if (!DepreciatedCurrentChunkTuple.Equals(World.GetChunkTuple(Translation)))
        {
            World.Chunks[DepreciatedCurrentChunkTuple].Mobs.Remove(this);
            World.AddMobToChunk(this);
        }

        if (CurrentArea != GridClass.CalculateArea(Translation))
        {
            CurrentArea = GridClass.CalculateArea(Translation);
            World.Grid.QueueRemoveItem(this);
            World.Grid.AddItem(this);
        }

        UpdateFloor();
        CalcWants(Floor);

        if (OnFloor)
        {
            TargetPoint.Match(
                some: Target => {
                if (Target.Pos.Flattened().DistanceTo(Translation.Flattened()) <= 2)
                {
                    TargetPoint = PointData.None();
                }
                else
                {
                    //Apply push toward TargetPoint but don't go to fast
                    Momentum += ClampVec3(
                        Target.Pos.Flattened() - Translation.Flattened(),
                        Acceleration * Delta + Friction * Delta,
                        Acceleration * Delta + Friction * Delta
                        );
                    Vector3 Clamped = ClampVec3(Momentum.Flattened(), 0, TopSpeed);
                    Momentum.x      = Clamped.x;
                    Momentum.z      = Clamped.z;
                }
            },

                none: () => { }
                );

            //Friction
            Vector3 Horz = Momentum.Flattened();
            Horz       = Horz.Normalized() * Clamp(Horz.Length() - Friction * Delta, 0, TopSpeed);
            Momentum.x = Horz.x;
            Momentum.z = Horz.z;
        }
        else                                                                               //Not on floor
        {
            Momentum.y = Clamp(Momentum.y - Gravity * Delta, -MaxFallSpeed, MaxFallSpeed); //Apply gravity
        }
        var OriginalChunkTuple = World.GetChunkTuple(Translation);

        Momentum = Move(Momentum, Delta, 1, 60, TopSpeed);

        Entities.MovedTick(this, OriginalChunkTuple);

        Entities.AsServerMaybePhaseOut(this);
        Entities.SendUpdate(Name, Translation);
    }
Example #29
0
 void Awake()
 {
     //target = GameObject.Find ("");    add a tag or name for
     grid = GetComponent <GridClass> ();
 }
Example #30
0
    public static void TryAddTileToPathfinder(Tile Branch)
    {
        Tile TryGetPlatform(Vector3 Position, Vector3 RaycastOffset = new Vector3())
        {
            var Area = GridClass.CalculateArea(Position);

            foreach (IInGrid Entry in Grid.GetItems(Area))
            {
                if (Entry is Tile OtherTile && OtherTile.Type == Items.ID.PLATFORM)
                {
                    PhysicsDirectSpaceState State = Branch.GetWorld().DirectSpaceState;

                    var RayBranchPos = Branch.Point.Pos + RaycastOffset;
                    var RayOtherPos  = OtherTile.Point.Pos + RaycastOffset;
                    var Excluding    = new Godot.Collections.Array {
                    };

                    var Results = State.IntersectRay(RayBranchPos, RayOtherPos, Excluding, 4);
                    if (Results.Count > 0)                    //Hit something in between
                    {
                        return(null);
                    }
                    else
                    {
                        return(OtherTile);
                    }
                }
            }

            return(null);
        }

        Tile TryGetSlope(Vector3 Position, Vector3 RaycastOffset = new Vector3())
        {
            var Area = GridClass.CalculateArea(Position);

            foreach (IInGrid Entry in Grid.GetItems(Area))
            {
                if (Entry is Tile OtherTile && OtherTile.Type == Items.ID.SLOPE)
                {
                    PhysicsDirectSpaceState State = Branch.GetWorld().DirectSpaceState;

                    var RayBranchPos = Branch.Point.Pos + RaycastOffset;
                    var RayOtherPos  = OtherTile.Point.Pos + RaycastOffset;
                    var Excluding    = new Godot.Collections.Array {
                    };

                    var Results = State.IntersectRay(RayBranchPos, RayOtherPos, Excluding, 4);
                    if (Results.Count > 0)                    //Hit something in between
                    {
                        return(null);
                    }
                    else
                    {
                        return(OtherTile);
                    }
                }
            }

            return(null);
        }

        bool IsSlopePointingAt(Tile Slope, Vector3 At)
        {
            float Rot = SnapToGrid(LoopRotation(Slope.RotationDegrees.y), 360, 4);

            Rot = LoopRotation(Rot);             //Make 360 become 0

            Vector3 Addend   = new Vector3(0, 0, PlatformSize / 3).Rotated(new Vector3(0, 1, 0), Deg2Rad(Rot));
            Vector3 SlopePos = Slope.Translation + Addend;

            if (Rot == 0)
            {
                return(At.z >= SlopePos.z);
            }
            if (Rot == 90)
            {
                return(At.x >= SlopePos.x);
            }
            if (Rot == 180)
            {
                return(At.z <= SlopePos.z);
            }
            if (Rot == 270)
            {
                return(At.x <= SlopePos.x);
            }

            throw new Exception("This `if` chain should have 100% coverage");
        }

        bool IsSlopePointingAway(Tile Slope, Vector3 At)
        {
            float Rot = SnapToGrid(LoopRotation(Slope.RotationDegrees.y), 360, 4);

            Rot = LoopRotation(Rot);             //Make 360 become 0

            Vector3 Addend   = new Vector3(0, 0, -PlatformSize / 3).Rotated(new Vector3(0, 1, 0), Deg2Rad(Rot));
            Vector3 SlopePos = Slope.Translation + Addend;

            if (Rot == 0)
            {
                return(At.z <= SlopePos.z);
            }
            if (Rot == 90)
            {
                return(At.x <= SlopePos.x);
            }
            if (Rot == 180)
            {
                return(At.z >= SlopePos.z);
            }
            if (Rot == 270)
            {
                return(At.x >= SlopePos.x);
            }

            throw new Exception("This `if` chain should have 100% coverage");
        }

        switch (Branch.Type)
        {
        case (Items.ID.PLATFORM): {
            Branch.Point = Pathfinder.AddPoint(Branch.Translation + new Vector3(0, 2, 0));

            {                     //Connect to platforms in the eight spaces around us
                var AheadPos  = Branch.Translation + new Vector3(0, 1, PlatformSize);
                var BehindPos = Branch.Translation + new Vector3(0, 1, -PlatformSize);
                var RightPos  = Branch.Translation + new Vector3(-PlatformSize, 1, 0);
                var LeftPos   = Branch.Translation + new Vector3(PlatformSize, 1, 0);

                Tile Ahead  = TryGetPlatform(AheadPos);
                Tile Behind = TryGetPlatform(BehindPos);
                Tile Right  = TryGetPlatform(RightPos);
                Tile Left   = TryGetPlatform(LeftPos);

                if (Ahead != null)
                {
                    Pathfinder.ConnectPoints(Branch.Point, Ahead.Point);
                }
                if (Behind != null)
                {
                    Pathfinder.ConnectPoints(Branch.Point, Behind.Point);
                }
                if (Right != null)
                {
                    Pathfinder.ConnectPoints(Branch.Point, Right.Point);
                }
                if (Left != null)
                {
                    Pathfinder.ConnectPoints(Branch.Point, Left.Point);
                }

                var AheadRightPos  = Branch.Translation + new Vector3(-PlatformSize, 1, PlatformSize);
                var AheadLeftPos   = Branch.Translation + new Vector3(PlatformSize, 1, PlatformSize);
                var BehindRightPos = Branch.Translation + new Vector3(-PlatformSize, 1, -PlatformSize);
                var BehindLeftPos  = Branch.Translation + new Vector3(PlatformSize, 1, -PlatformSize);

                Tile AheadRight  = null;
                Tile AheadLeft   = null;
                Tile BehindRight = null;
                Tile BehindLeft  = null;

                if (Ahead != null && Right != null)
                {
                    AheadRight = TryGetPlatform(AheadRightPos);
                }
                if (Ahead != null && Left != null)
                {
                    AheadLeft = TryGetPlatform(AheadLeftPos);
                }
                if (Behind != null && Right != null)
                {
                    BehindRight = TryGetPlatform(BehindRightPos);
                }
                if (Behind != null && Left != null)
                {
                    BehindLeft = TryGetPlatform(BehindLeftPos);
                }

                if (AheadRight != null)
                {
                    Pathfinder.ConnectPoints(Branch.Point, AheadRight.Point);
                }
                if (AheadLeft != null)
                {
                    Pathfinder.ConnectPoints(Branch.Point, AheadLeft.Point);
                }
                if (BehindRight != null)
                {
                    Pathfinder.ConnectPoints(Branch.Point, BehindRight.Point);
                }
                if (BehindLeft != null)
                {
                    Pathfinder.ConnectPoints(Branch.Point, BehindLeft.Point);
                }
            }

            {                     //Connect to slopes in the four cardinal directions (same Y)
                var AheadPos  = Branch.Translation + new Vector3(0, 1, PlatformSize);
                var BehindPos = Branch.Translation + new Vector3(0, 1, -PlatformSize);
                var RightPos  = Branch.Translation + new Vector3(-PlatformSize, 1, 0);
                var LeftPos   = Branch.Translation + new Vector3(PlatformSize, 1, 0);

                Tile Ahead  = TryGetSlope(AheadPos);
                Tile Behind = TryGetSlope(BehindPos);
                Tile Right  = TryGetSlope(RightPos);
                Tile Left   = TryGetSlope(LeftPos);

                Vector3 Pos = Branch.Translation;
                if (Ahead != null && IsSlopePointingAway(Ahead, Pos))
                {
                    Pathfinder.ConnectPoints(Branch.Point, Ahead.Point);
                }
                if (Behind != null && IsSlopePointingAway(Behind, Pos))
                {
                    Pathfinder.ConnectPoints(Branch.Point, Behind.Point);
                }
                if (Right != null && IsSlopePointingAway(Right, Pos))
                {
                    Pathfinder.ConnectPoints(Branch.Point, Right.Point);
                }
                if (Left != null && IsSlopePointingAway(Left, Pos))
                {
                    Pathfinder.ConnectPoints(Branch.Point, Left.Point);
                }
            }

            {                     //Connect to slopes in the four cardinal directions (lower Y)
                var AheadPos  = Branch.Translation + new Vector3(0, -PlatformSize + 1, PlatformSize);
                var BehindPos = Branch.Translation + new Vector3(0, -PlatformSize + 1, -PlatformSize);
                var RightPos  = Branch.Translation + new Vector3(-PlatformSize, -PlatformSize + 1, 0);
                var LeftPos   = Branch.Translation + new Vector3(PlatformSize, -PlatformSize + 1, 0);

                var  RaycastOffset = new Vector3(0, PlatformSize / 4, 0);
                Tile Ahead         = TryGetSlope(AheadPos, RaycastOffset);
                Tile Behind        = TryGetSlope(BehindPos, RaycastOffset);
                Tile Right         = TryGetSlope(RightPos, RaycastOffset);
                Tile Left          = TryGetSlope(LeftPos, RaycastOffset);

                Vector3 Pos = Branch.Translation;
                if (Ahead != null && IsSlopePointingAt(Ahead, Pos))
                {
                    Pathfinder.ConnectPoints(Branch.Point, Ahead.Point);
                }
                if (Behind != null && IsSlopePointingAt(Behind, Pos))
                {
                    Pathfinder.ConnectPoints(Branch.Point, Behind.Point);
                }
                if (Right != null && IsSlopePointingAt(Right, Pos))
                {
                    Pathfinder.ConnectPoints(Branch.Point, Right.Point);
                }
                if (Left != null && IsSlopePointingAt(Left, Pos))
                {
                    Pathfinder.ConnectPoints(Branch.Point, Left.Point);
                }
            }

            break;
        }

        case (Items.ID.SLOPE): {
            Branch.Point = Pathfinder.AddPoint(Branch.Translation + new Vector3(0, 2, 0));

            var Axis = new Vector3(0, 1, 0);
            var Rad  = Branch.Rotation.y;

            {                     //Connect to other slopes in four cardinal directions
                var AheadPos  = Branch.Translation + new Vector3(0, PlatformSize, PlatformSize).Rotated(Axis, Rad);
                var BehindPos = Branch.Translation + new Vector3(0, -PlatformSize, -PlatformSize).Rotated(Axis, Rad);
                var RightPos  = Branch.Translation + new Vector3(-PlatformSize, 0, 0).Rotated(Axis, Rad);
                var LeftPos   = Branch.Translation + new Vector3(PlatformSize, 0, 0).Rotated(Axis, Rad);

                var  RaycastOffset = new Vector3(0, PlatformSize / 4, 0);
                Tile Ahead         = TryGetSlope(AheadPos, RaycastOffset);
                Tile Behind        = TryGetSlope(BehindPos, RaycastOffset);
                Tile Right         = TryGetSlope(RightPos);
                Tile Left          = TryGetSlope(LeftPos);

                if (Ahead != null)
                {
                    Pathfinder.ConnectPoints(Branch.Point, Ahead.Point);
                }
                if (Behind != null)
                {
                    Pathfinder.ConnectPoints(Branch.Point, Behind.Point);
                }
                if (Right != null)
                {
                    Pathfinder.ConnectPoints(Branch.Point, Right.Point);
                }
                if (Left != null)
                {
                    Pathfinder.ConnectPoints(Branch.Point, Left.Point);
                }
            }

            {                     //Connect to platforms forward and backwards
                var AheadPos  = Branch.Translation + new Vector3(0, PlatformSize / 2, PlatformSize).Rotated(Axis, Rad);
                var BehindPos = Branch.Translation + new Vector3(0, 0, -PlatformSize).Rotated(Axis, Rad);

                var  RaycastOffset = new Vector3(0, PlatformSize / 4, 0);
                Tile Ahead         = TryGetPlatform(AheadPos, RaycastOffset);
                Tile Behind        = TryGetPlatform(BehindPos);

                if (Ahead != null)
                {
                    Pathfinder.ConnectPoints(Branch.Point, Ahead.Point);
                }
                if (Behind != null)
                {
                    Pathfinder.ConnectPoints(Branch.Point, Behind.Point);
                }
            }

            break;
        }

        default:
            return;
        }
    }