public void Update(InputHandler input) { curserPos = input.mousePos(); Vector2 curserWorldPos = curserPos + Camara.Location; hoverSmallPlayerInfo = false; NPC npc = npcManager.getNPCatPos(curserWorldPos); if (npc != null) curserColor = Color.OrangeRed; else curserColor = Color.BlueViolet; //hover on SmallPlayerInfo if (smallPlayerInfoBG_R.Contains((int)input.mousePos().X, (int)input.mousePos().Y)) { hoverSmallPlayerInfo = true; if (input.mouseLeftClick()) //click on small player info displayBigPlayerInfo = !displayBigPlayerInfo; } //keyboard shortcuts if (input.keyBoardKeyPress(Microsoft.Xna.Framework.Input.Keys.F3)) { Game.debugMode = !Game.debugMode; } }
public void Update(GameTime gameTime, NPC_Manager npcManager, InputHandler input) { Vector2 MouseDirection = Vector2.Zero; double MouseDeg; Vector2 MousePosition = Vector2.Zero; NPC npc ; //get mouse location MousePosition = input.mousePos(); MousePosition = (MousePosition + Camara.Location); MouseDirection = (MousePosition - Position); MouseDirection.Normalize(); MouseDeg = Math.Atan2(MouseDirection.X, MouseDirection.Y); MouseDeg = MouseDeg * 180 / Math.PI; if (input.mouseLeftHold()) { state = State.freeMoving; } else if (input.mouseLeftClick()) { npc = npcManager.getNPCatPos(MousePosition); if (npc != null) // CLICKED ON NPC { if (Vector2.Distance(Position, npc.getPosition()) <= 20) { state = State.meleeAttack; } } else { cellPath = pathfinder.FindCellPath(Position, MousePosition); if (cellPath != null) state = State.movingToPoint; else state = State.idle; } } else if (input.mouseRightClick()) { state = State.meleeAttack; } else if (input.mouseLeftRelease() && state == State.freeMoving) { state = State.idle; } if (state == State.freeMoving) { Direction = MouseDirection; FacingDeg = MouseDeg; Position += Direction * (float)gameTime.ElapsedGameTime.TotalSeconds * speed; } else if (state == State.meleeAttack) { if (attackTimer == attackTimerBase) { FacingDeg = MouseDeg; meleeAttack(FacingDeg, npcManager); // System.Console.WriteLine("ATTACK"); } attackTimer -= (float)gameTime.ElapsedGameTime.TotalSeconds; if (attackTimer <= 0) { state = State.idle; attackTimer = attackTimerBase; } } else if (state == State.movingToPoint) { MoveToPos = cellPath[0].pixelPositionCenter; if (Vector2.Distance(Position, MoveToPos) > 1) { Direction = MoveToPos - Position; Direction.Normalize(); FacingDeg = Math.Atan2(Direction.X, Direction.Y); FacingDeg = FacingDeg * 180 / Math.PI; Position += Direction * (float)gameTime.ElapsedGameTime.TotalSeconds * speed; } else { cellPath[0].color = Color.White; cellPath.RemoveAt(0); } if (cellPath.Count == 0) { state = State.idle; } } else if (state == State.idle) { FacingDeg = MouseDeg; } updateAnimation(gameTime); }