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; }
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; }
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; } }
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); }; }
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); }
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 }
void AddStateToCurrentGroup(PowerUpState myState) { if (m2.CurrentStateGroup != null) { m2.CurrentStateGroup.AddState(myState); } }
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; }
public void InitializeAt(Vector3 pos) { gameObject.SetActive(true); transform.position = pos; state = PowerUpState.IN_PLAY; timeOnInitialization = Time.time; }
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); }
/// <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(); }
public void AddState(PowerUpState state) { //_states.Add(state); if (_numOfStates > 0)// _linePositions.Count > 0) { _stateTransitions.Add(sd.CurrentState.FindChangedFieldsComparedTo(state)); } _numOfStates++; }
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); }
/// <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; }
public void NormalCreate() { if (PowerUpState != null || PowerUpState is Standard) { return; } SoundEventArgs.SetMethodCalled(); PowerUpState.Downgrade(); if (PowerUpState is Fire) { PowerUpState.Downgrade(); } }
/// <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; } } }
/// <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; }
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 = ""; } } } }
public void Downgrade() { if (protectionState is Helmeted) { protectionState.Protect(); } if (protectionState is ProtectionStates.Normal) { PowerUpState.Downgrade(); } if (protectionState is ProtectionStates.Normal) { protectionState.Protect(); } }
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(); }
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); }
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(); }
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; }
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 }); }
/// <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; }
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; }
void CollectedByEnemy(Player enemy) { state = PowerUpState.COLLECTED_BY_ENEMY; enemy.RegisterNewEffect(this); //ApplyEffectTo(enemy); effectsInPlay = ApplyEffectTo(enemy); StartCoroutine(effectsInPlay); }
public void cancelPowerups() { currentPowerupState = PowerUpState.None; playerController.onPowerupStateChanged(currentPowerupState); }
void CollectedBy(Player player) { state = PowerUpState.COLLECTED; player.inventory.Add(this); spawner.RemoveFromScreen(this); gameObject.SetActive(false); }
/// <summary> /// Invoked when dropped. /// </summary> public void OnDrop() { State = PowerUpState.DROPPING; }
/// <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; } } }
void Dodged() { Debug.Log("<color="+Utils.GetInverseColor(this.celestialAlignment)+">Esquivado</color>"); state = PowerUpState.DODGED; DeletePowerUp(); }
protected virtual void Start() { powerUpState = PowerUpState.InAttractMode; }
/// <summary> /// Immediately cancels the effect of the powerup and terminates its life-cycle /// </summary> public virtual void TerminateImmediate() { DisablePowerUpEffect(); CountDown = 0; State = PowerUpState.DEAD; }
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(); } }
/// <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); }
/// <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); }; }
/// <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); } }
protected virtual void Start() { powerUpState = PowerUpState.InAttractMode; powerUpCollected = false; }