public CharacterDialog(string title, bool disableNumbersAndSymbols, bool disableEnter)
     : base(Font.MediumFont, title, Lcd.Width, Lcd.Height-14)
 {
     keyBoard = new Keyboard(this.innerWindow, disableEnter,disableNumbersAndSymbols);
     keyBoard.OnOk += () => this.OnExit();
     keyBoard.OnCancel += () => {okWithEsc = true; OnExit();};
 }
Esempio n. 2
0
        public TextToSpeech(bool isQwerty)
        {
            InitializeComponent();

            clearTextConfirmation = new ClearTextConfirmation();

            btnCallouts.setFontSize();
            btnMenu.setFontSize();
            btnSpeak.setFontSize();

            initControlsRecursive(this.Controls);
            this.MouseClick += (sender, e) =>
            {
                updateCursor();
                //*TODO Delete temporary code
                getCurrentSentence();
            };

            if (isQwerty)
                alsKeyboard = new QwertyKeyboard();
            else
                alsKeyboard = new LargeButtonKeyboard();

            Controls.Add(alsKeyboard);
            alsKeyboard.Location = new Point(MainMenu.GAP, MainMenu.GAP);
            alsKeyboard.SendToBack();

            alsKeyboard.setClearConfirmation(true);
        }
Esempio n. 3
0
 public ScreenManager(Game game)
     : base(game)
 {
     menuScreen = new MenuScreen();
     gameScreen = new GameScreen();
     keyboard = new Keyboard();
 }
Esempio n. 4
0
        static void Main(string[] args)
        {
            Organizer org = new Organizer();
            Menu menu = new Menu();
            Keyboard key = new Keyboard();
            ConsoleComunicator communicator = new ConsoleComunicator();

            Engine eng = new Engine(key, org, menu, communicator);

            List<Entry> entries = new List<Entry>(){
                new Anniversary("Anniversary event","Does not expire event, hot when 15 are remaining or become 1 day old",DateTime.Now.AddDays(2)),
                new Meeting("Meeting event","Expires on the scheduled date and hour + 2 hours, hot when 1 day is remaining",DateTime.Now.AddMinutes(200)),
                new Memo("Memo","Just a Memo"),
                new ToDo("ToDo","Expires on the scheduled date&time, hot when 2 hours are remaining",DateTime.Now.AddMinutes(100))
            };

            foreach (Entry entry in entries)
            {
                org.Add(entry);
               }

            eng.Run();

            //Entry newE = org.GetCurrent();

            //if (newE.EntryType ==  EntryType.Anniversary)
            //{
            //    Anniversary ani = newE as Anniversary;
            //    Console.WriteLine(ani.DateOfAnniversary);
            //}
        }
Esempio n. 5
0
 static void Main(string[] args)
 {
     Keyboard kb1 = new Keyboard("Corsair", "black", "red");
     kb1.RemoveKeys();
     kb1.AddKeys(new Keys("white"));
     Console.WriteLine(kb1.ToString());
 }
Esempio n. 6
0
        public void Shutdown()
        {
            // Release the mouse.
            if (_Mouse != null)
            {
                _Mouse.Unacquire();
                _Mouse.Dispose();
                _Mouse = null;
            }

            // Release the keyboard.
            if (_Keyboard != null)
            {
                _Keyboard.Unacquire();
                _Keyboard.Dispose();
                _Keyboard = null;
            }

            // Release the main interface to direct input.
            if (_DirectInput != null)
            {
                _DirectInput.Dispose();
                _DirectInput = null;
            }
        }
Esempio n. 7
0
        static void Main()
        {
            using (var source = new CancellationTokenSource())
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                var form = new Form1();
                var manager = new EntityManager();
                var keyboard = new Keyboard();
                var systems = new SystemBase[] {
                    new EnemySpawnSystem(manager),
                    new FieldOfPlaySystem(manager),
                    new BulletEnemyCollisionSystem(manager),
                    new KeyboardSystem(manager, form, keyboard),
                    new LifetimeSystem(manager),
                    new MovementSystem(manager),
                    new RenderingSystem(form, manager)
                };

                PlayerTemplate.Create(manager);

                form.KeyDown += (s, e) => keyboard.KeyDown(e.KeyCode);
                form.KeyUp += (s, e) => keyboard.KeyUp(e.KeyCode);
                form.FormClosing += (s, e) => source.Cancel();
                form.Load += (s, e) => Run(systems, source.Token);

                Application.Run(form);
            }
        }
Esempio n. 8
0
 public void MessageKeyPressed(Keyboard.Key key)
 {
     foreach (Entity iEntity in entities)
     {
         iEntity.MessageKeyPressed(key);
     }
 }
Esempio n. 9
0
        public DemoGame()
            : base()
        {
            this.Window.Title = "Snowball Demo Game";

            this.graphicsDevice = new GraphicsDevice(this.Window);
            this.Services.AddService(typeof(IGraphicsDevice), this.graphicsDevice);

            this.keyboard = new Keyboard();
            this.Services.AddService(typeof(IKeyboard), this.keyboard);

            this.mouse = new Mouse(this.Window);
            this.Services.AddService(typeof(IMouse), this.mouse);

            this.gamePad = new GamePad(GamePadIndex.One);

            this.soundDevice = new SoundDevice();
            this.Services.AddService(typeof(ISoundDevice), this.soundDevice);

            this.starfield = new Starfield(this.graphicsDevice);

            this.ship = new Ship(this.graphicsDevice, this.keyboard, this.gamePad);

            this.console = new GameConsole(this.Window, this.graphicsDevice);
            this.console.InputEnabled = true;
            this.console.InputColor = Color.Blue;
            this.console.InputReceived += (s, e) => { this.console.WriteLine(e.Text); };
            this.console.IsVisibleChanged += (s, e) => { this.console.WriteLine("Console toggled."); };

            this.contentManager = new ContentManager<DemoGameContent>(this.Services);

            this.RegisterContent();
        }
Esempio n. 10
0
 /// <summary>
 /// Translates control key's SFML key code to GWEN's code.
 /// </summary>
 /// <param name="sfKey">SFML key code.</param>
 /// <returns>GWEN key code.</returns>
 private static Key TranslateKeyCode(Keyboard.Key sfKey)
 {
     switch (sfKey)
     {
         case Keyboard.Key.Back: return Key.Backspace;
         case Keyboard.Key.Return: return Key.Return;
         case Keyboard.Key.Escape: return Key.Escape;
         case Keyboard.Key.Tab: return Key.Tab;
         case Keyboard.Key.Space: return Key.Space;
         case Keyboard.Key.Up: return Key.Up;
         case Keyboard.Key.Down: return Key.Down;
         case Keyboard.Key.Left: return Key.Left;
         case Keyboard.Key.Right: return Key.Right;
         case Keyboard.Key.Home: return Key.Home;
         case Keyboard.Key.End: return Key.End;
         case Keyboard.Key.Delete: return Key.Delete;
         case Keyboard.Key.LControl: return Key.Control;
         case Keyboard.Key.LAlt: return Key.Alt;
         case Keyboard.Key.LShift: return Key.Shift;
         case Keyboard.Key.RControl: return Key.Control;
         case Keyboard.Key.RAlt: return Key.Alt;
         case Keyboard.Key.RShift: return Key.Shift;
     }
     return Key.Invalid;
 }
        public override void LoadContent()
        {
            //((ScreenWidth / 2) - 400)
            base.LoadContent();
            myNewLevelPosition = (new Vector2(((ScreenWidth / 2) - 300), 0));

            //descriptionBackgroundPosition = (new Vector2 (((ScreenWidth / 2) - 100), ((ScreenHeight / 2) - 100))) ;
            descriptionByTherapistPosition = (new Vector2(((ScreenWidth / 2) - 100), ((ScreenHeight / 2) - 100))) ;
            myDescriptionPosition = (new Vector2(((ScreenWidth / 2) - 300), ((ScreenHeight / 2) - 100)));

            //nameBackgroundPosition = (new Vector2(((ScreenWidth / 2) - 100), ((ScreenHeight / 2) - 40)));
            nameOfTherapistPosition = (new Vector2(((ScreenWidth / 2) - 100), ((ScreenHeight / 2) - 40)));
            myNamePosition = (new Vector2(((ScreenWidth / 2) - 300), ((ScreenHeight / 2) - 40)));

            font = Content.Load<SpriteFont>("font");
            nameOfTherapist = "";
            descriptionByTherapist = "";
            textBackgorund = Content.Load<Texture2D>("GUI/textBackground");
            myNewLevelTitle = Content.Load<Texture2D>("GUI/newLevel");

            btnCancel = MakeButton(0, 0, "GUI/cancel");
            btnCreate = MakeButton(((ScreenWidth) - 120), 0, "GUI/createButton");
            btnHelp = MakeButton(((ScreenWidth) - 55), ScreenHeight - 55, "HELP/helpIcon");
            delDesc = MakeButton(((ScreenWidth / 2) + 301), ((ScreenHeight / 2) - 107), "Gui/miniX");
            delName = MakeButton(((ScreenWidth / 2) + 301), ((ScreenHeight / 2) - 47), "Gui/miniX");

            myName = Content.Load<Texture2D>("GUI/name");
            clearNameButton = MakeButton(((ScreenWidth / 2) - 200), ((ScreenHeight / 2) - 40), "GUI/nothing");

            myDescription = Content.Load<Texture2D>("GUI/description");
            clearDescriptionButton = MakeButton(((ScreenWidth / 2) - 200), ((ScreenHeight / 2) - 100), "GUI/nothingHighlight");

            keyboard = new Keyboard(((ScreenWidth / 2) - 250), ((ScreenHeight) - 240), Content);
            keyboard.LoadContent();
        }
Esempio n. 12
0
		public Machine(byte[] appleIIe, byte[] diskIIRom)
		{
			Events = new MachineEvents();

			Cpu = new Cpu(this);
			Memory = new Memory(this, appleIIe);
			Keyboard = new Keyboard(this);
			GamePort = new GamePort(this);
			Cassette = new Cassette(this);
			Speaker = new Speaker(this);
			Video = new Video(this);
			NoSlotClock = new NoSlotClock(this);

			var emptySlot = new PeripheralCard(this);
			Slot1 = emptySlot;
			Slot2 = emptySlot;
			Slot3 = emptySlot;
			Slot4 = emptySlot;
			Slot5 = emptySlot;
			Slot6 = new DiskIIController(this, diskIIRom);
			Slot7 = emptySlot;

			Slots = new List<PeripheralCard> { null, Slot1, Slot2, Slot3, Slot4, Slot5, Slot6, Slot7 };
			Components = new List<MachineComponent> { Cpu, Memory, Keyboard, GamePort, Cassette, Speaker, Video, NoSlotClock, Slot1, Slot2, Slot3, Slot4, Slot5, Slot6, Slot7 };

			BootDiskII = Slots.OfType<DiskIIController>().Last();
		}
Esempio n. 13
0
 protected bool isKeyPressed(Keyboard.Key key)
 {
     if (Keyboard.IsKeyPressed(key))
         return true;
     else
         return false;
 }
Esempio n. 14
0
        public static void Init(TextScreenBase textScreen, Keyboard keyboard)
        {
            if (textScreen != null)
              {
            TextScreen = textScreen;
              }
              if (keyboard == null)
              {
            mDebugger.Send("No keyboard specified!");
            throw new SystemException("No keyboard specified!");
              }
              else
              {
            Keyboard = keyboard;
              }
              mDebugger.Send("Before Core.Global.Init");
              Core.Global.Init();
              mDebugger.Send("Static Devices");
              InitStaticDevices();
              mDebugger.Send("PCI Devices");
              InitPciDevices();
              mDebugger.Send("Done initializing Cosmos.HAL.Global");

              mDebugger.Send("ATA Primary Master");
              InitAta(Ata.ControllerIdEnum.Primary, Ata.BusPositionEnum.Master);

              //TODO Need to change code to detect if ATA controllers are present or not. How to do this? via PCI enum?
              // They do show up in PCI space as well as the fixed space.
              // Or is it always here, and was our compiler stack corruption issue?
              mDebugger.Send("ATA Secondary Master");
              InitAta(Ata.ControllerIdEnum.Secondary, Ata.BusPositionEnum.Master);
              //InitAta(BlockDevice.Ata.ControllerIdEnum.Secondary, BlockDevice.Ata.BusPositionEnum.Slave);
        }
Esempio n. 15
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            mKeyboard = new Keyboard(this, Resource.Xml.keyboard2);
            mTargetView = (EditText)FindViewById(Resource.Id.target);

            mKeyboardView = (CustomKeyboardView)FindViewById(Resource.Id.keyboard_view);
            mKeyboardView.Keyboard = mKeyboard;

            mTargetView.Touch += (sender, e) => {
                Log.Info("onTouch", "true");
                ShowKeyboardWithAnimation();
                e.Handled = true;
            };

            mKeyboardView.Key += (sender, e) => {
                long eventTime = JavaSystem.CurrentTimeMillis();
                KeyEvent ev = new KeyEvent(eventTime, eventTime, KeyEventActions.Down, e.PrimaryCode, 0, 0, 0, 0, KeyEventFlags.SoftKeyboard | KeyEventFlags.KeepTouchMode);

                this.DispatchKeyEvent(ev);
            };
        }
Esempio n. 16
0
 public void TestMethod1()
 {
     ComputerSystem mediator = new ComputerSystem();
     Computer computer = new Computer(mediator);
     Keyboard keyboard = new Keyboard(mediator);
     Screen screen = new Screen(mediator);
 }
Esempio n. 17
0
        /// <summary>
        /// Uses the input string to the constructor to create a navigation sequence through the keyboard
        /// </summary>
        private void CalculateNavigationPath()
        {
            this.navigationPath = String.Empty;

            Position startPosition = new Position(0, 0);
            Position currentPosition = startPosition;

            Keyboard keyBoard = new Keyboard();
            foreach (char a in searchCommand)
            {
                Key selectedKey = keyBoard.GetSelectedKey(a.ToString());
                //Handle Space character
                if (selectedKey.Value == " ")
                {
                    this.navigationPath += "S,";
                }
                else
                {
                    Position goToPosition = selectedKey.KeyPosition;
                    SetKeySequence(currentPosition, goToPosition);
                    this.navigationPath += "#,";
                    currentPosition = goToPosition;
                }
            }

            //Clean up hanging comma
            if (this.navigationPath.Length > 0)
                this.navigationPath = this.navigationPath.TrimEnd(',');
        }
Esempio n. 18
0
 public InputCommands(Keyboard keyboard, Mouse mouse, Touch touch, GamePad gamePad)
 {
     this.keyboard = keyboard;
     this.mouse = mouse;
     this.touch = touch;
     this.gamePad = gamePad;
 }
        public override void LoadContent()
        {
            base.LoadContent();
            searchQueryPosition = (new Vector2(((ScreenWidth / 2) - 275), 120));
            magnifyGlassPosition = (new Vector2(((ScreenWidth / 2) - 300), 120));
            listBackgroundPosition = (new Vector2( ((ScreenWidth / 2) - 300), 200));
            //searchBackground = (new Vector2( ((screenWidth / 2) - 280), 200));

            myLoadLevelTitlePosition = (new Vector2(((ScreenWidth / 2) - 300), 0));
            //myCancelButtonPosition = (new Vector2(0, 0));

            font = Content.Load<SpriteFont>("font");
            searchQuery = "";
            textBackgorund = Content.Load<Texture2D>("GUI/textBackground");
            magnifyGlass = Content.Load<Texture2D>("GUI/magnifyGlass");
            listBackground = Content.Load<Texture2D>("GUI/listBackground");
            myLoadLevelTitle = Content.Load<Texture2D>("GUI/loadGameTitle");

            btnHelp = MakeButton(((ScreenWidth) - 55), ScreenHeight - 55, "HELP/helpIcon");
            btnCancel = MakeButton(0, 0, "GUI/cancel");
            btnOpen = MakeButton(((ScreenWidth) - 120), 0, "GUI/openButton");
            delSearch = MakeButton( ((ScreenWidth / 2) - 19), 113, "Gui/miniX");
            goSearch = MakeButton(  ((ScreenWidth / 2) + 40), 113, "Gui/go");
            clearSearchButton = MakeButton( ((ScreenWidth / 2) - 275), 120, "GUI/nothing2");
            keyboard = new Keyboard(((ScreenWidth / 2) - 250), ((ScreenHeight) - 240), Content);
            keyboard.LoadContent();

            fileList = new List(levelNames.getFileNames(), 600, 15, 25, listBackgroundPosition, listBackground, font, Color.Black, Color.Yellow);
            // Load buttons 'n' stuff, yo!
        }
Esempio n. 20
0
		static void Main() {
			Timers timers = new Timers();
			Screen screen = new Screen();
			Keyboard keyboard = new Keyboard();
			Sound sound = new Sound();
			Chip8Emulator chip8 = new Chip8Emulator(timers, screen, keyboard, sound);
			Application.Run(new MainForm(chip8));
		}
Esempio n. 21
0
 public WeighingController()
     : base(new Log("log.txt",false))
 {
     _weighingUnit = new WeighingUnit(Logger,new Weight());
     _printer = new Printer(Logger);
     _display = new Display(Logger);
     _keyboard = new Keyboard(Logger);
 }
Esempio n. 22
0
		public Chip8Emulator(Timers timers, Screen screen, Keyboard keyboard, Sound sound) {
			_cpu = new Cpu();
			_memory = new Memory();
			_timers = timers;
			_screen = screen;
			_keyboard = keyboard;
			_sound = sound;
		}
Esempio n. 23
0
	// Use this for initialization
	void Awake () 
	{
        m_keyboard = GetComponentInParent<Keyboard>();

        // add event listener 
        UIButton btn = GetComponent<UIButton>();
        btn.onClick.Add(new EventDelegate(onKeyDown));
	}
Esempio n. 24
0
        public WarKeyController(IWarKeyView view)
        {
            this.view = view;
            this.model = view.GetCurrent();
            this.repository = new WarKeyModelRepository();

            keyboard = new Keyboard(this);
        }
Esempio n. 25
0
        private static RequestManager InitRequestManager(SessionManager sessionManager, IOverlay overlay)
        {
            var context = new DriverContext();
            var manager = new RequestManager(sessionManager);
            var utils = new Utils();
            var winUserWrap = new WinUserWrap();
            var keyboard = new Keyboard(new KeyboardWrap(), new KeyInteropWrap(), winUserWrap);
            IMouse mouse = new Mouse(winUserWrap);
            var wireKeyboard = new WireKeyboard(keyboard);

            // TODO circular dependency, bad smell?
            IUIAutomation uiAutomation = new UIAutomation();
            IElementFactory elementFactory = new ElementFactory();
            ((UIAutomation)uiAutomation).SetElementFactory(elementFactory);
            ((ElementFactory)elementFactory).SetUIAutomation(uiAutomation);
            IElementSearcher elementSearcher = new ElementSearcher(uiAutomation, elementFactory);

            var uacHandler = new UACPromptHandler(uiAutomation, keyboard);
            var windowFactory = new WindowFactory(uiAutomation, keyboard, winUserWrap);
            var windowUtils = new WindowUtils(uiAutomation, windowFactory);

            manager.AddHandler(new ActiveElementHandler(uiAutomation, overlay));
            manager.AddHandler(new ButtonUpHandler(mouse));
            manager.AddHandler(new ButtonDownHandler(mouse));
            manager.AddHandler(new ClearTextHandler(elementFactory));
            manager.AddHandler(new ClickElementHandler(mouse, overlay, elementFactory));
            manager.AddHandler(new ClickHandler(mouse));
            manager.AddHandler(new CloseWindowHandler(windowUtils));
            manager.AddHandler(new DeleteSessionHandler(sessionManager));
            manager.AddHandler(new DoubleClickHandler(mouse));
            manager.AddHandler(new FindElementHandler(uiAutomation, overlay, elementFactory, elementSearcher));
            manager.AddHandler(new FindElementsHandler(uiAutomation, overlay, elementFactory, elementSearcher));
            manager.AddHandler(new GetElementAttributeHandler(elementFactory));
            manager.AddHandler(new GetElementLocationHandler(elementFactory));
            manager.AddHandler(new GetElementLocationInViewHandler(elementFactory));
            manager.AddHandler(new GetElementSizeHandler(elementFactory));
            manager.AddHandler(new GetElementTagNameHandler());
            manager.AddHandler(new GetElementTextHandler());
            manager.AddHandler(new GetCurrentWindowHandler(uiAutomation));
            manager.AddHandler(new GetSourceHandler(uiAutomation));
            manager.AddHandler(new GetTitleHandler(uiAutomation));
            manager.AddHandler(new GetWindowLocationHandler(windowFactory, windowUtils));
            manager.AddHandler(new GetWindowsHandler(windowUtils));
            manager.AddHandler(new GetWindowSizeHandler(windowFactory, windowUtils));
            manager.AddHandler(new ImplicitWaitHandler());
            manager.AddHandler(new IsElementDisplayedHandler());
            manager.AddHandler(new IsElementEnabledHandler());
            manager.AddHandler(new IsElementSelectedHandler());
            manager.AddHandler(new MoveToHandler(mouse, overlay, elementFactory));
            manager.AddHandler(new NewSessionHandler(context, sessionManager, uacHandler, utils));
            manager.AddHandler(new SameElementHandler());
            manager.AddHandler(new ScreenshotHandler());
            manager.AddHandler(new SendKeysHandler(wireKeyboard));
            manager.AddHandler(new SetElementValueHandler(wireKeyboard, elementFactory));
            manager.AddHandler(new SwitchToWindowHandler(uiAutomation, windowFactory, windowUtils));

            return manager;
        }
Esempio n. 26
0
 private static void ResetPressedKeys(Keyboard.Key[] pressedKeys)
 {
     int i = 0;
     foreach (Keyboard.Key key in pressedKeys)
     {
         pressedKeys[i] = Keyboard.Key.Unknown;
         i++;
     }
 }
Esempio n. 27
0
 public void SetKeyboard(Keyboard k)
 {
     Controls.Remove(keyboard);
     keyboard = k;
     keyboard.OnPressed += Press_Key;
     keyboard.HideTextBox();
     Controls.Add(keyboard);
     frmEmailLogin_Resize(this, EventArgs.Empty);
 }
Esempio n. 28
0
        public static Keyboard GetInstance()
        {
            if (Instance == null)
            {
                Instance = new Keyboard();
            }

            return Instance;
        }
Esempio n. 29
0
 public KeyboardEvent(KeyEventType eventType, 
     Keyboard.VirtualKeyCodes keyData, 
     int aKeyFlags, char aChar)
 {
     fEventType = eventType;
     fKeyData = keyData;
     fKeyFlags = aKeyFlags;
     fKeyChar = aChar;
 }
        public void Build(string path, Keyboard keyboard)
        {
            if (string.IsNullOrWhiteSpace(path))
            {
                throw new ArgumentNullException(path);
            }

            Build(GetKeyboardDefinition(path), keyboard);
        }
Esempio n. 31
0
        private void MainWindowPreviewKeyUp(object sender, KeyEventArgs e)
        {
            switch (e.Key)
            {
            case Key.F11:
                this.FullScreen();
                break;

            case Key.Escape:
                this.RestoreScreen();
                break;

            case Key.MediaPlayPause:
            case Key.Space:
                this.PlayPause();
                break;

            case Key.Play:
                this.Play();
                break;

            case Key.Pause:
                this.Pause();
                break;

            case Key.VolumeMute:
                this.Mute();
                break;

            case Key.VolumeDown:
                this.VolumeDown();
                break;

            case Key.VolumeUp:
                this.VolumeUp();
                break;

            case Key.MediaNextTrack:
                this.Next();
                break;

            case Key.MediaPreviousTrack:
                this.Previous();
                break;

            case Key.MediaStop:
                this.Stop();
                break;

            case Key.Enter:
            case Key.SelectMedia:
            case Key.Apps:
                this.SelectMovie();
                break;

            case Key.Left:
                if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift))
                {
                    this.Previous();
                }
                else if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
                {
                    this.Rewind();
                }
                else
                {
                    this.SkipBack();
                }
                break;

            case Key.Right:
                if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift))
                {
                    this.Next();
                }
                else if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
                {
                    this.FastForward();
                }
                else
                {
                    this.Skip();
                }
                break;

            default:
                System.Diagnostics.Debug.WriteLine(e.Key.ToString());
                break;
            }

            this.ShowRoot();
        }
        // ---------------------------------------------------------------------------------------------------------------------------------------------------------
        public bool ClipboardCopy(View SourceView)
        {
            if (!SourceView.SelectedObjects.Any())
            {
                return(false);
            }

            ClipboardTransferSourceView = SourceView;   // must be before the unmarking

            UnmarkSelectedObjectsForCut();

            General.Execute(() => Clipboard.Clear(), "Cannot access Windows Clipboard!");
            ClipboardTransferSelectedObjects = SourceView.SelectedObjects.Where(vobj => vobj is VisualElement || vobj is VisualComplement).ToList();

            string Data          = null;
            var    DataContainer = new DataObject();

            // Copy Idea's visual representations Guids
            var VisRespsGuids = new StringBuilder();

            try
            {
                // Copy visual Representations and individual Complements Guids and Drawings
                var  DrawingComponents      = new Dictionary <Drawing, int>(); // Temporal storage for Drawing and z-order per object
                Rect TotalBounds            = Rect.Empty;
                var  SelectedRepresentators = ClipboardTransferSelectedObjects.CastAs <VisualElement, VisualObject>()
                                              .Select(velem => velem.OwnerRepresentation).Distinct();
                foreach (var Selection in SelectedRepresentators)
                {
                    VisRespsGuids.Append(Selection.GlobalId.ToString() + '\t');

                    var NewDrawings = Selection.CreateIntegralGraphic();
                    foreach (var NewDraw in NewDrawings)
                    {
                        TotalBounds = Rect.Union(TotalBounds, NewDraw.Key.Bounds);
                        DrawingComponents.Add(NewDraw.Key, NewDraw.Value);
                    }
                }

                var SelectedComplements = ClipboardTransferSelectedObjects.CastAs <VisualComplement, VisualObject>()
                                          .Where(vcomp => vcomp.Target.IsGlobal);
                foreach (var Selection in SelectedComplements)
                {
                    // Consider to append individual Complements?
                    // VisRespsGuids.Append(Selection.GlobalId.ToString() + '\t');

                    var NewDraw = Selection.CreateDraw(false);
                    TotalBounds = Rect.Union(TotalBounds, NewDraw.Bounds);
                    DrawingComponents.Add(NewDraw, Selection.ZOrder);
                }

                Data = VisRespsGuids.ToString();
                DataContainer.SetData(IdeaTransferFormat.Name, Data);

                // Draw considering z-order
                var DrawnObjects = new DrawingGroup();
                foreach (var DrawComponent in DrawingComponents.OrderBy(cmp => cmp.Value))
                {
                    DrawnObjects.Children.Add(DrawComponent.Key);
                }

                // Set margin
                TotalBounds = new Rect(TotalBounds.X - View.SNAPSHOT_MARGIN, TotalBounds.Y - View.SNAPSHOT_MARGIN,
                                       TotalBounds.Width + View.SNAPSHOT_MARGIN * 2.0, TotalBounds.Height + View.SNAPSHOT_MARGIN * 2.0);

                // Adjust position
                DrawnObjects.Transform = new TranslateTransform(-TotalBounds.X, -TotalBounds.Y);

                DrawnObjects.Children.Insert(0, new GeometryDrawing(Brushes.White, null, new RectangleGeometry(TotalBounds)));

                // Render to bitmap
                var Result = DrawnObjects.RenderToDrawingVisual().RenderToBitmap((int)TotalBounds.Width, (int)TotalBounds.Height);

                DataContainer.SetImage(Result);

                // Copy also as text only when pressing [Alt] (which takes precedence over image when pasting in MS-Office)
                if (Keyboard.IsKeyDown(Key.LeftAlt) || Keyboard.IsKeyDown(Key.RightAlt))
                {
                    // Copy only Ideas synopsis (without duplicates from shortcuts or synonyms)
                    var Ideas         = ClipboardTransferSelectedObjects.CastAs <VisualElement, VisualObject>().Select(velem => velem.OwnerRepresentation.RepresentedIdea).Distinct();
                    var IdeasSynopsis = new StringBuilder();

                    foreach (var Selection in Ideas)
                    {
                        IdeasSynopsis.AppendLine(Selection.GetTextSynopsis());
                    }

                    Data = IdeasSynopsis.ToString();
                    DataContainer.SetText(Data);
                }

                General.Execute(() => Clipboard.SetDataObject(DataContainer), "Cannot access Windows Clipboard!");
            }
            catch (Exception Problem)
            {
                Console.WriteLine("Cannot Copy content and place it into clipboard. Problem: " + Problem.Message);
                return(false);
            }

            return(true);
        }
Esempio n. 33
0
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            base.Update(gameTime);

            KeyboardState keyboardState = Keyboard.GetState();

            if (State == GameState.Playing)
            {
                _inputController.ProcessControls(gameTime);
            }

            else if (State == GameState.Transition)
            {
                _fadeInTexturePosX += FADE_IN_ANIMATION_SPEED * (float)gameTime.ElapsedGameTime.TotalSeconds;
            }

            else if (State == GameState.Initial)
            {
                bool isStartKeyPressed  = keyboardState.IsKeyDown(Keys.Up) || keyboardState.IsKeyDown(Keys.Space);
                bool wasStartKeyPressed = _previousKeyboardState.IsKeyDown(Keys.Up) || _previousKeyboardState.IsKeyDown(Keys.Space);
                if (isStartKeyPressed && !wasStartKeyPressed)
                {
                    StartGame();
                }
            }
            _entityManager.Update(gameTime);

            _previousKeyboardState = keyboardState;
        }
Esempio n. 34
0
 private void UserControl_Loaded(object pObjSender, RoutedEventArgs pObjArgs)
 {
     Focusable = true;
     Keyboard.Focus(this);
 }
Esempio n. 35
0
        protected override void OnKeyDown(KeyEventArgs e)
        {
            base.OnKeyDown(e);

            if (null == ViewModel)
            {
                return;
            }

            if (IsFocused)
            {
                if (Key.Delete == e.Key)
                {
                    FlowChart flowChart = ViewModel.Model;
                    flowChart.History.BeginTransaction("Destroy Selected Nodes");
                    {
                        NodeGraphManager.DestroySelectedNodes(ViewModel.Model);
                    }
                    flowChart.History.EndTransaction(false);
                }
                else if (Key.Escape == e.Key)
                {
                    FlowChart flowChart = ViewModel.Model;
                    flowChart.History.BeginTransaction("Destroy Selected Nodes");
                    {
                        NodeGraphManager.DeselectAllNodes(ViewModel.Model);
                    }
                    flowChart.History.EndTransaction(false);
                }
                else if (Key.A == e.Key)
                {
                    if (Keyboard.IsKeyDown(Key.LeftCtrl))
                    {
                        NodeGraphManager.SelectAllNodes(ViewModel.Model);
                    }
                    else
                    {
                        FitNodesToView(false);
                    }
                }
                else if (Key.F == e.Key)
                {
                    FitNodesToView(true);
                }
                else if (Key.Z == e.Key)
                {
                    if (Keyboard.IsKeyDown(Key.LeftCtrl))
                    {
                        History.NodeGraphHistory history = ViewModel.Model.History;
                        history.Undo();
                    }
                }
                else if (Key.Y == e.Key)
                {
                    if (Keyboard.IsKeyDown(Key.LeftCtrl))
                    {
                        History.NodeGraphHistory history = ViewModel.Model.History;
                        history.Redo();
                    }
                }
            }
        }
Esempio n. 36
0
 public void PointMove()
 {
     if (Keyboard.GetState().IsKeyDown(Keys.LeftControl) && Keyboard.GetState().IsKeyDown(Keys.LeftShift) && Keyboard.GetState().IsKeyDown(Keys.O) && keyStatePrevious.IsKeyUp(Keys.O))
     {
         PointMoveType(true);
     }
     else if ((Keyboard.GetState().IsKeyDown(Keys.LeftAlt) || Keyboard.GetState().IsKeyDown(Keys.RightAlt)) && Keyboard.GetState().IsKeyDown(Keys.O) && keyStatePrevious.IsKeyUp(Keys.O))
     {
         PointMoveType(false);
     }
     else if (Keyboard.GetState().IsKeyDown(Keys.O))
     {
         //Point grab and move by click and drag on the right mouse button
         if (Mouse.GetState().RightButton == ButtonState.Pressed && !mouseHoldR && inView)
         {
             mouseHoldR = true;
         }
         if (Mouse.GetState().RightButton == ButtonState.Pressed && mouseHoldR && inView)
         {
             mouseDrag          = new Vector2(mouseSpace.X, mouseSpace.Y);
             frame[fNum].Origin = new Vector2(mouseSpace.X, mouseSpace.Y);
         }
         if (Mouse.GetState().RightButton == ButtonState.Released && mouseHoldR && inView)
         {
             mouseHoldR = false;
         }
     }
 }
Esempio n. 37
0
        protected override void Update(GameTime gameTime)
        {
            //Checks to see if it is the Active window.
            isActive = this.IsActive;
            //Checks to see if the mouse is over the window
            inView = (Mouse.GetState().X <= GraphicsDevice.Viewport.Width && Mouse.GetState().Y <= GraphicsDevice.Viewport.Height && Mouse.GetState().X >= 0 && Mouse.GetState().Y >= 0);
            //Gets hitbox and if zero it skips tryting to get info on them.

            pNum = fNum;

            if (frame[fNum].hitbox.Count > 0)
            {
                frame[fNum].HasHitbox = true;
            }
            else
            {
                frame[fNum].HasHitbox = false;
            }
            //Get mouse info
            mouseSpace  = PointerPosition(new Vector2(Mouse.GetState().X, Mouse.GetState().Y));
            imageCoord  = new Vector2(mouseSpace.X, mouseSpace.Y) - frame[fNum].Offset;
            mouseCursor = new Rectangle((int)mouseSpace.X - 4, (int)mouseSpace.Y - 4, 8, 8);

            if (isActive && inView)
            {
                // Allows the game to exit
                if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || (Keyboard.GetState().IsKeyDown(Keys.Escape)) && inView)
                {
                    this.Exit();
                }
                // Camera manipulation and control
                input.InputCamera(ref mouseStatePrevious, ref camera, ref mouseSpace, ref mouseClick, ref mouseDrag, ref inView);
                // UPDATE THE CAMERA TO SHOW NEW VIEW AND RESIZE
                camera.UpdateCamera(GraphicsDevice.Viewport.AspectRatio);
                // Play Back
                input.InputShowPlay(ref keyStatePrevious, ref showFrame, ref play, ref fNum, ref boxSelected, frame.Count);
                // SAVES TO FRM FILES
                SaveToFRM();
                if (!play)
                {
                    //Mode Selection Toggle
                    input.Selection(ref keyStatePrevious, ref mode, ref boxSelected);
                    //Hitbox Key detection and Selection
                    if (!mode)
                    {
                        KeySelection();
                    }
                    //Hitbox Mouse detection and Selection
                    if (mode && !mouseHoldR && !mouseHoldL)
                    {
                        MouseSelection();
                    }
                    // Changes the Type of Hitbox we want from keyboard keys
                    input.InputBoxType(ref boxType);
                    //Hitbox Creation with the Left Mouse Button, Hitbox Creation.
                    HitboxCreation();
                    //Hitbox grab and move by click and drag on the right mouse button
                    HitboxMove();
                    //Point grab and move by click and drag on the right mouse button and holding P
                    PointMove();
                    //Hitbox DELETE
                    DeleteHitbox();
                }
            }
            // Play Back
            if (play)
            {
                Playback();
            }
            //FRAME UPDATE
            frame[fNum].Update();
            // The time since Update was called last
            GetFPS(gameTime);
            // Updates the Real time number feedback and info text
            if (inView)
            {
                TextOutput();
            }
            // Previous input state for future comparison
            mouseStatePrevious = Mouse.GetState();
            keyStatePrevious   = Keyboard.GetState();

            base.Update(gameTime);
        }
Esempio n. 38
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            // TODO: Add your update logic here

            //makes it so that if all the blocks are destroyed then the game will close adds the player another live and 100 points
            if (BricksPos.Count == 0)
            {
                BallPos   = new Vector2(PaddlePos.X + Paddle.Width / 2, PaddlePos.Y - Paddle.Height / 2);
                BallSpeed = new Vector2(-1, -1);
                score    += 100;

                //adding in the position of the first row of bricks
                BricksPos.Add(new Vector2(050, 080));
                BricksPos.Add(new Vector2(150, 080));
                BricksPos.Add(new Vector2(250, 080));
                BricksPos.Add(new Vector2(350, 080));
                BricksPos.Add(new Vector2(450, 080));
                BricksPos.Add(new Vector2(550, 080));
                BricksPos.Add(new Vector2(650, 080));

                //adding in the positions of the second row of bricks
                BricksPos.Add(new Vector2(050, 110));
                BricksPos.Add(new Vector2(650, 110));
                BricksPos.Add(new Vector2(350, 110));

                //adding in the positions of the third row of bricks
                BricksPos.Add(new Vector2(050, 140));
                BricksPos.Add(new Vector2(150, 140));
                BricksPos.Add(new Vector2(250, 140));
                BricksPos.Add(new Vector2(350, 140));
                BricksPos.Add(new Vector2(450, 140));
                BricksPos.Add(new Vector2(550, 140));
                BricksPos.Add(new Vector2(650, 140));

                //adding in the position of the fourth row of bricks
                BricksPos.Add(new Vector2(050, 170));
                BricksPos.Add(new Vector2(150, 170));
                BricksPos.Add(new Vector2(250, 170));
                BricksPos.Add(new Vector2(350, 170));
                BricksPos.Add(new Vector2(450, 170));
                BricksPos.Add(new Vector2(550, 170));
                BricksPos.Add(new Vector2(650, 170));

                //adding in the positions of the fifth row of bricks
                BricksPos.Add(new Vector2(050, 200));
                BricksPos.Add(new Vector2(150, 200));
                BricksPos.Add(new Vector2(250, 200));
                BricksPos.Add(new Vector2(350, 200));
                BricksPos.Add(new Vector2(450, 200));
                BricksPos.Add(new Vector2(550, 200));
                BricksPos.Add(new Vector2(650, 200));

                //adding in the positions of the sixth row of bricks
                BricksPos.Add(new Vector2(050, 230));
                BricksPos.Add(new Vector2(150, 230));
                BricksPos.Add(new Vector2(250, 230));
                BricksPos.Add(new Vector2(350, 230));
                BricksPos.Add(new Vector2(450, 230));
                BricksPos.Add(new Vector2(550, 230));
                BricksPos.Add(new Vector2(650, 230));

                //adding in the positions of the seventh row of bricks
                BricksPos.Add(new Vector2(050, 260));
                BricksPos.Add(new Vector2(150, 260));
                BricksPos.Add(new Vector2(250, 260));
                BricksPos.Add(new Vector2(350, 260));
                BricksPos.Add(new Vector2(450, 260));
                BricksPos.Add(new Vector2(550, 260));
                BricksPos.Add(new Vector2(650, 260));

                Numberlives++;
            }

            if (Numberlives > 0)
            {
                BallPos += BallSpeed;

                // has the left key controlling the direction it goes only allowing it to go left if it doesnt go off the screen
                if (Keyboard.GetState().IsKeyDown(Keys.Left))
                {
                    if (PaddlePos.X > 0)
                    {
                        PaddlePos.X -= 7;
                    }
                }

                // has the right key control the right direction but doesnt allow it to go off he screen
                if (Keyboard.GetState().IsKeyDown(Keys.Right))
                {
                    if (PaddlePos.X < 800 - Paddle.Width)
                    {
                        PaddlePos.X += 7;
                    }
                }
            }
            //creates the rectangles for the objects and adds collision properties to them
            Rectangle PaddleRectangle = new Rectangle((int)PaddlePos.X, (int)PaddlePos.Y, Paddle.Width, Paddle.Height);
            Rectangle BallRectangle   = new Rectangle((int)BallPos.X, (int)BallPos.Y, Ball.Width, Ball.Height);

            // makes it so that the ball will bounce off of the paddle
            if (BallRectangle.Intersects(PaddleRectangle) && BallSpeed.Y < 0)
            {
                BallSpeed.Y = -BallSpeed.Y + 0.5f;
            }

            if (BallRectangle.Intersects(PaddleRectangle) && BallSpeed.Y > 0)
            {
                BallSpeed.Y = -BallSpeed.Y - 0.5f;
            }

            //add in the actual boundaries of the game on the top and he two sides but not the bottom

            if (BallPos.Y < 0)
            {
                BallSpeed.Y = -BallSpeed.Y;
            }

            if (BallPos.X < 0 || BallPos.X > 800)
            {
                BallSpeed.X = -BallSpeed.X;
            }

            //tell the ball what to do if it goes below the paddle and off the screen

            if (BallPos.Y + Ball.Height > 800)
            {
                BallPos   = new Vector2(PaddlePos.X + Paddle.Width / 2, PaddlePos.Y - Paddle.Height / 2);
                BallSpeed = new Vector2(-1, -1);
                Numberlives--;
            }



            //checks if the ball collides with the bricks
            for (int i = BricksPos.Count - 1; i >= 0; i--)
            {
                Vector2 pos = BricksPos[i];


                Rectangle brickRectangle = new Rectangle((int)pos.X, (int)pos.Y, Block.Width, Block.Height);
                if (BallRectangle.Intersects(brickRectangle))
                {
                    BallSpeed.Y = -BallSpeed.Y;
                    BricksPos.Remove(pos);
                    score++;
                    break;
                }
            }



            base.Update(gameTime);
        }
        private void ProcessDebugKeys()
        {
            KeyboardState keyState = Keyboard.GetState();

            //toggle fullscreen
            if (_oldKeyboardState.IsKeyUp(Keys.F11) && keyState.IsKeyDown(Keys.F11))
            {
                graphics.ToggleFullScreen();
            }

            //freelook mode
            if (_oldKeyboardState.IsKeyUp(Keys.F1) && keyState.IsKeyDown(Keys.F1))
            {
                player1Renderer.freeCam = !player1Renderer.freeCam;
            }

            //minimap mode
            if (_oldKeyboardState.IsKeyUp(Keys.M) && keyState.IsKeyDown(Keys.M))
            {
                hud.showMinimap = !hud.showMinimap;
            }

            //wireframe mode
            if (_oldKeyboardState.IsKeyUp(Keys.F7) && keyState.IsKeyDown(Keys.F7))
            {
                world.ToggleRasterMode();
            }

            //diagnose mode
            if (_oldKeyboardState.IsKeyUp(Keys.F8) && keyState.IsKeyDown(Keys.F8))
            {
                _diagnosticMode = !_diagnosticMode;
            }

            //day cycle/dayMode
            if (_oldKeyboardState.IsKeyUp(Keys.F9) && keyState.IsKeyDown(Keys.F9))
            {
                world.dayMode = !world.dayMode;
                //Debug.WriteLine("Day Mode is " + world.dayMode);
            }

            //day cycle/nightMode
            if (_oldKeyboardState.IsKeyUp(Keys.F10) && keyState.IsKeyDown(Keys.F10))
            {
                world.nightMode = !world.nightMode;
                //Debug.WriteLine("Day/Night Mode is " + world.nightMode);
            }

            // Allows the game to exit
            if (keyState.IsKeyDown(Keys.Escape))
            {
                this.Exit();
            }

            // Release the mouse pointer
            if (_oldKeyboardState.IsKeyUp(Keys.F) && keyState.IsKeyDown(Keys.F))
            {
                this.releaseMouse   = !this.releaseMouse;
                this.IsMouseVisible = !this.IsMouseVisible;
            }

            // fixed time step
            if (_oldKeyboardState.IsKeyUp(Keys.F3) && keyState.IsKeyDown(Keys.F3))
            {
                graphics.SynchronizeWithVerticalRetrace = !graphics.SynchronizeWithVerticalRetrace;
                this.IsFixedTimeStep = !this.IsFixedTimeStep;
                Debug.WriteLine("FixedTimeStep and vsync are " + this.IsFixedTimeStep);
                graphics.ApplyChanges();
            }

            // stealth mode / keep screen space for profilers
            if (_oldKeyboardState.IsKeyUp(Keys.F4) && keyState.IsKeyDown(Keys.F4))
            {
                if (graphics.PreferredBackBufferHeight == preferredBackBufferHeight)
                {
                    graphics.PreferredBackBufferHeight = 100;
                    graphics.PreferredBackBufferWidth  = 160;
                }
                else
                {
                    graphics.PreferredBackBufferHeight = preferredBackBufferHeight;
                    graphics.PreferredBackBufferWidth  = preferredBackBufferWidth;
                }
                graphics.ApplyChanges();
            }

            this._oldKeyboardState = keyState;
        }
Esempio n. 40
0
        protected override void Update(GameTime gameTime)
        {
            //rzeczy do rysowania kwadratow reprezentujacych hitboxy
            GraphicsDevice.Clear(Color.CornflowerBlue);
            rect  = new Texture2D(graphics.GraphicsDevice, playerBoundsTex.Width, playerBoundsTex.Height);
            rect2 = new Texture2D(graphics.GraphicsDevice, enemyBoundsTex.Width, enemyBoundsTex.Height);

            Color[] data = new Color[playerBoundsTex.Width * playerBoundsTex.Height];
            for (int i = 0; i < data.Length; ++i)
            {
                data[i] = Color.Chocolate;
            }
            rect.SetData(data);

            Color[] data2 = new Color[enemyBoundsTex.Width * enemyBoundsTex.Height];
            for (int i = 0; i < data2.Length; ++i)
            {
                data2[i] = Color.Chocolate;
            }
            rect2.SetData(data2);

            coor  = new Vector2(ballPosition.X - 32, ballPosition.Y - 32);
            coor2 = new Vector2(smallPosition2.X - 2, smallPosition2.Y);

            //wylaczanie gry
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            var kstate = Keyboard.GetState();

            //czas miedzy wywolaniami update nie zawsze jest ten sam wiec, aby uzysac plynny ruch trzeba pomnozyc predkosc przez czas od ostatniego wywolania metody update
            if (kstate.IsKeyDown(Keys.Up))
            {
                ballPosition.Y -= ballSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
            }

            if (kstate.IsKeyDown(Keys.Down))
            {
                ballPosition.Y += ballSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
            }

            if (kstate.IsKeyDown(Keys.Left))
            {
                ballPosition.X -= ballSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
            }

            if (kstate.IsKeyDown(Keys.Right))
            {
                ballPosition.X += ballSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
            }

            //ustawienie granic okna
            if (ballPosition.X > Window.ClientBounds.Width - playerBoundsTex.Width / 2)
            {
                ballPosition.X = Window.ClientBounds.Width - playerBoundsTex.Width / 2;
            }
            if (ballPosition.Y > Window.ClientBounds.Height - playerBoundsTex.Height / 2)
            {
                ballPosition.Y = Window.ClientBounds.Height - playerBoundsTex.Height / 2;
            }

            if (ballPosition.X < playerBoundsTex.Width / 2)
            {
                ballPosition.X = playerBoundsTex.Width / 2;
            }
            if (ballPosition.Y < playerBoundsTex.Height / 2)
            {
                ballPosition.Y = playerBoundsTex.Height / 2;
            }

            //ballPosition.X = Math.Min(Math.Max(playerBoundsTex.Width / 2, ballPosition.X), graphics.PreferredBackBufferWidth - playerBoundsTex.Width / 2);
            //ballPosition.Y = Math.Min(Math.Max(playerBoundsTex.Height / 2, ballPosition.Y), graphics.PreferredBackBufferHeight - playerBoundsTex.Height / 2);

            playerBounds = new Rectangle((int)ballPosition.X - 32, (int)ballPosition.Y - 32, playerBoundsTex.Width, playerBoundsTex.Height);
            enemyBounds2 = new Rectangle((int)smallPosition2.X, (int)smallPosition2.Y, enemyBoundsTex.Width, enemyBoundsTex.Height);

            smallPosition2.X -= enemySpeed;
            if (smallPosition2.X < -20)
            {
                smallPosition2.X = 800;
            }

            if (playerBounds.Intersects(enemyBounds2))
            {
                napis3 = "Kolizja";
                napis  = "Gracz X:" + ballPosition.X + "Y:" + ballPosition.Y;
                napis2 = "NPC X:" + smallPosition2.X + "Y:" + smallPosition2.Y;
            }
            else
            {
                napis3 = "Brak Kolizji";
                napis  = "Gracz X:" + ballPosition.X + "Y:" + ballPosition.Y;
                napis2 = "NPC X:" + smallPosition2.X + "Y:" + smallPosition2.Y;
            }

            base.Update(gameTime);
        }
Esempio n. 41
0
        public void Update()
        {
            if (Keyboard.GetState().IsKeyDown(Keys.E))
            {
                myGame.GetPlayer().TakeDamage(2);
            }
            else if (Keyboard.GetState().IsKeyDown(Keys.Q))
            {
                myGame.Exit();
            }
            else if (Keyboard.GetState().IsKeyDown(Keys.R))
            {
                myGame.Reset();
            }
            else if (Keyboard.GetState().IsKeyDown(Keys.Z) || Keyboard.GetState().IsKeyDown(Keys.N))
            {
                myGame.GetPlayer().SlotA();
            }
            else if (Keyboard.GetState().IsKeyDown(Keys.X) || Keyboard.GetState().IsKeyDown(Keys.M))
            {
                myGame.GetPlayer().SlotB();
            }
            else if ((Keyboard.GetState().IsKeyDown(Keys.D1)))
            {
                myGame.GetPlayer().GetInventory().SetSlotBCommand(new BowCommand(myGame.GetPlayer()));
                myGame.GetPlayer().SlotB();
            }
            else if ((Keyboard.GetState().IsKeyDown(Keys.D2)))
            {
                myGame.GetPlayer().GetInventory().SetSlotBCommand(new WandCommand(myGame.GetPlayer()));
                myGame.GetPlayer().SlotB();
            }
            else if ((Keyboard.GetState().IsKeyDown(Keys.D3)))
            {
                myGame.GetPlayer().GetInventory().SetSlotBCommand(new BoomerangCommand(myGame.GetPlayer()));
                myGame.GetPlayer().SlotB();
            }
            else if ((Keyboard.GetState().IsKeyDown(Keys.D4)))
            {
                myGame.GetPlayer().GetInventory().SetSlotBCommand(new BombCommand(myGame.GetPlayer()));
                myGame.GetPlayer().SlotB();
            }
            else if ((Keyboard.GetState().IsKeyDown(Keys.D5)))
            {
                myGame.GetPlayer().GetInventory().SetSlotBCommand(new EmptyCommand(myGame.GetPlayer()));
                myGame.GetPlayer().SlotB();
            }
            else if ((Keyboard.GetState().IsKeyDown(Keys.I)) && delay <= 0)
            {
                delay = 20;
                if (myGame.items1.Count > 1)
                {
                    myGame.items2.Push(myGame.items1.Pop());
                }
            }
            else if ((Keyboard.GetState().IsKeyDown(Keys.U)) && delay <= 0)
            {
                delay = 20;
                if (myGame.items2.Count > 0)
                {
                    myGame.items1.Push(myGame.items2.Pop());
                }
            }
            else if ((Keyboard.GetState().IsKeyDown(Keys.W) || Keyboard.GetState().IsKeyDown(Keys.Up)) && !((Keyboard.GetState().IsKeyDown(Keys.S) || Keyboard.GetState().IsKeyDown(Keys.Down))))
            {
                myGame.GetPlayer().MoveUp();
            }
            else if ((Keyboard.GetState().IsKeyDown(Keys.S) || Keyboard.GetState().IsKeyDown(Keys.Down)) && !((Keyboard.GetState().IsKeyDown(Keys.W) || Keyboard.GetState().IsKeyDown(Keys.Up))))
            {
                myGame.GetPlayer().MoveDown();
            }
            else if ((Keyboard.GetState().IsKeyDown(Keys.A) || Keyboard.GetState().IsKeyDown(Keys.Left)) && !((Keyboard.GetState().IsKeyDown(Keys.D) || Keyboard.GetState().IsKeyDown(Keys.Right))))
            {
                myGame.GetPlayer().MoveLeft();
            }
            else if ((Keyboard.GetState().IsKeyDown(Keys.D) || Keyboard.GetState().IsKeyDown(Keys.Right)) && !((Keyboard.GetState().IsKeyDown(Keys.A) || Keyboard.GetState().IsKeyDown(Keys.Left))))
            {
                myGame.GetPlayer().MoveRight();
            }
            else if ((Keyboard.GetState().IsKeyDown(Keys.O)) && delay <= 0)
            {
                delay = 20;
                if (myGame.enemies1.Count > 1)
                {
                    myGame.enemies2.Push(myGame.enemies1.Pop());
                }
            }
            else if ((Keyboard.GetState().IsKeyDown(Keys.P)) && delay <= 0)
            {
                delay = 20;
                if (myGame.enemies2.Count > 0)
                {
                    myGame.enemies1.Push(myGame.enemies2.Pop());
                }
            }
            else
            {
                myGame.GetPlayer().Stop();
            }

            if (delay > 0)
            {
                delay--;
            }
        }
Esempio n. 42
0
        /// <summary>
        /// Performs a hit test on the design surface, raising <paramref name="callback"/> for each match.
        /// Hit testing continues while the callback returns true.
        /// </summary>
        public void HitTest(Point mousePosition, bool testAdorners, bool testDesignSurface, Predicate <DesignPanelHitTestResult> callback, HitTestType hitTestType)
        {
            if (mousePosition.X < 0 || mousePosition.Y < 0 || mousePosition.X > this.RenderSize.Width || mousePosition.Y > this.RenderSize.Height)
            {
                return;
            }
            // First try hit-testing on the adorner layer.

            bool continueHitTest = true;

            HitTestFilterCallback filterBehavior = CustomHitTestFilterBehavior ?? FilterHitTestInvisibleElements;

            CustomHitTestFilterBehavior = null;
            hitTestElements.Clear();

            if (testAdorners)
            {
                RunHitTest(
                    _adornerLayer, mousePosition, filterBehavior,
                    delegate(HitTestResult result) {
                    if (result != null && result.VisualHit != null && result.VisualHit is Visual)
                    {
                        DesignPanelHitTestResult customResult = new DesignPanelHitTestResult((Visual)result.VisualHit);
                        DependencyObject obj = result.VisualHit;
                        while (obj != null && obj != _adornerLayer)
                        {
                            AdornerPanel adorner = obj as AdornerPanel;
                            if (adorner != null)
                            {
                                customResult.AdornerHit = adorner;
                            }
                            obj = VisualTreeHelper.GetParent(obj);
                        }
                        continueHitTest = callback(customResult);
                        return(continueHitTest ? HitTestResultBehavior.Continue : HitTestResultBehavior.Stop);
                    }
                    else
                    {
                        return(HitTestResultBehavior.Continue);
                    }
                });
            }

            if (continueHitTest && testDesignSurface)
            {
                RunHitTest(
                    this.Child, mousePosition, filterBehavior,
                    delegate(HitTestResult result) {
                    if (result != null && result.VisualHit != null && result.VisualHit is Visual)
                    {
                        DesignPanelHitTestResult customResult = new DesignPanelHitTestResult((Visual)result.VisualHit);

                        ViewService viewService = _context.Services.View;
                        DependencyObject obj    = result.VisualHit;

                        if (hitTestType == HitTestType.ElementSelection)
                        {
                            if (Keyboard.IsKeyDown(Key.LeftAlt))
                            {
                                if (lastElement != null && lastElement != _context.RootItem.Component &&
                                    hitTestElements.Contains(lastElement))
                                {
                                    var idx = hitTestElements.IndexOf(lastElement) - 1;
                                    if (idx >= 0)
                                    {
                                        obj = hitTestElements[idx];
                                    }
                                }
                            }
                        }

                        while (obj != null)
                        {
                            if ((customResult.ModelHit = viewService.GetModel(obj)) != null)
                            {
                                break;
                            }
                            obj = VisualTreeHelper.GetParent(obj);
                        }
                        if (customResult.ModelHit == null)
                        {
                            customResult.ModelHit = _context.RootItem;
                        }

                        if (hitTestType == HitTestType.ElementSelection)
                        {
                            lastElement = obj;
                        }


                        continueHitTest = callback(customResult);
                        return(continueHitTest ? HitTestResultBehavior.Continue : HitTestResultBehavior.Stop);
                    }
                    else
                    {
                        return(HitTestResultBehavior.Continue);
                    }
                }
                    );
            }
        }
Esempio n. 43
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // escape key missing

            // Add your update logic here
            KeyboardState kb = Keyboard.GetState();

            if (kb.IsKeyDown(Keys.Back) && !oldKb.IsKeyDown(Keys.Back))
            {
                this.Exit();
            }

            // Methods from the Menus class to run the menus
            menus.Navigations(gameState, instructionState, kb, CurrentBackgroundC, oldKb, timer, gameOverTimer);
            gameState        = menus.GameStateValue();
            instructionState = menus.InstructionStateValue();

            if (gameState == GameState.Game)
            {
                if (changeSongs == false)
                {
                    changeSongs = true;
                    MediaPlayer.Stop();
                }

                // Pauses game. Currently does not work
                if (kb.IsKeyDown(Keys.P) && oldKb != kb)
                {
                    gameState = GameState.Paused;
                }

                // Update Player collision with map obstacles.
                firstMap.MapPlayerCollisions(p1);
                firstMap.MapPlayerCollisions(p2);

                CurrentBackgroundC = firstMap.FLOORCOLOR;

                p1.update(1, p2);
                p2.update(2, p1);


                RoundOverCheck();
            }

            if (gameState == GameState.StartScreen)
            {
                p1.Reset();
                p2.Reset();
                p1.TotalReset();
                p2.TotalReset();
                CurrentBackgroundC = Color.Black;
            }

            if (menus.ReturnTimer() >= 240)
            {
                //Reset
                p1.Reset();
                p2.Reset();
                while (p1.pRect.Intersects(p2.pRect))
                {
                    p2.newRandomStart();
                }
                //CurrentBackgroundC = Color.Black;
            }

            // Keep so the player can choose to exit the game
            if (gameState == GameState.Exit)
            {
                this.Exit();
            }

            // Splash screen timer
            timer++;

            if ((gameState == GameState.StartScreen || gameState == GameState.Instructions) && (MediaPlayer.State == MediaState.Stopped || changeSongs == true))
            {
                if (changeSongs == true)
                {
                    changeSongs = false;
                    MediaPlayer.Stop();
                }

                MediaPlayer.Play(songs[0]);
            }

            if (gameState == GameState.Game && MediaPlayer.State == MediaState.Stopped)
            {
                MediaPlayer.Play(songs[1]);
            }

            if (gameState == GameState.RoundOver)
            {
                MediaPlayer.Pause();
            }
            else
            {
                MediaPlayer.Resume();
            }
            if (gameState == GameState.GameOver)
            {
                MediaPlayer.Pause();
                changeSongs = true;
            }

            oldKb = kb;

            base.Update(gameTime);
        }
Esempio n. 44
0
 public Dkeyboard()
 {
     // Setting the old state of the keyboard so it can be compared
     oldState       = Keyboard.GetState();
     noPressedState = Keyboard.GetState();
 }
Esempio n. 45
0
        public void SaveToFRM()
        {
            if (Keyboard.GetState().IsKeyDown(Keys.LeftControl) && Keyboard.GetState().IsKeyDown(Keys.S) && keyStatePrevious.IsKeyUp(Keys.S))
            {
                frame[fNum].info.Clear();
                frame[fNum].info.Add("Center: " + (int)frame[fNum].Origin.X + " " + (int)frame[fNum].Origin.Y);
                frame[fNum].info.Add("Points:");
                for (int i = 0; i < frame[fNum].point.Count; i++)
                {
                    frame[fNum].info.Add(frame[fNum].point[i].Name + " " + (int)frame[fNum].point[i].Position.X + " " + (int)frame[fNum].point[i].Position.Y);
                }
                frame[fNum].info.Add("[end]");
                frame[fNum].info.Add("Hitbox:");
                for (int i = 0; i < frame[fNum].hitbox.Count; i++)
                {
                    frame[fNum].info.Add(frame[fNum].hitbox[i].Type.ToString() + " " +
                                         frame[fNum].hitbox[i].X1.ToString() + " " + frame[fNum].hitbox[i].Y1.ToString() + " " +
                                         frame[fNum].hitbox[i].X2.ToString() + " " + frame[fNum].hitbox[i].Y2.ToString());
                }
                frame[fNum].info.Add("[end]");

                fileLoader.SaveFRM(path, frame[fNum].Name, frame[fNum].info);
            }
            if (Keyboard.GetState().IsKeyDown(Keys.LeftControl) && Keyboard.GetState().IsKeyDown(Keys.LeftShift) && Keyboard.GetState().IsKeyDown(Keys.S) && keyStatePrevious.IsKeyUp(Keys.S))
            {
                for (int o = 0; o < frame.Count; o++)
                {
                    frame[o].info.Clear();
                    frame[o].info.Add("Center: " + (int)frame[o].Origin.X + " " + (int)frame[o].Origin.Y);
                    frame[o].info.Add("Points:");
                    for (int i = 0; i < frame[o].point.Count; i++)
                    {
                        frame[o].info.Add(frame[o].point[i].Name + " " + (int)frame[o].point[i].Position.X + " " + (int)frame[o].point[i].Position.Y);
                    }
                    frame[o].info.Add("[end]");
                    frame[o].info.Add("Hitbox:");
                    for (int i = 0; i < frame[o].hitbox.Count; i++)
                    {
                        frame[o].info.Add(frame[o].hitbox[i].Type.ToString() + " " +
                                          frame[o].hitbox[i].X1.ToString() + " " + frame[o].hitbox[i].Y1.ToString() + " " +
                                          frame[o].hitbox[i].X2.ToString() + " " + frame[o].hitbox[i].Y2.ToString());
                    }
                    frame[o].info.Add("[end]");

                    fileLoader.SaveFRM(path, frame[o].Name, frame[o].info);
                }
            }
        }
Esempio n. 46
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            // Increment current frame, left to right on sheet
            ++currentFrame.X;

            // Reset X to 0 if we reach the end of current row
            if (currentFrame.X >= sheetSize.X)
            {
                currentFrame.X = 0;

                // Increment the Y position
                ++currentFrame.Y;
                if (currentFrame.Y >= sheetSize.Y)
                {
                    // Reset Y position to 0 if we reach the end
                    currentFrame.Y = 0;
                }
            }

            base.Update(gameTime);
        }
Esempio n. 47
0
        void DesignPanel_KeyDown(object sender, KeyEventArgs e)
        {
            //pass the key event down to the underlying objects if they have implemented IKeyUp interface
            //OBS!!!! this call needs to be here, before the PlacementOperation.Start.
            //In case the underlying object has a operation of its own this operation needs to be set first
            foreach (DesignItem di in Context.Services.Selection.SelectedItems)
            {
                foreach (Extension ext in di.Extensions)
                {
                    var keyDown = ext as IKeyDown;
                    if (keyDown != null)
                    {
                        keyDown.KeyDownAction(sender, e);
                    }
                }
            }

            if (e.Key == Key.Left || e.Key == Key.Right || e.Key == Key.Up || e.Key == Key.Down)
            {
                e.Handled = true;

                PlacementType placementType = Keyboard.IsKeyDown(Key.LeftCtrl) ? PlacementType.Resize : PlacementType.Move;

                if (placementOp != null && placementOp.Type != placementType)
                {
                    placementOp.Commit();
                    placementOp = null;
                }

                if (placementOp == null)
                {
                    //check if any objects don't want the default action to be invoked
                    List <DesignItem> placedItems = Context.Services.Selection.SelectedItems.Where(x => x.Extensions.All(InvokeDefaultKeyDownAction)).ToList();

                    //if no remaining objects, break
                    if (placedItems.Count < 1)
                    {
                        return;
                    }

                    dx = 0;
                    dy = 0;

                    try
                    {
                        placementOp = PlacementOperation.Start(placedItems, placementType);
                    }
                    catch
                    {
                        MessageBox.Show("Operationen kan inte utföras på de objekt du valt.");
                    }
                }

                if (placementOp != null)
                {
                    switch (e.Key)
                    {
                    case Key.Left:
                        dx += Keyboard.IsKeyDown(Key.LeftShift) ? -10 : -1;
                        break;

                    case Key.Up:
                        dy += Keyboard.IsKeyDown(Key.LeftShift) ? -10 : -1;
                        break;

                    case Key.Right:
                        dx += Keyboard.IsKeyDown(Key.LeftShift) ? 10 : 1;
                        break;

                    case Key.Down:
                        dy += Keyboard.IsKeyDown(Key.LeftShift) ? 10 : 1;
                        break;
                    }

                    foreach (PlacementInformation info in placementOp.PlacedItems)
                    {
                        var bounds = info.OriginalBounds;

                        if (placementType == PlacementType.Move)
                        {
                            info.Bounds = new Rect(bounds.Left + dx,
                                                   bounds.Top + dy,
                                                   bounds.Width,
                                                   bounds.Height);
                        }
                        else if (placementType == PlacementType.Resize)
                        {
                            if (bounds.Width + dx >= 0 && bounds.Height + dy >= 0)
                            {
                                info.Bounds = new Rect(bounds.Left,
                                                       bounds.Top,
                                                       bounds.Width + dx,
                                                       bounds.Height + dy);
                            }
                        }
                        placementOp.CurrentContainerBehavior.SetPosition(info);
                    }
                }
            }
        }
Esempio n. 48
0
 /// <summary>
 /// Fx0A - LD Vx, K
 /// Wait for a key press, store the value of the key in Vx.
 /// All execution stops until a key is pressed, then the value of that key is stored in Vx.
 /// </summary>
 public override void Execute(Interpreter i, int pc, byte x, byte y, byte n, byte kk, ushort nnn)
 {
     i.V[x] = Keyboard.WaitForKey();
     i.Step();
 }
Esempio n. 49
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            // TODO: Add your update logic here

            base.Update(gameTime);
        }
 public KeyboardManager()
 {
     curr = Keyboard.GetState();
     prev = curr;
 }
Esempio n. 51
0
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            if (State.gameOver)
            {
                if (Keyboard.GetState().IsKeyDown(Keys.S))
                {
                    setupGame();
                }
            }
            else if (State.notStarted)
            {
                if (Keyboard.GetState().IsKeyDown(Keys.S))
                {
                    setupGame();
                    State.notStarted = false;
                }
            }
            else
            {
                State.leftScore  += checkScoreOnRight(ball) ? 1 : 0;
                State.rightScore += checkScoreOnLeft(ball) ? 1 : 0;
                ballAndPaddleCollision();
                moveAndBoundBall(gameTime);
                leftPaddle.position.Y += getLeftPaddlePositionYDiff(PADDLE_SPEED, gameTime);
                leftPaddle.position.Y  = getBoundY(leftPaddle);
                rightPaddle.position.Y = getRightPaddlePositionY();
                rightPaddle.position.Y = getBoundY(rightPaddle);
                ballAndPaddleCollision();
                State.gameOver = checkForGameEnd();
            }
            // TODO: Render Middle Dashed line
            // TODO: Maybe remove random ball speed and replace with geometry
            // TODO: Fix ball velocity jumping to max
            // TODO: Adjust ball velocity on paddle hits
            // TODO: Reset ball to center after score
            // TODO: functionalize ball movement


            base.Update(gameTime);
        }
 public void Init()
 {
     curr = Keyboard.GetState();
     prev = curr;
 }
Esempio n. 53
0
 /// <summary>
 /// Initialize members
 /// </summary>
 public void Initialize()
 {
     //  Save the empty state
     emptyKeyboardState = Keyboard.GetState();
     emptyGamePadState  = GamePad.GetState(playerIndex);
 }
 public void Update(GameTime _gameTime)
 {
     prev = curr;
     curr = Keyboard.GetState();
 }
Esempio n. 55
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            var stopwatch = Stopwatch.StartNew();

            KeyboardState = Keyboard.GetState();
            MouseState    = Mouse.GetState();

            if (KeyboardState.IsKeyDown(Keys.Escape) && (KeyboardState.IsKeyDown(Keys.LeftShift) || KeyboardState.IsKeyDown(Keys.RightShift)))
            {
                SaveAndExit();
            }

            if (KeyboardState.IsKeyDown(Keys.F1))
            {
                if (!debugKeyDown)
                {
                    debugKeyDown = true;
                    IsDebug      = !IsDebug;
                }
            }
            else
            {
                debugKeyDown = false;
            }

            if (KeyboardState.IsKeyDown(Keys.F2))
            {
                if (!worldBuilderKeyDown)
                {
                    worldBuilderKeyDown = true;
                    IsWorldBuilderOpen  = !IsWorldBuilderOpen;
                }
            }
            else
            {
                worldBuilderKeyDown = false;
            }

            if (KeyboardState.IsKeyDown(Keys.F3))
            {
                if (!pauseKeyDown)
                {
                    pauseKeyDown = true;
                    IsPaused     = !IsPaused;
                }
            }
            else
            {
                pauseKeyDown = false;
            }

            if (KeyboardState.IsKeyDown(Keys.F4))
            {
                if (!consoleKeyDown)
                {
                    consoleKeyDown = true;
                    IsConsoleOpen  = !IsConsoleOpen;
                }
            }
            else
            {
                consoleKeyDown = false;
            }

            if (KeyboardState.IsKeyDown(Keys.F5))
            {
                if (!godModeKeyDown)
                {
                    godModeKeyDown = true;

                    if (IsGodMode)
                    {
                        Player.ConnectToWorld();
                        Player.Velocity -= 0.3f;
                    }
                    else if (!IsGodMode)
                    {
                        Player.DisconnectFromWorld();
                        Player.Velocity += 0.3f;
                    }

                    IsGodMode = !IsGodMode;
                }
            }
            else
            {
                godModeKeyDown = false;
            }

            if (KeyboardState.IsKeyDown(Keys.F6))
            {
                if (!surroundingEffectsKeyDown)
                {
                    surroundingEffectsKeyDown = true;

                    IsSurroundingEffectsOff = !IsSurroundingEffectsOff;
                }
            }
            else
            {
                surroundingEffectsKeyDown = false;
            }

            Hud.Update(gameTime);

            if (IsPaused == false)
            {
                Ticks += (float)gameTime.ElapsedGameTime.TotalMilliseconds / (float)MilliSecondsPerTick;

                Camera.Update(gameTime);
                World.Update(gameTime);
            }

            base.Update(gameTime);

            stopwatch.Stop();
            UpdateElapsedMillis = stopwatch.ElapsedMilliseconds;
        }
Esempio n. 56
0
 public virtual void Update()
 {
     newKeyboard = Keyboard.GetState();
     GetPressedKeys();
 }
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            // get mouse state
            MouseState mouse = Mouse.GetState();

            // click left button on the teddy bear to make it explode
            if (mouse.LeftButton == ButtonState.Pressed &&
                leftButton == ButtonState.Released &&
                teddybear.Active &&
                teddybear.DrawRectangle.Contains(mouse.X, mouse.Y))
            {
                leftButton = ButtonState.Pressed;

                explosion.Play(teddybear.DrawRectangle.Center.X, teddybear.DrawRectangle.Center.Y);

                teddybear.Active = false;
            }

            // track the previous state
            if (mouse.LeftButton == ButtonState.Released)
            {
                leftButton = ButtonState.Released;
            }

            // click right button to replace the current teddy bear
            if (mouse.RightButton == ButtonState.Pressed && rightButton == ButtonState.Released)
            {
                rightButton = ButtonState.Pressed;

                teddybear = new TeddyBear(Content, WindowWidth, WindowHeight, @"graphics\teddybear", random.Next(0, WindowWidth), random.Next(0, WindowHeight), new Vector2((float)random.NextDouble(), (float)random.NextDouble()));
            }

            // track the previous state
            if (mouse.RightButton == ButtonState.Released)
            {
                rightButton = ButtonState.Released;
            }

            // click middle button to explode the curren teddy bear and replace to new one
            if (mouse.MiddleButton == ButtonState.Pressed && middleButton == ButtonState.Released)
            {
                middleButton = ButtonState.Pressed;

                if (teddybear.Active)
                {
                    explosion.Play(teddybear.DrawRectangle.Center.X, teddybear.DrawRectangle.Center.Y);
                }

                teddybear.Active = false;

                teddybear = new TeddyBear(Content, WindowWidth, WindowHeight, @"graphics\teddybear", random.Next(0, WindowWidth), random.Next(0, WindowHeight), new Vector2((float)random.NextDouble(), (float)random.NextDouble()));
            }

            // track the previous state
            if (mouse.MiddleButton == ButtonState.Released)
            {
                middleButton = ButtonState.Released;
            }

            teddybear.Update(gameTime);
            explosion.Update(gameTime);

            base.Update(gameTime);
        }
        /// <summary>Constructs a new instance.</summary>
        public FEZCobraIIEcoExtender()
        {
            this.ldr0                = null;
            this.ldr1                = null;
            this.debugLed            = null;
            this.storageDevices      = new IRemovable[2];
            this.sdCardStorageDevice = null;

            RemovableMedia.Insert += this.OnInsert;
            RemovableMedia.Eject  += this.OnEject;

            Controller.MouseConnected += (a, b) => {
                this.connectedMouse = b;
                this.OnMouseConnected(this, b);

                b.Disconnected += (c, d) => this.connectedMouse = null;
            };

            Controller.KeyboardConnected += (a, b) => {
                this.connectedKeyboard = b;
                this.OnKeyboardConnected(this, b);

                b.Disconnected += (c, d) => this.connectedKeyboard = null;
            };

            Controller.MassStorageConnected += (a, b) => {
                this.IsMassStorageConnected = true;

                this.MountStorageDevice("USB");

                b.Disconnected += (c, d) => {
                    this.IsMassStorageConnected = false;

                    if (this.IsMassStorageMounted)
                    {
                        this.UnmountStorageDevice("USB");
                    }
                };
            };

            this.IsSDCardMounted        = false;
            this.IsMassStorageConnected = false;
            this.IsMassStorageMounted   = false;

            this.sdCardDetect = new InputPort(G120.P1_8, false, Port.ResistorMode.PullUp);

            if (this.IsSDCardInserted)
            {
                this.MountStorageDevice("SD");
            }

            Controller.Start();

            this.NativeBitmapConverter = this.BitmapConverter;

            #region Sockets
            GT.SocketInterfaces.I2CBusIndirector nativeI2C = (s, sdaPin, sclPin, address, clockRateKHz, module) => new InteropI2CBus(s, sdaPin, sclPin, address, clockRateKHz, module);
            GT.Socket socket;

            socket = GT.Socket.SocketInterfaces.CreateNumberedSocket(1);
            socket.SupportedTypes   = new char[] { 'B', 'Y' };
            socket.CpuPins[3]       = G120.P2_13;
            socket.CpuPins[4]       = G120.P1_26;
            socket.CpuPins[5]       = G120.P1_27;
            socket.CpuPins[6]       = G120.P1_28;
            socket.CpuPins[7]       = G120.P1_29;
            socket.CpuPins[8]       = G120.P2_4;
            socket.CpuPins[9]       = G120.P2_2;
            socket.I2CBusIndirector = nativeI2C;
            GT.Socket.SocketInterfaces.RegisterSocket(socket);

            socket = GT.Socket.SocketInterfaces.CreateNumberedSocket(2);
            socket.SupportedTypes = new char[] { 'G' };
            socket.CpuPins[3]     = G120.P1_20;
            socket.CpuPins[4]     = G120.P1_21;
            socket.CpuPins[5]     = G120.P1_22;
            socket.CpuPins[6]     = G120.P1_23;
            socket.CpuPins[7]     = G120.P1_24;
            socket.CpuPins[8]     = G120.P1_25;
            socket.CpuPins[9]     = G120.P1_19;
            GT.Socket.SocketInterfaces.RegisterSocket(socket);

            socket = GT.Socket.SocketInterfaces.CreateNumberedSocket(3);
            socket.SupportedTypes   = new char[] { 'R', 'Y' };
            socket.CpuPins[3]       = G120.P2_12;
            socket.CpuPins[4]       = G120.P2_6;
            socket.CpuPins[5]       = G120.P2_7;
            socket.CpuPins[6]       = G120.P2_8;
            socket.CpuPins[7]       = G120.P2_9;
            socket.CpuPins[8]       = G120.P2_3;
            socket.CpuPins[9]       = G120.P2_5;
            socket.I2CBusIndirector = nativeI2C;
            GT.Socket.SocketInterfaces.RegisterSocket(socket);

            socket = GT.Socket.SocketInterfaces.CreateNumberedSocket(4);
            socket.SupportedTypes = new char[] { 'A', 'I', 'T', 'X' };
            socket.CpuPins[3]     = G120.P0_25;
            socket.CpuPins[4]     = G120.P0_24;
            socket.CpuPins[5]     = G120.P0_23;
            socket.CpuPins[6]     = G120.P1_0;
            socket.CpuPins[7]     = G120.P1_1;
            socket.CpuPins[8]     = G120.P0_27;
            socket.CpuPins[9]     = G120.P0_28;
            socket.AnalogInput3   = Cpu.AnalogChannel.ANALOG_2;
            socket.AnalogInput4   = Cpu.AnalogChannel.ANALOG_1;
            socket.AnalogInput5   = Cpu.AnalogChannel.ANALOG_0;
            GT.Socket.SocketInterfaces.SetAnalogInputFactors(socket, 3.3, 0, 12);
            GT.Socket.SocketInterfaces.RegisterSocket(socket);

            socket = GT.Socket.SocketInterfaces.CreateNumberedSocket(5);
            socket.SupportedTypes = new char[] { 'U', 'X' };
            socket.CpuPins[3]     = G120.P0_13;
            socket.CpuPins[4]     = G120.P0_2;
            socket.CpuPins[5]     = G120.P0_3;
            socket.CpuPins[6]     = G120.P1_4;
            socket.SerialPortName = "COM1";
            GT.Socket.SocketInterfaces.RegisterSocket(socket);

            socket = GT.Socket.SocketInterfaces.CreateNumberedSocket(6);
            socket.SupportedTypes = new char[] { 'S', 'X' };
            socket.CpuPins[3]     = G120.P2_21;
            socket.CpuPins[4]     = G120.P1_14;
            socket.CpuPins[5]     = G120.P1_16;
            socket.CpuPins[6]     = G120.P1_17;
            socket.CpuPins[7]     = GT.Socket.UnnumberedPin;
            socket.CpuPins[8]     = GT.Socket.UnnumberedPin;
            socket.CpuPins[9]     = GT.Socket.UnnumberedPin;
            socket.SPIModule      = SPI.SPI_module.SPI2;
            GT.Socket.SocketInterfaces.RegisterSocket(socket);

            socket = GT.Socket.SocketInterfaces.CreateNumberedSocket(7);
            socket.SupportedTypes   = new char[] { 'P', 'U', 'Y' };
            socket.CpuPins[3]       = G120.P0_4;
            socket.CpuPins[4]       = G120.P4_28;
            socket.CpuPins[5]       = G120.P4_29;
            socket.CpuPins[6]       = G120.P1_30;
            socket.CpuPins[7]       = G120.P3_26;
            socket.CpuPins[8]       = G120.P3_25;
            socket.CpuPins[9]       = G120.P3_24;
            socket.SerialPortName   = "COM4";
            socket.PWM7             = (Cpu.PWMChannel) 8;
            socket.PWM8             = Cpu.PWMChannel.PWM_7;
            socket.PWM9             = Cpu.PWMChannel.PWM_6;
            socket.I2CBusIndirector = nativeI2C;
            GT.Socket.SocketInterfaces.RegisterSocket(socket);

            socket = GT.Socket.SocketInterfaces.CreateNumberedSocket(8);
            socket.SupportedTypes = new char[] { 'I', 'K', 'U', 'X' };
            socket.CpuPins[3]     = G120.P0_10;
            socket.CpuPins[4]     = G120.P2_0;
            socket.CpuPins[5]     = G120.P0_16;
            socket.CpuPins[6]     = G120.P0_6;
            socket.CpuPins[7]     = G120.P0_17;
            socket.CpuPins[8]     = G120.P0_27;
            socket.CpuPins[9]     = G120.P0_28;
            socket.SerialPortName = "COM2";
            GT.Socket.SocketInterfaces.RegisterSocket(socket);

            socket = GT.Socket.SocketInterfaces.CreateNumberedSocket(9);
            socket.SupportedTypes = new char[] { 'A', 'O', 'S', 'X' };
            socket.CpuPins[3]     = G120.P0_12;
            socket.CpuPins[4]     = G120.P1_31;
            socket.CpuPins[5]     = G120.P0_26;
            socket.CpuPins[6]     = G120.P1_5;
            socket.CpuPins[7]     = G120.P0_18;
            socket.CpuPins[8]     = G120.P0_17;
            socket.CpuPins[9]     = G120.P0_15;
            socket.SPIModule      = SPI.SPI_module.SPI1;
            socket.AnalogOutput5  = Cpu.AnalogOutputChannel.ANALOG_OUTPUT_0;
            socket.AnalogInput3   = Cpu.AnalogChannel.ANALOG_6;
            socket.AnalogInput4   = Cpu.AnalogChannel.ANALOG_5;
            socket.AnalogInput5   = Cpu.AnalogChannel.ANALOG_3;
            GT.Socket.SocketInterfaces.SetAnalogInputFactors(socket, 3.3, 0, 12);
            GT.Socket.SocketInterfaces.SetAnalogOutputFactors(socket, 3.3, 0, 10);
            GT.Socket.SocketInterfaces.RegisterSocket(socket);

            socket = GT.Socket.SocketInterfaces.CreateNumberedSocket(10);
            socket.SupportedTypes = new char[] { 'C', 'I', 'X' };
            socket.CpuPins[3]     = G120.P0_11;
            socket.CpuPins[4]     = G120.P0_1;
            socket.CpuPins[5]     = G120.P0_0;
            socket.CpuPins[6]     = G120.P0_5;
            socket.CpuPins[8]     = G120.P0_27;
            socket.CpuPins[9]     = G120.P0_28;
            GT.Socket.SocketInterfaces.RegisterSocket(socket);

            #endregion Sockets
        }
Esempio n. 59
0
        public override int Update(GameTime gameTime)
        {
            var kstate = Keyboard.GetState();

            if (kstate.IsKeyDown(Keys.Escape))
            {
                PauseElaspsedTime += (float)gameTime.ElapsedGameTime.TotalMilliseconds;
                if (PauseElaspsedTime > PauseRate)
                {
                    PauseElaspsedTime = 0f;
                    return((int)Game1.GameStates.GamePause);
                }
            }

            //Checks if Player is Alive, Then respawns if thier are lives left
            int numPlayersAlive = 0;

            for (int cur = 0; cur < PlayerUnits.Count; cur++)
            {
                if (PlayerUnits[cur].Alive)
                {
                    numPlayersAlive++;
                }
            }
            if (numPlayersAlive < PlayerSpawnRate)
            {
                SpawnPlayer(gameTime);
            }
            for (int cur = 0; cur < PlayerUnits.Count; cur++)
            {
                if (PlayerUnits[cur].Active && PlayerUnits[cur].Alive)
                {
                    PlayerUnits[cur].Update(gameTime, graphics);
                }
            }

            //Checks if Enemy is Alive, Then respawn if thier are lives left
            int numEnemiesAlive = 0;

            for (int cur = 0; cur < EnemyUnits.Count; cur++)
            {
                if (EnemyUnits[cur].Alive)
                {
                    numEnemiesAlive++;
                }
            }
            if (numEnemiesAlive < EnemySpawnRate)
            {
                SpawnEnemy(gameTime);
            }
            int EnemiesUnitsAliveAndActive = 0;

            for (int cur = 0; cur < EnemyUnits.Count; cur++)
            {
                if (EnemyUnits[cur].Active && EnemyUnits[cur].Alive)
                {
                    EnemyUnits[cur].Update(gameTime, graphics);
                    EnemiesUnitsAliveAndActive++;
                }
            }
            foreach (Fish F in Fishs)
            {
                F.Update(gameTime, graphics);
            }

            return((int)Game1.GameStates.InPlay);
        }
Esempio n. 60
0
        /// <summary>
        /// Uses an Inspector to display update and display information to player.
        /// All user input that affects rendering of the stage is processed either
        /// from the gamepad or keyboard.
        /// See Player.Update(...) for handling of user events that affect the player.
        /// The current camera's place is updated after all other GameComponents have
        /// been updated.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // set info pane values
            time       = gameTime.TotalGameTime;
            fpsSecond += gameTime.ElapsedGameTime.TotalSeconds;
            updates++;
            if (fpsSecond >= 1.0)
            {
                inspector.setInfo(10,
                                  String.Format("{0} camera    Game time {1:D2}::{2:D2}::{3:D2}    {4:D} Updates/Seconds {5:D} Draws/Seconds",
                                                currentCamera.Name, time.Hours, time.Minutes, time.Seconds, updates.ToString(), draws.ToString()));
                draws     = updates = 0;
                fpsSecond = 0.0;
                inspector.setInfo(11, agentLocation(player));
                inspector.setInfo(12, agentLocation(npAgent));
                // inspector lines 13 and 14 can be used to describe player and npAgent's status
                inspector.setMatrices("player", "npAgent", player.AgentObject.Orientation, npAgent.AgentObject.Orientation);
            }
            // Process user keyboard events that relate to the render state of the the stage
            KeyboardState keyboardState = Keyboard.GetState();

            if (keyboardState.IsKeyDown(Keys.Escape))
            {
                Exit();
            }
            else if (keyboardState.IsKeyDown(Keys.B) && !oldKeyboardState.IsKeyDown(Keys.B))
            {
                DrawBoundingSpheres = !DrawBoundingSpheres;
            }
            else if (keyboardState.IsKeyDown(Keys.C) && !oldKeyboardState.IsKeyDown(Keys.C))
            {
                setCamera(1);
            }
            else if (keyboardState.IsKeyDown(Keys.X) && !oldKeyboardState.IsKeyDown(Keys.X))
            {
                setCamera(-1);
            }

            // key event handlers needed for Inspector
            // set help display on
            else if (keyboardState.IsKeyDown(Keys.H) && !oldKeyboardState.IsKeyDown(Keys.H))
            {
                inspector.ShowHelp     = !inspector.ShowHelp;
                inspector.ShowMatrices = false;
            }
            // set info display on
            else if (keyboardState.IsKeyDown(Keys.I) && !oldKeyboardState.IsKeyDown(Keys.I))
            {
                inspector.showInfo();
            }
            // set miscellaneous display on
            else if (keyboardState.IsKeyDown(Keys.M) && !oldKeyboardState.IsKeyDown(Keys.M))
            {
                inspector.ShowMatrices = !inspector.ShowMatrices;
                inspector.ShowHelp     = false;
            }
            // toggle update speed between FixedStep and ! FixedStep
            else if (keyboardState.IsKeyDown(Keys.T) && !oldKeyboardState.IsKeyDown(Keys.T))
            {
                FixedStepRendering = !FixedStepRendering;
            }
            oldKeyboardState = keyboardState; // Update saved state.
            base.Update(gameTime);            // update all GameComponents and DrawableGameComponents
            currentCamera.updateViewMatrix();
        }