/// <summary> /// +Y /// | /// -X ---+---- +X /// | /// -Y /// </summary> private void UpdateLookDirection() { var currentPosition = new Vector2(transform.position.x, transform.position.y); var direction = currentPosition - _lastFramePosition; var newWatchDirection = CalculateWatchDirection(direction); var newIdle = _playerMovement.enabled ? _playerMovement.IsIdle() : !aiPath.enabled; _lastFramePosition = currentPosition; if (_watchDirection != newWatchDirection || _idle != newIdle) { _watchDirection = newWatchDirection; _idle = newIdle; _animator.SetBool("Idle", _idle); _animator.SetTrigger(_watchDirection.ToString()); Debug.Log($"{_watchDirection} {_idle}"); } }
public override void Update() { if (Healthpoints <= 0) { MessageBox.Show("Game Over!: You died"); } else { if (StaticKeyboard.IsKeyDown(Keys.W) && _currentWalkDir == WalkDirection.None) { _currentWalkDir = WalkDirection.Jump; } if (StaticKeyboard.IsKeyDown(Keys.A)) { _currentWalkDir = WalkDirection.Left; _watchDir = WatchDirection.Left; _DeltaJumpHeight = 0; } if (StaticKeyboard.IsKeyDown(Keys.D)) { _currentWalkDir = WalkDirection.Right; _watchDir = WatchDirection.Right; _DeltaJumpHeight = 0; } // Gravity if (_hitbox.Y < Hitbox.Y + StaticDisplay.DisplayHeight / 2) { _hitbox.Y += Gravity * (float)StaticDisplay.FixedDelta; } // Animation on Jumping if (_currentWalkDir == WalkDirection.Jump) { Gravity = 12; if (_DeltaJumpHeight < maxJumpHeight) { _DeltaJumpHeight += 25 * (int)StaticDisplay.FixedDelta; _hitbox.Y -= 25 * (float)StaticDisplay.FixedDelta; } else if (_hitbox.Bottom >= StaticDisplay.DisplayHeight - 70 || IsCollision()) { _DeltaJumpHeight = 0; _currentWalkDir = WalkDirection.None; return; } } // Animation when running to the right if (_currentWalkDir == WalkDirection.Right) { if (_DeltaWalk < maxWalkWidth) { Textures.MobBitmaps.TryGetValue("HumanRightWalk", out Bitmap bitmap); { CurrentTexture = bitmap; } _DeltaWalk += 7 * (int)StaticDisplay.FixedDelta; _hitbox.X += 7 * (int)StaticDisplay.FixedDelta; } else { Textures.MobBitmaps.TryGetValue("HumanRight", out Bitmap bitmap); { CurrentTexture = bitmap; } _DeltaWalk = 0; _currentWalkDir = WalkDirection.None; } } // Animation when running to the left if (_currentWalkDir == WalkDirection.Left) { if (_DeltaWalk < maxWalkWidth) { Textures.MobBitmaps.TryGetValue("HumanLeftWalk", out Bitmap bitmap); { CurrentTexture = bitmap; } _DeltaWalk += 7 * (int)StaticDisplay.FixedDelta; _hitbox.X -= 7 * (int)StaticDisplay.FixedDelta; } else { Textures.MobBitmaps.TryGetValue("HumanLeft", out Bitmap bitmap); { CurrentTexture = bitmap; } _DeltaWalk = 0; _currentWalkDir = WalkDirection.None; } } } }