Esempio n. 1
0
        private void UpdateBuildAction(GameDuration elapsedDuration)
        {
            if (_placementCooldown > GameDuration.Zero)
            {
                _placementCooldown -= elapsedDuration;
            }

            var result = World.CastRay(
                PositionData.Placement.Pos + new EntityOffset(0, PhysicsValues.PlayerEyeHeight, 0),
                (EntityOffset)PositionData.Placement.Orientation,
                PhysicsValues.MiningDistance);

            if (result == null)
            {
                HighlightedBlock = null;
                _miningTime      = GameDuration.Zero;
            }
            else
            {
                if (RayCastResult.FaceEquals(HighlightedBlock, result) &&
                    _controller.IsKeyPressed(GameKey.Primary))
                {
                    _miningTime += elapsedDuration;

                    if (_miningTime.Seconds >= PhysicsValues.MiningTime)
                    {
                        _blockUpdates.Add(new BlockUpdateData
                        {
                            Pos      = result.BlockPos,
                            Material = 0,
                        });
                    }
                }
                else
                {
                    _miningTime = GameDuration.Zero;

                    if (_placementCooldown <= GameDuration.Zero && _controller.IsKeyPressed(GameKey.Secondary))
                    {
                        _placementCooldown.Seconds = PhysicsValues.PlacementCooldown;
                        _blockUpdates.Add(new BlockUpdateData
                        {
                            Pos      = result.BlockPos + result.Normal,
                            Material = 1,
                        });
                    }
                }

                HighlightedBlock = result;
            }
        }
Esempio n. 2
0
        public static bool FaceEquals(RayCastResult a, RayCastResult b)
        {
            if (a == null)
            {
                return b == null;
            }

            if (b == null)
            {
                return false;
            }

            return a.BlockPos == b.BlockPos
                && a.Normal == b.Normal;
        }
Esempio n. 3
0
        public static bool FaceEquals(RayCastResult a, RayCastResult b)
        {
            if (a == null)
            {
                return(b == null);
            }

            if (b == null)
            {
                return(false);
            }

            return(a.BlockPos == b.BlockPos &&
                   a.Normal == b.Normal);
        }