Example #1
0
		public ThreadedRendering ()
			: base()
		{
            this.Title = "A n d r o i d   N o w";
			//lock (_Game.UpdateLock)
			{
				this.Width = _CanvasWidth;
				this.Height = _CanvasHeight;
                this.WindowState = OpenTK.WindowState.Fullscreen; // Hard-coded quik-fix
			}
			Keyboard.KeyDown += delegate(object sender, KeyboardKeyEventArgs e)
			{
                KeyEventArgs key_args = new KeyEventArgs();
                key_args.Key = e.Key;
                if (key_args.Key == Configuration.KeyReset)
				{
					if(KeysPressed.Contains (Configuration.KeyResetModifier))
					{
                        this.Exit();
					}
					else
                    {
                        // Hard-coded quik-fix crap; don't leave this here too long...
                        //if(_Game != null)
                        //{
                        //    lock(_Game.UpdateLock)
                        //    {
                        //        if(_Game.CurrentScene.Name == "SceneFirstMenu")
                        //            key_args.Key = Configuration.KeyDoAction; // HACK: change the meaning of "game start" button (i.e. reset)
                        //        else
                                    Reset = true;
                        //    }
                        //}
                    }
				}
                // Hard-coded classic Alt-F4 because we're cool
                else if (key_args.Key == Key.F4)
                {
                    if (KeysPressed.Contains(Key.AltLeft) || KeysPressed.Contains(Key.AltRight))
                    {
                        this.Exit();
                    }
                }
                else if (key_args.Key == Configuration.KeyToggleDrawBlueprints)
                {
                    Configuration.DrawBlueprints ^= true;
                }
                else if (key_args.Key == Configuration.KeyToggleShowDebugVisuals)
                {
                    Configuration.ShowDebugVisuals ^= true;
                }
                if(_Game != null)
                {
                    lock(_Game.UpdateLock)
    				{
                        IInputAccepter[] accepters = _Game.InputAccepterGroup;
                        bool key_press = true;
    					for(int i = 0; i < accepters.Length; i++)
                            key_press = key_press && accepters[i].KeyDown(this, key_args);
                        if (key_press)
                        {
                            if(KeysPressed.Contains(key_args.Key))
                                KeysPressed.Remove(key_args.Key);
                            else
                                KeysPressed.Add(key_args.Key, DateTime.Now);
                        }
                    }
                }
				
			};
			Keyboard.KeyUp += delegate(object sender, KeyboardKeyEventArgs e)
			{
                KeyEventArgs key_args = new KeyEventArgs();
                key_args.Key = e.Key;
                if(_Game == null)
                    return;
                lock(_Game.UpdateLock)
                {
                    if (key_args.Key == Configuration.KeyToggleFullScreen)
    				{
                        if(_Game != null)
                        {
    						if (this.WindowState == WindowState.Fullscreen)
    							this.WindowState = WindowState.Normal;
    						else
    							this.WindowState = WindowState.Fullscreen;
    						OnResize(null);
                        }
    				}
    				IInputAccepter[] accepters = _Game.InputAccepterGroup;
    				bool key_press = true;
                    if(_Game != null)
                    {
    					for(int i = 0; i < accepters.Length; i++)
                            key_press = key_press && accepters[i].KeyUp(this, key_args);
                        if (key_press && KeysPressed.Contains(key_args.Key))
                            KeysPressed.Remove(key_args.Key);
                    }
                }
			};
			Resize += delegate(object sender, EventArgs e)
			{
				// Note that we cannot call any OpenGL methods directly. What we can do is set
				// a flag and respond to it from the rendering thread.
                var _lock = _Game == null ? e : _Game.UpdateLock;
                lock (_lock)
				{
					Width = Math.Max (Width, _CanvasWidth);
					Height = Math.Max (Height, _CanvasHeight);
					VieportChanged = true;
					ViewportWidth = Width;
					ViewportHeight = Height;
					int multi = ViewportWidth / _CanvasWidth;
					multi = Math.Min(multi, ViewportHeight / _CanvasHeight);
					FBOScaleX = multi * _CanvasWidth;
					FBOScaleY = multi * _CanvasHeight;
				}
			};
		}
Example #2
0
 public bool KeyUp(object sender, KeyEventArgs e)
 {
     return true;
 }
Example #3
0
 public bool KeyDown(object sender, KeyEventArgs e)
 {
     if (e.Key == Configuration.KeyDoAction || e.Key == Configuration.KeyUseEquippedItem || e.Key == Configuration.KeyJump) {
         Next();
         return false;
     }
     return true;
 }
Example #4
0
 /// <summary>
 /// Constructs a new KeyEventArgs instance.
 /// </summary>
 /// <param name="args">An existing KeyEventArgs instance to clone.</param>
 public KeyEventArgs(KeyEventArgs args)
 {
     Key = args.Key;
 }
Example #5
0
        public bool KeyUp(object sender, KeyEventArgs e)
        {
            if (e.Key == Configuration.KeyUseEquippedItem && _WieldingGun) {
                UpdateEventHandler late;
                late = (u_sender, u_e) =>
                {
                    // TODO: Un-hard-code this:
                    Vector2d bullet_velo =
                        new Vector2d(TileX * Math.Cos(_AimAngle), Math.Sin (_AimAngle));
                    //bullet_velo.Normalize();

                    bullet_velo.Y *= _AnimationCurrent == AnimationAimGunFwdCrouch ? 0.0 : 1.0;
                    bullet_velo *= 1000;

                    double shot_offset_x = (SizeX + 3) * TileX;
                    double shot_offset_y = SizeY * (Crouching ? -0.1 :
                        _AnimationCurrent == AnimationAimGunFwdDown ? -0.4 :
                        _AnimationCurrent == AnimationAimGunFwdUp ? 0.8 : 0.25);

                    Sound.Play ("sfx_shoot_gun");
                    var bullet = new BasicBullet (this._RenderSet.Scene,
                                                 this.PositionX + shot_offset_x,
                                                  this.PositionY + shot_offset_y,
                                                  bullet_velo.X, bullet_velo.Y);
                    GunStowTimer.Restart ();
                    return true;
                };
                _RenderSet.Scene.Game.AddUpdateEventHandler (this, late);
            } else if (e.Key == Configuration.KeyDown) {
                _WouldCrouch = false;
            }
            return true;
        }
Example #6
0
 public bool KeyDown(object sender, KeyEventArgs e)
 {
     if (e.Key == Configuration.KeyDoAction && !_WieldingGun) {
         DoActionHere ();
     //            }
     //            else if (e.Key == Configuration.KeyJump) {
     //                Jump ();
     } else if (e.Key == Configuration.KeyUseEquippedItem) {
         _WieldingGun = true;
     } else if (e.Key == Configuration.KeyDown) {
         _WouldCrouch = true;
     }
     return true;
 }