override public void update(float dt) { //Console.WriteLine(path.Count); double distance = Math.Sqrt(Math.Pow(target.hitBox.Center.X - owner.hitBox.Center.X, 2) + Math.Pow(target.hitBox.Center.Y - owner.hitBox.Center.Y, 2)); if (distance > 50) { Vector2 attackVector = new Vector2(owner.hitBox.Center.X - target.hitBox.Center.X, owner.hitBox.Center.Y - target.hitBox.Center.Y); attackVector.Normalize(); attackVector *= 50; attackVector.X += target.hitBox.Center.X; attackVector.Y += target.hitBox.Center.Y; Point attackPos = new Point((int)attackVector.X, (int)attackVector.Y); Vector2 movement = new Vector2(attackPos.X - owner.hitBox.Center.X, attackPos.Y - owner.hitBox.Center.Y); movement.Normalize(); movement *= 5; //owner.movementIntent /= 3f; owner.velocity.X = movement.X; owner.velocity.Y = movement.Y; owner.isWalking = true; owner.setGaze(attackPos); } else { owner.setGaze(target.hitBox.Center); Punch punch = new Punch(owner.animationList, owner); if (!owner.animationList.has(punch)) { owner.animationList.pushFront(punch); } } }
private void UpdateInput() { keyBoardState = Keyboard.GetState(); mouseState = Mouse.GetState(); curMousePosX = mouseState.X; curMousePosY = mouseState.Y; Vector2 playerDirection = new Vector2(curMousePosX - origin.X, curMousePosY - origin.Y); playerDirection.Normalize(); player.setGaze(playerDirection); if (!player.lockedMovement) { if (keyBoardState.IsKeyDown(Keys.A)) { player.movementIntent.X = -.7f; player.isWalking = true; } if (keyBoardState.IsKeyDown(Keys.D)) { player.movementIntent.X = .7f; player.isWalking = true; } if (keyBoardState.IsKeyDown(Keys.W)) { player.movementIntent.Y = -.7f; player.isWalking = true; } if (keyBoardState.IsKeyDown(Keys.S)) { player.movementIntent.Y = .7f; player.isWalking = true; } } if (keyBoardState.IsKeyUp(Keys.A) && keyBoardState.IsKeyUp(Keys.D)) { player.movementIntent.X = 0; } if (keyBoardState.IsKeyUp(Keys.W) && keyBoardState.IsKeyUp(Keys.S)) { player.movementIntent.Y = 0; } if (keyBoardState.IsKeyDown(Keys.F)) { //Follow follow = new Follow(badGuy.behaviorList, badGuy, player, world); //if (!badGuy.behaviorList.has(follow)) // badGuy.behaviorList.pushFront(follow); } if (keyBoardState.IsKeyDown(Keys.E)) { //Wander wander = new Wander(badGuy.behaviorList, badGuy, world, r); //if (!badGuy.behaviorList.has(wander)) // badGuy.behaviorList.pushFront(wander); Point mouseWorldPoint = new Point(curMousePosX + cam.drawSpace.X, curMousePosY + cam.drawSpace.Y); Vector2 playerToMouse = new Vector2(mouseWorldPoint.X - player.body.Center.X, mouseWorldPoint.Y - player.body.Center.Y); float length = playerToMouse.Length(); if (length < worldManager.curWorld.tileSize) { Point mouseTilePos = new Point(mouseWorldPoint.X / worldManager.curWorld.tileSize, mouseWorldPoint.Y / worldManager.curWorld.tileSize); actorManager.handleActorUse(player, mouseTilePos); //LoadNextWorld(); } } if (keyBoardState.IsKeyDown(Keys.G)) { //gameUpdate = LoadWorldUpdate; //gameDraw = LoadWorldDraw; Console.WriteLine("shit"); //isLoadingWorld = true; //LoadNextWorld(); //Thread thread = new Thread(new ThreadStart(LoadNextWorld)); //thread.IsBackground = true; //thread.Start(); } if (mouseState.LeftButton == ButtonState.Pressed) { Punch punchAnimation = new Punch(player.animationList, player); if (!player.animationList.has(punchAnimation)) player.animationList.pushFront(punchAnimation); } }
public override void Execute(Actor player) { Punch punchAnimation = new Punch(player.animationList, player); if (!player.animationList.has(punchAnimation)) player.animationList.pushFront(punchAnimation); }