예제 #1
0
 public PlayerMovementEffectPlayer(UxContext uxContext, RogueskivGame game)
     : base(uxContext, audioFilename: "player_movement")
 {
     Game = game;
     PlayerMovementComp     = game.Entities.GetSingleComponent <PlayerComp, BoundedMovementComp>();
     PlayerPositionComp     = game.Entities.GetSingleComponent <PlayerComp, CurrentPositionComp>();
     PlayerLastPositionComp = game.Entities.GetSingleComponent <PlayerComp, LastPositionComp>();
 }
예제 #2
0
        private void SimpleBounce(MovementComp movementComp, CurrentPositionComp currentPositionComp)
        {
            var currentFixedPos  = GetFixedPosition(currentPositionComp.Position);
            var newFixedPosition =
                2 * (BounceLimit - GetFixedMargin(movementComp)) - currentFixedPos;

            SetFixedPosition(currentPositionComp, newFixedPosition);
        }
예제 #3
0
 public bool CheckBounce(
     MovementComp movementComp,
     CurrentPositionComp currentPositionComp,
     LastPositionComp lastPositionComp
     ) =>
 movementComp.SimpleBounce
         ? CheckSimpleBounce(movementComp, currentPositionComp, lastPositionComp)
         : CheckPreciseBounce(movementComp, currentPositionComp, lastPositionComp);
예제 #4
0
 private static float GetLastMovementDistanceIfPlayer(
     MovementComp movementComp,
     CurrentPositionComp positionComp,
     LastPositionComp lastPositionComp
     ) =>
 movementComp.SimpleBounce
         ? 0
         : Distance.Get(
     lastPositionComp.Position.Substract(positionComp.Position)
     );
예제 #5
0
        public override void Init(Game game)
        {
            Game = (RogueskivGame)game;
            var playerComp = Game.Entities.GetWithComponent <PlayerComp>().Single();

            PlayerHealthComp    = playerComp.GetComponent <HealthComp>();
            CurrentPositionComp = playerComp.GetComponent <CurrentPositionComp>();
            LastPositionComp    = playerComp.GetComponent <LastPositionComp>();
            TimerComp           = Game.Entities.GetSingleComponent <TimerComp>();
        }
예제 #6
0
        public override void Init(Game game)
        {
            Game = game;

            var playerEntity = Game
                               .Entities
                               .GetWithComponent <PlayerComp>()
                               .Single();

            PlayerComp    = playerEntity.GetComponent <PlayerComp>();
            PlayerPosComp = playerEntity.GetComponent <CurrentPositionComp>();

            FOVComp = Game.Entities.GetSingleComponent <FOVComp>();
            var boardComp = Game.Entities.GetSingleComponent <BoardComp>();

            FOVComp.Init(boardComp, PlayerComp);
        }
예제 #7
0
        private bool CheckSimpleBounce(
            MovementComp movementComp,
            CurrentPositionComp currentPositionComp,
            LastPositionComp lastPositionComp
            )
        {
            var hasTraversed = HasTraversed(currentPositionComp, lastPositionComp, movementComp);

            if (!hasTraversed)
            {
                return(false);
            }

            // for HorizontalWalls: check if position.X when crossing the limit is between wall.minX and wall.maxX
            // for VerticalWalls  : check if position.Y when crossing the limit is between wall.minY and wall.maxY

            var currentFixedPos = GetFixedPosition(currentPositionComp.Position);
            var currentVarPos   = GetVariablePosition(currentPositionComp.Position);

            var lastFixedPos = GetFixedPosition(lastPositionComp.Position);
            var lastVarPos   = GetVariablePosition(lastPositionComp.Position);

            var deltaFixed = (currentFixedPos - lastFixedPos);
            var deltaVar   = (currentVarPos - lastVarPos);

            var fromLastToWallFixedPos  = (BounceLimit - GetFixedMargin(movementComp) - lastFixedPos);
            var variablePosCrossingWall = lastVarPos + deltaVar * (fromLastToWallFixedPos / deltaFixed);

            var minVarPos = VariablePosition;
            var maxVarPos = VariablePosition + Size;

            var isInFrontOrBehind = (
                (variablePosCrossingWall + movementComp.Radius) >= minVarPos &&
                (variablePosCrossingWall - movementComp.Radius) <= maxVarPos
                );

            if (!isInFrontOrBehind)
            {
                return(false);
            }

            ReverseSpeed(movementComp, -movementComp.BounceMomentumConservationFactor);
            SimpleBounce(movementComp, currentPositionComp);

            return(true);
        }
예제 #8
0
        public override void Init(Game game)
        {
            Game = (RogueskivGame)game;

            BoardComp = Game.Entities.GetSingleComponent <BoardComp>();

            var player = Game
                         .Entities
                         .GetWithComponent <PlayerComp>()
                         .Single();

            PlayerId = player.Id;

            PlayerPosComp      = player.GetComponent <CurrentPositionComp>();
            PlayerHealthComp   = player.GetComponent <HealthComp>();
            PlayerMovementComp = player.GetComponent <MovementComp>();
        }
예제 #9
0
        private static void PreciseBounce(
            MovementComp movementComp,
            CurrentPositionComp currentPositionComp,
            LastPositionComp lastPositionComp,
            PointF bouncePosition
            )
        {
            var distance = Distance.Get(currentPositionComp.Position, bouncePosition);

            if (distance > movementComp.Radius)
            {
                return;
            }

            // TODO get proper bouncing angle
            var angle = Math.Atan2(
                lastPositionComp.Position.Y - bouncePosition.Y,
                lastPositionComp.Position.X - bouncePosition.X
                );
            var cosAngle = (float)Math.Cos(angle);
            var sinAngle = (float)Math.Sin(angle);

            currentPositionComp.SetPosition(
                bouncePosition.X + (cosAngle * movementComp.Radius * PRECISE_BOUNCE_MARGIN_FACTOR),
                bouncePosition.Y + (sinAngle * movementComp.Radius * PRECISE_BOUNCE_MARGIN_FACTOR)
                );

            var speed = movementComp.BounceMomentumConservationFactor * Distance.Get(movementComp.Speed);

            movementComp.Speed = new PointF(
                speed * cosAngle,
                speed * sinAngle
                );

            movementComp.HasBounced = true;
        }
예제 #10
0
 protected abstract bool HasTraversed(
     CurrentPositionComp currentPositionComp, LastPositionComp lastPositionComp, MovementComp movementComp
     );
예제 #11
0
        private bool CheckPreciseBounce(
            MovementComp movementComp,
            CurrentPositionComp currentPositionComp,
            LastPositionComp lastPositionComp
            )
        {
            var currentFixedPos = GetFixedPosition(currentPositionComp.Position);
            var currentVarPos   = GetVariablePosition(currentPositionComp.Position);

            var lastFixedPos = GetFixedPosition(lastPositionComp.Position);
            var lastVarPos   = GetVariablePosition(lastPositionComp.Position);

            var deltaFixed = (currentFixedPos - lastFixedPos);
            var deltaVar   = (currentVarPos - lastVarPos);

            var fixedMargin             = GetFixedMargin(movementComp);
            var fromLastToWallFixedPos  = BounceLimit - fixedMargin - lastFixedPos;
            var variablePosCrossingWall = deltaFixed != 0
                ? lastVarPos + deltaVar * (fromLastToWallFixedPos / deltaFixed)
                : 0; // TODO division by 0?

            var minVarPos = VariablePosition;
            var maxVarPos = VariablePosition + Size;

            var isInFrontOrBehind = (
                variablePosCrossingWall > minVarPos &&
                variablePosCrossingWall < maxVarPos
                );

            if (isInFrontOrBehind)
            {
                var hasTraversed = HasTraversed(currentPositionComp, lastPositionComp, movementComp);
                if (hasTraversed)
                {
                    ReverseSpeed(movementComp, -movementComp.BounceMomentumConservationFactor);
                    SimpleBounce(movementComp, currentPositionComp);
                    movementComp.HasBounced = true;

                    return(true);
                }
            }

            PointF?advancedBouncePosition = null;
            var    isInStartCorner        = (Math.Abs(minVarPos - variablePosCrossingWall) < movementComp.Radius);

            if (isInStartCorner)
            {
                advancedBouncePosition = GetStartPosition(movementComp);
            }

            else
            {
                var isInEndCorner = (Math.Abs(maxVarPos - variablePosCrossingWall) < movementComp.Radius);
                if (isInEndCorner)
                {
                    advancedBouncePosition = GetEndPosition(movementComp);
                }
            }

            if (advancedBouncePosition.HasValue)
            {
                // do not return true because no more checks needed (I hope)
                PreciseBounce(
                    movementComp,
                    currentPositionComp,
                    lastPositionComp,
                    advancedBouncePosition.Value
                    );
            }

            return(false);
        }