示例#1
0
        public void SaveStoredEntity()
        {
            SaveEntity sE = saveEnt[0];

            saveEnt.RemoveAt(0);
            Entity e = sE.entity;

            int[] des = sE.destination;

            int[] worldIndex = GetIndices(new float[] { des[0] * 8, des[1] * 8, des[2] });
            if (worldIndex[0] < 0 || worldIndex[0] >= worldSize || worldIndex[1] < 0 || worldIndex[1] >= worldSize)
            {
                Chunk.SaveToChunk(des, e);
            }
            else
            {
                world[worldIndex[0], worldIndex[1]].ents.Add(e);
            }
        }
示例#2
0
        public void MoveDir(Entity e, float[] mag)
        {
            int[] index = { -1, -1 };
            {
                bool found = false;
                for (int x = 0; x < worldSize && !found; x++)
                {
                    for (int y = 0; y < worldSize && !found; y++)
                    {
                        if (world[x, y].ents.Contains(e))
                        {
                            found    = true;
                            index[0] = x;
                            index[1] = y;
                            break;
                        }
                    }
                }
            }

            if (index[0] == -1 || index[1] == -1)
            {
                return;
            }
            world[index[0], index[1]].ents.Remove(e);

            e.X += mag[0];
            e.Y += mag[1];

            bool movedChunk = false;

            int[] chunkMove = new int[2];
            if (e.X < 0)
            {
                Game.DebugBreakPoint();

                movedChunk   = true;
                chunkMove[0] = -1;
                e.chunkX--;
            }
            else if (e.X >= 8)
            {
                Game.DebugBreakPoint();

                movedChunk   = true;
                chunkMove[0] = 1;
                e.chunkX++;
            }
            else
            {
                chunkMove[0] = 0;
            }

            if (e.Y < 0)
            {
                Game.DebugBreakPoint();

                movedChunk   = true;
                chunkMove[1] = -1;
                e.chunkY--;
            }
            else if (e.Y >= 8)
            {
                Game.DebugBreakPoint();

                movedChunk   = true;
                chunkMove[1] = 1;
                e.chunkY++;
            }
            else
            {
                chunkMove[1] = 0;
            }

            e.X = (e.X + 8) % 8;
            e.Y = (e.Y + 8) % 8;

            int[] chunkCoords = { index[0] + chunkMove[0], index[1] + chunkMove[1] };

            if (chunkCoords[0] < 1 || chunkCoords[0] >= (worldSize - 1) || chunkCoords[1] < 1 || chunkCoords[1] >= (worldSize - 1))
            {
                Game.DebugBreakPoint();

                int[]      des = { (world[index[0], index[1]].coords[0] + chunkMove[0]), (world[index[0], index[1]].coords[1] + chunkMove[1]), (world[index[0], index[1]].coords[2]) };
                SaveEntity sE  = new SaveEntity(e, des);
                saveEnt.Add(sE);
                Thread t = new Thread(SaveStoredEntity);
                threads.Add(new ThreadQueue(t));
            }
            else if (movedChunk)
            {
                Game.DebugBreakPoint();

                world[chunkCoords[0], chunkCoords[1]].ents.Add(e);
            }
            else
            {
                world[chunkCoords[0], chunkCoords[1]].ents.Add(e);
            }
        }