コード例 #1
0
        public void Update(IEditableWorld editableWorld, long frame)
        {
            var targetPositions = editableWorld.Entities
                                  .Where(entity => entity.Has <CameraTarget>())
                                  .Select(entity => entity.Get <Position>());

            var camera = editableWorld.Entities.FirstOrDefault(entity => entity.Has <Camera>());

            if (camera == null)
            {
                camera = new Entity(
                    Position.Zero,
                    new Camera());
            }
            var cameraPositionComponent = camera.Get <Position>();

            if (targetPositions.Any())
            {
                var averageTargetPosition = targetPositions.Aggregate(Vector2.Zero, (acc, position) => position.ToVector() + acc) / targetPositions.Count();
                var targetLeftOfCamera    = averageTargetPosition.X - CAMERA_WIDTH / 2;
                var targetPosition        =
                    new Vector2(
                        (int)Math.Floor(targetLeftOfCamera / CAMERA_WIDTH) * CAMERA_WIDTH + CAMERA_WIDTH,
                        averageTargetPosition.Y);

                var newPosition = cameraPositionComponent.ToVector() + ((targetPosition - cameraPositionComponent.ToVector()) * CAMERA_MOVEMENT_SPEED);
                camera = camera.Set(new Position((int)newPosition.X, (int)newPosition.Y));
            }

            editableWorld.UpdateEntity(camera);

            View = Matrix.CreateTranslation(new Vector3(-cameraPositionComponent.ToVector(), 0));
        }
コード例 #2
0
 public void Load(IEditableWorld _)
 {
     Projection = Matrix.CreateOrthographic(
         CAMERA_WIDTH,
         CAMERA_WIDTH / ASPECT_RATIO,
         0,
         10);
 }
コード例 #3
0
        public void Load(IEditableWorld _)
        {
            var textureFiles = Directory.GetFiles("GameLogic/Content/", "*.png");

            foreach (string texture in textureFiles)
            {
                var textureName = Path.GetFileNameWithoutExtension(texture);
                using (var fileStream = new FileStream(texture, FileMode.Open, FileAccess.Read))
                {
                    Textures[textureName] = Texture2D.FromStream(graphics, fileStream);
                }
            }
        }
コード例 #4
0
ファイル: Extensions.cs プロジェクト: yts233/Minecraft
        public static int FillFast(this IEditableWorld world, int x1, int y1, int z1, int x2, int y2, int z2, BlockState block)
        {
            int count = 0;
            int ix1   = Math.Min(x1, x2),
                ix2   = Math.Max(x1, x2),
                iy1   = Math.Min(y1, y2),
                iy2   = Math.Max(y1, y2),
                iz1   = Math.Min(z1, z2),
                iz2   = Math.Max(z1, z2);
            int cx1   = ix1 >> 4,
                cx2   = ix2 >> 4,
                cz1   = iz1 >> 4,
                cz2   = iz2 >> 4;

            for (int cz = cz1; cz <= cz2; cz++)
            {
                for (int cx = cx1; cx <= cx2; cx++)
                {
                    if (!(world.GetChunk(cx, cz) is IBlockEditor chunk))
                    {
                        continue;
                    }

                    int bx1 = Math.Max(ix1 - (cx << 4), 0);
                    int bx2 = Math.Min(ix2 - (cx << 4), 15);
                    int bz1 = Math.Max(iz1 - (cz << 4), 0);
                    int bz2 = Math.Min(iz2 - (cz << 4), 15);
                    for (int y = iy1; y <= iy2; y++)
                    {
                        for (int z = bz1; z <= bz2; z++)
                        {
                            for (int x = bx1; x <= bx2; x++)
                            {
                                chunk.SetBlock(x, y, z, block);
                            }
                        }
                    }
                }
            }

            return(count);
        }
コード例 #5
0
        public void Update(IEditableWorld editableWorld, long frame)
        {
            foreach (var entity in editableWorld.Entities.ToList())
            {
                var updatedEntity = entity;

                updatedEntity = updatedEntity.Update(editableEntity =>
                {
                    foreach (var system in SystemManager.EntityUpdaterSystems)
                    {
                        if (system.SubscribedUpdateComponents.Any(updatedEntity.Has))
                        {
                            system.Update(editableEntity, frame);
                        }
                    }
                });

                editableWorld.UpdateEntity(updatedEntity);
            }
        }
コード例 #6
0
        public void Update(IEditableWorld editableWorld, long frame)
        {
            var inputs = InputManager.GetInputStates(frame);

            foreach (var inputState in inputs)
            {
                if (inputState.Enter.IsPressed())
                {
                    if (!editableWorld.Entities.Any(entity => entity.Has <Player>() && entity.Get <Player>().PlayerID == inputState.PlayerID))
                    {
                        editableWorld.UpdateEntity(new Entity(
                                                       Position.Zero,
                                                       new Player(inputState.PlayerID, PlayerState.Idle),
                                                       Idle,
                                                       new Velocity(0, 0),
                                                       new Animated(6, 0, false)
                                                       ));
                    }
                }
            }
        }