Esempio n. 1
0
 public Parser(Game1 game)
 {
     this.game = game;
     blockFactory = new BlockFactory(game);
     itemFactory = new ItemFactory(game);
     enemyFactory = new EnemyFactory(game);
     latestCheckpoint = new List<Vector2>();
 }
Esempio n. 2
0
 public Sprite(Scene scene, Vector2 position, Texture2D texture, Rectangle sourceRect, int timePerFrame, int numberOfFrames, bool isAnimated)
 {
     this.scene = scene;
        this.isAnimated = isAnimated;
        this.numberOfFrames = numberOfFrames;
        this.position = position;
        this.texture = texture;
        this.timePerFrame = timePerFrame;
        this.sourceRect = sourceRect;
        this.origin.X = 0;
        this.origin.Y = 0;
        Velocity = new Vector2(0, 0);
        blockFactory = new BlockFactory(scene.Game);
        itemFactory = new ItemFactory(scene.Game);
        enemyFactory = new EnemyFactory(scene.Game);
        this.sounds = new SoundMachine(scene.Game);
       // frameWidth = sourceRect.Width / numberOfFrames;
        frameWidth = 16;
        collisionBox = new CollisionBox(position.X, position.Y, 32, SourceRect.Height*2);
 }
Esempio n. 3
0
        public void AddingEntity(StreamReader reader)
        {
            var    line   = reader.ReadLine();
            var    values = line.Split(',');
            Tile   tile   = new Tile();
            string n      = values[0];
            int    x      = Convert.ToInt32(values[1]);
            int    y      = Convert.ToInt32(values[2]);

            tile.Position = Grid.Position(x, y);
            string itemName = "";
            string pipeName = "";
            int    itemNum  = 0;

            if (values.Length > 3 && !string.IsNullOrEmpty(values[3]))
            {
                itemName = values[3];
                itemNum  = Convert.ToInt32(values[4]);
            }
            if (values.Length > 7 && !string.IsNullOrEmpty(values[7]))
            {
                pipeName      = values[5];
                _pipePosition = new Vector2(Convert.ToInt32(values[6]), Convert.ToInt32(values[7]));
            }
            else if (values.Length > 5 && !string.IsNullOrEmpty(values[5]))
            {
                pipeName      = values[3];
                _pipePosition = new Vector2(Convert.ToInt32(values[4]), Convert.ToInt32(values[5]));
            }

            if (n.Equals("Mario"))
            {
                Mario = new MarioEntity(tile.Position, Sounds);
                movingEntities.Add(Mario);
            }
            else if (n.Equals("EnemyPipe"))
            {
                tile.Entity = new EnemyPipeEntity(tile.Position, tiles, movingEntities);
            }
            else if (n.Equals("Pole"))
            {
                tile.Entity = FlagFactory.BuildSprite(tile.Position);
            }
            else if (n.Equals("Boo"))
            {
                tile.Entity = BooFactory.BuildSprite(Mario, tile.Position);
            }
            else if (Enum.TryParse(n, out ItemCreation.ItemType itemType))
            {
                tile.Entity = ItemCreation.BuildItemEntity(itemType, tile.Position, Sounds);
            }
            else if (Enum.TryParse(n, out EnemyFactory.EnemyType enemyType))
            {
                tile.Entity = EnemyFactory.BuildEnemySprite(enemyType, tile.Position, Mario);
                movingEntities.Add(tile.Entity);
            }
            else if (Enum.TryParse(n, out BlockCreation.SceneBlock sceneBlock))
            {
                tile.Entity = BlockCreation.BuildSceneBlock(sceneBlock, tile.Position);
            }
            else if (Enum.TryParse(n, out BlockCreation.Blocks blockType))
            {
                tile.Entity = BlockCreation.BuildBlockEntity(blockType, tile.Position, Sounds);
                if ((tile.Entity is QuestionBlockEntity || tile.Entity is BrickBlockEntity) &&
                    (Enum.TryParse(itemName, out ItemCreation.ItemType item)))   //adding item to question block entity
                {
                    for (int i = 0; i < itemNum; i++)
                    {
                        Entity one = ItemCreation.BuildItemEntity(item, tile.Position, Sounds);
                        tile.Entity.AddItem(one, tiles, movingEntities, Mario);
                    }
                }
                else if (tile.Entity is BridgeBlockEntity && Enum.TryParse(itemName, out ItemCreation.ItemType axe))
                {
                    Entity _axe   = ItemCreation.BuildItemEntity(axe, new Vector2(tile.Position.X + 32, tile.Position.Y - 64), Sounds);
                    Tile   theAxe = new Tile {
                        Entity = _axe
                    };
                    tiles.Add(theAxe);
                    (tile.Entity as BridgeBlockEntity).AxeLink(_axe as AxeEntity);
                    for (int i = 0; i < itemNum; i++)//adding bridge blocks
                    {
                        Entity one = BlockCreation.BuildBlockEntity(BlockCreation.Blocks.BridgeBlock, new Vector2(tile.Position.X - i * 32, tile.Position.Y), Sounds);
                        (one as BridgeBlockEntity).AxeLink(_axe as AxeEntity);
                        tile.Entity.AddItem(one, tiles, movingEntities, Mario);
                    }
                }
                else if (tile.Entity is PipeBlockEntity && Enum.TryParse(itemName, out EnemyFactory.EnemyType enemy) && Enum.TryParse(pipeName, out BlockCreation.Blocks block))
                {
                    Entity plant = EnemyFactory.BuildEnemySprite(enemy, tile.Position, Mario);
                    tile.Entity.AddItem(plant, tiles, movingEntities, Mario);
                    _first        = tile.Entity as PipeBlockEntity;
                    _pipePosition = Grid.Position((int)_pipePosition.X, (int)_pipePosition.Y);
                    Entity second = BlockCreation.BuildBlockEntity(block, _pipePosition, Sounds);
                    Tile   two    = new Tile {
                        Entity = second
                    };
                    _first.SetWarpDestination(second as PipeBlockEntity, Mario);
                    tiles.Add(two);
                    Grid.AddtoGrid(second);
                }
                else if (tile.Entity is PipeBlockEntity && Enum.TryParse(pipeName, out BlockCreation.Blocks pipe))
                {
                    _first        = tile.Entity as PipeBlockEntity;
                    _pipePosition = Grid.Position((int)_pipePosition.X, (int)_pipePosition.Y);
                    Entity second = BlockCreation.BuildBlockEntity(pipe, _pipePosition, Sounds);
                    Tile   two    = new Tile {
                        Entity = second
                    };
                    _first.SetWarpDestination(second as PipeBlockEntity, Mario);
                    tiles.Add(two);
                    Grid.AddtoGrid(second);
                }
            }

            if (tile.Entity != null)
            {
                tiles.Add(tile);
                //Grid.AddtoGrid(tile.Entity);
            }
        }
Esempio n. 4
0
        public void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.

            screenHeight = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height;
            screenWidth = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width;
            backgroundTexture = game.Content.Load<Texture2D>("SMSearlysky");

            reader = XmlReader.Create("map.xml");

            sprites = new List<Sprite>();

            spriteBatch = new SpriteBatch(game.GraphicsDevice);
            blockFactory = new BlockFactory(game);
            itemFactory = new ItemFactory(game);
            enemyFactory = new EnemyFactory(game);
            Parse(reader);

            keyboardCont = new KeyboardController(game, mario);
            gamePadCont = new GamePadController(game, mario);
            collision = new Collision(mario, this);
            MakeFloor();
            // TODO: use this.Content to load your game content here
        }