Esempio n. 1
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            ButtonLegend.Initialize(Content);
            RucksackInterface.Initialize(Content);

            // Build random map
            Palette p = Content.Load<Palette>(@"palette\00001");
            Map map = new Map(p, 160, 90);

            players = new List<Player>();

            int numPlayers = (GamePad.GetState(PlayerIndex.One).IsConnected ? 1 : 0) +
                (GamePad.GetState(PlayerIndex.Two).IsConnected ? 1 : 0) +
                (GamePad.GetState(PlayerIndex.Three).IsConnected ? 1 : 0) +
                (GamePad.GetState(PlayerIndex.Four).IsConnected ? 1 : 0);

            Rectangle view;
            switch (numPlayers) {
                case 1:
                    view = new Rectangle(0, 0, graphics.PreferredBackBufferWidth,
                        graphics.PreferredBackBufferHeight);
                    break;
                case 2:
                    view = new Rectangle(0, 0, graphics.PreferredBackBufferWidth / 2,
                        graphics.PreferredBackBufferHeight);
                    break;
                case 3:
                case 4:
                    view = new Rectangle(0, 0, graphics.PreferredBackBufferWidth / 2,
                        graphics.PreferredBackBufferHeight / 2);
                    break;
                default:
                    view = default(Rectangle);
                    break;
            }

            // Always add player 1
            players.Add(new Player(
                PlayerIndex.One,
                new View(view, 0, 0),
                new Entity(Content.Load<EntityGraphics>(@"entity\00000"), map, 15, 15)
            ));

            // Conditionally add more players
            if (GamePad.GetState(PlayerIndex.Two).IsConnected)
                players.Add(new Player(
                    PlayerIndex.Two,
                    new View(view, view.Width, 0),
                    new Entity(Content.Load<EntityGraphics>(@"entity\00001"), map, 15, 20)
                ));
            if (GamePad.GetState(PlayerIndex.Three).IsConnected)
                players.Add(new Player(
                    PlayerIndex.Three,
                    new View(view, 0, view.Height),
                    new Entity(Content.Load<EntityGraphics>(@"entity\00002"), map, 20, 5)
                ));
            if (GamePad.GetState(PlayerIndex.Four).IsConnected)
                players.Add(new Player(
                    PlayerIndex.Four,
                    new View(view, view.Width, view.Height),
                    new Entity(Content.Load<EntityGraphics>(@"entity\00003"), map, 20, 20)
                ));
            base.Initialize();
        }
Esempio n. 2
0
 public static Tile[] getNearbyTiles(Map m, int i, int j, int layer)
 {
     Tile[] nearby = new Tile[9];
     int count = 0;
     for (int y = j - 1; y <= j + 1; ++y) {
         for (int x = i - 1; x <= i + 1; ++x) {
             if (x >= 0 && y >= 0 && x < m.width && y < m.height)
                 nearby[count] = m.tiles[x, y, layer];
             else
                 nearby[count] = m.tiles[i, j, layer];
             ++count;
         }
     }
     return nearby;
 }