Пример #1
0
    protected virtual void PowerUpCollected(GameObject player)
    {
        if (State == PowerUpState.IsCollected || State == PowerUpState.IsExpiring)
        {
            return;
        }
        State = PowerUpState.IsCollected;


        PlayerController = player.GetComponent <PlayerController>();
        Player           = player.GetComponent <Player_G>();

        gameObject.transform.parent   = Player.gameObject.transform;
        gameObject.transform.position = Player.gameObject.transform.position;

        // Collection effects
        PowerUpEffects();


        // Payload
        PowerUpPayload();

        // Send message to any listeners
        foreach (GameObject go in EventSystemListeners.main.listeners)
        {
            ExecuteEvents.Execute <IPowerUpEvents>(go, null, (x, y) => x.OnPowerUpCollected(this, Player));
        }



        Collider.enabled = false;
    }
Пример #2
0
    protected virtual void PowerUpCollected(GameObject gameObjectCollectingPowerUp)
    {
        if (gameObjectCollectingPowerUp.tag != "Player")
        {
            return;
        }

        if (powerUpState == PowerUpState.IsCollected || powerUpState == PowerUpState.IsExpiring)
        {
            return;
        }

        powerUpState     = PowerUpState.IsCollected;
        playerController = gameObjectCollectingPowerUp.GetComponent <PlayerController>();

        gameObject.transform.parent   = playerController.gameObject.transform;
        gameObject.transform.position = playerController.gameObject.transform.position;

        PowerUpEffects();

        PowerUpPayload();

        foreach (GameObject go in EventSystemListeners.main.listeners)
        {
            ExecuteEvents.Execute <IPowerUpEvents> (go, null, (x, y) => x.OnPowerUpCollected(this, playerController));
        }

        //spriteRenderer.enabled = false;
    }
Пример #3
0
 protected virtual void Start()
 {
     // 道具的初始状态是 “吸引模式”
     powerUpState = PowerUpState.InAttractMode;
     // 找到玩家
     player = GameObject.FindObjectOfType <PlayerFSMSystem>();
 }
    void Update()
    {
        timer += Time.deltaTime;

        if (_state == PowerUpState.OnField && timer >= fieldTime)
        {
            Destroy(powerUp, 0.5f);
            powerUp = null;
            _state  = PowerUpState.Waiting;
            timer   = 0f;
        }
        if ((_state == PowerUpState.Start && timer >= spawnTime) ||
            (_state == PowerUpState.Waiting && timer >= intervalTime))
        {
            Spawn();
            _state = PowerUpState.OnField;
            timer  = 0f;
        }
        if (_state == PowerUpState.Granted && timer >= powerUpDuration)
        {
            _state          = PowerUpState.Waiting;
            powerUpDuration = 0f;
            timer           = 0f;
        }
    }
Пример #5
0
    void Start()
    {
        _menu = GetComponentInChildren <GameMenu>();
        _hud  = GetComponentInChildren <GameHud>();


        _camEffects    = Camera.main.GetComponent <CameraEffects>();
        _camController = Camera.main.GetComponent <CameraController>();

        _hud.FinalScoreMode(false);
        _hud.gameObject.SetActive(false);
        _menu.Show(OnStartNewGame, null);

        _introState = new IntroState(this)
        {
            TimeInState = 5, TimeAwake = 4f
        };
        _unarmedState             = new UnarmedState(this);
        _accState                 = new AccState(this);
        _powerUpState             = new PowerUpState(this);
        _blockadesAndEnemiesState = new BlockadeAndEnemiesState(this);
        _aliensState              = new AliensState(this);
        _pauseState               = new PauseState(this);
        _aliensFinalState         = new AliensFinalState(this);

        _accState.ExitState = _unarmedState;

        Spawner = new Spawner(GamePrefabs);
        Spawner.OnRewardEvent += (reward_pts) =>
        {
            pts += reward_pts;
            _hud.SetPoints(pts);
        };
    }
Пример #6
0
    private void FixedUpdate()
    {
        if (PlayerController.StateGroupManager.IsRewinding)
        {
            //OneRewind();
            m2.CurrentStateGroup.OneRewind();

            //PutObjectInState(newState);


            return; //do not bother with physics when we are rewinding
        }



        PowerUpState newState = new PowerUpState(m2.CurrentState);



        if (CollectedChanged)
        {
            CollectedChanged = false;

            newState.Collected = !m2.CurrentState.Collected;
        }



        PutObjectInState(newState);
    }
Пример #7
0
    public PowerUpState OneRewind()
    {
//        PowerUpState newState = _states[_states.Count - 1];
//      _states.RemoveAt(_states.Count - 1);
        //  return newState;



        ChangedFieldsCollection psd = _stateTransitions[_stateTransitions.Count - 1];

        PowerUpState previousState = (PowerUpState)sd.CurrentState.RetrievePreviousState(psd);// PlayerState.SubtractFromPlayerState(new PlayerState(), psd);



        //Debug.Log("previous state powerups " + previousState.NumOfPowerUps);//.Count);

        sm.PutObjectInState(previousState);// new PlayerState(newState));



        _stateTransitions.RemoveAt(_stateTransitions.Count - 1);
        //        _statesRemovedDuringRewinding++;

        _numOfStates--; //   _linePositions.RemoveAt(_linePositions.Count - 1);
                        //      StatesChangedSoUpdateLineRenderer();


        return(previousState);
        //  return -1; //minus one indicates that we haven't finished rewinding yet
    }
Пример #8
0
 void AddStateToCurrentGroup(PowerUpState myState)
 {
     if (m2.CurrentStateGroup != null)
     {
         m2.CurrentStateGroup.AddState(myState);
     }
 }
Пример #9
0
    protected virtual void PowerUpCollected(GameObject gameObjectCollectingPowerUp)
    {
        if (gameObjectCollectingPowerUp.tag != "Player")
        {
            return;
        }
        if (powerUpState == PowerUpState.IsCollected || powerUpState == PowerUpState.IsExpiring)
        {
            return;
        }
        powerUpState = PowerUpState.IsCollected;

        playerBrain = gameObjectCollectingPowerUp.GetComponent <BaseEntity> ();

        gameObject.transform.parent   = playerBrain.gameObject.transform;
        gameObject.transform.position = playerBrain.gameObject.transform.position;

        // Collection effects
        PowerUpEffects();

        // Payload
        PowerUpPayload();

        // Send message to any listeners
        foreach (GameObject go in EventSystemListeners.main.listeners)
        {
            ExecuteEvents.Execute <IPowerUpEvents> (go, null, (x, y) => x.OnPowerUpCollected(this, playerBrain));
        }

        spriteRenderer.enabled = false;
    }
Пример #10
0
 public void InitializeAt(Vector3 pos)
 {
     gameObject.SetActive(true);
     transform.position = pos;
     state = PowerUpState.IN_PLAY;
     timeOnInitialization = Time.time;
 }
Пример #11
0
    public IState RetrievePreviousState(ChangedFieldsCollection cfc)
    {//it doesn't affect the original object, it creates a clone
        PowerUpState clone = new PowerUpState(this);

        foreach (ChangedField cf in cfc.ChangedFields)
        {
            typeof(PowerUpState).GetField(cf.Name).SetValue(clone, cf.OldValue);
        }

        return(clone);
    }
Пример #12
0
        /// <summary>
        /// 道具过期时调用
        /// </summary>
        protected virtual void PowerUpHasExpired()
        {
            if (powerUpState == PowerUpState.IsExpiring)
            {
                return;
            }
            powerUpState = PowerUpState.IsExpiring;

            //Debug.Log("Power Up has expired, removing after a delay for: " + gameObject.name);
            DestroySelfAfterDelay();
        }
Пример #13
0
    public void AddState(PowerUpState state)
    {
        //_states.Add(state);

        if (_numOfStates > 0)// _linePositions.Count > 0)
        {
            _stateTransitions.Add(sd.CurrentState.FindChangedFieldsComparedTo(state));
        }

        _numOfStates++;
    }
Пример #14
0
 public virtual void Throw()
 {
     gameObject.SetActive(true);
     state = PowerUpState.TROWN;
     Soul soul = Game.soul;
     float xPos, yPos;
     PlayerStats playerStats = players[enemyIndex].stats;
     xPos = playerStats.transform.position.x;
     yPos = (playerStats.transform.position.y - soul.transform.position.y) * 0.25f;
     this.transform.position = new Vector3(xPos,yPos,0f);
 }
Пример #15
0
        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="position"> Location in game.</param>
        /// <param name="width"> Width.</param>
        /// <param name="height"> Height.</param>
        /// <param name="level"> Level object.</param>
        /// <param name="content"> ContentManager object.</param>
        public PowerUp(Vector2 position, int width, int height, Level level, ContentManager content) :
            base(position, width, height, level)
        {
            TerminalVelocity = new Vector2(70, 350);

            Solid = false;

            _spawningSound = content.Load <SoundEffect>("Audio/smw_powerupappears");

            _spawnSpeed = 50;
            State       = PowerUpState.IDLE;
        }
Пример #16
0
 public void NormalCreate()
 {
     if (PowerUpState != null || PowerUpState is Standard)
     {
         return;
     }
     SoundEventArgs.SetMethodCalled();
     PowerUpState.Downgrade();
     if (PowerUpState is Fire)
     {
         PowerUpState.Downgrade();
     }
 }
Пример #17
0
        /// <summary>
        /// Function gets called when a collision with this object occurs.
        /// </summary>
        /// <param name="ent"> Entity this object collides with.</param>
        /// <param name="penetration"> Amount of penetration.</param>
        /// <param name="side"> The side the objects collide on.</param>
        /// <param name="axis"> The axis that is being checked.</param>
        /// <param name="fromBounds"> Where the colliding entity came from.</param>
        public override void OnCollision(Entity ent, int penetration, CollisionTester.CollisionSide side, CollisionTester.Axis axis, Rectangle fromBounds)
        {
            if (!(ent is Enemy))
            {
                ResolveCollision(ent, penetration, side);

                if (ent.Solid && axis == CollisionTester.Axis.X)
                {
                    TurnAround();
                    State = PowerUpState.MOVING;
                }
            }
        }
Пример #18
0
        /// <summary>
        /// Invoked when spawned
        /// </summary>
        public void OnSpawn()
        {
            Parent.Score.IncreaseScore(1000);

            _spawnStartPositionY = Position.Y;
            velocity.Y           = -_spawnSpeed;

            if (_spawningSound != null)
            {
                _spawningSound.Play();
            }

            State = PowerUpState.SPAWNING;
        }
Пример #19
0
    public void updateState(PowerUpState state, float count)
    {
        if (state == PowerUpState.Active)
        {
            icon.color = Color.white;
        }
        else if (state == PowerUpState.CoolDown)
        {
            icon.color = new Color(0.8f, 0.8f, 0.8f);
        }
        else if (state == PowerUpState.Available)
        {
            icon.color = Color.green;
        }

        if (count >= 0)
        {
            if (state == PowerUpState.CoolDown)
            {
                if (skillData.whileCoolDown == CoolDownType.TimeBased)
                {
                    StartCoroutine(updateTime(count));
                }
                else if (skillData.whileCoolDown == CoolDownType.XHits)
                {
                    countDown.text = count.ToString("0");
                }
                else
                {
                    countDown.text = "";
                }
            }
            else if (state == PowerUpState.Active)
            {
                if (skillData.whileActive == CoolDownType.TimeBased)
                {
                    StartCoroutine(updateTime(count));
                }
                else if (skillData.whileActive == CoolDownType.XHits)
                {
                    countDown.text = count.ToString("0");
                }
                else
                {
                    countDown.text = "";
                }
            }
        }
    }
Пример #20
0
 public void Downgrade()
 {
     if (protectionState is Helmeted)
     {
         protectionState.Protect();
     }
     if (protectionState is ProtectionStates.Normal)
     {
         PowerUpState.Downgrade();
     }
     if (protectionState is ProtectionStates.Normal)
     {
         protectionState.Protect();
     }
 }
Пример #21
0
    protected virtual void PowerUpHasExpired()
    {
        if (powerUpState == PowerUpState.IsExpiring)
        {
            return;
        }
        powerUpState = PowerUpState.IsExpiring;

        foreach (GameObject go in EventSystemListeners.main.listeners)
        {
            ExecuteEvents.Execute <IPowerUpEvents> (go, null, (x, y) => x.OnPowerUpExpired(this, playerBrain));
        }
        Debug.Log("Power Up has expired, removing after a delay for: " + gameObject.name);
        DestroySelfAfterDelay();
    }
Пример #22
0
    public ChangedFieldsCollection FindChangedFieldsComparedTo(IState statef)// PlayerState state)
    {
        ChangedFieldsCollection result = new ChangedFieldsCollection();


        PowerUpState state = (PowerUpState)statef;



        if (Collected != state.Collected)
        {
            result.AddChangedField(new ChangedField(Collected, "Collected", typeof(bool)));
        }

        return(result);
    }
Пример #23
0
    protected virtual void PowerUpHasExpired()
    {
        if (State == PowerUpState.IsExpiring)
        {
            return;
        }
        State = PowerUpState.IsExpiring;


        // Send message to any listeners
        foreach (GameObject go in EventSystemListeners.main.listeners)
        {
            ExecuteEvents.Execute <IPowerUpEvents>(go, null, (x, y) => x.OnPowerUpExpired(this, Player));
        }

        DestroySelfAfterDelay();
    }
Пример #24
0
    public void PutObjectInState(PowerUpState newState)
    {
        //check what changed


        if (m2.CurrentState.Collected != newState.Collected)
        {
            gameObject.GetComponent <SpriteRenderer>().enabled = !newState.Collected;
        }



        if (PlayerController.StateGroupManager.IsRewinding == false) //(don't add state while we are rewinding)
        {
            AddStateToCurrentGroup(newState);                        //  _states.Add(newState);
        }

        m2.CurrentState = newState;
    }
    public void getPowerUp(PowerUpState newState)
    {
        powerUp = newState;

        if (currentMario)
        {
            Destroy(currentMario);
        }
        if (powerUp == PowerUpState.small)
        {
            currentMario = Instantiate(smallMario);
        }
        else if (powerUp == PowerUpState.big)
        {
            currentMario = Instantiate(bigMario);
        }
        currentMario.transform.parent        = transform;
        currentMario.transform.localPosition = Vector3.zero;
    }
Пример #26
0
        public void Hit(Vector2 bulletPosition)
        {
            var powerUpStateIndex = (int)State;

            powerUpStateIndex++;
            if (powerUpStateIndex > 2)
            {
                powerUpStateIndex = 0;
            }

            State = (PowerUpState)powerUpStateIndex;

            Speed = -3f;

            direction = new Vector2(this.Position.X - bulletPosition.X, 1);

            Messenger.Default.Send(new PowerUpStateChangedMessage {
                PowerUp = this
            });
        }
Пример #27
0
        /// <summary>
        /// 拾取这个道具时要做的事情
        /// </summary>
        /// <param name="gameObjectCollectingPowerUp"></param>
        protected virtual void PowerUpCollected(GameObject gameObjectCollectingPowerUp)
        {
            // 将道具的状态修改为已经拾取了
            powerUpState = PowerUpState.IsCollected;

            // 这里可以把道具的位置移动到玩家那里去(这块使用 Tween 可以平滑移动)
            // 将升级游戏对象移动到收集它的玩家的下方,这对于功能来说并不是必要的
            // 但它在游戏对象层次结构中更简洁
            gameObject.transform.DOLocalMove(player.gameObject.transform.position, .5f)
            .OnComplete(() => gameObject.transform.parent = player.gameObject.transform);

            // 执行道具的效果
            PowerUpEffects();

            // Payload
            PowerUpPayload();

            // 现在可以让当前对象消失了(只是关闭了渲染,但是这个道具本身还在 Player 身上)
            spriteRenderer.enabled = false;
            box.enabled            = false;
        }
Пример #28
0
    protected virtual void PowerUpCollected(GameObject gameObjectCollectingPowerUp)
    {
        // We only care if we've been collected by the player
        if (gameObjectCollectingPowerUp.tag != "Player")
        {
            return;
        }

        // We only care if we've not been collected before
        if (powerUpState == PowerUpState.IsCollected || powerUpState == PowerUpState.IsExpiring)
        {
            return;
        }
        powerUpState = PowerUpState.IsCollected;

        // We must have been collected by a player, store handle to player for later use
        playerBrain = gameObjectCollectingPowerUp.GetComponent <PlayerBrain> ();

        // We move the power up game object to be under the player that collect it, this isn't essential for functionality
        // presented so far, but it is neater in the gameObject hierarchy
        gameObject.transform.parent     = playerBrain.gameObject.transform;
        gameObject.transform.localScale = new Vector3(.1f, .1f, .1f);
        gameObject.transform.position   = playerBrain.gameObject.transform.position + powerUpOffset;

        // Collection effects
        PowerUpEffects();

        // Payload
        PowerUpPayload();

        // Send message to any listeners
        //foreach (GameObject go in EventSystemListeners.main.listeners)
        //{
        //    ExecuteEvents.Execute<IPowerUpEvents> (go, null, (x, y) => x.OnPowerUpCollected (this, playerBrain));
        //}

        // Now the power up visuals can go away
        //spriteRenderer.enabled = false;
    }
Пример #29
0
 void CollectedByEnemy(Player enemy)
 {
     state = PowerUpState.COLLECTED_BY_ENEMY;
     enemy.RegisterNewEffect(this);
     //ApplyEffectTo(enemy);
     effectsInPlay = ApplyEffectTo(enemy);
     StartCoroutine(effectsInPlay);
 }
Пример #30
0
    public void cancelPowerups()
    {
        currentPowerupState = PowerUpState.None;

        playerController.onPowerupStateChanged(currentPowerupState);    
    }
Пример #31
0
 void CollectedBy(Player player)
 {
     state = PowerUpState.COLLECTED;
     player.inventory.Add(this);
     spawner.RemoveFromScreen(this);
     gameObject.SetActive(false);
 }
Пример #32
0
 /// <summary>
 /// Invoked when dropped.
 /// </summary>
 public void OnDrop()
 {
     State = PowerUpState.DROPPING;
 }
Пример #33
0
 /// <summary>
 /// Updates the powerup
 /// </summary>
 public void Update(float deltaTime)
 {
     if (State == PowerUpState.ATTACHED)
     {
         CountDown -= deltaTime;
         if (CountDown >= 0)
             UpdatePowerUpEffect();
         else
         {
             DisablePowerUpEffect();
             State = PowerUpState.DEAD;
         }
     }
 }
Пример #34
0
 void Dodged()
 {
     Debug.Log("<color="+Utils.GetInverseColor(this.celestialAlignment)+">Esquivado</color>");
     state = PowerUpState.DODGED;
     DeletePowerUp();
 }
Пример #35
0
 protected virtual void Start()
 {
     powerUpState = PowerUpState.InAttractMode;
 }
Пример #36
0
 /// <summary>
 /// Immediately cancels the effect of the powerup and terminates its life-cycle
 /// </summary>
 public virtual void TerminateImmediate()
 {
     DisablePowerUpEffect();
     CountDown = 0;
     State = PowerUpState.DEAD;
 }
Пример #37
0
 void UpdateSelfDestroyTimer()
 {
     if(Time.time - timeOnInitialization >= selfDestroyTime){
         state = PowerUpState.SELF_DESTROY;
         // TODO llamar corrutina de animacion o lo que sea | efectos en los segundos previos al destruir
         DeletePowerUp();
     }
 }
Пример #38
0
        /// <summary>
        /// Update function (IMonoUpdatable)
        /// </summary>
        /// <param name="gameTime"> Gametime.</param>
        public override void Update(GameTime gameTime)
        {
            switch (State)
            {
            case PowerUpState.IDLE:
                //
                break;

            case PowerUpState.SPAWNING:

                Gravity = 0;

                if (Position.Y <= (_spawnStartPositionY - Height))
                {
                    State = PowerUpState.MOVE_START;
                }

                break;

            case PowerUpState.MOVE_START:

                // Randomnize the move direction after spawning
                // true -> right
                // false <- left
                bool direction = ((new Random()).Next(-1, 1) >= 0);

                Gravity = Parent.Gravity;

                // Set velocity
                velocity.X = TerminalVelocity.X;

                // Randomnize the move direction after spawning
                if (!direction)
                {
                    float invertedVelX = velocity.X * -1;

                    FacingDirection = Facing.LEFT;
                    velocity.X      = invertedVelX;
                }

                State = PowerUpState.MOVING;

                Collidable = true;

                break;

            case PowerUpState.DROPPING:

                velocity.X = 0;
                velocity.Y = _spawnSpeed;

                Gravity = 0;

                if (Grounded)
                {
                    State = PowerUpState.MOVING;
                }

                Collidable = true;

                break;

            case PowerUpState.MOVING:

                velocity.X = TerminalVelocity.X;

                Gravity = Parent.Gravity;

                if (FacingDirection == Facing.LEFT)
                {
                    float invertedVelX = velocity.X * -1;
                    velocity.X = invertedVelX;
                }

                break;
            }

            base.Update(gameTime);
        }
Пример #39
0
 /// <summary>
 /// Attaches the powerUp to the player that just collected it.
 /// </summary>
 /// <param name="player">The player that collected the powerup</param>
 public void CollectedByPlayer(ConnectedPlayer player)
 {
     this.AttachedPlayer = player;
     State = PowerUpState.ATTACHED;
     EnablePowerUpEffect();
 }
    void Start()
    {
        _menu = GetComponentInChildren<GameMenu>();
        _hud = GetComponentInChildren<GameHud>();

        _camEffects = Camera.main.GetComponent<CameraEffects>();
        _camController = Camera.main.GetComponent<CameraController>();

        _hud.FinalScoreMode(false);
        _hud.gameObject.SetActive(false);
        _menu.Show(OnStartNewGame, null);

        _introState = new IntroState(this) { TimeInState = 5, TimeAwake = 4f };
        _unarmedState = new UnarmedState(this);
        _accState = new AccState(this);
        _powerUpState = new PowerUpState(this);
        _blockadesAndEnemiesState = new BlockadeAndEnemiesState(this);
        _aliensState = new AliensState(this);
        _pauseState = new PauseState(this);
        _aliensFinalState = new AliensFinalState(this);

        _accState.ExitState = _unarmedState;

        Spawner = new Spawner(GamePrefabs);
        Spawner.OnRewardEvent += (reward_pts) =>
        {
            pts += reward_pts;
            _hud.SetPoints(pts);
        };
    }
Пример #41
0
 /// <summary>
 /// Collect a powerup state.
 /// None cannot be collected.
 /// </summary>
 /// <param name="powerup"></param>
 public void collectPowerup(PowerUpState powerup)
 {
     if (powerup != PowerUpState.None && powerup != currentPowerupState){
         currentPowerupState = powerup;
         playerController.onPowerupStateChanged(currentPowerupState);
     }
 }
Пример #42
0
 protected virtual void Start()
 {
     powerUpState     = PowerUpState.InAttractMode;
     powerUpCollected = false;
 }