/// <summary> /// Verifica se existem novas teclas sendo pressionadas. /// Quando não existem mais teclas pressionadas, emita um evento. /// </summary> private void ObserverEvents() { bool isOldClick = false; while (true) { if (isMouseDown) { SetMouseDown(false); keyboardState = OpenTK.Input.Keyboard.GetState(); OnKeyDown(); EmitCapturedEvent(); isOldClick = true; } else if (IsAnyKeyDown()) { keyboardState = OpenTK.Input.Keyboard.GetState(); OnKeyDown(); if (isOldClick) { isOldClick = false; EventBlock(); } } else { EmitCapturedEvent(); } } }
public TkKeyboardState(OpenTK.Input.KeyboardState tkState) { if (tkState.IsAnyKeyDown) { Keys = all_keys.Where(tkState.IsKeyDown); } }
public PlayerNameState(GameEngine engine, MainMenuState ms) { eng = engine; mouse = eng.Mouse; savedGameStates = new Stack<XmlNodeList>(); savedGameChoices = new Stack<string>(); _ms = ms; Assembly assembly = Assembly.GetExecutingAssembly(); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); lookat = new Vector3(0, 0, 2); eye = new Vector3(0, 0, 5); _old_state = OpenTK.Input.Keyboard.GetState(); // Get the current state of the keyboard eng.StateTextureManager.LoadTexture("menu", assembly.GetManifestResourceStream("U5Designs.Resources.Textures.menu.png")); menu = eng.StateTextureManager.GetTexture("menu"); saveFont = QFont.FromQFontFile("Fonts/myHappySans.qfont", new QFontLoaderConfiguration(true)); saveFont.Options.DropShadowActive = true; start_x = saveFont.Measure("Name: ").Width; //title = QFont.FromQFontFile("myHappySans.qfont", new QFontLoaderConfiguration(true)); title = QFont.FromQFontFile("Fonts/myRock.qfont", new QFontLoaderConfiguration(true)); title.Options.DropShadowActive = true; name = ""; numOfButtons = savedGameChoices.Count - 1; }
protected override void OnUpdateFrame(OpenTK.FrameEventArgs e) { OpenTK.Input.KeyboardState input = OpenTK.Input.Keyboard.GetState(); if (input.IsKeyDown(OpenTK.Input.Key.Escape)) { Exit(); } base.OnUpdateFrame(e); }
private static void InputTick(object sender, EventArgs e) { float speed = 0.01f * (float)ControlsWindow.camSpeed; OpenTK.Input.MouseState mouseState = OpenTK.Input.Mouse.GetState(); OpenTK.Input.KeyboardState keyboardState = OpenTK.Input.Keyboard.GetState(); if (keyboardState.IsKeyDown(Key.Up)) { dragY = dragY + speed; } if (keyboardState.IsKeyDown(Key.Down)) { dragY = dragY - speed; } if (keyboardState.IsKeyDown(Key.Left)) { angle = angle + speed; } if (keyboardState.IsKeyDown(Key.Right)) { angle = angle - speed; } if (keyboardState.IsKeyDown(Key.Z)) { dragZ = dragZ - speed; } if (keyboardState.IsKeyDown(Key.X)) { dragZ = dragZ + speed; } if (keyboardState.IsKeyDown(Key.Q)) { angle = angle + 0.5f; } if (keyboardState.IsKeyDown(Key.E)) { angle = angle - 0.5f; } //if (mouseInRender) //{ //dragZ = (mouseState.WheelPrecise / speed) - (7.5f); //Startzoom is at -7.5f //} }
public TkKeyboardState(OpenTK.Input.KeyboardState tkState) { if (tkState.IsAnyKeyDown) { foreach (var key in all_keys) { if (tkState.IsKeyDown(key)) { Keys.SetPressed(key, true); } } } }
private void handleState(object sender, KeyboardKeyEventArgs e) { var state = e.Keyboard; if (state.Equals(lastState)) { return; } lastState = state; PendingStates.Enqueue(new InputState { Keyboard = new TkKeyboardState(state) }); FrameStatistics.Increment(StatisticsCounterType.KeyEvents); }
public override void UpdateInput(bool isActive) { OpenTK.Input.KeyboardState state = OpenTK.Input.Keyboard.GetState(); PressedKeys.Clear(); if (state.IsAnyKeyDown) { foreach (Key k in Enum.GetValues(typeof(Key))) { if (state.IsKeyDown(k)) { PressedKeys.Add(k); } } } }
public static void Update() { try { _kbState = OpenTK.Input.Keyboard.GetState(); } catch { //OpenTK's keyboard class isn't thread safe. //In rare cases (sometimes it takes up to 10 minutes to occur) it will //be updating the keyboard state when we call GetState() and choke. //Until I fix OpenTK, it's fine to just swallow it because input continues working. if (System.Diagnostics.Debugger.IsAttached) { System.Console.WriteLine("OpenTK Keyboard thread is angry."); } } }
public LoadGameState(GameEngine engine, MainMenuState ms) { eng = engine; mouse = eng.Mouse; savedGameStates = new Stack<XmlNodeList>(); savedGameChoices = new Stack<string>(); _ms = ms; Assembly assembly = Assembly.GetExecutingAssembly(); musicFile = new AudioFile(assembly.GetManifestResourceStream("U5Designs.Resources.Music.Menu.ogg")); musicFile.Play(); // Clear the color to work with the SplashScreen so it doesn't white out //GL.ClearColor(0.0f, 0.0f, 0.0f, 0.0f); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); lookat = new Vector3(0, 0, 2); eye = new Vector3(0, 0, 5); _old_state = OpenTK.Input.Keyboard.GetState(); // Get the current state of the keyboard eng.StateTextureManager.LoadTexture("menu", assembly.GetManifestResourceStream("U5Designs.Resources.Textures.menu.png")); menu = eng.StateTextureManager.GetTexture("menu"); saveFont = QFont.FromQFontFile("Fonts/myHappySans.qfont", new QFontLoaderConfiguration(true)); saveFont.Options.DropShadowActive = true; //title = QFont.FromQFontFile("myHappySans.qfont", new QFontLoaderConfiguration(true)); title = QFont.FromQFontFile("Fonts/myRock.qfont", new QFontLoaderConfiguration(true)); title.Options.DropShadowActive = true; saveFontHighlighted = QFont.FromQFontFile("Fonts/myHappySans2.qfont", new QFontLoaderConfiguration(true)); saveFont.Options.DropShadowActive = true; //QFont.CreateTextureFontFiles("Fonts/HappySans.ttf", 48, "myHappySans2"); // Load available saved games // Setup saved game data SavedGameDataSetup(); numOfButtons = savedGameChoices.Count - 1; }
public bool UpdateHotkeys(Inp.KeyboardState newKeyboardState, Inp.KeyboardState oldKeyboardState) { if (Hotkey != Inp.Key.Unknown && (newKeyboardState.IsKeyDown(Inp.Key.LControl) || newKeyboardState.IsKeyDown(Inp.Key.RControl)) && newKeyboardState.IsKeyDown(Hotkey) && oldKeyboardState.IsKeyUp(Hotkey)) { if (BoundBool != null) { BoundBool.Value = !BoundBool.Value; } if (OnActivate != null) { OnActivate(this); } Main.EndCutsceneMode(); if (SaveSettingsOnHotkey) { Main.SaveSettings(); } return(true); } return(false); }
private void RenderFrame(RenderInfo renderInfo) { UpdateMouse(); GL.Viewport(0, 0, renderInfo.Width, renderInfo.Height); _keyboardState = Keyboard.GetState(); _mouseState = Mouse.GetState(); var client = _connectionManager.Client; if (client != null) { client.UpdateState(); _renderer.Render(client, renderInfo); } else { GL.ClearColor(0f, 0f, 0f, 1f); GL.Clear(ClearBufferMask.ColorBufferBit); } _uiRenderer.Render(renderInfo, _wasWindowGrabbed ? MouseMode.Grabbed : MouseMode.Free, _gameControl, GetInputState()); }
private void Inputs() { OpenTK.Input.KeyboardState state = OpenTK.Input.Keyboard.GetState(); if (state.IsKeyDown(Key.Space) && lastKeystate.IsKeyUp(Key.Space)) { autoRotate = !autoRotate; } this.lastKeystate = state; if (state.IsKeyDown(Key.A)) { left = true; } if (state.IsKeyDown(Key.S)) { down = true; } if (state.IsKeyDown(Key.D)) { right = true; } if (state.IsKeyDown(Key.W)) { up = true; } if (state.IsKeyUp(Key.A)) { left = false; } if (state.IsKeyUp(Key.S)) { down = false; } if (state.IsKeyUp(Key.D)) { right = false; } if (state.IsKeyUp(Key.W)) { up = false; } if (state.IsKeyDown(Key.Right)) { xdist = -0.05f; cube.SetTranslation(xdist, 'x'); } if (state.IsKeyDown(Key.Left)) { xdist = 0.05f; cube.SetTranslation(xdist, 'X'); } if (state.IsKeyDown(Key.Up)) { ydist = 0.05f; cube.SetTranslation(ydist, 'Y'); } if (state.IsKeyDown(Key.Down)) { ydist = -0.05f; cube.SetTranslation(ydist, 'Y'); } if (state.IsKeyDown(Key.Escape)) { this.Exit(); } }
public static bool UpdateAllSlots(int shaderID, int mouseX, int mouseY, ref Inp.KeyboardState newKeyboardState, ref Inp.MouseState newMouseState, ref Inp.MouseState oldMouseState, MarbleSelection marbleSelection, Rectangle clientRectangle, Camera camera, ref Matrix4 projection, ref Matrix4 view, List <Marble> marbles, List <MarbleMove> moves, ref int undoLevel, bool spinningMarbles, bool animateMoves, ref Marble lastMarbleRemovedForWin) { if (Game.FlashTicksAreAscending) { Game.FlashTicks++; if (Game.FlashTicks > Game.MAX_FLASH_TICKS) { Game.FlashTicks -= 2; Game.FlashTicksAreAscending = false; } } else { Game.FlashTicks--; if (Game.FlashTicks < 0) { Game.FlashTicks = 1; Game.FlashTicksAreAscending = true; } } if (Selected != null) { SelectionAnimationTick++; if (SelectionAnimationTick > MAX_SELECTION_ANIMATION_TICK) { SelectionAnimationTick = 0; } } Marble oldSelected = Selected; for (int i = 1; i < Game.LIGHT_COUNT; i++) { Game.SetLightEnabled(shaderID, i, false); } HighlightedSlot = null; if (marbleSelection == MarbleSelection.None || (marbleSelection == MarbleSelection.Mouse && (mouseX < 0 || mouseY < 0 || mouseX > clientRectangle.Width || mouseY > clientRectangle.Height))) { foreach (Marble m in marbles) { m.Update(shaderID, spinningMarbles); } return(false); } Marble highlightedMarble = null; float closestMarbleDistance = float.MaxValue; float distance = float.NaN; //Vector2 mousePosNDC = MousePositionInNDC(); //float rotY = (float)Math.Atan(-mousePosNDC.Y * Math.Tan(VerticalFieldOfView / 2f)); //float rotX = -(float)Math.Atan(mousePosNDC.X * Math.Tan(HorizontalFieldOfView(VerticalFieldOfView) / 2f)); //float rot = (float)Math.Atan(mousePosNDC.Length * (float)Math.Tan(VerticalFieldOfView / 2f)); //float rotY = (float)Math.Atan(-mousePosNDC.Y * (float)Math.Tan(VerticalFieldOfView / 2f)); //float rotX = -(float)Math.Atan(mousePosNDC.X * (float)Math.Tan(HorizontalFieldOfView(VerticalFieldOfView) / 2f)); //Matrix4 xRotation = Matrix4.CreateFromAxisAngle(CameraUp(), rotX); //Vector3 ray = Vector3.Transform(CameraForward(), xRotation); //ray = Vector3.Transform(ray, Matrix4.CreateFromAxisAngle(CameraRight(), rotY)); //Vector3 ray = Vector3.TransformPerspective(CameraForward(), Matrix4.CreateFromAxisAngle(CameraUp(), rotX) * Matrix4.CreateFromAxisAngle(CameraRight(), rotY)); Vector3 ray; if (marbleSelection == MarbleSelection.Mouse) { ray = Utils.MousePickRay(mouseX, mouseY, clientRectangle, ref projection, ref view); } else { ray = camera.Forward; } bool pickHad = false; //Vector3 ray = Vector3.Transform(CameraForward(), Matrix4.CreateRotationZ(HorizontalFieldOfView(VerticalFieldOfView) / 2f)); //Vector3 ray = Vector3.Transform(CameraForward(), Matrix4.CreateRotationZ(MousePositionInNDC().X * -(float)Math.Tan(HorizontalFieldOfView(VerticalFieldOfView) / VerticalFieldOfView / MathHelper.PiOver2))); List <int> emptySlots = new List <int>(); for (int i = 0; i < STARTING_COUNT; i++) { emptySlots.Add(i); } Vector3 raySource = marbleSelection == MarbleSelection.Mouse ? camera.Position : camera.FocusPoint; foreach (Marble m in marbles) { if (!m.Alive) { continue; } emptySlots.Remove(m.PositionSlot); Vector3 marblePos = m.Position(); if (MouseIsOver(marblePos, 1f, raySource, ray, ref distance, closestMarbleDistance)) { pickHad = true; highlightedMarble = m; HighlightedSlot = m.PositionSlot; closestMarbleDistance = distance; } } if (Selected != null) { emptySlots.RemoveAll(i => !SlotIsValid(i, marbles)); foreach (int i in emptySlots) { if (MouseIsOver(Position(i), 0.375f, raySource, ray, ref distance, closestMarbleDistance)) { pickHad = true; highlightedMarble = null; HighlightedSlot = i; closestMarbleDistance = distance; } } if (!pickHad) { foreach (int i in emptySlots) { if (MouseIsOver(Position(i), 1f, raySource, ray, ref distance, closestMarbleDistance)) { //pickHad = true; HighlightedSlot = i; closestMarbleDistance = distance; } } } } bool moveMade = false; if (newMouseState.LeftButton == Inp.ButtonState.Pressed && oldMouseState.LeftButton == Inp.ButtonState.Released) { if (HighlightedSlot != null) { bool shift = newKeyboardState.IsKeyDown(Inp.Key.ShiftLeft) || newKeyboardState.IsKeyDown(Inp.Key.ShiftRight); //marbles.Remove(GetMarbleInSlot(HighlightedSlot.Value, marbles)); Marble marbleToBeRemoved; if (!shift && marbles.Count(m => m.Alive) == STARTING_COUNT) { if (animateMoves) { highlightedMarble.AnimateFromSlot = highlightedMarble.PositionSlot; highlightedMarble.AnimationTick = MAX_ANIMATION_TICKS; highlightedMarble.AnimatingAsInitialRemoval = true; } highlightedMarble.Alive = false; if (undoLevel > 0) { moves.RemoveRange(moves.Count - undoLevel, undoLevel); undoLevel = 0; } moves.Add(new MarbleMove(highlightedMarble.PositionSlot, -1, -1, highlightedMarble.Type)); } else if (SlotIsValid(HighlightedSlot.Value, marbles, out marbleToBeRemoved)) { // Remove a marble if (undoLevel > 0) { moves.RemoveRange(moves.Count - undoLevel, undoLevel); undoLevel = 0; } moves.Add(new MarbleMove(Selected.PositionSlot, marbleToBeRemoved.PositionSlot, HighlightedSlot.Value, marbleToBeRemoved.Type)); if (animateMoves) { Selected.AnimateFromSlot = Selected.PositionSlot; Selected.AnimationTick = 0; marbleToBeRemoved.AnimateFromSlot = marbleToBeRemoved.PositionSlot; marbleToBeRemoved.AnimationTick = 0; } Selected.PositionSlot = HighlightedSlot.Value; marbleToBeRemoved.Alive = false; moveMade = true; //if (!Selected.CanMove(marbles)) Selected = null; if (marbles.Count(m => m.Alive) == 1) { lastMarbleRemovedForWin = marbleToBeRemoved; } } else if (shift) { camera.FocusPoint = highlightedMarble.Position(); } else if (highlightedMarble == Selected) { Selected = null; } else { Selected = highlightedMarble; } } else { Selected = null; } } foreach (Marble m in marbles) { m.Update(shaderID, spinningMarbles); } if (Selected != oldSelected) { SelectionAnimationTick = 0; } return(moveMade); }
public MainMenuState(GameEngine engine) { eng = engine; savedGameStates = new Stack<XmlNodeList>(); savedGameChoices = new Stack<string>(); mouse = eng.Mouse; // Load all the textures eng.StateTextureManager.RenderSetup(); Assembly assembly = Assembly.GetExecutingAssembly(); eng.StateTextureManager.LoadTexture("menu", assembly.GetManifestResourceStream("U5Designs.Resources.Textures.menu.png")); menu = eng.StateTextureManager.GetTexture("menu"); // QFont _buttons = new List<String>(); _buttons.Add("Play Game"); _buttons.Add("Load Saved Game"); _buttons.Add("Level Designer"); _buttons.Add("Quit"); button = QFont.FromQFontFile("Fonts/myHappySans.qfont", new QFontLoaderConfiguration(true)); button.Options.DropShadowActive = true; //title = QFont.FromQFontFile("myHappySans.qfont", new QFontLoaderConfiguration(true)); title = QFont.FromQFontFile("Fonts/myRock.qfont", new QFontLoaderConfiguration(true)); title.Options.DropShadowActive = false; buttonHighlight = QFont.FromQFontFile("Fonts/myHappySans2.qfont", new QFontLoaderConfiguration(true)); buttonHighlight.Options.DropShadowActive = true; // QFont.CreateTextureFontFiles("Fonts/HappySans.TTF", 32, "myStoryBright"); // Use this to create new Fonts that you will texture // QFont.CreateTextureFontFiles("Fonts/Comfortaa-Regular.ttf", 32, "myComfort"); // Use this to create new Fonts that you will texture // End QFonts musicFile = new AudioFile(assembly.GetManifestResourceStream("U5Designs.Resources.Music.Menu.ogg")); musicFile.Play(); // Setup saved game data SavedGameDataSetup(); // Display available saved game states DisplayAvailableSaves(); // Clear the color to work with the SplashScreen so it doesn't white out GL.ClearColor(0.0f, 0.0f, 0.0f, 0.0f); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); lookat = new Vector3(0, 0, 2); eye = new Vector3(0, 0, 5); _old_state = OpenTK.Input.Keyboard.GetState(); // Get the current state of the keyboard arX = -200.0f; b1Y = 0.0f; b2Y = -50.0f; b3Y = -100.0f; b4Y = -150.0f; enterdown = false; // TEST // //LoadSavedState(1); }
/// <summary> /// PlayState is the state in which the game is actually playing, this should only be called once when a new game is made. /// </summary> /// <param name="engine">Pointer to the game engine</param> /// <param name="lvl">the level ID</param> public LevelDesignerState(GameEngine engine, MainMenuState menustate, int lvl) : base(engine, menustate, lvl) { //eng.WindowState = WindowState.Normal; //eng.WindowBorder = WindowBorder.Fixed; current_level = lvl; LoadLevel.Load(lvl, this); Old_Key_State = Keyboard.GetState(); //Have to load the next few things here for now because they require the GraphicsContext foreach (RenderObject ro in renderList) { if (ro.is3dGeo) { ro.texture.init(); } } //HUD Health Bar Assembly assembly = Assembly.GetExecutingAssembly(); eng.StateTextureManager.LoadTexture("Healthbar", assembly.GetManifestResourceStream("U5Designs.Resources.Textures.healthbar_top.png")); Healthbar = eng.StateTextureManager.GetTexture("Healthbar"); eng.StateTextureManager.LoadTexture("bHealth", assembly.GetManifestResourceStream("U5Designs.Resources.Textures.healthbar_bottom.png")); bHealth = eng.StateTextureManager.GetTexture("bHealth"); //initialize camera camera = new Camera(eng.ClientRectangle.Width, eng.ClientRectangle.Height, player, this); player.cam = camera; // undo this when done testing ObjList = LoadLevel.Load(current_level); player.inLevelDesignMode = true; levelMusic.Stop(); //Thread t = new Thread(new ThreadStart(CreateLevelDesignForm)); //t.ApartmentState = ApartmentState.STA; //t.Start(); ObstaclesList = GetItemsFromDir("Obstacles.obstacles.txt"); EnemiesList = GetItemsFromDir("Enemies.enemies.txt"); ObjectList.Add(0, ObstaclesList); ObjectList.Add(1, EnemiesList); _xml_obstacle_list = new Dictionary<int, List<Vector3>>(); // Add everything from previous list into this list. Problem is we have no idea what the object is. //foreach (GameObject obj in objList) //{ // if (obj is Obstacle) // { // } //} _xml_dec_list = new Dictionary<Vector3, int>(); _xml_enemy_list = new Dictionary<int, List<Vector3>>(); _xml_sound_list = new Dictionary<string, int>(); _xml_bg_list = new Dictionary<BackGroundData, int>(); _xml_boss_area_list = new Dictionary<Vector3, int>(); _xml_boss_bounds_list = new Dictionary<Vector3, int>(); _xml_boss_center_list = new Dictionary<Vector3, int>(); _xml_end_region = new List<Vector3>(); //StartDesignerThread(); currentObj = QFont.FromQFontFile("Fonts/myHappySans.qfont", new QFontLoaderConfiguration(true)); currentObj.Options.DropShadowActive = false; controls = QFont.FromQFontFile("Fonts/myHappySans.qfont", new QFontLoaderConfiguration(true)); controls.Options.DropShadowActive = false; ahSnap = QFont.FromQFontFile("Fonts/myHappySans.qfont", new QFontLoaderConfiguration(true)); ahSnap.Options.DropShadowActive = false; whichList = QFont.FromQFontFile("Fonts/myHappySans.qfont", new QFontLoaderConfiguration(true)); whichList.Options.DropShadowActive = false; controlsText = new StringBuilder(); controlsText.AppendLine("WASD - Camera/Character Movement"); controlsText.AppendLine("Up,Down,Left,Right - Movement selected object"); controlsText.AppendLine("Mouse Click Left/Right - Select/Add/Remove Objects"); controlsText.AppendLine("[ ] - Switch Objects"); controlsText.AppendLine("; - Switch between different objects"); controlsText.AppendLine("\\ - Switch number of units to move"); }
/// <summary> /// Deals with Hardware input relivant to the playstate /// </summary> private void DealWithInput() { KeyboardState New_Key_State = Keyboard.GetState(); // SAVE THE CURRENT LEVEL TO A NEW LEVEL if (New_Key_State.IsKeyDown(Key.Period) && !Old_Key_State.IsKeyDown(Key.Period) || New_Key_State.IsKeyDown(Key.BracketLeft) && !Old_Key_State.IsKeyDown(Key.BracketLeft) || New_Key_State.IsKeyDown(Key.BracketRight) && !Old_Key_State.IsKeyDown(Key.BracketRight) || New_Key_State.IsKeyDown(Key.Slash) && !Old_Key_State.IsKeyDown(Key.Slash) || New_Key_State.IsKeyDown(Key.Semicolon) && !Old_Key_State.IsKeyDown(Key.Semicolon)) showUI = true; if (New_Key_State.IsKeyDown(Key.Period) && !Old_Key_State.IsKeyDown(Key.Period)) { _write_level_file("TestLevelWrite", 99); Console.WriteLine("Level Written"); } // Allow snapping for movement if (New_Key_State.IsKeyDown(Key.Slash) && !Old_Key_State.IsKeyDown(Key.Slash)) { AllowSnapping = !AllowSnapping; if (AllowSnapping) { UnitsToMove = 10.0f; } else { UnitsToMove = 1.0f; } Console.WriteLine("Snapping is: {0}", AllowSnapping.ToString()); } if (New_Key_State.IsKeyDown(Key.Semicolon) && !Old_Key_State.IsKeyDown(Key.Semicolon)) { int totalKeys = ObjectList.Keys.Count; listKey += 1; objectIter = 0; if (listKey > totalKeys - 1) { listKey = 0; } Console.WriteLine(" You are in {0}", listKey); } // If we are in 2D View, Allow user to zoom out and in with W and S if (!enable3d) { if (New_Key_State.IsKeyDown(Key.W)) { orthoWidth = Math.Max(192, orthoWidth - orthoWidth * 0.01); orthoHeight = Math.Max(108, orthoHeight - orthoHeight * 0.01); camera.Set2DCamera(orthoWidth, orthoHeight); } if (New_Key_State.IsKeyDown(Key.S)) { orthoWidth = Math.Min(1920, orthoWidth + orthoWidth * 0.01); orthoHeight = Math.Min(1080, orthoHeight + orthoHeight * 0.01); camera.Set2DCamera(orthoWidth, orthoHeight); } } // Testing the Level Design feature of re-loading LoadLevel after changing coords for a given game object if (eng.Keyboard[Key.F5]) { LevelDesignerState lds = new LevelDesignerState(eng, menustate, current_level); if (!window.IsActive) { window.Show(); } eng.ChangeState(lds); //LoadLevel.Load(0, pst); } if (eng.Keyboard[Key.Escape] || eng.Keyboard[Key.Tilde]) { //eng.PushState(menustate); eng.PushState(pms); } //********************** tab if (!camera.isInTransition && player.onGround) { if (eng.Keyboard[Key.Tab] && !tabDown) { enable3d = !enable3d; tabDown = true; player.velocity.Z = 0; camera.startTransition(enable3d); //figure out if the player gets a grace jump if (enable3d && player.onGround && !VectorUtil.overGround3dLoose(player, physList)) { player.viewSwitchJumpTimer = 1.0; } } else if (!eng.Keyboard[Key.Tab]) { tabDown = false; } } // Allow movement of the selected objects if (!enable3d) { if (New_Key_State.IsKeyDown(Key.Up) && !Old_Key_State.IsKeyDown(Key.Up)) { MoveObjects(SelectedObject, new Vector3(0.0f, UnitsToMove, 0.0f)); } if (New_Key_State.IsKeyDown(Key.Down) && !Old_Key_State.IsKeyDown(Key.Down)) { MoveObjects(SelectedObject, new Vector3(0.0f, -UnitsToMove, 0.0f)); } if (New_Key_State.IsKeyDown(Key.Left) && !Old_Key_State.IsKeyDown(Key.Left)) { MoveObjects(SelectedObject, new Vector3(-UnitsToMove, 0.0f, 0.0f)); } if (New_Key_State.IsKeyDown(Key.Right) && !Old_Key_State.IsKeyDown(Key.Right)) { MoveObjects(SelectedObject, new Vector3(UnitsToMove, 0.0f, 0.0f)); } // Moving between obstacles if (New_Key_State.IsKeyDown(Key.BracketLeft) && !Old_Key_State.IsKeyDown(Key.BracketLeft)) { if (objectIter - 1 < 0) objectIter = ObjectList[listKey].Count - 1; else objectIter--; Console.WriteLine("Using {0}", ObjectList[listKey][objectIter]); } if (New_Key_State.IsKeyDown(Key.BracketRight) && !Old_Key_State.IsKeyDown(Key.BracketRight)) { if (objectIter + 1 > ObjectList[listKey].Count - 1) objectIter = 0; else objectIter++; Console.WriteLine("Using {0}", ObjectList[listKey][objectIter]); } } #region 3D Move Controls else { if (New_Key_State.IsKeyDown(Key.Up) && !Old_Key_State.IsKeyDown(Key.Up) && !eng.Keyboard[Key.ControlLeft]) { MoveObjects(SelectedObject, new Vector3(UnitsToMove, 0.0f, 0.0f)); } if (New_Key_State.IsKeyDown(Key.Down) && !Old_Key_State.IsKeyDown(Key.Down) && !eng.Keyboard[Key.ControlLeft]) { MoveObjects(SelectedObject, new Vector3(-UnitsToMove, 0.0f, 0.0f)); } if (New_Key_State.IsKeyDown(Key.Left) && !Old_Key_State.IsKeyDown(Key.Left)) { MoveObjects(SelectedObject, new Vector3(0.0f, 0.0f, -UnitsToMove)); } if (New_Key_State.IsKeyDown(Key.Right) && !Old_Key_State.IsKeyDown(Key.Right)) { MoveObjects(SelectedObject, new Vector3(0.0f, 0.0f, UnitsToMove)); } if (New_Key_State.IsKeyDown(Key.Up) && !Old_Key_State.IsKeyDown(Key.Up) && eng.Keyboard[Key.ControlLeft]) { MoveObjects(SelectedObject, new Vector3(0.0f, UnitsToMove, 0.0f)); } if (New_Key_State.IsKeyDown(Key.Down) && !Old_Key_State.IsKeyDown(Key.Down) && eng.Keyboard[Key.ControlLeft]) { MoveObjects(SelectedObject, new Vector3(0.0f, -UnitsToMove, 0.0f)); } } #endregion Old_Key_State = New_Key_State; }
public void Update(Vector2 mousePosInNDC, Inp.MouseState newMouseState, Inp.MouseState oldMouseState, Inp.KeyboardState newKeyboardState, Inp.KeyboardState oldKeyboardState) { //bool activated = UpdateHotkeys(newKeyboardState, oldKeyboardState); if (MouseIsOver(mousePosInNDC)) { if (newMouseState.LeftButton == Inp.ButtonState.Released) { ContainingMenu.SelectedButton = this; } if (MousePressedHereWithoutRelease && newMouseState.LeftButton == Inp.ButtonState.Released) { if (BoundBool != null) { BoundBool.Value = !BoundBool.Value; } if (OnActivate != null) { OnActivate(this); } } if (newMouseState.LeftButton == Inp.ButtonState.Pressed && oldMouseState.LeftButton == Inp.ButtonState.Released) { MousePressedHereWithoutRelease = true; } } else if (ContainingMenu.SelectedButton == this) { ContainingMenu.SelectedButton = null; } if (newMouseState.LeftButton == Inp.ButtonState.Released) { MousePressedHereWithoutRelease = false; } else if (MousePressedHereWithoutRelease && BoundFloat != null) { BoundFloat.Value = (mousePosInNDC.X - PositionX()) / Width * Main.AspectRatio(); } if (BoundFloat != null) { if (BoundFloat.Value < 0f) { BoundFloat.Value = 0f; } else if (BoundFloat.Value > 1f) { BoundFloat.Value = 1f; } } }
public static void Initialize() { _kbState = OpenTK.Input.Keyboard.GetState(); }
private void DealWithInput() { // Testing buttons OpenTK.Input.KeyboardState _new_state = OpenTK.Input.Keyboard.GetState(); if ((_new_state.IsKeyDown(Key.Down) && !_old_state.IsKeyDown(Key.Down)) || (_new_state.IsKeyDown(Key.S) && !_old_state.IsKeyDown(Key.S))) { // Down key was just pressed if (_cur_butn < numOfButtons) { // Increment the current button index so you draw the highlighted button of the next button _cur_butn += 1; eng.selectSound.Play(); } else if (_cur_butn >= numOfButtons) { // Were on the last button in the list so reset to the top of the button list _cur_butn = 0; eng.selectSound.Play(); } } if ((_new_state.IsKeyDown(Key.Up) && !_old_state.IsKeyDown(Key.Up)) || (_new_state.IsKeyDown(Key.W) && !_old_state.IsKeyDown(Key.W))) { // Down key was just pressed if (_cur_butn > 0) { // Increment the current button index so you draw the highlighted button of the next button _cur_butn -= 1; eng.selectSound.Play(); } else if (_cur_butn <= 0) { // Were on the last button in the list so reset to the top of the button list _cur_butn = numOfButtons; eng.selectSound.Play(); } } _old_state = _new_state; if (eng.Keyboard[Key.Escape] && !escapedown) { //eng.Exit(); musicFile.Stop(); eng.PushState(_ms); } else if (!eng.Keyboard[Key.Escape]) { escapedown = false; } //********************** enter if (eng.Keyboard[Key.Enter] && !enterdown) { enterdown = true; handleButtonPress(); } else if (!eng.Keyboard[Key.Enter]) { enterdown = false; } //Minus - Toggle fullscreen if (eng.Keyboard[Key.Minus]) { eng.toggleFullScreen(); } }
private void DealWithInput() { OpenTK.Input.KeyboardState _new_state = OpenTK.Input.Keyboard.GetState(); // Loop over all available keys and type out to the screen for (int i = 0; i < (int)Key.LastKey; i++) { Key k = (Key)i; // 49 = enter bool current = _new_state.IsKeyDown(k); bool previous = _old_state.IsKeyDown(k); if (current && !previous) { // new key pressed //NewKeyDownDetected(k); for (int i2 = 0; i2 < alpha.Length; i2++) { if (k.ToString().CompareTo(alpha[i2].ToString()) == 0) { name += k.ToString(); } } if (i == 53 && name.Length > 0) { name = name.Remove(name.Length - 1); } } else if (!current && previous) { //NewKeyUpDetected(k); } else { // Constant keypress } } _old_state = _new_state; if ((eng.Keyboard[Key.Escape] || (eng.Keyboard[Key.Tilde])) && !escapedown) { eng.Exit(); } else if (!eng.Keyboard[Key.Escape] && !eng.Keyboard[Key.Tilde]) { escapedown = false; } //********************** enter if (eng.Keyboard[Key.Enter] && !enterdown) { enterdown = true; loadPlayState(0); // Load game } else if (!eng.Keyboard[Key.Enter]) { enterdown = false; } //Minus - Toggle fullscreen if (eng.Keyboard[Key.Minus]) { eng.toggleFullScreen(); } }
public LevelSelect(GameEngine engine) : base(engine) { eng = engine; savedGameStates = new Stack<XmlNodeList>(); savedGameChoices = new Stack<string>(); mouse = eng.Mouse; // Load all the textures eng.StateTextureManager.RenderSetup(); Assembly assembly = Assembly.GetExecutingAssembly(); eng.StateTextureManager.LoadTexture("menu", assembly.GetManifestResourceStream("U5Designs.Resources.Textures.menu.png")); menu = eng.StateTextureManager.GetTexture("menu"); eng.StateTextureManager.LoadTexture("arrow", assembly.GetManifestResourceStream("U5Designs.Resources.Textures.arrow.png")); arrow = eng.StateTextureManager.GetTexture("arrow"); eng.StateTextureManager.LoadTexture("load", assembly.GetManifestResourceStream("U5Designs.Resources.Textures.btn_loadlevel.png")); load_nopress = eng.StateTextureManager.GetTexture("load"); eng.StateTextureManager.LoadTexture("loadpress", assembly.GetManifestResourceStream("U5Designs.Resources.Textures.btn_loadlevel_hover.png")); load_press = eng.StateTextureManager.GetTexture("loadpress"); eng.StateTextureManager.LoadTexture("quit", assembly.GetManifestResourceStream("U5Designs.Resources.Textures.btn_exit.png")); quit_nopress = eng.StateTextureManager.GetTexture("quit"); eng.StateTextureManager.LoadTexture("quitpress", assembly.GetManifestResourceStream("U5Designs.Resources.Textures.btn_exit_hover.png")); quit_press = eng.StateTextureManager.GetTexture("quitpress"); eng.StateTextureManager.LoadTexture("play", assembly.GetManifestResourceStream("U5Designs.Resources.Textures.btn_play.png")); play_nopress = eng.StateTextureManager.GetTexture("play"); eng.StateTextureManager.LoadTexture("playpress", assembly.GetManifestResourceStream("U5Designs.Resources.Textures.btn_play_hover.png")); play_press = eng.StateTextureManager.GetTexture("playpress"); eng.StateTextureManager.LoadTexture("ld", assembly.GetManifestResourceStream("U5Designs.Resources.Textures.btn_leveldesign.png")); ld_nopress = eng.StateTextureManager.GetTexture("ld"); eng.StateTextureManager.LoadTexture("ldpress", assembly.GetManifestResourceStream("U5Designs.Resources.Textures.btn_leveldesign_hover.png")); ld_press = eng.StateTextureManager.GetTexture("ldpress"); musicFile = new AudioFile(assembly.GetManifestResourceStream("U5Designs.Resources.Sound.Retribution.ogg")); musicFile.Play(); // Setup saved game data SavedGameDataSetup(); // Display available saved game states DisplayAvailableSaves(); // Clear the color to work with the SplashScreen so it doesn't white out GL.ClearColor(0.0f, 0.0f, 0.0f, 0.0f); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); lookat = new Vector3(0, 0, 2); eye = new Vector3(0, 0, 5); _old_state = OpenTK.Input.Keyboard.GetState(); // Get the current state of the keyboard arX = -150.0f; b1Y = 0.0f; b2Y = -100.0f; b3Y = -200.0f; b4Y = -250.0f; // TEST // enterdown = false; LoadSavedState(1); }
public GameOverState(MainMenuState prvstate, GameEngine engine, PlayState ps) { eng = engine; menu = prvstate; _ps = ps; _old_state = OpenTK.Input.Keyboard.GetState(); lookat = new Vector3(0, 0, 2); eye = new Vector3(0, 0, 5); xf = 1.0f; yf = 1.0f; // TO DO: CHANGE THE GAME OVER SCREEN eng.StateTextureManager.RenderSetup(); Assembly audAssembly = Assembly.GetExecutingAssembly(); eng.StateTextureManager.LoadTexture("go", audAssembly.GetManifestResourceStream("U5Designs.Resources.Textures.GameOverTextures.gameover.png")); goBackground = eng.StateTextureManager.GetTexture("go"); /* eng.StateTextureManager.LoadTexture("arrow", audAssembly.GetManifestResourceStream("U5Designs.Resources.Textures.GameOverTextures.arrow.png")); arrow = eng.StateTextureManager.GetTexture("arrow"); eng.StateTextureManager.LoadTexture("back2menu", audAssembly.GetManifestResourceStream("U5Designs.Resources.Textures.GameOverTextures.btn_backtomenu.png")); mainmenu = eng.StateTextureManager.GetTexture("back2menu"); eng.StateTextureManager.LoadTexture("back2menupress", audAssembly.GetManifestResourceStream("U5Designs.Resources.Textures.GameOverTextures.btn_backtomenu_hover.png")); menu_pressed = eng.StateTextureManager.GetTexture("back2menupress"); eng.StateTextureManager.LoadTexture("restartlevel", audAssembly.GetManifestResourceStream("U5Designs.Resources.Textures.GameOverTextures.btn_restart.png")); restart = eng.StateTextureManager.GetTexture("restartlevel"); eng.StateTextureManager.LoadTexture("restartlevelpress", audAssembly.GetManifestResourceStream("U5Designs.Resources.Textures.GameOverTextures.btn_restart_hover.png")); restart_pressed = eng.StateTextureManager.GetTexture("restartlevelpress"); eng.StateTextureManager.LoadTexture("exitgame", audAssembly.GetManifestResourceStream("U5Designs.Resources.Textures.GameOverTextures.btn_exit.png")); exit = eng.StateTextureManager.GetTexture("exitgame"); eng.StateTextureManager.LoadTexture("exitpress", audAssembly.GetManifestResourceStream("U5Designs.Resources.Textures.GameOverTextures.btn_exit_hover.png")); exit_pressed = eng.StateTextureManager.GetTexture("exitpress"); * */ // QFont //Assembly assembly = Assembly.GetExecutingAssembly(); //eng.StateTextureManager.LoadTexture("menu", assembly.GetManifestResourceStream("U5Designs.Resources.Textures.menu.png")); //bg = eng.StateTextureManager.GetTexture("menu"); _buttons = new List<String>(); _buttons.Add("Restart Level ??"); _buttons.Add("Return to Main Menu"); _buttons.Add("Quit"); button = QFont.FromQFontFile("Fonts/myHappySans.qfont", new QFontLoaderConfiguration(true)); button.Options.DropShadowActive = true; //title = QFont.FromQFontFile("myHappySans.qfont", new QFontLoaderConfiguration(true)); title = QFont.FromQFontFile("Fonts/myRock.qfont", new QFontLoaderConfiguration(true)); title.Options.DropShadowActive = false; buttonHighlight = QFont.FromQFontFile("Fonts/myHappySans2.qfont", new QFontLoaderConfiguration(true)); buttonHighlight.Options.DropShadowActive = true; //QFont.CreateTextureFontFiles("Fonts/Rock.TTF", 48, "myRock"); // Use this to create new Fonts that you will texture // End QFonts //restart_btn = eng.StateTextureManager.GetTexture("restart"); //quit_btn = eng.StateTextureManager.GetTexture("quit_button"); arX = -200.0f; b1Y = -50.0f; b2Y = -100.0f; b3Y = -150.0f; timeTillNextState = 4; }