Exemplo n.º 1
0
        /// <summary>
        /// Load enemies from file.
        /// Loads from "/levels/", you only need to put "level1.xml"
        /// </summary>
        /// <param name="file">file name to load</param>
        public static void LoadEnemies(string file)
        {
            MainScene scene = Program.game.GetScene <MainScene>();

            // Open document
            XmlDocument doc = new XmlDocument();

            doc.Load("levels/" + file);

            // Current enemy position to load
            Vector2 CurPos = new Vector2(scene.PlayPosition.X, scene.PlayPosition.Y);

            foreach (XmlElement node in doc.DocumentElement.ChildNodes)
            {
                // Create new enemy and add to scene
                Enemy enemy = AllEnemies[node.GetAttribute("type")]();
                enemy.Position = CurPos;
                scene.Add(enemy);

                // Set enemy position
                CurPos.X += EnemySize;
                if (CurPos.X > 420)
                {
                    CurPos.X  = scene.PlayPosition.X;
                    CurPos.Y += EnemySize;
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// class used for the player
        /// </summary>
        public Player()
        {
            MainScene scene = Program.game.GetScene <MainScene>();

            // Set position
            SetPosition(new Vector2(scene.PlayPosition.X + scene.PlayWidth.X,
                                    scene.PlayPosition.Y + scene.PlayWidth.Y));

            // Set image
            AddGraphic(playerImage);

            // Add collider
            BoxCollider Collider = new BoxCollider(30, 30, Tags.Player);

            AddCollider(Collider);

            // Initialize bullet
            Image       playerBullet   = new Image("Assets/playerBullet.png");
            BoxCollider bulletCollider = new BoxCollider(playerBullet.Width, playerBullet.Height, Tags.Player);

            bullet            = new Bullet(-6.0f, new Vector2(0, 0), bulletCollider);
            bullet.Visible    = false;
            bullet.Collidable = false;
            bullet.AddGraphic(playerBullet);
            scene.Add(bullet);
        }