矩形问题包含方法

问题描述

| 我建立了一个太空侵略者游戏,问题是击中灵敏度太敏感了。这是我跟踪玩家是否被击中的方式。
 bool playersWasShot=false;
 foreach (var shotsInvader in Invadershots)
 {    // below is the Area representing the image size. and the location of the invaders shot
      if(playership.Area.Contains(shotsInvader.Location))
      {
           //player was shot game over.
           playersWasShot=true;
           break;
      }
 }
PlayerShip类的area属性:
// move simply updates the position of the ship on the x-axis as i move the ship.
// as you can guess. the second variable represents the size of the picture

Area =new Rectangle(new Point(move,900),Properties.Resources.player.Size); 
Shots类中的Shot Location属性将随着镜头移动到 播放器
// the shot,travels to the player on the y-axis only
Location=new Point(Location.X,invaderShotLocation);
当游戏结束时,我检查了调试器。.这就是我得到的: 这行:
if(playership.Area.Contains(shotsInvader.Location))
{
//i put a debugging point inside this if statment!!!
}
代表船上的信息:
player Area {X=90,Y=900,Width=54,Height=33}
Location    {X=60,Y=900}
代表拍摄的侵略者信息:
Location {X=140,Y=900}
射门甚至没有进入玩家的飞船内。
        public static Bitmap SHIP = Properties.Resources.player;
    public Point Location;
    public int move=10;
    public Rectangle Area { set { } get { return new Rectangle(new Point(move,Properties.Resources.player.Size); } }

    public void Draw(Graphics g)
    {
这些是控制所有运动和绘制的舰船类中的2种方法
        if (game.Alive) //checks if the player is alive.
        {
             // draws the SHIP picture. 900 is a fixed field..thats where the ship is
             // it is on the y axis that never changes.. x-axis do change..depending
          // on where i move the ship to.
                 g.DrawImage(SHIP,move,900); 
                Location = new Point(move,900); 
        }
        else
        {

            g.DrawImage(SHIP,900,SHIP.Width,SHIP.Height);
            Location = new Point(move,900);
        }
    }



    public void Move(Direction d)
    {

        switch (d)
        {
//当我按下指示向左或向右移动的箭头时,会传递一个枚举                 case Direction.LEFT:移动-= 10;打破;                 方向:右移+ = 10;打破;             }             Area = new Rectangle(new Point(move,900),SHIP.Size);         } 注意=当玩家在打击侵略者时应用相同的逻辑,并且仅在射击时提示侵略者消失 在Shot类中发现错误。球员和侵略者的射门分享: ..我发现了错误。那是铅球课。我现在修改它。问题已经解决     

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)