private void setupEnvironments(Car car, World world, Game game, Move move)
        {
            TilePos.TileSize = game.TrackTileSize;

            GlobalMap.InstanceInit(world);
            GlobalMap.Instance.SetupEnvironment(world, game);

            AngleReachEvent.setupEnvironment(game);

            MoveToAngleFunction.setupEnvironment(world);
            MoveToPoint.setupEnvironment(world);

            PhysicExtensions.setupEnvironment(game);
            PhysicEventsCalculator.setupEnvironment(game, world);

            CollisionSide.SetupEnvironment(game);
            CollisionCircle.SetupEnvironment(game);
            CollisionDetector.SetupEnvironment(game, GlobalMap.Instance);

            map.SetupEnvironment(car, GlobalMap.Instance);
            path.SetupEnvironment(car, GlobalMap.Instance, world, game);

            foreach (IAction action in actions.Values)
            {
                action.setupEnvironment(car, world, game, path);
            }

            foreach (AdditionalPoints action in additionalPointsActions)
            {
                action.setupEnvironment(car, world, game, path);
            }
        }
Exemple #2
0
	// Use this for initialization
	void Start () {
        gameObject.AddComponent<MoveToPoint>();
        aim = gameObject.GetComponent<MoveToPoint>(); // object tracked for aiming
        aim.moveRate = this.moveRate;

        click = gameObject.AddComponent<MoveOnClick>();
	}
    public void Restart()
    {
        // Init BB

        m_Blackboard = new Blackboard();
        m_Blackboard.Trans = transform;
        m_Blackboard.Player = GameObject.FindGameObjectWithTag("Player").transform;
        m_Blackboard.Destination = transform.position + new Vector3(10, 0, 5);

        m_Bt = new BehaviorTree();
        m_Bt.m_Blackboard = m_Blackboard;

        // Init tree
        Repeat repeat = new Repeat(ref m_Bt, -1);
        Sequence randomMove = new Sequence(ref m_Bt);
        PickRandomTarget pickTarget = new PickRandomTarget();
        MoveToPoint moveBehavior = new MoveToPoint();

        randomMove.m_Children.Add(moveBehavior);
        randomMove.m_Children.Add(pickTarget);

        // Try out Chase behavior
        m_Chase = new Chase(moveBehavior, m_Bt);
        m_Flee = new Flee(moveBehavior, m_Bt);

        repeat.m_Child = randomMove;

        m_Bt.Start(repeat, this.SequenceComplete);
    }
Exemple #4
0
        private void InitStateMachine()
        {
            StateMachine = new StateMachine();

            void AddTransition(IState from, IState to, Func <bool> condition) =>
            StateMachine.AddTransition(from, to, condition);

            void AddAnyTransition(IState state, Func <bool> condition) =>
            StateMachine.AddAnyTransition(state, condition);

            Func <bool> ReachedMovePoint() => () => PointToMove == null;
            Func <bool> HasPointToMove() => () => PointToMove != null;
            Func <bool> IsTimeOutFinished() => () => timer.finished;
            Func <bool> IsStopped() => () => CurrentVerticalMove == MinAxisMove;
            Func <bool> HasTarget() => () => currentTarget != null;
            Func <bool> HasNoTarget() => () => currentTarget == null;

            Idle idle = new Idle(this, Animator);
            SearchPointToMove searchPointToMove = new SearchPointToMove(this);
            MoveToPoint       moveToPoint       = new MoveToPoint(this, Animator);
            TimeOut           timeOut           = new TimeOut(this, timer);
            Attack            attack            = new Attack(this);

            AddTransition(idle, timeOut, IsStopped());
            AddTransition(timeOut, searchPointToMove, IsTimeOutFinished());
            AddTransition(searchPointToMove, moveToPoint, HasPointToMove());
            AddTransition(moveToPoint, idle, ReachedMovePoint());
            AddTransition(attack, idle, HasNoTarget());

            AddAnyTransition(attack, HasTarget());

            StateMachine.SetEntryPoint(idle);
        }
    public void SequenceComplete(Status status)
    {
        PickRandomTarget pickTarget = new PickRandomTarget();
        MoveToPoint moveBehavior = new MoveToPoint();

        randomMove.m_Children.Add(moveBehavior);
        randomMove.m_Children.Add(pickTarget);
    }
Exemple #6
0
 void Awake()
 {
     _isSlowMod = false;
     _shoot = GetComponent< PlayerShoot > ();
     ChangeMoveMod ();
     _moveToPoint = GetComponent< MoveToPoint > ();
     _moveToPoint.enabled = false;
     _pauseMenu = GameObject.Find ("Pause");
     _pauseMenu.SetActive (false);
 }
Exemple #7
0
 // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
 override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
 {
     moveToPoint = animator.gameObject.GetComponent <MoveToPoint>();
     fOV         = animator.gameObject.GetComponent <FieldOfView>();
     enemy       = animator.gameObject.GetComponent <EnemyAI>();
     anim        = animator;
     //Raise playerSpottedEvent (triggers music change)
     anim.gameObject.GetComponent <EnemyAI>().RaiseSpottedEvent();
     //Increase speed
     anim.gameObject.GetComponent <NavMeshAgent>().speed = 8;
 }
Exemple #8
0
    // Start is called before the first frame update
    public void Start()
    {
        rb = GetComponent <Rigidbody2D>();

        GetComponent <Damageable>().damageAction +=
            (n) => rb.AddForce(15 * Mathf.Sign(n.transform.lossyScale.x) * Vector2.right, ForceMode2D.Impulse);
        GetComponent <Damageable>().dieAction += () => Destroy(gameObject);

        motion = GetComponent <MoveXCommand>();

        attackCommand = GetComponent <ZombiAttack>();


        stateMachine = GetComponent <UnitStateMachine>();

        Patroler patroler = new Patroler(new StateInfo(transform, stateMachine), transform.position)
        {
            speed = BaseSpeed * 0.7f,
            time  = 3f
        };
        Follower follower = new Follower(new StateInfo(transform, stateMachine))
        {
            maxSpeed = BaseSpeed
        };
        MoveToPoint motionToPoint = new MoveToPoint(new StateInfo(transform, stateMachine), patroler.point, patroler)
        {
            speed = new Vector2(BaseSpeed * 0.8f, 0)
        };

        //stateMachine.SetState(patroler);
        stateMachine.Initialize(follower);


        target = GameObject.FindGameObjectWithTag(targetTag).GetComponent <Rigidbody2D>();
        follower.SetTarget(target);


        detectPlayer.Enter += () => stateMachine.SetState(follower);

        attackZone.Enter += () => stateMachine.SetState(new IdleState(new StateInfo(transform, stateMachine)));
        attackZone.Stay  += () => attackCommand.Execute();
        attackZone.Exit  += () => stateMachine.SetState(follower);

        //lostZone.Exit += () =>
        //{
        //    if (stateMachine.currentState == follower)
        //    {
        //        stateMachine.SetState(new WaitState(transform, stateMachine, 1, motionToPoint));
        //    }
        //};
    }
    private void Update()
    {
        lastFire += Time.deltaTime;
        try
        {
            GameObject target = FindTarget();
            if (target != null && lastFire > timeReload)
            {
                if (turret != null)
                {
                    //Quaternion quaternion = Quaternion.AngleAxis(1, Vec)
                    //float yRotate = Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg;
                    //turret.transform.localRotation = new Vector3(turret.transform.localRotation.x, , turret.transform.localRotation.z);
                    turret.transform.LookAt(target.transform.position, Vector3.up);
                }

                GameObject newBullet = poolManager.Spawn(bullet, pointGeneratorBullet.transform.position, pointGeneratorBullet.transform.rotation);//Instantiate(bullet, this.transform);

                Debug.Log(gameObject.name + " create bullet");
                MoveToPoint moveToPointBullet = newBullet.GetComponent <MoveToPoint>();
                if (moveToPointBullet != null)
                {
                    moveToPointBullet.MoveTo(pointGeneratorBullet.transform.position, target);
                }

                DealingDamage dealingDamageBullet = newBullet.GetComponent <DealingDamage>();
                if (dealingDamageBullet != null)
                {
                    UnitData unitData = gameObject.GetComponent <UnitData>();
                    if (unitData != null)
                    {
                        dealingDamageBullet.SetTeam(unitData.team);
                    }
                    else
                    {
                        Debug.LogWarning("Try get UnitData is faled (" + gameObject.name + ")");
                    }
                }
                else
                {
                    Debug.LogWarning("Try get DealingDamage is faled (" + gameObject.name + ")");
                }
                lastFire = 0;
            }
        }
        catch
        {
            Debug.LogError("Error in target " + targets[0].name);
        }
    }
    public GameObject ThrowCard(Card card, Vector3 spawnPoint, Vector3 targetPoint, bool noNoise = false)
    {
        GameObject newObj = Instantiate(CardPrefab);

        newObj.GetComponent <CardVisualBehavior>().SetCard((card));
        newObj.transform.position = spawnPoint;

        MoveToPoint moveToPoint = newObj.AddComponent <MoveToPoint>();

        moveToPoint.targetPoint = targetPoint;
        moveToPoint.speed       = 2.0f;
        if (!noNoise)
        {
            GetComponent <AudioSource>().PlayOneShot(PlayCardSound);
        }
        return(newObj);
    }
Exemple #11
0
    void InstantiatePeriodically()
    {
        Vector2    rand       = Random.insideUnitCircle * 6;
        Vector3    spawnPoint = spawnCenter + new Vector3(rand.x, 0, rand.y);
        GameObject ball       = Instantiate(prefab, spawnPoint, Quaternion.identity);

        Rigidbody   rb  = ball.GetComponent <Rigidbody>();
        Transform   tra = ball.GetComponent <Transform>();
        MoveToPoint mtp = ball.GetComponent <MoveToPoint>();

        tra.localScale *= Random.Range(0.5f, 2.0f);
        rb.mass        *= Random.Range(0.5f, 2.0f);
        mtp.ScaleMovePower(Random.Range(0.5f, 2.0f));
        mtp.ScaleMaxAngularVelocity(Random.Range(0.5f, 2.0f));


        Invoke("InstantiatePeriodically", period);
    }
Exemple #12
0
    // Use this for initialization
    void Start()
    {
        index = 1;

        movePlayer = new MoveToPoint();
        ph         = new PathController(gameObject);

        gameObject.transform.GetComponentInParent <CheckPath>().OnTriggerObjects += delegate()
        {
            Vector2 pos;
            IEnumerable <GameObject> boots;

            ph.GetOverlap(out pos, out boots);

            ph.GetValue(boots, pos);
        };

        isClick.GetComponent <Floor>().gg += delegate(List <Node> n)
        {
            MoveCome            = true;
            movePlayer.pathStep = 1;
        };
    }
Exemple #13
0
 // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
 override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
 {
     distract    = animator.gameObject.GetComponent <Distractable>();
     moveToPoint = animator.gameObject.GetComponent <MoveToPoint>();
 }
Exemple #14
0
 // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
 override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
 {
     moveToPoint = animator.gameObject.GetComponent <MoveToPoint>();
     patrol      = animator.gameObject.GetComponent <PatrolV2>();
     animator.gameObject.GetComponent <EnemyAI>().RaisePatrolEvent();
 }
    public void Restart()
    {
        // Creating and setting some basic values for the blackboard
        m_Blackboard = new Blackboard();
        m_Blackboard.Trans = transform;
        m_Blackboard.StartPoint = transform.position;
        GameObject player = GameObject.FindGameObjectWithTag("Player");
        if (player) {
            m_Blackboard.Player = player.transform;
        }
        m_Blackboard.Destination = transform.position + new Vector3(10, 0, 5);
        m_Blackboard.LookAtObject = GetComponent<Looker>();

        //-------------------------------------------------------------------------
        // Higher level sequence/selectors which we'll add leaf behaviors to later
        //-------------------------------------------------------------------------
        Sequence randomMove = new Sequence();
        Sequence moveToBeacon = new Sequence();

        //----------------------------------------------------------------------------------
        // Create leaf behaviors. Should only need one of each.
        // Some of these get used often (MoveToPoint), others are specific (CheckForBeacon)
        //----------------------------------------------------------------------------------
        MoveToPoint moveToPoint = new MoveToPoint();
        PickRandomTarget pickRandomTarget = new PickRandomTarget();
        CheckForBeacon checkForBeacon = new CheckForBeacon();
        ChasePlayer chasePlayer = new ChasePlayer();
        Stunned stunned = new Stunned();

        //---------------------------------------------------------------------------------------
        // Building the subtrees.
        // Add children to subtrees in left to right order, since each AddChild is doing a push_back
        //----------------------------------------------------------------------------------------
        moveToBeacon.AddChild(checkForBeacon);
        moveToBeacon.AddChild(moveToPoint);

        randomMove.AddChild(pickRandomTarget);
        randomMove.AddChild(moveToPoint);

        //--------------------------------------------------
        // Add subtrees to the root.
        // Like before, add behaviors in left to right order
        //--------------------------------------------------
        m_Root.AddChild(stunned);
        m_Root.AddChild(moveToBeacon);
        m_Root.AddChild(chasePlayer);
        m_Root.AddChild(randomMove);

        //m_Blackboard.MovementPath = NavGraphConstructor.Instance.FindPathToLocation(m_Blackboard.Trans.position, m_Blackboard.Destination);
        //m_Blackboard.PathCurrentIdx = 0;

        //		repeat.m_Child = randomMove;
        //
        //		// Try out Chase behavior
        //		m_Chase = new Chase(moveBehavior, m_Bt);
        //		m_Flee = new Flee(moveBehavior, m_Bt);
        //
        //		List<Behavior> tree = new List<Behavior>();
        //		tree.Add(repeat);
        //		tree.Add(m_Chase);
        //
        //		root.m_Children = tree;
        //
        //		m_Bt.Start(root, this.SequenceComplete);
    }
Exemple #16
0
 private void Awake()
 {
     moveToPoint = GetComponent <MoveToPoint>();
 }