本文整理汇总了C#中Microsoft.Xna.Framework.Rectangle.Intersects方法的典型用法代码示例。如果您正苦于以下问题:C# Rectangle.Intersects方法的具体用法?C# Rectangle.Intersects怎么用?C# Rectangle.Intersects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Xna.Framework.Rectangle
的用法示例。
在下文中一共展示了Rectangle.Intersects方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Update
public void Update(GameTime gameTime)
{
Pad rightPlayer = PongGame.GameWorld.rightPlayer; //copy by reference
Pad leftPlayer = PongGame.GameWorld.leftPlayer;
//making collision mask
ballRect = new Rectangle((int)(position.X-origin.X), (int)(position.Y-origin.Y), ballTex.Width, ballTex.Height);
//position update
position.X += velocity.X;
position.Y += velocity.Y;
//collision check
if (position.Y - origin.Y < 0 || position.Y + origin.Y > PongGame.GameDimensions.Y)
{
velocity.Y *= -1;
}
if (ballRect.Intersects(rightPlayer.padRect) && (lastIntersectID == 0 || lastIntersectID == -1))
{
velocity.X *= (-1 + (position.Y - (rightPlayer.position.Y + rightPlayer.origin.Y)) * bounceMod);
lastIntersectID = 1;
}
if (ballRect.Intersects(leftPlayer.padRect) && (lastIntersectID == 1 || lastIntersectID == -1))
{
velocity.X *= (-1 + (position.Y - (leftPlayer.position.Y + leftPlayer.origin.Y)) * bounceMod);
lastIntersectID = 0;
}
}
示例2: MouseClicked
public void MouseClicked(int x, int y, ref GameType gameType)
{
mouseClick = new Rectangle(x, y, 10, 10);
if (mouseClick.Intersects(Bouton_Exit))
{
Game1.GetGame().Exit();
}
else if (mouseClick.Intersects(Bouton_Options))
{
gameType = GameType.Menu_Option_Type;
}
else if (mouseClick.Intersects(Bouton_Multi))
{
gameType = GameType.Menu_Play_Multi_Type;
}
else if (mouseClick.Intersects(Bouton_Play))
{
gameType = GameType.Menu_Play_Type;
}
else if (mouseClick.Intersects(Bouton_Solo))
{
gameType = GameType.Menu_Play_Solo_Type;
}
}
示例3: MouseClicked
void MouseClicked(int x, int y, ref GameType gameType)
{
mouseClick = new Rectangle(x, y, 10, 10);
if (mouseClick.Intersects(Bouton_Play))
{
gameType = GameType.Menu_Play_Type;
}
if (mouseClick.Intersects(Bouton_Exit))
{
Game1.GetGame().Exit();
}
if (mouseClick.Intersects(Bouton_Options))
{
gameType = GameType.Menu_Option_Type;
}
if (mouseClick.Intersects(Bouton_Solo))
{
gameType = GameType.Menu_Play_Solo_Type;
}
if (mouseClick.Intersects(host))
{
System.Diagnostics.Process.Start("C:/Users/epita/Desktop/Final/zbra/bin/Debug/zbra.exe");
}
if (mouseClick.Intersects(join))
{
System.Diagnostics.Process.Start("C:/Users/epita/Desktop/Final/Client/bin/Debug/Client.exe");
}
if (mouseClick.Intersects(local))
{
gameType = GameType.Menu_Play_Multi_Type;
}
}
示例4: Mouseclik
public Screen Mouseclik(int x, int y)
{
Rectangle mouserec = new Rectangle(x, y, 10, 10);
if (mouserec.Intersects(level1rect))
{
GlobalVar.texture = "textsable";
GlobalVar.xmlfile = "pets";
GlobalVar.sound = "grassland";
current = Screen.GamePlayScreen;
}
else if (mouserec.Intersects(level2rect))
{
GlobalVar.texture = "textg";
GlobalVar.xmlfile = "Level";
GlobalVar.sound = "grassland";
current = Screen.GamePlayScreen;
}
else if (mouserec.Intersects(level3rect))
{
GlobalVar.texture = "textsable";
GlobalVar.xmlfile = "Level";
GlobalVar.sound = "grassland";
current = Screen.GamePlayScreen;
}
else if (mouserec.Intersects(backbutton))
{
current = Screen.ChooseWorldScreen;
}
return (current);
}
示例5: checkPaddleCollision
public void checkPaddleCollision(Rectangle paddle, SoundEffectInstance soundEngineInstance)
{
Rectangle ballLocation = new Rectangle((int)position.X, (int)position.Y,
sprite.Width, sprite.Height);
if (paddle.Intersects(ballLocation) && !inCollision)
{
inCollision = true;
// La balle émet le son approprié
soundEngineInstance.Volume = 0.75f;
soundEngineInstance.Play();
//Collision avec le top de la palette
if (ballLocation.Intersects(new Rectangle(paddle.X, paddle.Y, paddle.Width, 0)))
{
direction.Y *= -1;
position.Y = paddle.Y - sprite.Height;
float paddleCenter = paddle.X + (paddle.Width/2);
float ballCenter = position.X + sprite.Width/2;
direction.X = (ballCenter - paddleCenter) / (paddle.Width / 2);
direction = Vector2.Normalize(direction);
}
}
else if(!paddle.Intersects(ballLocation))
inCollision = false;
}
示例6: Mouseclik
public Screen Mouseclik(int x, int y)
{
Rectangle mouserec = new Rectangle(x, y, 10, 10);
if (mouserec.Intersects(world1rect))
{
VibrateController vc = VibrateController.Default;
vc.Start(TimeSpan.FromMilliseconds(100));
return (Screen.ChooseLevelScreen);
}
else if (mouserec.Intersects(world2rect))
{
VibrateController vc = VibrateController.Default;
vc.Start(TimeSpan.FromMilliseconds(100));
return (Screen.ChooseLevelScreen2);
}
else if (mouserec.Intersects(world3rect))
{
VibrateController vc = VibrateController.Default;
vc.Start(TimeSpan.FromMilliseconds(100));
return (Screen.ChooseLevelScreen3);
}
else if (mouserec.Intersects(backbuttonw))
{
VibrateController vc = VibrateController.Default;
vc.Start(TimeSpan.FromMilliseconds(100));
return (Screen.StartScreen);
}
return (Screen.ChooseWorldScreen);
}
示例7: MouseClicked
void MouseClicked(int x, int y, ref GameType gametype)
{
mouseClick = new Rectangle(x, y, 10, 10);
if (mouseClick.Intersects(Bouton_Play))
{
gametype = GameType.Menu_Play_Type;
}
else if (mouseClick.Intersects(Bouton_Exit))
{
Game1.GetGame().Exit();
}
else if (mouseClick.Intersects(Bouton_Res))
{
gametype = GameType.Menu_Option_Type;
}
else if (mouseClick.Intersects(Bouton_Full))
{
Game1.GetGame().IsFullScreen = !Game1.GetGame().IsFullScreen;
}
else if (mouseClick.Intersects(Bouton_Sound))
{
SoundEffect.MasterVolume = 1.0f - SoundEffect.MasterVolume;
MediaPlayer.Volume = 1.0f - MediaPlayer.Volume;
}
}
示例8: Mouseclik
public Screen Mouseclik(int x, int y)
{
Rectangle mouserec = new Rectangle(x, y, 10, 10);
if (mouserec.Intersects(world1rect))
{
current = Screen.ChooseLevelScreen;
return (current);
}
else if (mouserec.Intersects(world2rect))
{
current = Screen.ChooseLevelScreen2;
return (current);
}
else if (mouserec.Intersects(world3rect))
{
current = Screen.ChooseLevelScreen3;
return (current);
}
else if (mouserec.Intersects(backbuttonw))
{
current = Screen.StartScreen;
return (current);
}
return (current);
}
示例9: GetCollidingSide
public static Direction GetCollidingSide(Rectangle rectangle)
{
if (!IsCollidingWithSide(rectangle))
{
return Direction.NONE;
}
var left = new Rectangle((int)Position.X - 1, (int)Position.Y, 2, 600);
var right = new Rectangle((int)Position.X + 799, (int)Position.Y, 2, 600);
var top = new Rectangle((int)Position.X, (int)Position.Y - 1, 800, 2);
var bottom = new Rectangle((int)Position.X, (int)Position.Y + 599, 800, 2);
if (rectangle.Intersects(left))
{
return Direction.LEFT;
}
if (rectangle.Intersects(right))
{
return Direction.RIGHT;
}
if (rectangle.Intersects(top))
{
return Direction.UP;
}
if (rectangle.Intersects(bottom))
{
return Direction.DOWN;
}
return Direction.NONE;
}
示例10: MouseClicked
public void MouseClicked(int x, int y, GameMaster sender)
{
Rectangle mouseClickRect = new Rectangle(x, y, 10, 10);
//int resumeWidth = resumeButton.Width / 2;
//int resumeHeight = resumeButton.Height / 2;
Rectangle resumeButtonRect = new Rectangle(screenCenter.X - (resumeButton.Width / 2), 400, resumeButton.Width, resumeButton.Height);
//int quitGameWidth = quitGameButton.Width / 2;
//int quitGameHeight = quitGameButton.Height / 2;
Rectangle quitGameButtonRect = new Rectangle(screenCenter.X - (quitGameButton.Width / 2), 500, quitGameButton.Width, quitGameButton.Height);
if (mouseClickRect.Intersects(resumeButtonRect))
{
sender.gameState = PacManMulti.GameMaster.GameState.Playing;
sender.restart = false;
sender.isPaused = false;
}
else if (mouseClickRect.Intersects(quitGameButtonRect))
{
sender.gameState = PacManMulti.GameMaster.GameState.StartMenu;
sender.restart = true;
sender.isPaused = false;
}
}
示例11: HandleBulletZombieCollision
public void HandleBulletZombieCollision(Player p, EnemyHandler e)
{
foreach (Bullet b in p.bullets)
if (b.Visible)
{
bulletRectangle = new Rectangle((int)b.X, (int)b.Y, 2, 1);
foreach (ZombieDispenser zd in e.zombies)
foreach (Zombie z in zd.zombies)
if (z.Visible)
{
zombieRectangle = new Rectangle((int)(z.X + 18 * z.Scale), (int)(z.Y + 19 * z.Scale), (int)(28 * z.Scale), (int)(45 * z.Scale));
zombieHeadRectangle = new Rectangle((int)(z.X + 18 * z.Scale), (int)(z.Y + 4 * z.Scale), (int)(22 * z.Scale), (int)(15 * z.Scale));
if (bulletRectangle.Intersects(zombieRectangle))
{
z.Hitpoints -= bulletDmg;
b.SprayBlood = true;
b.Visible = false;
}
else if(bulletRectangle.Intersects(zombieHeadRectangle))
{
z.Hitpoints = 0;
p.Score += 5;
b.SprayBlood = true;
b.Visible = false;
}
}
}
}
示例12: UpdateButtons
public void UpdateButtons(GameTime GameTime)
{
bool pressed = Input.MousePressed(MouseButtons.Left);
bool released = Input.MouseReleased(MouseButtons.Left);
Rectangle mouseCurrent = new Rectangle((int)Input.MousePosition.X, (int)Input.MousePosition.Y, 5, 5);
Rectangle mousePrevious = new Rectangle((int)Input.MousePositionPrevious.X, (int)Input.MousePositionPrevious.Y, 5, 5);
foreach (Button button in _Buttons)
{
if (mouseCurrent.Intersects(button.CollisionBox))
{
// Pressed
if (Input.MousePressed(MouseButtons.Left))
button.OnPressed();
// Released
else if (Input.MouseReleased(MouseButtons.Left))
button.OnReleased();
// On Enter
else if (mousePrevious.Intersects(button.CollisionBox) == false)
button.OnEnter();
// On Hover
else
button.OnHover();
}
// On Exit
else if (mousePrevious.Intersects(button.CollisionBox))
{
button.OnExit();
}
}
}
示例13: HasCollisionWithObject
public static bool HasCollisionWithObject(Player player, int targetPositionX, int targetPositionY, Map map, Vector2 mapPosition)
{
Rectangle playerRect = new Rectangle(targetPositionX, targetPositionY, player.Image.Width,
player.Image.Height);
foreach(var mapElement in map.MapElements)
{
var mapElementRect = new Rectangle(mapElement.TopLeftX + (int) mapPosition.X,
mapElement.TopLeftY + (int) mapPosition.Y,
mapElement.Image.Width,
mapElement.Image.Height);
if (playerRect.Intersects(mapElementRect))
{
return true;
}
}
foreach (var mapCreature in map.MapCreatures)
{
var mapCreatureRect = new Rectangle(mapCreature.TopLeftX + (int)mapPosition.X,
mapCreature.TopLeftY + (int)mapPosition.Y,
mapCreature.Image.Width,
mapCreature.Image.Height);
if (playerRect.Intersects(mapCreatureRect))
{
return true;
}
}
return false;
}
示例14: Intersects
public bool Intersects(Rectangle rec)
{
int BoundHeight = (int)EndPos.Y - (int)StartPos.Y;
int BoundWidth =(int)EndPos.X - (int)StartPos.X;
if (rec.Intersects(new Rectangle((int)StartPos.X, (int)StartPos.Y, BoundWidth == 0 ? 1 : BoundWidth, BoundHeight == 0 ? 1 : BoundHeight)))
return true;
return rec.Intersects(new Rectangle((int)StartPos.X, (int)StartPos.Y, BoundWidth == 0 ? 1 : BoundWidth, BoundHeight == 0 ? 1 : BoundHeight));
}
示例15: Update
public void Update()
{
mousePosition = new Vector2(Mouse.GetState().X, Mouse.GetState().Y);
Cursor_Rectangle = new Rectangle(Convert.ToInt32(mousePosition.X + mouseSpeed.X), Convert.ToInt32(mousePosition.Y + mouseSpeed.Y), Cursor_Texture.Width, Cursor_Texture.Height);
if (Cursor_Rectangle.Intersects(Game_Rectangle) && Mouse.GetState().LeftButton == ButtonState.Pressed) { Menu_State = false; Bool_Play = true; Bool_Save = false; Bool_Load = false; }
else if (Cursor_Rectangle.Intersects(Exit_Rectangle) && Mouse.GetState().LeftButton == ButtonState.Pressed) { Exit = true; }
else if (Cursor_Rectangle.Intersects(Save_Rectangle) && Mouse.GetState().LeftButton == ButtonState.Pressed) { Bool_Save = true; Bool_Load = false; Bool_Play = false; }
else if (Cursor_Rectangle.Intersects(Load_Rectangle) && Mouse.GetState().LeftButton == ButtonState.Pressed) { Bool_Load = true; Bool_Save = false; Bool_Play = false; }
}