private void ProcessNoCollisionAtState_FreeFalling(MovableEntity character)
        {
            if (character.Velocity.LengthSquared > 0)
            {
                Vector3 boundMin = character.GetCharacterCollisionBound().GetMin();
                // Raycast from bottom height point
                Vector3 rayCastStartPosition = new Vector3(character.GetCharacterCollisionBound().GetOrigin());
                rayCastStartPosition.Y = boundMin.Y;

                FRay  ray = new FRay(rayCastStartPosition, character.Velocity);
                float intersectionDistance = LandscapeRayIntersection.Intersection_TerrainRay(GameWorld.GetWorldInstance().GetLevel().Terrain.GetData(), ray);

                // Character is still in free fall, just update position
                if (intersectionDistance < 0.0f || RAYCAST_INTERSECTION_FAR(BodyMechanics.GetFreeFallDistanceInVelocity(character.Velocity), intersectionDistance))
                {
                    character.SetPosition(BodyMechanics.UpdateFreeFallPosition(character.ComponentTranslation, character.Velocity));
                }

                // Character could be elevated on terrain
                else
                {
                    Vector3 CharacterNewPosition = ray.GetPositionInTime(intersectionDistance);
                    CharacterNewPosition.Y += character.GetCharacterCollisionBound().GetExtent().Y;
                    character.SetPosition(CharacterNewPosition);
                    character.ActorState = BehaviorState.IDLE;
                }
            }

            character.pushPosition();
        }
        private void ProcessNoCollisionAtState_Move(MovableEntity character)
        {
            Vector3 boundMin = character.GetCharacterCollisionBound().GetMin();
            Vector3 origin   = character.GetCharacterCollisionBound().GetOrigin();

            // Ray cast from middle height position to avoid miss ray casting
            Vector3 rayCastStartPosition = new Vector3(origin);

            FRay  rayDown = new FRay(rayCastStartPosition, -GameWorld.GetWorldInstance().GetLevel().Camera.GetLocalSpaceUpVector());
            float intersectionDistance = LandscapeRayIntersection.Intersection_TerrainRay(GameWorld.GetWorldInstance().GetLevel().Terrain.GetData(), rayDown);

            // Subtract length of bound extent from middle height position
            float boundExtent = origin.Y - boundMin.Y;
            float actualIntersectionDistance = intersectionDistance - boundExtent;

            // Character is in free fall, next position will be calculated in next tick
            if (intersectionDistance < 0.0f || RAYCAST_INTERSECTION_FAR(BodyMechanics.GetFreeFallDistanceInVelocity(character.Velocity), actualIntersectionDistance))
            {
                character.ActorState = BehaviorState.FREE_FALLING;
            }

            // Check if character can reach that height
            else
            {  // Character could be elevated on terrain
                Vector3 CharacterNewPosition = rayDown.GetPositionInTime(intersectionDistance);
                CharacterNewPosition.Y += character.GetCharacterCollisionBound().GetExtent().Y;
                character.SetPosition(CharacterNewPosition);
                character.ActorState = BehaviorState.IDLE;
            }


            // Push current position to stack
            character.pushPosition();
        }
예제 #3
0
        private static void BoundFrom(MovableEntity mov, Entity ent)
        {
            int       replay = 0;
            FloatRect rect   = mov.GetFloatRect();

            while (CollisionDetector.IsSticking(rect, ent.GetFloatRect()))
            {
                float angle = (float)(Math.PI - Math.Atan2(mov.PreviousVelocity.Y, mov.PreviousVelocity.X) * 2);
                if (mov.GetType() == Entities.EntitiesContainer.Ball.GetType() && ent.GetType() == Entities.EntitiesContainer.Player1.GetType())
                {
                    angle = GetValidAngleForBallAndPlayer(mov, ent);
                    Entities.EntitiesContainer.Ball.WasHitWith(Entities.EntitiesContainer.GetPlayer(ent.ID));
                    AudioSystem.AudioController.PlaySound("HIT");
                }
                mov.Velocity = GetBoundVector(mov, angle, replay > 0 ? true : false);
                rect.Left    = mov.GetFloatRect().Left + mov.Velocity.X;
                rect.Top     = mov.GetFloatRect().Top + mov.Velocity.Y;
                replay++;

                if (replay > 3)
                {
                    mov.ResetPosition();
                }
            }
        }
예제 #4
0
 private void ClearEntities()
 {
     dialogueEntity1 = null;
     dialogueEntity2 = null;
     player          = null;
     enemy           = null;
 }
예제 #5
0
    /// <summary>
    /// Chooses a random row with its corresponding information.
    /// Then casts a ray where the Enemy is supposed to be relocated. If the ray
    /// doesn't collide with any other entity, the Enemy is relocated and removed from the _enemyToRearrange list.
    /// </summary>
    /// <param name="enemy">Enemy to rearrange</param>
    /// <returns>True if the Enemy is relocated. False otherwise.</returns>
    private bool TryToRearrangeEnemy(MovableEntity enemy)
    {
        int     randSpawnPoint = (int)Random.Range(0, _mapRows);
        Vector3 position       = _rowData[randSpawnPoint].SpawnPosition - new Vector3(0, 0, 0.3f);;
        Vector3 rayOrigin      = position - Vector3.back;
        Vector3 rayDirection   = Vector3.forward;
        Ray     ray            = new Ray(rayOrigin, rayDirection);

        if (!Physics.Raycast(ray, 15))
        {
            Quaternion rotation = Quaternion.Euler(0, position.x > 0 ? -180 : 0, 0);
            Vector2    movement = _rowData[randSpawnPoint].SpawnPosition.x > 0 ? new Vector2(-1.0f, 0.0f) : new Vector2(1.0f, 0.0f);

            float xAdjust = _rowData[randSpawnPoint].SpawnPosition.x > 0 ? enemy.SpriteData.bounds.size.x : -enemy.SpriteData.bounds.size.x;
            enemy.transform.position = position + new Vector3(xAdjust, 0, 0);


            enemy.transform.rotation = rotation;
            enemy.AssignMovement(movement, _rowData[randSpawnPoint].AssignedSpeed);

            return(true);
        }

        return(false);
    }
예제 #6
0
        /// <summary>
        /// Method in charge of removing one of the escorting enemies. If there is no more escorting enemies, it deactives
        /// anything unnecessary and checks if the character is over water, in which case it will die. Otherwise, the character is freed,
        /// the score is added and the bouncing animation is launched. It is called when any EnemyDeadEvent is launched.
        /// <seealso cref="GameManager.EnemyDeadEvent"/>
        /// <seealso cref="GameManager.AddScore"/>
        /// </summary>
        /// <param name="enemy"></param>
        public void RemoveEnemy(MovableEntity enemy)
        {
            if (enemy == _enemy1)
            {
                _enemy1 = null;
                _remainingEnemies--;
            }
            else if (enemy == _enemy2)
            {
                _enemy2 = null;
                _remainingEnemies--;
            }

            if (_remainingEnemies == 0)
            {
                ((MovableEntity)owner).MovementDirection            = Vector3.zero;
                gameObject.GetComponent <CapsuleCollider>().enabled = false;
                ((MovableEntity)owner).IsActive       = false;
                GameManager.SINGLETON.EnemyDeadEvent -= RemoveEnemy;
                speechBubble.SetActive(false);

                if (CheckIsOverWater())
                {
                    gameObject.GetComponent <AudioSource>().PlayOneShot(splashSound);
                    Die();
                }
                else
                {
                    GameManager.SINGLETON.AddScore(100, transform.position);
                    gameObject.GetComponent <AudioSource>().Play();
                    owner.GetComponent <AnimationBounce>().StartSingleBounce(transform.position);
                }
            }
        }
예제 #7
0
 public ArriveBehavior(MovableEntity agent, Vector2 target, float decelerationDist)
 {
     Agent          = agent;
     TargetPosition = target;
     SlowingRadius  = decelerationDist;
     TargetRadius   = 10.0f;
 }
예제 #8
0
 protected override void OnExit(MovableEntity entity)
 {
     foreach (var state in states)
     {
         state.OnExit(entity);
     }
 }
예제 #9
0
 protected override void OnMove(MovableEntity entity, ref Vector2 finalVelocity)
 {
     foreach (var state in states)
     {
         state.OnMove(entity, ref finalVelocity);
     }
 }
예제 #10
0
        public void Move(MovableEntity movableEntity)
        {
            var vel = movableEntity.Rigidbody.velocity;

            OnMove(movableEntity, ref vel);
            movableEntity.Rigidbody.velocity = vel;
        }
예제 #11
0
    public override bool EndMove(Vector3 direction)
    {
        Vector3       pos = my.position;
        RaycastHit    hitUnder, hitForward;
        MovableEntity carrier = null;

        bool somethingUnder = Physics.Raycast(pos, -yAxis, out hitUnder, 1, layerMask);
        bool underForward   = Physics.Raycast(pos + my.forward, -yAxis, out hitForward, 1, layerMask);

        if (!somethingUnder && !underForward)
        {
            // there's a hole
            CarriedBy(null);
            ChangePosition(pos, RoundPosition(pos - yAxis), timeToFall, -yAxis); // fall
            return(false);
        }
        else if (somethingUnder && !underForward)
        {
            carrier = hitUnder.transform.GetComponent <MovableEntity>();
        }
        else if (underForward && !somethingUnder)
        {
            carrier = hitForward.transform.GetComponent <MovableEntity>();
        }

        CarriedBy(carrier);
        return(true);
    }
예제 #12
0
    public override bool CanMove(Vector3 direction)
    {
        if (Frozen)
        {
            return(false);
        }

        Vector3    pos = my.position;
        RaycastHit hit;

        if (!EatenA && Physics.Raycast(pos, direction, out hit, 1, layerMask))
        {
            MovableEntity movable = hit.transform.GetComponent <MovableEntity>();
            if (!(movable && movable.CanMove(direction)))
            {
                return(false);
            }
            movable.Push(direction);
        }
        if (!EatenB && Physics.Raycast(pos + my.forward, direction, out hit, 1, layerMask))
        {
            MovableEntity movable = hit.transform.GetComponent <MovableEntity>();
            if (!(movable && movable.CanMove(direction)))
            {
                return(false);
            }
            movable.Push(direction);
        }
        return(true);
    }
예제 #13
0
    public override void StopEating()
    {
        GameplayManager.instance.AddMove(new RecordableMove(currentlyEating, RecordableMove.eType.StopEating));

        Eating = false;
        currentlyEating.transform.parent = (currentlyEating as Carrot).level.transform;
        currentlyEating = null;
    }
예제 #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Interpose"/> class.
 /// </summary>
 /// <param name="player">The player.</param>
 /// <param name="priority">The priority.</param>
 /// <param name="weight">The weight.</param>
 /// <param name="first">The first entity.</param>
 /// <param name="second">The second entity.</param>
 public Interpose(Player player, int priority, double weight,
                  MovableEntity first, MovableEntity second) : base(player, priority, weight)
 {
     First  = first;
     Second = second;
     Arrive = new Arrive(player, priority, weight, player.Position);
     PreferredDistanceFromSecond = Vector.GetDistanceBetween(Second.Position, First.Position) / 2.0;
 }
예제 #15
0
    public override void Init(MovableEntity entity, MoveState state)
    {
        var dude = state as DudeMoveState;

        dude.Cursor = entity.transform.Find("Cursor");

        dude.Dudes = GameObject.FindGameObjectsWithTag("Player").ToList();
    }
예제 #16
0
 public void SetBindingKeyboardKey(Keys key, ActionTypeBinding actionBinding)
 {
     if (playerCamera.GetThirdPersonTarget() != null)
     {
         MovableEntity thirdPersonEntity = playerCamera.GetThirdPersonTarget();
         Factory_BindActionToKey(key, actionBinding);
     }
 }
    public override void Tick(MovableEntity entity, MoveState state)
    {
        var hori = entity.Input.GetAxis("CursorHorizontal");
        var vert = entity.Input.GetAxis("CursorVertical");

        entity.transform.localPosition = entity.transform.localPosition.normalized / 2 +
                                         Vector3.Lerp(entity.transform.localPosition, new Vector3(hori, 0, vert).normalized *_range, 0.5f);
    }
예제 #18
0
 public void StartEating(MovableEntity movable, Vector3 direction)
 {
     Eating          = true;
     currentlyEating = movable;
     JustAte         = true;
     eatParticles.Play();
     currentlyEating.Eat(my.position + direction);
     GameplayManager.instance.AddMove(new RecordableMove(currentlyEating, RecordableMove.eType.StartEating));
 }
예제 #19
0
        private IEnumerator EndRoutine(MovableEntity winner)
        {
            VictoryEffect.ExecuteIfPresent(winner.transform.position);
            Playing = false;
            yield return(new WaitForSeconds(WaitDuration));

            EndPanel.Show();
            ToSelectOnEnd.Select();
            //SetInputMaps(true);
        }
예제 #20
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Interpose"/> class.
        /// </summary>
        /// <param name="player">The player.</param>
        /// <param name="priority">The priority.</param>
        /// <param name="weight">The weight.</param>
        /// <param name="first">The first entity.</param>
        /// <param name="secondPosition">The second position that is used instead of entity.
        /// The artificial second entity is created at this position.</param>
        public Interpose(Player player, int priority, double weight,
                         MovableEntity first, Vector secondPosition) : base(player, priority, weight)
        {
            First  = first;
            Second = new Ball(new FootballBall()) // artificial movable entity for representing second
            {
                Position = secondPosition
            };

            Arrive = new Arrive(player, priority, weight, player.Position);
            PreferredDistanceFromSecond = Vector.GetDistanceBetween(Second.Position, First.Position) / 2.0;
        }
 public MovableEntity CreateMovableEntity(string EntityType, Vector2 position, Texture2D texture = null, List <Entity> entities = null, int extra = 0)
 {
     try
     {
         MovableEntity entity = (MovableEntity)Activator.CreateInstance(Type.GetType($"GameEngine1.GameObjects.{EntityType}"), new object[] { position, texture, entities, extra });
         return(entity);
     }
     catch (Exception)
     {
         throw;
     }
 }
예제 #22
0
 public void SetDialogueEntities(MovableEntity d1, MovableEntity d2)
 {
     player          = d1;
     enemy           = d2;
     dialogueEntity1 = d1.gameObject.GetComponent <DialogueEntity>();
     dialogueEntity2 = d2.gameObject.GetComponent <DialogueEntity>();
     d1.isTalking    = true;
     d2.isTalking    = true;
     d1.SetDirection(Direction.IDLE);
     d2.SetDirection(Direction.IDLE);
     StartDialogue();
 }
예제 #23
0
    private void Awake()
    {
        animator             = GetComponent <Animator>();
        animator.logWarnings = false;

        MovableEntity entity = GetComponent <MovableEntity>();

        entity.moved           += onMoved;
        entity.obstacleEntered += onObstacleEntered;

        showHint();
    }
예제 #24
0
        /// <summary>
        /// Method to assign an escorting enemy to the character when spawning. Used by SpawnManager.
        /// <seealso cref="SpawnManager.SpawnCharacter"/>
        /// </summary>
        /// <param name="enemy">Enemy to assign.</param>
        public void AssignEnemy(MovableEntity enemy)
        {
            if (_enemy1 == null)
            {
                _enemy1 = enemy;
            }
            else
            {
                _enemy2 = enemy;
            }

            _remainingEnemies++;
        }
예제 #25
0
    public void CarriedBy(MovableEntity movable)
    {
        if (movable)
        {
            movable.carrying = this;
        }
        else if (carriedBy)
        {
            carriedBy.carrying = null;
        }

        carriedBy = movable;
    }
예제 #26
0
    bool HandleCollision(Transform obstacle, Vector3 direction)
    {
        MovableEntity movable = obstacle.GetComponent <MovableEntity>();

        if (movable)
        {
            return(CollideWithMovableObject(movable, direction));
        }
        else
        {
            return(false);         // blocked by wall
        }
    }
        private void Process_RegularOBB(CollisionOutputRegularOBB data)
        {
            MovableEntity    character      = data.GetCharacterRootComponent() as MovableEntity;
            Entity           collidedEntity = data.GetCollidedRootComponent() as Entity;
            List <BoundBase> collidedBounds = data.GetCollidedBoundingBoxes();

            switch (character.ActorState)
            {
            case BehaviorState.FREE_FALLING: ProcessCollisionAtState_FreeFalling(character, collidedEntity, collidedBounds); break;

            case BehaviorState.MOVE: ProcessCollisionAtState_Move(character, collidedEntity, collidedBounds); break;
            }
        }
예제 #28
0
    public override void Setup(MovableEntity entity, MoveState state)
    {
        var dude = state as DudeMoveState;

        dude.Tr = entity.transform;

        dude.Rb = entity.gameObject.AddComponent <Rigidbody>();
        dude.Rb.freezeRotation         = true;
        dude.Rb.useGravity             = false;
        dude.Rb.collisionDetectionMode = CollisionDetectionMode.ContinuousDynamic;

        _pool = ObjectPooler.Instance;
        _fx   = ScreenEffects.Instance;
    }
예제 #29
0
        private static float GetValidAngleForBallAndPlayer(MovableEntity ball, Entity player)
        {
            float lenghtOfArea = player.GetFloatRect().Height * 1.3f / 8;
            float middleOfBall = ball.GetFloatRect().Top + ball.GetFloatRect().Height / 2;
            float touchingArea = (middleOfBall - player.GetFloatRect().Top) / lenghtOfArea;

            float bounceAngle;

            switch ((int)touchingArea)
            {
            case 1:
                bounceAngle = 15;
                break;

            case 2:
                bounceAngle = 45;
                break;

            case 3:
                bounceAngle = 75;
                break;

            case 4:
                bounceAngle = 105;
                break;

            case 5:
                bounceAngle = -105;
                break;

            case 6:
                bounceAngle = -75;
                break;

            case 7:
                bounceAngle = -45;
                break;

            case 8:
                bounceAngle = -15;
                break;

            default:
                bounceAngle = 90;
                break;
            }

            return((float)((Math.PI * bounceAngle) / 180));
        }
예제 #30
0
    public override void FixedTick(MovableEntity entity, MoveState state)
    {
        var dude = state as DudeMoveState;

        if (dude.Rb.velocity.y < -5.5f || dude.Rb.velocity.y > 0 && !entity.Input.GetButton("Jump"))
        {
            dude.GravityScale = dude.FallMultiplier;
        }
        else
        {
            dude.GravityScale = 1;
        }

        ApplyGravity(dude);
    }
예제 #31
0
 public override void Dispose()
 {
     this.entity = null;
     this.checkPoint = null;
     this.dtoGameTime = null;
     this.timeToCompleteMaze = null;
     this.mapExamMenu = null;
     this.pauseMenu = null;
     this.gameOverMenu = null;
     this.gameOverData = null;
     this.TotalGameTime = null;
     this.UserProfie = null;
     this.Walls = null;
     this.Weapons = null;
     base.Dispose();
 }
예제 #32
0
        public override void LoadGame(MenuSelections menuSelections)
        {
            this.Gamestate = GameState.Loading;
            string mapPath = "XmlData/Maps/" + menuSelections.MapName;
            LevelMapXMLData mapData = Load.LoadMapData(mapPath);
            map = new MazeMap(mapData);

            entity = new Ball("Graphics/ball", new Rectangle(110, 350, 40, 40), 5);
            checkPoint = new CheckPoint("Graphics/checkpoint", Rectangle.Empty);
            checkPoint.Color = Color.White;
            checkPoint.Visible = true;
            PositionCheckPoint();

            TotalGameTime = new TimeKeeper();
            dtoGameTime = new DrawableTextObject()
            {
                Color = Color.BlueViolet,
                Font = Load.LoadFont("Fonts/font"),
                Position = new Vector2(Width/3 + 50, 0),
                Visible = true,
            };

            TileMap tMap = map as TileMap;
            camera = new AdjustableTileCamera(ref tMap, Width, Height);
            camController = camera.GetController();
            camera.MonitorRectangle(entity);
            camera.LeftScrollPoint = 199;
            camera.RightScrollPoint = camera.Width - 199;
            camera.VerticalDisposition = entity.Height * 2;
            camera.TopScrollPoint = 199;
            camera.BottomScrollPoint = camera.Height - 150;
            camera.HorizontalDisposition = entity.Width * 2;
            camera.FixedHorizontalPoints = new Vector2(199, camera.Width - 199);
            camera.FixedVerticalPoints = new Vector2(199, camera.Height - 149);
            camera.SetEdgeCusionSpacing(100);
            camera.UseEdgeCusions = true;
            camera.ScrollTime = 250;
            TopBorder = LeftBorder = 0;
            RightBorder = Width;
            BottomBorder = Height;

            countDownTimer = 3;
            countDown = new DrawableTextObject()
            {
                Font = Load.LoadFont("Fonts/countDownFont"),
                Color = Color.BlueViolet,
                Position = new Vector2(325, 100),
                Visible = true,
                Text = new StringBuilder(countDownTimer.ToString())
            };

            Walls = new List<Wall>();
            CreateWalls();

            StartGame();
        }