예제 #1
0
        // -------------------------------------------

        /*
         * Change the animation
         */
        public override void ChangeState(int _newState)
        {
            if (IsMine())
            {
                NetworkEventController.Instance.DispatchNetworkEvent(EVENT_PLAYER_NEW_STATE, NetworkID.GetID(), _newState.ToString());
                base.ChangeState(_newState);
            }
        }
예제 #2
0
        // -------------------------------------------

        /*
         * Change the animation
         */
        public override void ChangeAnimation(int _animation, bool _isLoop)
        {
            if (IsMine())
            {
                bool isThereChange = (m_animation != _animation);
                base.ChangeAnimation(_animation, _isLoop);
                if (isThereChange)
                {
                    NetworkEventController.Instance.DispatchNetworkEvent(EVENT_PLAYER_NEW_ANIMATION, NetworkID.GetID(), _animation.ToString());
                }
            }
        }
        // -------------------------------------------

        /*
         * Element's logic
         */
        public override void ChangeState(int _newState)
        {
            base.ChangeState(_newState);

            switch (m_state)
            {
            case STATE_RUNNING:
                switch (m_animationDefinition)
                {
                case EnemyData.ANIMATION_IDLE:
                    ChangeAnimation(ANIMATION_IDLE, true);
                    break;

                case EnemyData.ANIMATION_WALK:
                    ChangeAnimation(ANIMATION_WALK, true);
                    break;

                case EnemyData.ANIMATION_RUN:
                    ChangeAnimation(ANIMATION_RUN, true);
                    break;
                }
                break;

            case STATE_DIE:
                ChangeAnimation(ANIMATION_DIE, true);
                break;

            case STATE_DIE_BY_EXPLOSION:
                ChangeAnimation(ANIMATION_IDLE, true);
                break;

            case STATE_DISAPPEAR:
                ChangeAnimation(ANIMATION_DIE, true);
                break;
            }

            if (GameEventController.Instance.IsGameMaster())
            {
                NetworkEventController.Instance.DispatchNetworkEvent(EVENT_ENEMY_NEW_STATE, NetworkID.GetID(), _newState.ToString());
            }
        }
        // -------------------------------------------

        /*
         * Change the animation
         */
        public override void ChangeAnimation(int _animation, bool _isLoop)
        {
            base.ChangeAnimation(_animation, _isLoop);

            if (GameEventController.Instance.IsGameMaster())
            {
                NetworkEventController.Instance.DispatchNetworkEvent(EVENT_ENEMY_NEW_ANIMATION, NetworkID.GetID(), _animation.ToString(), _isLoop.ToString());
            }
        }
        // -------------------------------------------

        /*
         * Apply damage on the enemy's life
         */
        public void Damage(float _value, Vector3 _positionImpact)
        {
            NetworkEventController.Instance.DispatchNetworkEvent(EVENT_ENEMY_LIFE_UPDATED, NetworkID.GetID(), (m_life - _value).ToString());
            FXController.Instance.NewFXImpact(_positionImpact);
        }
        // -------------------------------------------

        /*
         * Initialization of the element
         */
        public override void Initialize(params object[] _list)
        {
            if ((m_dataEnemy == null) && (_list[0] != null))
            {
                m_dataEnemy = ItemMultiObjectEntry.Parse((string)_list[0]);

                this.gameObject.tag = TAG_ENEMY;
                m_enter             = (int)m_dataEnemy.Objects[1];
                m_exit                = (int)m_dataEnemy.Objects[2];
                m_trajectory          = new Vector2(m_enter, m_exit);
                m_animationDefinition = (string)m_dataEnemy.Objects[3];
                m_speed               = (float)(((float)((int)m_dataEnemy.Objects[4])) / 10f);
                m_life                = (int)m_dataEnemy.Objects[5];

                if (GameEventController.Instance.TotalPlayersInGame > 1)
                {
                    float lastLife = m_life;
                    m_life = m_life * GameEventController.Instance.TotalPlayersInGame;
                    m_life = m_life * 0.9f;
                }

                // SET UP IN FIRST WAYPOINT
                m_waypointIndex = 0;
                List <Vector3> ways = EnemiesController.Instance.WaypointsEnemies(m_trajectory);
                m_waypoints = new List <Vector3>();
                for (int i = 0; i < ways.Count; i++)
                {
                    m_waypoints.Add(Utilities.ClonePoint(ways[i]));
                }
                m_waypointPosition = m_waypoints[m_waypointIndex];
                transform.position = m_waypointPosition;
                FXController.Instance.NewFXAppearEnemy(m_waypointPosition);
                SoundsConstants.PlayFXEnemyAppear();
                transform.localScale = new Vector3(GameConfiguration.CELL_SIZE, GameConfiguration.CELL_SIZE, GameConfiguration.CELL_SIZE);

                // UPDATE TO NEXT WAYPOINT
                UpdateToNextWaypoint();

                InitializeCommon();

                ChangeState(STATE_RUNNING);

                if (IsMine())
                {
                    NetworkEventController.Instance.DispatchNetworkEvent(NetworkEventController.EVENT_WORLDOBJECTCONTROLLER_INITIAL_DATA, NetworkID.GetID(), m_dataEnemy.ToString());
                }
            }
        }