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; } }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // TODO: Add your initialization logic here base.Initialize(); Vector2 playerStartPos = new Vector2(43, 2); Camara.screenResWidth = screenResWidth; Camara.screenResHeight = screenResHeight; Camara.zoom = 1f; input = new InputHandler(this); //groundTiles = new tileSet(TileSizeWidth, TileSizeHeight, Content.Load<Texture2D>(@"tileSets/groundTiles")); gameWorld = new World(Content, "TheWorld", ChunkSizeWidth, ChunkSizeHeight, TileSizeWidth, TileSizeHeight, playerStartPos); player = new Player(Content, gameWorld); player.Position = playerStartPos;// gameWorld.playerStartTile(); npcManager = new NPC_Manager(Content, gameWorld); hud = new Hud(Content, GraphicsDevice, player, gameWorld, npcManager); Camara.Location.X = (player.Position.X) - screenResWidth / 2; Camara.Location.Y = (player.Position.Y) - screenResHeight / 2; }
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); }