コード例 #1
0
ファイル: Bouncer.cs プロジェクト: BNHeadrick/Bros
        /**
         * Determines whether or not this bouncer is passable
         *@param brew the brew we have
         *@return true or false
         */
        public bool canPass(Brew brew, int x, int y, int w, int h, int px, int py, int pw, int ph)
        {
            // ensure color is correct
            Console.WriteLine(color + " // " + brew.getColor());
            if (hasColor(brew))
            {
                // ensure path not blocked
                Area area = GameplayManager.ActiveArea;
                int dir = atPathStart ? 1 : -1;
                // check obj at x,y
                switch (getPath(0))
                {
                    case PATH_DOWN:
                        if (py > y && px - pw / 2 < x + w / 2 && px + pw / 2 > x - w / 2)
                        {
                            return false;
                        }
                        break;
                    case PATH_LEFT:
                        if (px > x && py - ph / 2 < y + h / 2 && py + ph / 2 > y - h / 2)
                        {
                            return false;
                        }
                        break;
                    case PATH_RIGHT:
                        if (px < x && py - ph / 2 < y + h / 2 && py + ph / 2 > y - h / 2)
                        {
                            return false;
                        }
                        break;
                    case PATH_UP:
                        if (py < y && px - pw / 2 < x + w / 2 && px + pw / 2 > x - w / 2)
                        {
                            return false;
                        }
                        break;
                }
                for (int i = atPathStart ? 0 : path.Count - 1; atPathStart ? (i < path.Count) : (i >= 0); i += dir)
                {
                    if (path[i] == PATH_UP * dir)
                    {
                        y -= Area.TILE_HEIGHT;
                    }
                    else if (path[i] == PATH_DOWN * dir)
                    {
                        y += Area.TILE_HEIGHT;
                    }
                    else if (path[i] == PATH_LEFT * dir)
                    {
                        x -= Area.TILE_WIDTH;
                    }
                    else if (path[i] == PATH_RIGHT * dir)
                    {
                        x += Area.TILE_WIDTH;
                    }

                    // check obj at x,y
                    if (area.objectAt(x, y, w, Area.TILE_HEIGHT-2, false))
                    {
                        return false;
                    }
                }
            }
            else
            {
                return false;
            }
            return true;
        }
コード例 #2
0
ファイル: Bouncer.cs プロジェクト: BNHeadrick/Bros
 /**
  * Determines if we have the color
  *@param
  *@return
  */
 public bool hasColor(Brew brew)
 {
     for (int i = 1; i <= color; i <<= 1)
     {
         if ((i & color) != 0 && (i & brew.getColor()) == 0)
         {
             return false;
         }
     }
     return true;
 }