System::Void Form1_KeyDown(System::Object^ sender, System::Windows::Forms::KeyEventArgs^ e)
{
static const Int32 movePoints=1;
if((e->Modifiers&(Keys::Alt|Keys::Control|Keys::Shift))==(Keys)0)
{
Point location=panel->Location;
switch(e->KeyCode)
{
case Keys::Up:
location.Y-=movePoints;
if(location.Y<0)
{
location.Y=0;
}
break;
case Keys::Down:
location.Y+=movePoints;
break;
case Keys::Left:
location.X-=movePoints;
if(location.X<0)
{
location.X=0;
}
break;
case Keys::Right:
location.X+=movePoints;
break;
default:
return;
}
panel->Location=location;
}
}
System::Void Form1_KeyDown(System::Object^ sender, System::Windows::Forms::KeyEventArgs^ e)
{
static const Int32 movePoints=1;
if((e->Modifiers&(Keys::Alt|Keys::Control|Keys::Shift))==(Keys)0)
{
Point location=panel->Location;
switch(e->KeyCode)
{
case Keys::Up:
location.Y-=movePoints;
if(location.Y<0)
{
location.Y=0;
}
break;
case Keys::Down:
location.Y+=movePoints;
break;
case Keys::Left:
location.X-=movePoints;
if(location.X<0)
{
location.X=0;
}
break;
case Keys::Right:
location.X+=movePoints;
break;
default:
return;
}
panel->Location=location;
}
}
Vector2 location = Vector2.Zero;
const float distance = 2.0f;
protected override void Update(GameTime gameTime)
{
GamePadState gamePadState=GamePad.GetState(PlayerIndex.One);
KeyboardState keyboardState=Keyboard.GetState();
if (gamePadState.Buttons.Back == ButtonState.Pressed ||
keyboardState.IsKeyDown(Keys.Escape))
{
this.Exit();
}
double gamePadMove = Math.Sqrt(Math.Pow(gamePadState.ThumbSticks.Left.X, 2) +
Math.Pow(gamePadState.ThumbSticks.Left.Y, 2));
if(gamePadMove<0.1)
{
if (keyboardState.IsKeyDown(Keys.Up))
{
location.Y -= distance;
}
if (keyboardState.IsKeyDown(Keys.Down))
{
location.Y += distance;
}
if (keyboardState.IsKeyDown(Keys.Left))
{
location.X -= distance;
}
if (keyboardState.IsKeyDown(Keys.Right))
{
location.X += distance;
}
}
else
{
location.X += gamePadState.ThumbSticks.Left.X * distance;
location.Y -= gamePadState.ThumbSticks.Left.Y * distance;
}
if (location.Y < 0)
{
location.Y = 0;
}
else
{
int bottom = Window.ClientBounds.Height - image.Height;
if(location.Y>bottom)
{
location.Y = bottom;
}
}
if (location.X < 0)
{
location.X = 0;
}
else
{
int right = Window.ClientBounds.Width - image.Width;
if(location.X>right)
{
location.X = right;
}
}
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Deferred, SaveStateMode.None);
spriteBatch.Draw(background, Vector2.Zero, Color.White);
spriteBatch.Draw(image, location, Color.White);
spriteBatch.End();
base.Draw(gameTime);
}
Если Вы уже зарегистрированы на Портале - войдите в систему, если Вы еще не регистрировались - пройдите простую процедуру регистрации.