public MergingIterator(IComparator comparator, IList<IIterator> children) { if (children == null) throw new ArgumentNullException("children"); this.comparator = comparator; this.children = children; direction = Direction.Forward; current = null; }
public void SeekToLast() { AssertNotDisposed(); foreach (var iterator in children) { iterator.SeekToLast(); } FindLargest(); direction = Direction.Reverse; }
public void SeekToFirst() { AssertNotDisposed(); foreach (var iterator in children) { iterator.SeekToFirst(); } FindSmallest(); direction = Direction.Forward; }
Vector2 speed; // Speed of player #endregion Fields #region Constructors public Player() { playerTexture = Ressources.player; playerHitboxTexture = Ressources.playerHitbox; playerHitbox = Collision.CollisionMapSprite(playerHitboxTexture); position.X = Settings.Current.StartPositionX; position.Y = Settings.Current.StartPositionY; playerSize.X = Settings.Current.SpriteWidth; playerSize.Y = Settings.Current.SpriteHeight; maxSpeed = Settings.Current.MaxSpeed; speed.X = 0; speed.Y = 0; maxAcceleration = Settings.Current.Acceleration; acceleration.X = 0; acceleration.Y = 0; drawingRectangle = new Rectangle((int)position.X, (int)position.Y, playerSize.X, playerSize.Y); frameLine = 0; frameRow = 0; direction = Direction.Down; animationTimer = 0; animationSpeed = Settings.Current.AnimationSpeed; }
/** * Ustawia odpowiedni kierunek w układzie współrzędnych po wykonaniu rotacji. */ private static void SetDirection(Direction RotationDir) { switch (Dir) { case Direction.North: if (RotationDir == Direction.West) { Dir = Direction.West; } else if (RotationDir == Direction.East) { Dir = Direction.East; } break; case Direction.South: if (RotationDir == Direction.West) { Dir = Direction.East; } else if (RotationDir == Direction.East) { Dir = Direction.West; } break; case Direction.West: if (RotationDir == Direction.West) { Dir = Direction.South; } else if (RotationDir == Direction.East) { Dir = Direction.North; } break; case Direction.East: if (RotationDir == Direction.West) { Dir = Direction.North; } else if (RotationDir == Direction.East) { Dir = Direction.South; } break; } }
//Update & Draw public void Update(MouseState mouse, KeyboardState keyboard, GamePadState gamePadState) { if ((keyboard.IsKeyDown(Keys.Up) && keyboard.IsKeyUp(Keys.Down)) || gamePadState.IsButtonDown(Buttons.DPadUp)) { direction = Direction.Up; acceleration.Y = -maxAcceleration; } if ((keyboard.IsKeyDown(Keys.Down) && keyboard.IsKeyUp(Keys.Up)) || gamePadState.IsButtonDown(Buttons.DPadDown)) { direction = Direction.Down; acceleration.Y = maxAcceleration; } if ((keyboard.IsKeyDown(Keys.Left) && keyboard.IsKeyUp(Keys.Right)) || gamePadState.IsButtonDown(Buttons.DPadLeft)) { direction = Direction.Left; acceleration.X = -maxAcceleration; } if ((keyboard.IsKeyDown(Keys.Right) && keyboard.IsKeyUp(Keys.Left)) || gamePadState.IsButtonDown(Buttons.DPadRight)) { direction = Direction.Right; acceleration.X = maxAcceleration; } if (keyboard.IsKeyUp(Keys.Up) && keyboard.IsKeyUp(Keys.Down) && gamePadState.IsButtonUp(Buttons.DPadUp) && gamePadState.IsButtonUp(Buttons.DPadDown)) { if (speed.Y < -maxAcceleration) acceleration.Y = maxAcceleration; else if (speed.Y > maxAcceleration) acceleration.Y = -maxAcceleration; else { acceleration.Y = 0; speed.Y = 0; } } if (keyboard.IsKeyUp(Keys.Left) && keyboard.IsKeyUp(Keys.Right) && gamePadState.IsButtonUp(Buttons.DPadLeft) && gamePadState.IsButtonUp(Buttons.DPadRight)) { if (speed.X < -maxAcceleration) acceleration.X = maxAcceleration; else if (speed.X > maxAcceleration) acceleration.X = -maxAcceleration; else { acceleration.X = 0; speed.X = 0; } } Move(); if (animateOnce) { animationTimer++; animateOnce = false; } if (keyboard.IsKeyUp(Keys.Up) && keyboard.IsKeyUp(Keys.Down) && keyboard.IsKeyUp(Keys.Left) && keyboard.IsKeyUp(Keys.Right) && gamePadState.IsButtonUp(Buttons.DPadUp) && gamePadState.IsButtonUp(Buttons.DPadDown) && gamePadState.IsButtonUp(Buttons.DPadLeft) && gamePadState.IsButtonUp(Buttons.DPadRight)) { animationTimer = 0; frameLine = 0; } drawingRectangle.X = (int)position.X; drawingRectangle.Y = (int)position.Y; switch (direction) { case Direction.Up: frameRow = 2; break; case Direction.Down: frameRow = 0; break; case Direction.Left: frameRow = 1; break; case Direction.Right: frameRow = 3; break; } }
public void Next() { AssertNotDisposed(); Debug.Assert(IsValid); // Ensure that all children are positioned after key(). // If we are moving in the forward direction, it is already // true for all of the non-current_ children since current_ is // the smallest child and key() == current_->key(). Otherwise, // we explicitly position the non-current_ children. if (direction != Direction.Forward) { foreach (var child in children) { if (child == current) continue; child.Seek(Key); if (child.IsValid && comparator.Compare(Key, child.Key) == 0) { child.Next(); } } direction = Direction.Forward; } current.Next(); FindSmallest(); }
public void Prev() { AssertNotDisposed(); Debug.Assert(IsValid); // Ensure that all children are positioned before key(). // If we are moving in the reverse direction, it is already // true for all of the non-current_ children since current_ is // the largest child and key() == current_->key(). Otherwise, // we explicitly position the non-current_ children. if (direction != Direction.Reverse) { foreach (var child in children) { if (child == current) continue; child.Seek(Key); if (child.IsValid) { // Child is at first entry >= key(). Step back one to be < key() child.Prev(); } else { // Child has no entries >= key(). Position at last entry. child.SeekToLast(); } } direction = Direction.Reverse; } current.Prev(); FindLargest(); }
public static VolumeData Convolve1D( VolumeData data, Direction direction ) { VolumeData temp = new VolumeData( data.Width, data.Height, data.Depth ); temp.Height = data.Height; temp.Width = data.Width; temp.Depth = data.Depth; int kernelSize = 5; double[] kernel1D = { 0.0833333333333333, -0.666666666666667, 0, 0.666666666666667, -0.0833333333333333 }; short[] doubleIndexes = { -2, -1, 0, +1, +2 }; // check the odd size of kernel1D int _depth = data.Depth; int _width = data.Width; int _height = data.Height; switch ( direction ) { case Direction.Horizontal: unsafe { //for ( int i = kernelSize / 2 + 1; i < ( data.Width - ( kernelSize / 2 + 1 ) ) - 2; i++ ) for ( int k = 0; k < _depth; k++ ) for ( int i = 0; i < _width; i++ ) for ( int j = 0; j < _height; j++ ) { double sum = 0.0; for ( int m = 0; m < kernelSize; m++ ) { // try // { int indexes = i + doubleIndexes[m]; if ( indexes <= 0 ) indexes = Math.Abs( indexes ); if ( indexes >= _width ) indexes = _width - 1; //-( indexes - data.Width ); //double a = data.Volume[ i + m, j, k ]; double a = data[indexes, j, k]; double b = kernel1D[m]; sum += a*b; //temp[ i, j, k ] += data[ indexes, j, k ] * kernel1D[ m ]; //} //catch ( Exception e ) //{ // int a = 5; //} } // testing direct access temp[i, j, k] = sum; } } break; } return temp; }