Exemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        if (MovementAxis == MovementAxis.None || isStoped)
        {
            return;
        }

        var movementBeforeStop = MovementDirection;
        var newPositionInfo    = MovementUtils.GetPosition(transform, MovementDirection, EnemySpeed, positionOnPreviousFrame);

        if (newPositionInfo.nextTile?.TileType == TileType.Wall)
        {
            isStoped = true;
            var animationSequence = MovementUtils.DoWallCollisionAnimation(MovementDirection, transform, wallCollisionAnimationSpeed);
            animationSequence[0].AppendCallback(() => isStoped = false);
            WallCollisionEvent(gameObject);
            ChooseNextDirection(movementBeforeStop);
        }
        else
        {
            transform.position = newPositionInfo.newPosition;
        }

        positionOnPreviousFrame = transform.position;
    }
Exemplo n.º 2
0
    public void SerializeToStream(ref IBitStream stream)
    {
        sbyte triggeringMoverActorIndex = (sbyte)m_triggeringMover.ActorIndex;

        stream.Serialize(ref triggeringMoverActorIndex);
        MovementUtils.SerializeLightweightPath(m_triggeringPath, stream);
        AbilityResultsUtils.SerializeSequenceStartDataListToStream(ref stream, m_seqStartDataList);

        if (m_effectResults != null)
        {
            sbyte responseType = (sbyte)MovementResults_GameplayResponseType.Effect;
            stream.Serialize(ref responseType);
            m_effectResults.SerializeToStream(ref stream);
        }
        else if (m_barrierResults != null)
        {
            sbyte responseType = (sbyte)MovementResults_GameplayResponseType.Barrier;
            stream.Serialize(ref responseType);
            m_barrierResults.SerializeToStream(ref stream);
        }
        else if (m_powerupResults != null)
        {
            sbyte responseType = (sbyte)MovementResults_GameplayResponseType.Powerup;
            stream.Serialize(ref responseType);
            m_powerupResults.SerializeToStream(ref stream);
        }
        else if (m_gameModeResults != null)
        {
            sbyte responseType = (sbyte)MovementResults_GameplayResponseType.GameMode;
            stream.Serialize(ref responseType);
            m_gameModeResults.SerializeToStream(ref stream);
        }
    }
Exemplo n.º 3
0
 Vector3 CalculateMovementVector(Vector2 normalizedRawInput)
 {
     inputRelativeToWorldPlane = MovementUtils.MovementRelativeToCamera(normalizedRawInput, mainCamera);
     inputRelativeToSlope      = _groundDetection.InputAdjustedForCurrentSlope(inputRelativeToWorldPlane);
     correctedMovement         = _obstacleAvoidance.AvoidObstacles(inputRelativeToSlope, _groundDetection.GroundRelationship_.groundNormal);
     return(correctedMovement);
 }
Exemplo n.º 4
0
    public void Move()
    {
        move = false;
        BoulderMovement movement = movements[currMovement];
        Vector3         endPos   = transform.position + movement.offset;

        Coroutine rotation = null;

        rotation = StartCoroutine(MovementUtils.SmoothRotationConst(boulder, Vector3.back, movement.rotSpeed));

        StartCoroutine(MovementUtils.SmoothMovement((bool done) => {
            if (rotation != null)
            {
                StopCoroutine(rotation);
            }
            if (!movement.onGround)
            {
                PlaySoundInterval(impactAudio, 0, 0.5f);
            }
            currMovement++;
            move = true;
        }, gameObject, endPos, movement.speed));

        //Play or dust ps
        if (movement.onGround)
        {
            rollingAudio.Play();
            dust.Play();
        }
        else
        {
            rollingAudio.Stop();
            dust.Stop();
        }
    }
        public void ResolveMovement()
        {
            Dictionary <int, BoardSquarePathInfo> paths = new Dictionary <int, BoardSquarePathInfo>();

            foreach (ActorData actor in GameFlowData.Get().GetActors())
            {
                paths.Add(actor.ActorIndex, ResolveMovement(actor));
            }

            Dictionary <int, BoardSquarePathInfo> nodes = new Dictionary <int, BoardSquarePathInfo>(paths);
            bool finished = false;

            for (float time = 0; !finished; time += RESOLUTION_STEP)
            {
                if (!ResolveSubstep(nodes, time, out finished))
                {
                    // TODO optimize
                    time  = -RESOLUTION_STEP;
                    nodes = new Dictionary <int, BoardSquarePathInfo>(paths);
                    Log.Info("Restarting movement resolution loop");
                }
            }

            var movementActions = ArtemisServerBarrierManager.Get().OnMovement(paths);

            ArtemisServerResolutionManager.Get().SendMovementActions(movementActions);

            // TODO ClientMovementManager.MsgServerMovementStarting

            foreach (ActorData actor in GameFlowData.Get().GetActors())
            {
                BoardSquarePathInfo start = paths[actor.ActorIndex];
                BoardSquarePathInfo end   = start;
                while (end.next != null)
                {
                    end = end.next;
                }

                ActorTeamSensitiveData atsd = actor.TeamSensitiveData_authority;

                // TODO GetPathEndpoint everywhere

                // TODO movement camera bounds
                actor.MoveFromBoardSquare    = end.square;
                actor.InitialMoveStartSquare = end.square;

                atsd.CallRpcMovement(
                    GameEventManager.EventType.Invalid,
                    GridPosProp.FromGridPos(start.square.GetGridPosition()),
                    GridPosProp.FromGridPos(end.square.GetGridPosition()),
                    MovementUtils.SerializePath(start),
                    ActorData.MovementType.Normal,
                    false,
                    false);

                atsd.MovementLine?.m_positions.Clear();
            }
            Log.Info("Movement resolved");
        }
Exemplo n.º 6
0
 public bool TriggerMatchesMovement(ActorData mover, BoardSquarePathInfo curPath)
 {
     if (m_alreadyReacted || mover != m_triggeringMover)
     {
         return(false);
     }
     return(MovementUtils.ArePathSegmentsEquivalent_FromBeginning(m_triggeringPath, curPath));
 }
 public void Set()
 {
     StartCoroutine(MovementUtils.SmoothMovement((bool done) => {
         trigger.SetActive(true);
         GameSound.Stop("ElevatorMovement");
     }, gameObject, setPosition, speed));
     GameSound.Play("ElevatorMovement");
 }
Exemplo n.º 8
0
    public void Move()
    {
        move = false;
        PlatformMovement movement = movements[currMovement];
        Vector3          endPos   = transform.position + movement.offset;

        StartCoroutine(MovementUtils.SmoothMovement((bool done) => {
            move = true;
        }, gameObject, endPos, movement.speed));
    }
Exemplo n.º 9
0
    private void MovementWithChangeDirection()
    {
        var movementDirectionFromInput = SwipeDetector.GetDirectionFromSwipes();

        if (movementDirectionFromInput != Vector3.zero)
        {
            if (MovementDirection != Vector3.zero)
            {
                transform.position = new Vector3(Mathf.Round(transform.position.x), Mathf.Round(transform.position.y), Mathf.Round(transform.position.z));
            }
            MovementDirection = movementDirectionFromInput;
        }


        if (MovementDirection == Vector3.zero)
        {
            return;
        }

        if (animationSequence.Any())
        {
            animationSequence.ForEach(a => a.Kill());
            animationSequence.Clear();

            transform.localScale = Vector3.one;
            transform.position   = new Vector3(Mathf.Round(transform.position.x), Mathf.Round(transform.position.y), Mathf.Round(transform.position.z));
        }

        var newPositionInfo = MovementUtils.GetPosition(transform, MovementDirection, PlayerSpeed, positionOnPreviousFrame);

        transform.position = newPositionInfo.newPosition;
        if (newPositionInfo.nextTile?.TileType == TileType.Wall)
        {
            if (MovementUtils.CheckSpikesCollision(newPositionInfo.nextTile, MovementDirection))
            {
                //var camera = GamePlayPrefabsSettings.Prefabs.MainCamera;
                //camera.transform.SetParent(null);
                GameplaySettings.MainCamera.transform.SetParent(null);
                Destroy(transform.gameObject);
            }
            else
            {
                animationSequence = MovementUtils.DoWallCollisionAnimation(MovementDirection, transform, wallCollisionAnimationSpeed);
                animationSequence[0].AppendCallback(() => animationSequence.Clear());

                MovementDirection = Vector3.zero;
                WallCollisionEvent(gameObject);
            }
        }

        positionOnPreviousFrame = transform.position;
    }
    public override void ExitAction()
    {
        if (movement != null)
        {
            StopCoroutine(movement);
        }

        movement = StartCoroutine(MovementUtils.SmoothMovement((bool done) => {
            GameSound.Stop("ElevatorMovement");
            movement = null;
        }, platform, setPosition, speed));
        GameSound.Play("ElevatorMovement");
    }
Exemplo n.º 11
0
    public void WallGoUp()
    {
        Vector3 targetPos = initPos + offset;

        if (movement != null)
        {
            StopCoroutine(movement);
        }
        movement = MovementUtils.SmoothMovement((bool end) => {
            movement = null;
        }, wallToRemove, targetPos, movementSpeed);
        StartCoroutine(movement);
    }
Exemplo n.º 12
0
 public override void ExitAction()
 {
     if (movement != null)
     {
         StopCoroutine(movement);
     }
     movement = MovementUtils.SmoothMovement((bool end) => {
         //Reset gem shader
         gemRend.material.shader = initGemShader;
         gemRend.material.SetColor("_EmissionColor", initGemEmissionColor);
         movement = null;
     }, gameObject, initPos, movementSpeed);
     StartCoroutine(movement);
 }
Exemplo n.º 13
0
    public override Transform SimulateMovement(Vector3 direction, GameObject objectClone, int playerSide)
    {
        Transform pieceCloneTransform           = null;
        bool      isCurrentSimulationInProgress = true;

        while (isCurrentSimulationInProgress)
        {
            bool       possible      = false;
            Quaternion startRotation = objectClone.transform.rotation;

            do
            {
                possible = AiUtils.IsLineGapPossible(objectClone, AiUtils.GetBottomPiecePositions(playerSide, objectClone), playerSide);
                if (possible)
                {
                    if (MovementUtils.IsRotationPossible(objectClone))
                    {
                        MovementGeneratorUtils.SimulateNextRotation(objectClone, true);
                    }
                    else
                    {
                        break;
                    }
                }
                else
                {
                    break;
                }
            }while (objectClone.transform.rotation.eulerAngles.y != startRotation.eulerAngles.y);

            if (possible)
            {
                bool isMovePossible = MovementUtils.IsMovementPossible(direction, objectClone);
                if (isMovePossible)
                {
                    MovementGeneratorUtils.SimulateNextTranslation(objectClone, direction);
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(objectClone.transform);
            }
        }

        return(pieceCloneTransform);
    }
Exemplo n.º 14
0
        public override void Deserialize(NetworkReader reader, GameObject context)
        {
            var board = context.GameManager.Board;

            EventType  = (GameEventManager.EventType)reader.ReadInt32();
            Start      = GeneratedNetworkCode._ReadGridPosProp_None(reader);
            EndGridPos = GeneratedNetworkCode._ReadGridPosProp_None(reader);
            EndSquare  = board.GetBoardSquare(GridPos.FromGridPosProp(EndGridPos));
            var pathBytes = reader.ReadBytesAndSize();

            Path                   = MovementUtils.DeSerializePath(board, pathBytes);
            MovementType           = (ActorData.MovementType)reader.ReadInt32();
            DisappearAfterMovement = reader.ReadBoolean();
            Respawning             = reader.ReadBoolean();
        }
Exemplo n.º 15
0
    public override void Action()
    {
        Vector3 targetPos = initPos + offset;

        //Make gem glow
        gemRend.material.shader = glowGemShader;
        gemRend.material.SetColor("_EmissionColor", gemEmissionColor);
        if (movement != null)
        {
            StopCoroutine(movement);
        }
        movement = MovementUtils.SmoothMovement((bool end) => {
            movement = null;
        }, gameObject, targetPos, movementSpeed);
        StartCoroutine(movement);
    }
Exemplo n.º 16
0
    public override Transform SimulateMovement(Vector3 direction, GameObject objectClone, int playerSide)
    {
        Transform  pieceCloneTransform = null;
        Quaternion startRotation       = objectClone.transform.rotation;
        Vector3    startPosition       = objectClone.transform.position;

        do
        {
            while (true)
            {
                bool isGapPossible = AiUtils.IsLineGapPossible(objectClone, AiUtils.GetBottomPiecePositions(playerSide, objectClone), playerSide);

                if (!isGapPossible)
                {
                    this.UpdateValidPositionCriteriaList(objectClone, playerSide);
                }

                if (!MovementUtils.IsMovementPossible(direction, objectClone))
                {
                    break;
                }
                else
                {
                    MovementGeneratorUtils.SimulateNextTranslation(objectClone, direction);
                }
            }

            objectClone.transform.SetPositionAndRotation(startPosition, objectClone.transform.rotation);

            if (MovementUtils.IsRotationPossible(objectClone))
            {
                MovementGeneratorUtils.SimulateNextRotation(objectClone, true);
                startPosition = objectClone.transform.position;
            }
            else
            {
                break;
            }
        }while (objectClone.transform.rotation.eulerAngles.y != startRotation.eulerAngles.y);

        return(pieceCloneTransform);
    }
Exemplo n.º 17
0
    private bool IsMoveForbiden(KeyCode keyPushed)
    {
        Vector3 movementDirection = new Vector3();

        switch (keyPushed)
        {
        case KeyCode.RightArrow:
            movementDirection = Vector3.right;
            break;

        case KeyCode.LeftArrow:
            movementDirection = Vector3.left;
            break;

        default:
            break;
        }

        return(!MovementUtils.IsMovementPossible(movementDirection, this.gameObject));
    }
Exemplo n.º 18
0
    public override IaData CalculateAction(GameObject currentSimulatedObject, int sideId)
    {
        GameObject simulatedObjectClone = PieceUtils.ClonePieceObject(currentSimulatedObject);

        IaData iaInformations = new IaData();

        Vector3    finalCalculatedPosition;
        Quaternion finalCalculatedRotation;

        this.SimulateMovement(Vector3.right, simulatedObjectClone, sideId);

        simulatedObjectClone.transform.SetPositionAndRotation(currentSimulatedObject.transform.position, currentSimulatedObject.transform.rotation);

        bool isMovePossible = MovementUtils.IsMovementPossible(Vector3.left, simulatedObjectClone);

        if (isMovePossible)
        {
            MovementGeneratorUtils.SimulateNextTranslation(simulatedObjectClone, Vector3.left);
        }

        this.SimulateMovement(Vector3.left, simulatedObjectClone, sideId);

        if (ValidPositionCriteriaList.Count != 0)
        {
            //Order position criterias by distance descending then take the one with the highest distance property(which mean the one with less peace on ground)
            PositionCriteria positionCriteria = ValidPositionCriteriaList.OrderByDescending(criteria => criteria.Distance).First();
            finalCalculatedPosition = positionCriteria.ValidPosition;
            finalCalculatedRotation = positionCriteria.ValidRotation;
        }
        else
        {
            finalCalculatedPosition = currentSimulatedObject.transform.position;
            finalCalculatedRotation = currentSimulatedObject.transform.rotation;
        }

        iaInformations.TargetPosition = finalCalculatedPosition;
        iaInformations.TargetRotation = finalCalculatedRotation;

        Destroy(simulatedObjectClone);
        return(iaInformations);
    }
Exemplo n.º 19
0
    // Update is called once per frame
    void Update()
    {
        if (!active)
        {
            return;
        }

        if (ready && down)
        {
            ready = false;
            down  = false;

            //Activate
            StartCoroutine(MovementUtils.SmoothMovement((bool done) => {
                StartCoroutine(Deactivate());
            }, spikes, upPos, speed));
            spikeRisingAudio.Play();

            StartCoroutine(WaitCoolDown());
        }
    }
Exemplo n.º 20
0
        public static ClientMovementResults DeSerializeClientMovementResultsFromStream(Component context,
                                                                                       ref IBitStream stream)
        {
            sbyte invalidActorIndex = (sbyte)ActorData.s_invalidActorIndex;

            stream.Serialize(ref invalidActorIndex);
            var   triggeringPath   = MovementUtils.DeSerializeLightweightPath(context, stream);
            var   seqStartDataList = DeSerializeSequenceStartDataListFromStream(ref stream);
            sbyte num = 0;

            stream.Serialize(ref num);
            var gameplayResponseType             = (MovementResults_GameplayResponseType)num;
            ClientEffectResults  effectResults   = null;
            ClientBarrierResults barrierResults  = null;
            ClientAbilityResults powerupResults  = null;
            ClientAbilityResults gameModeResults = null;

            switch (gameplayResponseType)
            {
            case MovementResults_GameplayResponseType.Effect:
                effectResults = DeSerializeClientEffectResultsFromStream(context, ref stream);
                break;

            case MovementResults_GameplayResponseType.Barrier:
                barrierResults = DeSerializeClientBarrierResultsFromStream(context, ref stream);
                break;

            case MovementResults_GameplayResponseType.Powerup:
                powerupResults = DeSerializeClientAbilityResultsFromStream(context, ref stream);
                break;

            case MovementResults_GameplayResponseType.GameMode:
                gameModeResults = DeSerializeClientAbilityResultsFromStream(context, ref stream);
                break;
            }

            return(new ClientMovementResults(context.GameFlowData.FindActorByActorIndex(invalidActorIndex),
                                             triggeringPath, seqStartDataList, effectResults, barrierResults, powerupResults, gameModeResults));
        }
Exemplo n.º 21
0
 void Update()
 {
     moveRight = MovementUtils.Move(ShouldMove(), moveRight, transform, initialX, moveAmplitude, platformMoveSpeed);
 }
Exemplo n.º 22
0
 protected IEnumerator SmoothRotation(System.Action <bool> done, Quaternion end, float inverseRotationTime)
 {
     return(MovementUtils.SmoothRotation(done, gameObject, end, inverseRotationTime));
 }
Exemplo n.º 23
0
 protected IEnumerator SmoothMovement(System.Action <bool> done, Vector3 end, float inverseMoveTime)
 {
     return(MovementUtils.SmoothMovement(done, gameObject, end, inverseMoveTime));
 }
Exemplo n.º 24
0
    // Update is called once per frame
    void FixedUpdate()
    {
        if (IsMoving)
        {
            elapsedTime += Time.deltaTime;
            float verticalMove = -1f;

            Vector3 newGameObjectVelocity = new Vector3();

            Vector3 newPosition = new Vector3();

            if (Input.GetKey(DetectPlayerMovement(DirectionEnum.Direction.RIGHT)))
            {
                if (!this.IsMoveForbiden(KeyCode.RightArrow))
                {
                    newPosition = this.transform.position + Vector3.right;
                    this.MoveObjectToNewPosition(newPosition);
                }
            }
            else if (Input.GetKey(DetectPlayerMovement(DirectionEnum.Direction.LEFT)))
            {
                if (!this.IsMoveForbiden(KeyCode.LeftArrow))
                {
                    newPosition = this.transform.position + Vector3.left;
                    this.MoveObjectToNewPosition(newPosition);
                }
            }

            if (Input.GetKey(DetectPlayerRotation(DirectionEnum.Direction.RIGHT)) && !this.IsRotationLocked)
            {
                bool isClockwise = true;
                if (MovementUtils.IsRotationPossible(this.gameObject))
                {
                    this.RotateObject(isClockwise);
                }

                this.IsRotationLocked = true;
            }
            else if (Input.GetKey(DetectPlayerRotation(DirectionEnum.Direction.LEFT)) && !this.IsRotationLocked)
            {
                bool isClockwise = false;
                if (MovementUtils.IsRotationPossible(this.gameObject))
                {
                    this.RotateObject(isClockwise);
                }

                this.IsRotationLocked = true;
            }

            if ((Input.GetKeyUp(DetectPlayerRotation(DirectionEnum.Direction.LEFT)) || Input.GetKeyUp(DetectPlayerRotation(DirectionEnum.Direction.RIGHT))) && this.IsRotationLocked)
            {
                this.IsRotationLocked = false;
            }

            if (Input.GetKey(DetectPlayerMovement(DirectionEnum.Direction.DOWN)))
            {
                newGameObjectVelocity = new Vector3(gameObJectRigidBody.velocity.x, gameObJectRigidBody.velocity.y, verticalMove * GameUtils.FetchPlayerPieceSpeed(OwnerId));
            }
            else
            {
                newGameObjectVelocity = new Vector3(this.gameObJectRigidBody.velocity.x, this.gameObJectRigidBody.velocity.y, -0.5f * GameUtils.FetchPlayerPieceSpeed(OwnerId));
            }

            this.gameObJectRigidBody.velocity = newGameObjectVelocity;
        }
    }
Exemplo n.º 25
0
 private bool IsRotateForbiden()
 {
     return(!MovementUtils.IsRotationPossible(this.gameObject));
 }
Exemplo n.º 26
0
    public void Open()
    {
        Vector3 targetPos = initPos + offset;

        StartCoroutine(MovementUtils.SmoothMovement((bool end) => {}, gameObject, targetPos, movementSpeed));
    }
Exemplo n.º 27
0
        public static void Draw(SpriteBatch spriteBatch, GameTime gameTime, MovingEntity movingEntity)
        {
            var livingEntityType = LivingEntityType.lookup[movingEntity.LivingEntityType];
            WalkingDirection newWalkingDirection = MovementUtils.GetWalkingDirectionFromVector(movingEntity.Direction);

            movingEntity.RendererInformation.Update(gameTime, newWalkingDirection);

            if (!movingEntity.IsWalking)
            {
                movingEntity.RendererInformation.currentAnimation.Reset();
            }

            var adjustedYPosition = movingEntity.Position.Y + movingEntity.YPositionDepthOffset;

            if (movingEntity.IsDead())
            {
                movingEntity.RendererInformation.Update(gameTime, WalkingDirection.Left);
                movingEntity.RendererInformation.currentAnimation.Reset();

                spriteBatch.Draw(movingEntity.RendererInformation.currentAnimation, new Vector2((int)movingEntity.Position.X, (int)movingEntity.Position.Y), rotation: MathHelper.Pi / 2, color: Color.White, layerDepth: GeometryUtils.GetLayerDepthFromPosition(movingEntity.Position.X, adjustedYPosition));
            }
            else
            {
                spriteBatch.Draw(movingEntity.RendererInformation.currentAnimation, new Vector2((int)movingEntity.Position.X, (int)movingEntity.Position.Y), color: Color.White, layerDepth: GeometryUtils.GetLayerDepthFromPosition(movingEntity.Position.X, adjustedYPosition));
            }

            // Draw Speech Bubble
            if (movingEntity.RendererInformation.SpeechLine != null)
            {
                var depth  = GeometryUtils.GetLayerDepthFromPosition(movingEntity.Position.X, adjustedYPosition);
                var depth2 = GeometryUtils.GetLayerDepthFromPosition(movingEntity.Position.X + 1, adjustedYPosition);

                var bubbleYOffset = (int)movingEntity.Position.Y - livingEntityType.SpriteBounds.Y - 20;

                var stringWidth      = font.MeasureString(movingEntity.RendererInformation.SpeechLine).X;
                var bubbleWidth      = stringWidth - 8;
                var bubbleStartPos   = new Vector2((int)movingEntity.Position.X - 10 - bubbleWidth, bubbleYOffset);
                var bubbleContentPos = new Vector2((int)movingEntity.Position.X - bubbleWidth, bubbleYOffset);
                var bubbleEndPos     = new Vector2((int)movingEntity.Position.X - 10, bubbleYOffset);

                // Draw bubble start
                spriteBatch.Draw(SimulationGame.ContentManager.Load <Texture2D>(@"GUI\SpeechBubble"), bubbleStartPos, new Rectangle(0, 0, 10, 27), Color.White, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, depth);

                // Draw bubble content
                spriteBatch.Draw(SimulationGame.ContentManager.Load <Texture2D>(@"GUI\SpeechBubble"), bubbleContentPos, new Rectangle(10, 0, 20, 27), Color.White, 0.0f, Vector2.Zero, new Vector2((stringWidth - 18) / 20.0f, 1.0f), SpriteEffects.None, depth);

                // Draw string
                spriteBatch.DrawString(font, movingEntity.RendererInformation.SpeechLine, new Vector2(bubbleContentPos.X, bubbleYOffset + 5), Color.White, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, depth2);

                // Draw bubble end
                spriteBatch.Draw(SimulationGame.ContentManager.Load <Texture2D>(@"GUI\SpeechBubble"), bubbleEndPos, new Rectangle(110, 0, 27, 27), Color.White, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, depth);
            }

            // Draw Health
            if (movingEntity.CurrentLife < movingEntity.MaximumLife)
            {
                spriteBatch.Draw(healthTexture, new Vector2(movingEntity.Position.X - livingEntityType.SpriteBounds.X / 2, movingEntity.Position.Y - livingEntityType.SpriteBounds.Y),
                                 new Rectangle(0, 0, 1, 1), Color.Red, 0.0f, Vector2.Zero, new Vector2(((float)movingEntity.CurrentLife / (float)movingEntity.MaximumLife) * livingEntityType.SpriteBounds.X, 2.0f), SpriteEffects.None, GeometryUtils.GetLayerDepthFromPosition(movingEntity.Position.X, adjustedYPosition));
            }

            if (SimulationGame.IsDebug)
            {
                if (movingEntity.IsBlocking())
                {
                    SimulationGame.PrimitiveDrawer.Rectangle(movingEntity.UnionBounds.ToXnaRectangle(), Color.Red);
                }
                else if (movingEntity.IsHitable())
                {
                    SimulationGame.PrimitiveDrawer.Rectangle(movingEntity.HitBoxBounds.ToXnaRectangle(), Color.White);
                    SimulationGame.PrimitiveDrawer.Rectangle(movingEntity.BlockingBounds.ToXnaRectangle(), Color.Red);
                }
            }
        }
Exemplo n.º 28
0
 private bool IsMoveForbiden(Vector3 movementDirection)
 {
     return(!MovementUtils.IsMovementPossible(movementDirection, this.gameObject));
 }
Exemplo n.º 29
0
    IEnumerator Deactivate()
    {
        yield return(new WaitForSeconds(upTime));

        StartCoroutine(MovementUtils.SmoothMovement((bool done) => { down = true; }, spikes, downPos, speed));
    }
Exemplo n.º 30
0
        private void MovementUpdate(float deltaTime, out Vector3 nextPosition, out Quaternion nextRotation)
        {
            m_LastDeltatime = deltaTime;

            float currentAcceleration = MaxAcceleration;

            if (currentAcceleration < 0)
            {
                currentAcceleration *= -MaxSpeed;
            }

            if (UpdatePosition)
            {
                m_SimulatedPosition = transform.position;
            }
            if (UpdateRotation)
            {
                m_SimulatedRotation = transform.rotation;
            }

            var currentPosition = m_SimulatedPosition;

            interpolator.MoveToCircleIntersection(currentPosition, LookAheadDis);
            var dir = (SteerPosition - currentPosition);

            float distanceToEnd = dir.magnitude + Mathf.Max(0, interpolator.RemainingDistance);

            var prevTargetReached = ReachedEndOfPath;

            ReachedEndOfPath = distanceToEnd <= EndReachedDis && interpolator.Valid;
            if (!prevTargetReached && ReachedEndOfPath)
            {
                OnTargetReached();
            }

            float slowDown;

            var forward = m_SimulatedRotation * Vector3.forward;

            if (interpolator.Valid && !IsStopped)
            {
                slowDown = distanceToEnd < SlowDownDis?Mathf.Sqrt(distanceToEnd / SlowDownDis) : 1;

                //Todo: Get end of path mode
                if (ReachedEndOfPath)
                {
                    Velocity -= Vector3.ClampMagnitude(Velocity, currentAcceleration * deltaTime);
                }
                else
                {
                    Velocity += MovementUtils.CalculateAccelerationToReachPoint(dir, dir.normalized * MaxSpeed, Velocity,
                                                                                currentAcceleration, RotationSpeed, MaxSpeed, forward) * deltaTime;
                }
            }
            else
            {
                slowDown  = 1;
                Velocity -= Vector3.ClampMagnitude(Velocity, currentAcceleration * deltaTime);
            }

            Velocity = MovementUtils.ClampVelocity(Velocity, MaxSpeed, slowDown, SlowWhenNotFacingTarget, forward);

            //Todo: RVO Controller

            var delta = m_LastDeltaPosition = CalculateDeltaToMoveThisFrame(distanceToEnd, deltaTime);

            nextPosition = currentPosition + delta;

            CalculateNextRotation(slowDown, out nextRotation);
        }