예제 #1
0
파일: World.cs 프로젝트: reinei/Adventure
 public void Event_Noise(Position pos, NoiseType type)
 {
     long range = NoiseRanges[type];
     foreach (Entitys.Entity e in GetEntitys_Range(pos, range))
     {
         e.Event_Noise(pos, 1 - pos.Distance(e.Pos) / range);
     }
 }
예제 #2
0
파일: World.cs 프로젝트: reinei/Adventure
 public Chunk GetChunk(Position chunkpos)
 {
     Chunk c;
     if (LoadedChunks.TryGetValue(chunkpos, out c))
     {
         return LoadedChunks[chunkpos];
     }
     else
     {
         c = Chunk.LoadFromFile(chunkpos);
         if (c == null)
         {
             LoadedChunks[chunkpos] = WorldGen.Generate(chunkpos);
         }
         return LoadedChunks[chunkpos];
     }
 }
예제 #3
0
파일: World.cs 프로젝트: reinei/Adventure
 public static Chunk LoadFromFile(Position chunkpos)
 {
     //TODO
     return null;
 }
예제 #4
0
파일: World.cs 프로젝트: reinei/Adventure
 public void SetTile(Position pos, Tile tile)
 {
     Position chunkpos = GetChunkPosition(pos);
     Position chunkindex = GetChunkTileIndex(pos, chunkpos);
     Chunk c = GetChunk(chunkpos);
     c.Idle = 0;
     c.Tiles[chunkindex.x, chunkindex.y, chunkindex.z] = tile;
 }
예제 #5
0
파일: World.cs 프로젝트: reinei/Adventure
 public Chunk(Position pos)
 {
     this.Pos = pos;
 }
예제 #6
0
파일: World.cs 프로젝트: reinei/Adventure
 public Tile GetTile(Position pos)
 {
     Position chunkpos = GetChunkPosition(pos);
     Position chunkindex = GetChunkTileIndex(pos, chunkpos);
     Chunk c = GetChunk(chunkpos);
     c.Idle = 0;
     return c.Tiles[chunkindex.x, chunkindex.y, chunkindex.z];
 }
예제 #7
0
파일: World.cs 프로젝트: reinei/Adventure
 public void MoveEntity(Entitys.Entity e, Position dest)
 {
     Position chunkpos_before = GetChunkPosition(e.Pos);
     e.Pos = dest;
     Position chunkpos_after = GetChunkPosition(e.Pos);
     if (chunkpos_before != chunkpos_after)
     {
         GetChunk(chunkpos_before).Entitys.Remove(e);
         GetChunk(chunkpos_after).Entitys.Add(e);
     }
 }
예제 #8
0
파일: World.cs 프로젝트: reinei/Adventure
 public List<Entitys.Entity> GetEntitys(Position chunkpos)
 {
     Chunk c = GetChunk(chunkpos);
     c.Idle = 0;
     return c.Entitys;
 }
예제 #9
0
파일: World.cs 프로젝트: reinei/Adventure
        public List<Entitys.Entity> GetEntitys_Range(Position pos, long range)
        {
            List<Entitys.Entity> Entitys = new List<Entitys.Entity>();
            List<Position> ChunksInRange = new List<Position>();
            Position Chunk_Start = GetChunkPosition(pos.translate(-range, -range, -range));
            Position Chunk_End = GetChunkPosition(pos.translate(range, range, range));

            //Get all chunks in range
            for (long x = Chunk_Start.x; x <= Chunk_End.x; x++)
            {
                for (long y = Chunk_Start.y; y <= Chunk_End.y; y++)
                {
                    for (long z = Chunk_Start.z; z <= Chunk_End.z; z++)
                    {
                        ChunksInRange.Add(new Position(x, y, z));
                    }
                }
            }

            //Get all entitys in range
            foreach (Position p in ChunksInRange)
            {
                List<Entitys.Entity> ChunkEntitys = GetChunk(p).Entitys;
                foreach (Entitys.Entity e in ChunkEntitys)
                {
                    if (pos.Distance(e.Pos) <= range)
                    {
                        Entitys.Add(e);
                    }
                }
            }

            return Entitys;
        }
예제 #10
0
파일: World.cs 프로젝트: reinei/Adventure
 public Position GetChunkTileIndex(Position tilepos, Position chunkpos)
 {
     long x = tilepos.x - chunkpos.x * Chunk.Size;
     long y = tilepos.y - chunkpos.y * Chunk.Size;
     long z = tilepos.z - chunkpos.z * Chunk.Size;
     if (tilepos.x < 0) x = -(x - Chunk.Size);
     if (tilepos.y < 0) y = -(y - Chunk.Size);
     if (tilepos.z < 0) z = -(z - Chunk.Size);
     return new Position(x, y, z);
 }
예제 #11
0
파일: World.cs 프로젝트: reinei/Adventure
 public Position GetChunkPosition(Position tilepos)
 {
     long x = tilepos.x / Chunk.Size;
     long y = tilepos.y / Chunk.Size;
     long z = tilepos.z / Chunk.Size;
     if (tilepos.x < 0) x--;
     if (tilepos.y < 0) y--;
     if (tilepos.z < 0) z--;
     return new Position(x, y, z);
 }
예제 #12
0
 public double Distance(Position c)
 {
     return Distance(this, c);
 }
예제 #13
0
 public static double Distance(Position c1, Position c2)
 {
     return Math.Sqrt(Math.Pow(c2.x - c1.x, 2) + Math.Pow(c2.y - c1.y, 2) + Math.Pow(c2.z - c1.z, 2));
 }
예제 #14
0
파일: Gpi.cs 프로젝트: reinei/Adventure
 public bool Intersects(Position p)
 {
     return ((p.x >= X && p.x <= X + W) && (p.y >= Y && p.y < Y + H));
 }