All pastes #982057 Raw Edit

Unnamed

public text v1 · immutable
·published 2008-04-12 07:22 UTC
rendered paste body
public override void Update( GameTime gameTime ) {
            kbs = Keyboard.GetState();
            Vector2 old = Position;
            bool c_up = false;
            bool c_left = false;
            bool c_down = false;
            bool c_right = false;
            //bool collision = false;
            foreach ( BlockManager.block bs in b.blocks ) {
                if ( bs.Rect.Intersects( new Rectangle( ( int ) Position.X - 1, ( int ) Position.Y - 1, 34, 34 ) ) ) {
                    
                    if ( bs.Rect.Intersects( new Rectangle( ( int ) Position.X, ( int ) Position.Y - 1, 32, 32 ) ) )
                        c_up = true;
                    if ( bs.Rect.Intersects( new Rectangle( ( int ) Position.X, ( int ) Position.Y + 1, 32, 32 ) ) )
                        c_down = true;
                    if ( bs.Rect.Intersects( new Rectangle( ( int ) Position.X - 1, ( int ) Position.Y, 32, 32 ) ) )
                        c_left = true;
                    if ( bs.Rect.Intersects( new Rectangle( ( int ) Position.X + 1, ( int ) Position.Y, 32, 32 ) ) )
                        c_right = true;
                }
            }

            if ( kbs.IsKeyDown( Keys.Up ) && !c_up ) {
                Position.Y -= speed;
            }
            if ( kbs.IsKeyDown( Keys.Down ) && !c_down ) {
                Position.Y += speed;
            }
            if ( kbs.IsKeyDown( Keys.Left ) && !c_left ) {
                Position.X -= speed;
            }
            if ( kbs.IsKeyDown( Keys.Right ) && !c_right ) {
                Position.X += speed;
            }

            base.Update( gameTime );
        }
    }