Exemple #1
0
        /// <summary>
        /// Generates the map from texture and layout input.
        /// </summary>
        /// <param name="textureNames">A list of textures that correspond to a layout.</param>
        /// <param name="tempLayout">The layout of the map.</param>
        private void GenerateMap(List<string> textureNames, List<List<int>> tempLayout)
        {
            // Load all the textures into the game that are needed by map
            List<Texture2D> textures = new List<Texture2D>();
            foreach (string tex in textureNames)
                textures.Add(game.Content.Load<Texture2D>(tex));

            // Add entities to the map as needed from reading the layout
            for(int y = 0; y < tempLayout.Count(); y++)
            {
                for(int x = 0; x < tempLayout[y].Count(); x++)
                {
                    switch(tempLayout[y][x])
                    {
                        case 0:
                            break;
                        case 1:
                            // Add a block
                            map[y,x] = new Block(game, spriteBatch, textures[tempLayout[y][x]-1],
                                new Rectangle((x*blockWidth), (hudBuffer+(y*blockHeight)), blockWidth, blockHeight));
                            break;
                        case 2:
                            // Add a blue moveable block
                            map[y,x] = new MoveableBlock(game, spriteBatch, textures[tempLayout[y][x]-1],
                                new Rectangle((x*blockWidth), (hudBuffer+(y*blockHeight)), blockWidth, blockHeight),
                                Color.Blue);
                            break;
                        case 3:
                            // Add a red moveable block
                            map[y, x] = new MoveableBlock(game, spriteBatch, textures[tempLayout[y][x] - 1],
                                new Rectangle((x * blockWidth), (hudBuffer + (y * blockHeight)), blockWidth, blockHeight),
                                Color.Red);
                            break;
                        case 4:
                            // Add red matter
                            map[y, x] = new Matter(game, spriteBatch, null,
                                new Rectangle((x * blockWidth), (hudBuffer + (y * blockHeight)), blockWidth, blockHeight),
                                Color.Red);
                            break;
                        case 5:
                            // Add blue matter
                            map[y, x] = new Matter(game, spriteBatch, null,
                                new Rectangle((x * blockWidth), (hudBuffer + (y * blockHeight)), blockWidth, blockHeight),
                                Color.Blue);
                            break;
                        case 8:
                            // Add the exit
                            exit = new Exit(game, spriteBatch, null,
                                new Rectangle((x * blockWidth), (hudBuffer + (y * blockHeight)), blockWidth, blockHeight));
                            break;
                        case 9:
                            // Add the player
                            player = new Player(game, spriteBatch,
                                new Rectangle((x * blockWidth), (hudBuffer + (y * blockHeight)), blockWidth, blockHeight),
                                this);
                            break;
                    }
                }
            }
        }
Exemple #2
0
 /// <summary>
 /// Applies a movement to a moveable block.
 /// </summary>
 /// <param name="target">The moveable block to be moved.</param>
 /// <param name="move">The movement.</param>
 /// <param name="origin">The origin.</param>
 /// <param name="color">The color of the block.</param>
 private void ApplyPush(MoveableBlock target, Movement move, Vector2 origin, Color color)
 {
     ((MoveableBlock)target).Move(move);
     if(color == Color.Red)
         HUD.DecreaseRedMatter();
     else if (color == Color.Blue)
         HUD.DecreaseBlueMatter();
     map[(int)origin.Y, (int)origin.X] = null;
     Vector2 dest = GridIndexOf(new Vector2(move.End.X, move.End.Y));
     map[(int)dest.Y, (int)dest.X] = target;
     GenerateLightning(move.Direction, new Vector2(move.Start.X, move.Start.Y), color);
     SoundMixer.Instance(game).PlayShoot(false);
 }