Exemplo n.º 1
0
		public override void ProcessEvent(GameTime gameTime, GameEvent e)
		{
			if (!e.IsInstant)
			{
				RadioWave wave = null;

				if (!waves.TryGetValue(e, out wave))
				{
					// this signal is new
					cps.RecordEvent();

                    if (cps.EventsPerSecond > game.GameObject.CpsLimit)
                    {
						// if its excess - cut if off
                        e.IsHandled = true;
                        return;
                    }
					
					// create a new wave
					wave = new RadioWave();
                    waves.Add(e, wave);
				}
				
                double signalTraveledDistance = wave.Radius;

				// if reached max, remove signal, report processed
				if (signalTraveledDistance >= GameEngine.MaxWaveTravelDistance)
				{
					e.IsHandled = true;
	            	waves.Remove(e);
					return;
				}

				wave.IsHeroActive = hero.CanReceiveSignals;
				bool wasEnclosingHero = wave.IsEnclosingHero;
				wave.IsEnclosingHero = signalTraveledDistance >= this.hero.DistanceToTower;

				// if hero is not in transaction and the signal was in front of him and now it's past him, then...
				if (hero.CanReceiveSignals && !wasEnclosingHero && wave.IsEnclosingHero)
				{
					// hero is receiving the signal
	            	waves.Remove(e);
				}
				else
				{
					// hero either missed the signal or it hasn't reached him yet
					e.IsHandled = false;
					return;
				}
			}
			
			e.IsHandled = true;
			
			if (hero.CanReceiveSignals)
			{
				switch (e.EventType)
				{
	                case GameEventType.Up: this.hero.Direction = Direction.VectorUp; this.hero.Speed = this.hero.DefaultSpeed; break;
	                case GameEventType.Down: this.hero.Direction = Direction.VectorDown; this.hero.Speed = this.hero.DefaultSpeed; break;
	                case GameEventType.Left: this.hero.Direction = Direction.VectorLeft; this.hero.Speed = this.hero.DefaultSpeed; break;
	                case GameEventType.Right: this.hero.Direction = Direction.VectorRight; this.hero.Speed = this.hero.DefaultSpeed; break;
		            case GameEventType.Explosion: PlantBomb(); break;
				}
			}

            base.ProcessEvent(gameTime, e);
		}
Exemplo n.º 2
0
        public override void ProcessEvent(GameTime gameTime, GameEvent e)
        {
            if (!e.IsInstant)
            {
                RadioWave wave = null;

                if (!waves.TryGetValue(e, out wave))
                {
                    // this signal is new
                    cps.RecordEvent();

                    if (cps.EventsPerSecond > game.GameObject.CpsLimit)
                    {
                        // if its excess - cut if off
                        e.IsHandled = true;
                        return;
                    }

                    // create a new wave
                    wave = new RadioWave();
                    waves.Add(e, wave);
                }

                double signalTraveledDistance = wave.Radius;

                // if reached max, remove signal, report processed
                if (signalTraveledDistance >= GameEngine.MaxWaveTravelDistance)
                {
                    e.IsHandled = true;
                    waves.Remove(e);
                    return;
                }

                wave.IsHeroActive = hero.CanReceiveSignals;
                bool wasEnclosingHero = wave.IsEnclosingHero;
                wave.IsEnclosingHero = signalTraveledDistance >= this.hero.DistanceToTower;

                // if hero is not in transaction and the signal was in front of him and now it's past him, then...
                if (hero.CanReceiveSignals && !wasEnclosingHero && wave.IsEnclosingHero)
                {
                    // hero is receiving the signal
                    waves.Remove(e);
                }
                else
                {
                    // hero either missed the signal or it hasn't reached him yet
                    e.IsHandled = false;
                    return;
                }
            }

            e.IsHandled = true;

            if (hero.CanReceiveSignals)
            {
                switch (e.EventType)
                {
                case GameEventType.Up: this.hero.Direction = Direction.VectorUp; this.hero.Speed = this.hero.DefaultSpeed; break;

                case GameEventType.Down: this.hero.Direction = Direction.VectorDown; this.hero.Speed = this.hero.DefaultSpeed; break;

                case GameEventType.Left: this.hero.Direction = Direction.VectorLeft; this.hero.Speed = this.hero.DefaultSpeed; break;

                case GameEventType.Right: this.hero.Direction = Direction.VectorRight; this.hero.Speed = this.hero.DefaultSpeed; break;

                case GameEventType.Explosion: PlantBomb(); break;
                }
            }

            base.ProcessEvent(gameTime, e);
        }