public static void Update() { if (ControlInput.IsKeyPressed(Keys.Enter) && menuLayer == MenuLayer.Tiles && menuLayer == lastMenuLayer) { menuLayer = MenuLayer.Editor; } if (enabled) { Input(); Layer(); Selection(); } if (ControlInput.IsKeyPressed(Keys.Escape) && menuLayer == MenuLayer.Game) { enabled = !enabled; if (enabled) { gameState = GameState.Pause; } else if (!enabled) { gameState = GameState.Play; } } if (ControlInput.IsKeyPressed(Keys.Escape) && menuLayer == MenuLayer.Editor || ControlInput.IsKeyPressed(Keys.Escape) && menuLayer == MenuLayer.Tiles) { menuLayer = MenuLayer.Editor; enabled = !enabled; } }
private static void Input() { if (ControlInput.IsKeyPressed(Keys.Up)) { currentItem--; } else if (ControlInput.IsKeyPressed(Keys.Down)) { currentItem++; } else if (ControlInput.IsKeyPressed(Keys.Enter) && menuLayer == lastMenuLayer) { ItemSelect(); } if (lastMenuLayer != menuLayer) { currentItem = 0; } lastMenuLayer = menuLayer; }
public void Update(GameTime gameTime) { var pos = MathHelper.Clamp(rigidbody.Position.X, 0, ConvertUnits.ToSimUnits(Screen.width - rect.Width)); rigidbody.Position = new Vector2(pos, rigidbody.Position.Y); buttonPressed = false; if (Keyboard.GetState().IsKeyDown(Keys.D)) { rigidbody.Position = new Vector2(rigidbody.Position.X + moveSpeed * gameTime.DeltaTime(), rigidbody.Position.Y); buttonPressed = true; flip = SpriteEffects.None; if (grounded && aniState != AnimationState.Jump) { aniState = AnimationState.Walk; } } else if (Keyboard.GetState().IsKeyDown(Keys.A)) { rigidbody.Position = new Vector2(rigidbody.Position.X - moveSpeed * gameTime.DeltaTime(), rigidbody.Position.Y); buttonPressed = true; flip = SpriteEffects.FlipHorizontally; if (grounded && aniState != AnimationState.Jump) { aniState = AnimationState.Walk; } } if (ControlInput.IsKeyPressed(Keys.Space) && grounded && aniState != AnimationState.Jump) { rigidbody.ApplyForce(new Vector2(0f, jumpForce)); aniState = AnimationState.Jump; } if (ControlInput.IsKeyPressed(Keys.R)) { rigidbody.Position = ConvertUnits.ToSimUnits(initPos); rigidbody.ResetDynamics(); } Raycast(); if (!grounded && aniState != AnimationState.Jump) { aniState = AnimationState.Fall; } else if (!grounded && rigidbody.LinearVelocity.Y > 0) { aniState = AnimationState.Fall; } else if (grounded && !buttonPressed && aniState != AnimationState.Jump) { aniState = AnimationState.Idle; } else if (grounded && aniState == AnimationState.Jump && !ControlInput.IsKeyPressed(Keys.Space)) { aniState = AnimationState.Idle; } // Console.WriteLine(grounded + " / " + aniState); //Console.WriteLine(rigidbody.LinearVelocity.Y); setClip(); animator.Frames(gameTime); animator.Update(gameTime); rect = animator.UpdateRect; }
private void Input() { if (Menu.menuLayer == MenuLayer.Tiles && !Menu.enabled) { if (ControlInput.IsKeyPressed(Keys.Up) && !buttonUpLocked) { currentTile -= 4; bCursorPos = new Vector2(bCursorPos.X, bCursorPos.Y - cursorOffseth); } else if (ControlInput.IsKeyPressed(Keys.Down) && !buttonDownLocked) { currentTile += 4; bCursorPos = new Vector2(bCursorPos.X, bCursorPos.Y + cursorOffseth); } else if (ControlInput.IsKeyPressed(Keys.Right) && !buttonRightLocked) { currentTile += 1; bCursorPos = new Vector2(bCursorPos.X + cursorOffseth, bCursorPos.Y); } else if (ControlInput.IsKeyPressed(Keys.Left) && !buttonLeftLocked) { currentTile -= 1; bCursorPos = new Vector2(bCursorPos.X - cursorOffseth, bCursorPos.Y); } currentTile = MathHelper.Clamp(currentTile, 0, 16); //Console.WriteLine(currentTile); // guide cursor row bCursorPos.X = MathHelper.Clamp(bCursorPos.X, normalbCursorPos.X, 483); //483 bCursorPos.Y = MathHelper.Clamp(bCursorPos.Y, normalbCursorPos.Y, 380); //460 // ugly code in coming !!!!! AAAAAAAAAAAAHHHH Console.WriteLine(bCursorPos); if (bCursorPos.X == normalbCursorPos.X) { buttonLeftLocked = true; } else if (bCursorPos.X == 483) //483 { buttonRightLocked = true; } else { buttonRightLocked = buttonLeftLocked = false; } if (bCursorPos.Y == normalbCursorPos.Y) { buttonUpLocked = true; } else if (bCursorPos.Y == 380) //460 { buttonDownLocked = true; } else { buttonUpLocked = buttonDownLocked = false; } } /// if (Menu.menuLayer == MenuLayer.Editor && !Menu.enabled) { if (ControlInput.IsKeyPressed(Keys.Left)) { position.X -= move; } else if (ControlInput.IsKeyPressed(Keys.Right)) { position.X += move; } else if (ControlInput.IsKeyPressed(Keys.Up)) { position.Y -= move; } else if (ControlInput.IsKeyPressed(Keys.Down)) { position.Y += move; } else if (ControlInput.IsKeyPressed(Keys.Space) && canPlant) { if ((TileType)currentTile == TileType.EnemyBlu) { Scene.ActorObjects.Add(new Enemy(position)); } else if ((TileType)currentTile == TileType.PlayerSpawn) { Scene.PlayerList.Add(new Player(position)); } else { Scene.levelObjects.Add(new Tile((TileType)currentTile, position)); } } /* * else if (ControlInput.IsKeyPressed(Keys.F1)) * { * LevelIO.Save(); * } * else if (ControlInput.IsKeyPressed(Keys.F2)) * { * LevelIO.Load(); * } */ else if (ControlInput.IsKeyPressed(Keys.Delete)) { for (int i = 0; i < Scene.levelObjects.Count; i++) { if (Scene.levelObjects[i].position.Equals(this.position)) { Scene.levelObjects[i].rigidbody.Dispose(); Scene.levelObjects.Remove(Scene.levelObjects[i]); } } for (int i = 0; i < Scene.ActorObjects.Count; i++) { if (Scene.ActorObjects[i].position.Equals(this.position)) { Scene.ActorObjects[i].rigidbody.Dispose(); Scene.ActorObjects.Remove(Scene.ActorObjects[i]); } } for (int i = 0; i < Scene.PlayerList.Count; i++) { if (Scene.PlayerList[i].position.Equals(this.position)) { Scene.PlayerList[i].rigidbody.Dispose(); Scene.PlayerList.Remove(Scene.PlayerList[i]); } } } CheckPosition(); position.X = MathHelper.Clamp(position.X, 0, position.X); position.Y = MathHelper.Clamp(position.Y, 0, position.Y); } }