我在玩游戏2D时遇到问题
现在到现在为止我做了: 创建播放器+地图+键盘+鼠标 现在我正在与玩家和地图进行碰撞
如果玩家通过一个或多个具有该代码的块
,我会尝试using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using System.Windows.Forms;
class UpdateCollision
{
Player myPlayer;
Map myMap;
public void Initialize(Player myPlayer, Map myMap)
{
this.myPlayer = myPlayer;
this.myMap = myMap;
}
public void Update(GameTime gameTime)
{
// Use the Rectangle's built-in intersect function to
// determine if two objects are overlapping
Rectangle Player;
Rectangle Block;
// Only create the rectangle once for the player
Player = new Rectangle((int)myPlayer.Position.X,
(int)myPlayer.Position.Y,
myPlayer.Width,
myPlayer.Height);
// Do the collision between the player and the Block
int i, j;
// For each block in the game
for (i = 0; i < myMap.Height / myMap.pictureSize; i++)
{
for (j = 0; j < myMap.Width / myMap.pictureSize; j++)
{
// If the block is Draw
if(myMap.Blocks[i, j].isAlive)
{
Block = new Rectangle((int)myMap.Blocks[i, j].X,
(int)myMap.Blocks[i, j].Y,
myMap.pictureSize,
myMap.pictureSize);
// Determine if the two objects collided with each
// other
if (Player.Intersects(Block))
{
MessageBox.Show(myMap.Blocks[i, j].X+ ","+myMap.Blocks[i, j].Y);
}
}
}
}
}
public void Draw (SpriteBatch spriteBatch)
{
}
}
即使很难
也永远不会进入消息框会议图像
答案 0 :(得分:2)
@ Pierre-Luc Pineault谢谢你 我玩了那个
我的错误是Blocks类中的错误 我将Y设置为X,将X设置为Y,所以现在它都很难过了
谢谢