public override void Update(GameTime gameTime, InputState inputState, InputState lastInputState) { base.Update(gameTime, inputState, lastInputState); //Chau Van Sang adds isCursor for cursor flickering if (isFocused == true) { temp_speed_flicker += 1; if (temp_speed_flicker == speed_flick) { isCursor_flicker = !isCursor_flicker; temp_speed_flicker = 0; } if (HelperFunction.IsKeyPress(Keys.Back)) { if (textBuffer.Length > 0) { if (Font.MeasureString(textBuffer).X > rect.Width) { textBuffer.Remove(textBuffer.Length - 1, 1); return; } textBuffer.Remove((CursorPosition - 1).Clamp(textBuffer.Length, 0), 1); CursorPosition--; } } } }
/// <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 CONTENT_MANAGER.inputState = new InputState(Mouse.GetState(), Keyboard.GetState()); if (HelperFunction.IsKeyPress(Keys.F1)) { SCREEN_MANAGER.goto_screen("TestAnimationScreen"); } if (HelperFunction.IsKeyPress(Keys.F2)) { Unit.Load(); CONTENT_MANAGER.ShowMessageBox("Unit stats reloaded"); } if (HelperFunction.IsKeyPress(Keys.F3)) { SCREEN_MANAGER.goto_screen("TestConsole"); } SCREEN_MANAGER.Update(gameTime); lastInputState = inputState; base.Update(gameTime); }
public override void Update(GameTime gameTime) { canvas.Update(CONTENT_MANAGER.inputState, CONTENT_MANAGER.lastInputState); if (HelperFunction.IsKeyPress(Keys.OemTilde)) { console.IsVisible = !console.IsVisible; } }
public override void Update(GameTime gameTime, InputState inputState, InputState lastInputState) { base.Update(gameTime, inputState, lastInputState); if (isPressed) { OnButtonPressed(this, new UIEventArgs(inputState, lastInputState)); } if (HelperFunction.IsKeyPress(Hotkey)) { OnMouseClick(this, new UIEventArgs(inputState, lastInputState)); } }
public override void Update(InputState inputState, InputState lastInputState) { base.Update(inputState, lastInputState); //Chau Van Sang adds isCursor for cursor flickering if (isFocused == true) { temp_speed_flicker += 1; if (temp_speed_flicker == speed_flick) { isCursor_flicker = !isCursor_flicker; temp_speed_flicker = 0; } if (HelperFunction.IsKeyPress(Keys.Back)) { if (textBuffer.Length > 0) { if (font.MeasureString(textBuffer).X > rect.Width) { textBuffer.Remove(textBuffer.Length - 1, 1); return; } textBuffer.Remove((CursorPosition - 1).Clamp(textBuffer.Length, 0), 1); CursorPosition--; } } if (inputState.keyboardState.IsKeyDown(Keys.LeftControl) && HelperFunction.IsKeyPress(Keys.V)) { string paste = CONTENT_MANAGER.GetClipboard(); textBuffer.Append(paste); CursorPosition += paste.Length; } } }
public override void Update(GameTime gameTime) { mouseInputState = CONTENT_MANAGER.inputState.mouseState; lastMouseInputState = CONTENT_MANAGER.lastInputState.mouseState; keyboardInputState = CONTENT_MANAGER.inputState.keyboardState; lastKeyboardInputState = CONTENT_MANAGER.lastInputState.keyboardState; selectedMapCell = Utility.HelperFunction.TranslateMousePosToMapCellPos(mouseInputState.Position, camera, map.Width, map.Height); if (HelperFunction.IsKeyPress(Keys.OemTilde)) { console.IsVisible = !console.IsVisible; } #region change unit and animation if (console.IsVisible) //suck all input in to the input box { console.Update(CONTENT_MANAGER.inputState, CONTENT_MANAGER.lastInputState); } else //accept input { //cylce through unit if (HelperFunction.IsKeyPress(Keys.Left)) { if (currentUnit == UnitType.Soldier) { currentUnit = UnitType.Battleship; } else { currentUnit = currentUnit.Previous(); } } if (HelperFunction.IsKeyPress(Keys.Right)) { if (currentUnit == UnitType.Battleship) { currentUnit = UnitType.Soldier; } else { currentUnit = currentUnit.Next(); } } //cycle through animation if (HelperFunction.IsKeyPress(Keys.Up)) { if (currentAnimation == AnimationName.idle) { currentAnimation = AnimationName.done; } else { currentAnimation = currentAnimation.Previous(); } } if (HelperFunction.IsKeyPress(Keys.Down)) { if (currentAnimation == AnimationName.done) { currentAnimation = AnimationName.idle; } else { currentAnimation = currentAnimation.Next(); } } //cycle through color if (HelperFunction.IsKeyPress(Keys.E)) { if (currentColor == GameData.Owner.Yellow) { currentColor = GameData.Owner.Red; } else { currentColor = currentColor.Next(); } } if (HelperFunction.IsKeyPress(Keys.Q)) { if (currentColor == GameData.Owner.Red) { currentColor = GameData.Owner.Yellow; } else { currentColor = currentColor.Previous(); } } } Unit unit = map[position].unit; UnitType nextUnit = unit.UnitType; GameData.Owner nextOwner = unit.Owner; AnimationName nextAnimation = unit.Animation.CurntAnimationName.ToEnum <AnimationName>(); bool isChanged = false; if (nextUnit != currentUnit) { isChanged = true; } if (nextOwner != currentColor) { isChanged = true; } if (nextAnimation != currentAnimation) { isChanged = true; } if (isChanged) { map[position].unit = UnitCreationHelper.Create(currentUnit, currentColor, startingAnimation: currentAnimation); } map[position].unit.Animation.Update(gameTime); #endregion if (mouseInputState.LeftButton == ButtonState.Released && lastMouseInputState.LeftButton == ButtonState.Pressed) { SelectUnit(); } //if (isMovingUnitAnimPlaying) //{ // UpdateMovingUnit(gameTime); //} //calculate movepath if (isMovePathCalculated) { if (movementRange.Contains(selectedMapCell) && selectedMapCell != lastSelectedMapCell) { //update movement path movementPath = DijkstraHelper.FindPath(dijkstarGraph, selectedMapCell); dirarrowRenderer.UpdatePath(movementPath); lastSelectedMapCell = selectedMapCell; } } base.Update(gameTime); }
private void InitCanvas() { canvas = new Canvas(); Label label_name = new Label("Untitled", new Point(400, 0), new Vector2(200, 20), CONTENT_MANAGER.Fonts["default"]) { Origin = new Vector2(-2, -2), BackgroundColor = Color.LightGray }; label_snippet = new Label("", new Point(400, 30), new Vector2(20, 20), CONTENT_MANAGER.Fonts["default"]) { Origin = new Vector2(-2, -2) }; CONTENT_MANAGER.gameInstance.Window.TextInput += (obj, e) => { //if (label_name.IsFocused) { if (char.IsLetterOrDigit(e.Character)) { label_name.Text += e.Character; } else if (e.Key == Keys.Back) { int cc = label_name.Text.Length - 1; if (cc >= 0) { label_name.Text = label_name.Text.Remove(cc); } } } }; pictureBox_spritesheet = new PictureBox(CONTENT_MANAGER.Sprites[texture], new Point(50, 0), null, null); pictureBox_snippet = new PictureBox(CONTENT_MANAGER.Sprites[texture], new Point(400, 70), Rectangle.Empty, null); pictureBox_spritesheet.MouseDrag += (obj, e) => { if (e.Size != Point.Zero) { //DrawingHelper.RemoveShape(selectedFrame); //selectedFrame = DrawingHelper.GetRectangle(e, Color.Red, false); //DrawingHelper.DrawShape(selectedFrame); selectedFrame = new Rectangle((e.Location.ToVector2() * pictureBox_spritesheet.Scale).ToPoint(), (e.Size.ToVector2() * pictureBox_spritesheet.Scale).ToPoint()); label_snippet.Text = selectedFrame.ToString(); e.Location = new Point(e.Location.X - pictureBox_spritesheet.Position.X, e.Location.Y - pictureBox_spritesheet.Position.Y); pictureBox_snippet.SourceRectangle = e; } }; pictureBox_spritesheet.KeyPress += (obj, e) => { if (HelperFunction.IsKeyPress(Keys.OemPlus)) { pictureBox_spritesheet.Scale += 0.1f; scaleChanged = true; } if (HelperFunction.IsKeyPress(Keys.OemMinus)) { if (pictureBox_spritesheet.Scale > 1) { pictureBox_spritesheet.Scale -= 0.1f; scaleChanged = true; } } }; Button button_new = new Button("New", new Point(650, 30), new Vector2(60, 30), CONTENT_MANAGER.Fonts["default"]) { ButtonColorReleased = Color.White }; button_new.MouseClick += (o, e) => { animationPlayer.StopAnimation(); label_name.Text = "Untitled"; }; Button button_add_sprite = new Button("Add F", new Point(720, 30), new Vector2(60, 30), CONTENT_MANAGER.Fonts["default"]) { ButtonColorReleased = Color.White }; button_add_sprite.MouseClick += (obj, e) => { if (string.IsNullOrWhiteSpace(label_name.Text)) { label_name.Text = "Please enter the name of this animation"; } else if (!animation_list.ContainsKey(label_name.Text)) { animation_list.Add(label_name.Text, new List <Rectangle>() { pictureBox_snippet.SourceRectangle }); } else { animation_list[label_name.Text].Add(pictureBox_snippet.SourceRectangle); } }; animationPlayer = new AnimationPlayer(new AnimatedEntity(), new Point(700, 70)); Button button_test_animation = new Button("Test", new Point(790, 30), new Vector2(60, 30), CONTENT_MANAGER.Fonts["default"]) { ButtonColorReleased = Color.White }; button_test_animation.MouseClick += (o, e) => { string animationName = label_name.Text; Animation animation = new Animation(animationName, true, 1, null); foreach (var frame in animation_list[animationName]) { animation.AddKeyFrame(frame); } if (animationPlayer.ContainAnimation(animation.Name)) { animationPlayer.RemoveAnimation(animation.Name); } animationPlayer.AddAnimation(animation); animationPlayer.LoadContent(pictureBox_snippet.Texture2D); animationPlayer.PlayAnimation(animation.Name); }; Button button_export = new Button("Export", new Point(860, 30), new Vector2(60, 30), CONTENT_MANAGER.Fonts["default"]) { ButtonColorReleased = Color.White }; button_export.MouseClick += (o, e) => { var animdata = JsonConvert.SerializeObject(animationPlayer.AnimatedEntity, Formatting.Indented); File.WriteAllText($"{label_name.Text}.txt", animdata); }; canvas.AddElement("label_test", label_name); canvas.AddElement("label_snippet", label_snippet); canvas.AddElement("pictureBox_test", pictureBox_spritesheet); canvas.AddElement("pictureBox_snippet", pictureBox_snippet); canvas.AddElement("button_add_sprite", button_add_sprite); canvas.AddElement("animationPlayer", animationPlayer); canvas.AddElement("button_test_animation", button_test_animation); canvas.AddElement("button_export", button_export); canvas.AddElement("button_new", button_new); }
private void MoveSnippet() { //with shift : move the whole snippet rectangle //without shift : adjust the size of the snippet rectangle bool checkShift = HelperFunction.IsKeyDown(Keys.LeftShift) || HelperFunction.IsKeyDown(Keys.RightShift); //with ctrl : press to move //without ctrl : hold down to move bool checkCtrl = HelperFunction.IsKeyDown(Keys.LeftControl) || HelperFunction.IsKeyDown(Keys.RightControl); Rectangle rekt = pictureBox_snippet.SourceRectangle; Point position = rekt.Location; Point size = rekt.Size; if ((HelperFunction.IsKeyDown(Keys.Left) && !checkCtrl) || (HelperFunction.IsKeyPress(Keys.Left) && checkCtrl)) { if (checkShift) { //move size size = new Point(MathHelper.Clamp(size.X - 1, 0, size.X), size.Y); } else { position = new Point(MathHelper.Clamp(position.X - 1, 0, position.X), position.Y); } } if ((HelperFunction.IsKeyDown(Keys.Right) && !checkCtrl) || (HelperFunction.IsKeyPress(Keys.Right) && checkCtrl)) { if (checkShift) { //move size size = new Point(size.X + 1, size.Y); } else { position = new Point(position.X + 1, position.Y); } } if ((HelperFunction.IsKeyDown(Keys.Up) && !checkCtrl) || (HelperFunction.IsKeyPress(Keys.Up) && checkCtrl)) { if (checkShift) { //move size size = new Point(size.X, MathHelper.Clamp(size.Y - 1, 0, size.Y)); } else { position = new Point(position.X, MathHelper.Clamp(position.Y - 1, 0, position.Y)); } } if ((HelperFunction.IsKeyDown(Keys.Down) && !checkCtrl) || (HelperFunction.IsKeyPress(Keys.Down) && checkCtrl)) { if (checkShift) { //move size size = new Point(size.X, size.Y + 1); } else { position = new Point(position.X, position.Y + 1); } } rekt.Location = position; rekt.Size = size; if (pictureBox_snippet.SourceRectangle != rekt || scaleChanged) { scaleChanged = false; pictureBox_snippet.SourceRectangle = rekt; label_snippet.Text = rekt.ToString(); if (selectedFrame != null) { selectedFrame.Location = new Point(pictureBox_spritesheet.Position.X + position.X * (int)pictureBox_spritesheet.Scale, pictureBox_spritesheet.Position.Y + position.Y * (int)pictureBox_spritesheet.Scale); selectedFrame.Size = (size.ToVector2() * pictureBox_spritesheet.Scale).ToPoint(); } } }
public override void Update(GameTime gameTime) { inQueue = new List <NetIncomingMessage>(); var msgCount = client.ReadMessages(inQueue); outQueue = new List <NetOutgoingMessage>(); if (HelperFunction.IsKeyDown(Keys.Escape)) { client.Disconnect("Smell ya later"); CONTENT_MANAGER.GameInstance.Exit(); } if (!Players.ContainsKey(ID) && HelperFunction.IsKeyPress(Keys.R)) { outQueue.Add(NetCommand.WriteCommand(ID, Command.CreatePlayer, 112f, 112f)); } foreach (var player in Players.Values) { player.Update(gameTime); } foreach (var msg in inQueue) { switch (msg.MessageType) { case NetIncomingMessageType.DiscoveryResponse: Console.WriteLine("Found server at " + msg.SenderEndPoint + " name: " + msg.ReadString()); client.Connect(msg.SenderEndPoint); break; case NetIncomingMessageType.Data: { NetCommand netcmd = NetCommand.ReadCommand(msg); switch (netcmd.Command) { case Command.CreatePlayer: Console.WriteLine(netcmd); SpawnPlayer(netcmd); break; case Command.DestroyPlayer: if (Players.ContainsKey(netcmd.LL)) { world.Remove(Players[netcmd.LL].collision); Players.Remove(netcmd.LL); } break; case Command.QuerryPlayerPosition: AnswerPosition(); break; case Command.ChangePlayerColor: case Command.MovePlayer: case Command.RotatePlayer: case Command.StopPlayer: case Command.CreateBullet: case Command.MoveBullet: case Command.DestroyBullet: Players[netcmd.ID].ExecuteCommand(netcmd); break; } } break; } } foreach (var msg in outQueue) { client.SendMessage(msg, NetDeliveryMethod.ReliableOrdered); } client.FlushSendQueue(); client.Recycle(inQueue); canvas.Update(gameTime, CONTENT_MANAGER.CurrentInputState, CONTENT_MANAGER.LastInputState); }