public void moveTo(Vector2 targ) { EBounds.moveX((int)targ.X - Bounds.X); EBounds.moveY((int)targ.Y - Bounds.Y); }
public override void update(TimeSpan elapsed) { if (SlatedToRemove) { return; } // ### Tick updates Moved = false; tElapsed = elapsed; freeMoveForward = false; if (attackDelay > 0) { attackDelay -= elapsed.Milliseconds; } if (showHpTicks > 0) { showHpTicks -= elapsed.Milliseconds; } // ### Update entity State isOnFloor = Map.isRectOnFloor(EBounds, facing, this); if (!Alive) { if (State == EntityState.Dead) { return; } else if (State != EntityState.Dying) { die(); } else if (!isOnFloor) { EBounds.moveY(2); } else { setState(EntityState.Dead); dropItems(); } return; } // ### Update movement State based on movement if (msVel.X != 0 && State != EntityState.Jumping) { setState(EntityState.Moving); if (msVel.X < 0) { facing = Direction.Left; } else { facing = Direction.Right; } } else if (State == EntityState.Moving) // If State still 'Moving' but not moving, change State { setState(EntityState.Standing); } // ### Update X position int currXSpeed = (int)(getRealXSpeed() * speedMultiplier); if (attackDelay > ATTACK_DELAY_MS * 0.625f && speedMultiplier > 0.25f) // If attacked recently while jumping, move slower { speedMultiplier *= 0.93f; } else if (speedMultiplier < MAX_SPEED) { speedMultiplier += 0.033f; } else { speedMultiplier = MAX_SPEED; // Don't overshoot } Moved = moveXWithVelocity(currXSpeed); // ### Update Y Position if (State == EntityState.Jumping) // Gravity { msVel.Y -= GRAVITY_PER_MS; } else if (jumpDelay > 0) // Tick jump delay { jumpDelay -= elapsed.Milliseconds; } // Subtract so everything else doesn't have to be switched (0 is top) EBounds.moveY((int)-getRealYSpeed()); if (Bounds.Top >= Map.getPixelHeight() - Bounds.Height / 2) { EBounds.moveY((int)getRealYSpeed()); // Undo the move fallWithGravity(); } else if (Bounds.Bottom <= 0) { EBounds.moveY((int)getRealYSpeed()); // Undo the move hitGround(); } else if (getRealYSpeed() > 0) { int newY = Map.checkBoundsYUp(Bounds, facing); if (newY != Bounds.Y) // Hit something { EBounds.moveY(newY - Bounds.Y); // Move down correct amount (+) fallWithGravity(); } } else if (getRealYSpeed() < 0) { int newY = Map.checkBoundsYDown(Bounds, facing); if (newY != Bounds.Y) // Hit something { EBounds.moveY(newY - Bounds.Y); // Move up correct amount (-) hitGround(); } } // ### Run the entities customizable AI if (aiEnabled()) { AI.run(); } }
public override void update(TileMap map, TimeSpan elapsed) { if (SlatedToRemove) { return; } tElapsed = elapsed; isOnFloor = map.isRectOnFloor(EBounds.StandRect); if (attackDelay > 0) { attackDelay -= elapsed.Milliseconds; } if (showHpTicks > 0) { showHpTicks -= elapsed.Milliseconds; } // ### Update entity State if (!Alive) { DidMove = false; if (State == EntityState.Dead) { return; } else if (State != EntityState.Dying) { die(); } else if (!isOnFloor) { EBounds.moveY(2); } else { setState(EntityState.Dead); dropItems(); } return; } isOnFloor = map.isRectOnFloor(EBounds.StandRect); // ### Run the entities customizable AI if (ai != null) { ai(this, map); } else { runAI(map); } // ### Update movement State based on movement if (msVel.X != 0 && State != EntityState.Jumping) { setState(EntityState.Moving); if (msVel.X < 0) { facing = Direction.Left; } else { facing = Direction.Right; } } else if (State == EntityState.Moving) // If State still 'Moving' but not moving, change State { setState(EntityState.Standing); } // ### Update X position int currXSpeed = (int)(getRealXSpeed() * speedMultiplier); if (attackDelay > ATTACK_DELAY_MS * 0.625f && speedMultiplier > 0.25f) // If attacked recently while jumping, move slower { speedMultiplier *= 0.93f; } else if (speedMultiplier < MAX_SPEED) { speedMultiplier += 0.033f; } else { speedMultiplier = MAX_SPEED; // Don't overshoot } int oldX = EBounds.X; EBounds.moveX(currXSpeed); if (bounds.Right > map.getPixelWidth()) { EBounds.moveX((map.getPixelWidth() - bounds.Width) - bounds.X); // msVel.X = 0; } else if (bounds.Left <= 0) { EBounds.moveX(-bounds.X); // msVel.X = 0; } else if (msVel.X > 0) { int newX = map.checkBoundsXRight(bounds.Rect); updateBoundsX(map, newX); } else if (msVel.X < 0) { int newX = map.checkBoundsXLeft(bounds.Rect); updateBoundsX(map, newX); } if (oldX != EBounds.X) { DidMove = true; } else { DidMove = false; } // ### Update Y Position if (State == EntityState.Jumping) // Gravity { msVel.Y -= GRAVITY_PER_MS; } else if (jumpDelay > 0) // Tick jump delay { jumpDelay -= elapsed.Milliseconds; } // Subtract so everything else doesn't have to be switched (0 is top) EBounds.moveY((int)-getRealYSpeed()); if (bounds.Top >= map.getPixelHeight() - bounds.Height / 2) { EBounds.moveY((int)getRealYSpeed()); // Undo the move fallWithGravity(); } else if (bounds.Bottom <= 0) { EBounds.moveY((int)getRealYSpeed()); // Undo the move hitGround(); } else if (getRealYSpeed() > 0) { int newY = map.checkBoundsYUp(bounds.Rect); if (newY != bounds.Y) // Hit something { EBounds.moveY(newY - bounds.Y); // Move down correct amount (+) fallWithGravity(); } } else if (getRealYSpeed() < 0) { int newY = map.checkBoundsYDown(bounds.Rect); if (newY != bounds.Y) // Hit something { EBounds.moveY(newY - bounds.Y); // Move up correct amount (-) hitGround(); } } }