IsVisible() public method

public IsVisible ( ) : bool
return bool
Beispiel #1
0
 public void EatFood(uint index)
 {
     if (index < numPlayers)
     {
         Player p = player[index];
         if (p.IsVisible())
         {
             p.EatFood();
         }
     }
 }
Beispiel #2
0
        public Direction GetDirectionOfNearestPlayer(uint x, uint y)
        {
            uint bestX        = 0;
            uint bestY        = 0;
            uint bestDistance = 10000;

            for (uint i = 0; i < numPlayers; i++)
            {
                Player pP = player[i];
                if (pP.IsVisible())
                {
                    uint distance = (uint)(Math.Abs((int)pP.x - (int)x) + Math.Abs((int)pP.y - (int)y));
                    if (distance < bestDistance)
                    {
                        bestDistance = distance;
                        bestX        = pP.x;
                        bestY        = pP.y;
                    }
                }
            }
            if (bestDistance == 10000)
            {
                return(Direction.kDirNone);
            }
            int  dx       = (int)(bestX - x);
            int  dy       = (int)(bestY - y);
            byte bitField = 0;

            if (dy > 0)
            {
                bitField |= 8;
            }
            else if (dy < 0)
            {
                bitField |= 4;
            }
            if (dx > 0)
            {
                bitField |= 2;
            }
            else if (dx < 0)
            {
                bitField |= 1;
            }

            //     7 0 1
            //     6 + 2
            //     5 4 3


            return((Direction)kDirTable[bitField]);
        }
Beispiel #3
0
        public void GetCOG(ref float x, ref float y)
        {
            x = 0.0f;
            y = 0.0f;
            int liveCount = 0;

            for (uint i = 0; i < numPlayers; i++)
            {
                Player pP = player[i];
                if (pP.IsVisible())
                {
                    x += pP.x;
                    y += pP.y;
                    ++liveCount;
                }
            }
            if (liveCount > 0)
            {
                x /= liveCount;
                y /= liveCount;
            }
        }
Beispiel #4
0
        public void Move(uint stick, Direction dir)
        {
            if (stick < 4 && dir < (Direction)8)
            {
                if (stick < numPlayers)
                {
                    Player p = player[stick];
                    p.dir = dir;
                    TimeSpan delta = time - p.lastMoveTime;
                    if (p.IsVisible() && delta.Milliseconds >= kMsPerMove)
                    {
                        p.lastMoveTime = time;
                        byte x = p.x;
                        byte y = p.y;
                        MoveCoords(ref x, ref y, dir);
                        MapData d     = map.Get(x, y);
                        bool    bMove = false;
                        switch (d)
                        {
                        case MapData.kSpace:
                            bMove = true;
                            break;

                        case MapData.kLock:
                            if (p.keys > 0)
                            {
                                --p.keys;
                                map.OpenLock(x, y);
                                bMove = true;
                            }
                            break;

                        case MapData.kKey:
                            ++p.keys;
                            bMove = true;
                            break;

                        case MapData.kFood:
                            ++p.food;
                            bMove = true;
                            break;

                        case MapData.kMoney:
                            p.score += 10;
                            bMove    = true;
                            break;

                        case MapData.kBomb:
                            ++p.bombs;
                            bMove = true;
                            break;

                        case MapData.kDown:
                        {
                            p.state = PlayerState.kInWarp;
                            map.Set(p.x, p.y, MapData.kSpace);
                            if (IsPartyInWarp())
                            {
                                ChangeLevel(1);
                            }
                        }
                        break;

                        default:
                            break;
                        }
                        if (bMove)
                        {
                            map.Set(p.x, p.y, MapData.kSpace);
                            map.Set(x, y, (MapData)((int)MapData.kPlayer0 + stick));
                            p.x = x;
                            p.y = y;
                        }
                    }
                }
            }
            else
            {
                Debug.MyDebugBreak();
            }
        }