Esempio n. 1
0
 public void Init(ChunkEntity entity, UnityChunkDoor[] doors, UnityChunkTrigger[] triggers)
 {
     m_Doors     = doors;
     m_Triggers  = triggers;
     m_Triggered = false;
     m_Entity    = entity;
 }
        public static ChunkEntity CreateChunk(IntVector3 position = default(IntVector3))
        {
            var chunk = new ChunkEntity();

            chunk.Initialise(position);

            return(chunk);
        }
Esempio n. 3
0
    //実体を生成するメソッド。地形データなどは生成せず、すでに存在する場合に使用される。
    public void generateObj()
    {
        if (entity == null)
        {
            (entity = new GameObject("chunk-" + x + "," + z).AddComponent <ChunkEntity> ()).init(this);
        }
        else
        {
            reloadEntity();
        }

        for (int a = 0; a < objs.Count; a++)
        {
            objs [a].generate();
        }
    }
        public static ChunkEntity CreateFlatGrassChunk(IntVector3 position = default(IntVector3))
        {
            var chunk = new ChunkEntity();

            for (int x = 0; x < ChunkEntity.ChunkSize; x++)
            {
                for (int y = 0; y < ChunkEntity.ChunkSize; y++)
                {
                    for (int z = 0; z < ChunkEntity.ChunkSize; z++)
                    {
                        chunk.SetBlock(new GrassBlock(chunk, new IntVector3(x, y, z)));
                    }
                }
            }

            chunk.Initialise(position);

            return(chunk);
        }
Esempio n. 5
0
        public void LoadChunk(ChunkEntity entity, IChunk chunk)
        {
            UnityChunk unityChunk = chunk as UnityChunk;

            UnityChunkDoor[] chunkDoors = unityChunk.GetComponentsInChildren <UnityChunkDoor>();
            foreach (var chunkDoor in chunkDoors)
            {
                LoadChunkDoor(unityChunk, chunkDoor);
            }

            UnityChunkTrigger[] chunkTriggers = unityChunk.GetComponentsInChildren <UnityChunkTrigger>();
            foreach (var chunkTrigger in chunkTriggers)
            {
                LoadChunkTrigger(unityChunk, chunkTrigger);
            }

            unityChunk.Init(entity, chunkDoors, chunkTriggers);
            OpenDoor(chunk);
        }
 public void DestroyChunk(ChunkEntity chunk)
 {
     chunk.Destroy();
     Chunks[chunk.Position] = null;
 }
Esempio n. 7
0
 private bool EntityCanMoveIntoPosition(ChunkEntity entity, int x, int y)
 {
     // Get the current Z position.
     Chunk c = this.m_DynamicLoader.LocateAtPoint(x, y);
     if (entity.WorldZ < 0 || entity.WorldZ > 63)
         return false;
     if (c.m_Blocks[x - c.GlobalX, y - c.GlobalY, entity.WorldZ] == null ||
         c.m_Blocks[x - c.GlobalX, y - c.GlobalY, entity.WorldZ].Transparent)
         return true;
     if (entity.WorldZ != 0 && (c.m_Blocks[x - c.GlobalX, y - c.GlobalY, entity.WorldZ - 1] == null ||
                                c.m_Blocks[x - c.GlobalX, y - c.GlobalY, entity.WorldZ - 1].Transparent))
     {
         entity.WorldZ -= 1;
         return true;
     }
     if (!c.m_Blocks[x - c.GlobalX, y - c.GlobalY, entity.WorldZ].Impassable)
         return true;
     if (entity.WorldZ != 0 && !c.m_Blocks[x - c.GlobalX, y - c.GlobalY, entity.WorldZ - 1].Impassable)
     {
         entity.WorldZ -= 1;
         return true;
     }
     return false;
 }
Esempio n. 8
0
        protected override void HandleRenderOfEntity(GameContext context, IEntity a)
        {
            if (!FilteredFeatures.IsEnabled(Feature.RenderEntities))
            {
                return;
            }

            if (a is ChunkEntity)
            {
                // Ensure we have a chunk manager to source chunks from.
                if (!(context.World is RPGWorld))
                {
                    return;
                }
                this.Octree = (context.World as RPGWorld).ChunkOctree;
                if (this.Octree == null)
                {
                    return;
                }
                if (this.Chunk == null)
                {
                    this.Chunk = this.Octree.Get(0, 0, 0);
                }

                // Special handling for entities in the 3D world.
                ChunkEntity ce  = a as ChunkEntity;
                Vector2     pos = this.TranslatePoint(ce.X, ce.Y, ce.Z);

                // Set depth information.
                if (RenderingBuffers.DepthBuffer != null && FilteredFeatures.IsEnabled(Feature.IsometricOcclusion))
                {
                    // Draw image with depth.
                    float depth = ((
                                       ((int)((ce.X < 0) ? Chunk.Width : 0) + (ce.X / Scale.CUBE_X) % Chunk.Width) +
                                       ((int)((ce.Y < 0) ? Chunk.Height : 0) + (ce.Y / Scale.CUBE_Y) % Chunk.Height) +
                                       ((int)((ce.Z < 0) ? Chunk.Depth : 0) + ((ce.Z / Scale.CUBE_Z) - 1) % Chunk.Depth)) / 255f);
                    this.m_OccludingSpriteBatch.DrawOccludable(
                        context.Textures[ce.Image],
                        new Rectangle((int)(pos.X - ce.ImageOffsetX), (int)(pos.Y - ce.ImageOffsetY),
                                      context.Textures[ce.Image].Width, context.Textures[ce.Image].Height),
                        ce.Color.ToPremultiplied(),
                        depth
                        );
                }
                else
                {
                    // Draw image normally.
                    context.SpriteBatch.Draw(
                        context.Textures[ce.Image],
                        new Rectangle((int)(pos.X - ce.ImageOffsetX), (int)(pos.Y - ce.ImageOffsetY),
                                      context.Textures[ce.Image].Width, context.Textures[ce.Image].Height),
                        ce.Color.ToPremultiplied()
                        );
                }
            }
            else
            {
                // Render using the default settings.
                base.HandleRenderOfEntity(context, a);
            }
        }