private void ProcessPressed(GameTime gameTime, Keys key) { GameEvent e = null; switch (key) { case Keys.Up : e = new GameEvent(GameEventType.Up, gameTime, false); break; case Keys.Down: e = new GameEvent(GameEventType.Down, gameTime, false); break; case Keys.Left: e = new GameEvent(GameEventType.Left, gameTime, false); break; case Keys.Right: e = new GameEvent(GameEventType.Right, gameTime, false); break; case Keys.Space: e = new GameEvent(GameEventType.Stop, gameTime, true); break; } if (e != null) { e.IsInstant = e.EventType == GameEventType.Stop || pressedKeys.Contains(Keys.LeftControl) || pressedKeys.Contains(Keys.RightControl); game.EnqueueEvent(e); } }
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); }
public override bool EventAllowed(GameEvent e) { if (e.EventType == GameEventType.Explosion) { return this.Hero.BombCount == -1 || this.Hero.BombCount > 0; } return true; }
public void Enqueue(GameEvent e) { queue.Enqueue(e); }
public virtual bool EventAllowed(GameEvent e) { return(true); }