Пример #1
0
        /// <summary>
        /// Loads in barricades
        /// </summary>
        static void InitializeBarricades()
        {
            // Open XML document
            XmlDocument doc = new XmlDocument();

            doc.Load("barricades.xml");

            // Loop through each node to spawn barricade

            foreach (XmlElement node in doc.DocumentElement.ChildNodes)
            {
                // Spawn 4 barricades
                for (int i = 0; i < 4; i++)
                {
                    Barricade barricade = new Barricade();

                    barricade.Position = new Vector2(Convert.ToSingle(node.GetAttribute("posx")) + i * 200, Convert.ToSingle(node.GetAttribute("posy")));

                    Program.game.GetScene <MainScene>().Add(barricade);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Check if bullet collides with barricade.
        /// </summary>
        /// <param name="scene">scene</param>
        void CheckBarricade(MainScene scene)
        {
            Barricade barricade = (Barricade)Collider.CollideEntity(X, Y, Tags.Barricade);

            if (barricade != null)
            {
                // Check if player bullet hits barricade
                if (Collider.Tags[0] == (int)Tags.Player)
                {
                    barricade.TakeDamage();
                    Visible    = false;
                    Collidable = false;
                }

                // Check if enemy bullet hits barricade
                else
                {
                    barricade.TakeDamage();
                    RemoveSelf();
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Called to initialize the game
        /// Note: must be added to Game.FirstScene before calling
        /// </summary>
        public void Initialize()
        {
            OnBegin = delegate
            {
                Enemy.Initialize();
                Barricade.Initialize();
                MainScene scene = Program.game.GetScene <MainScene>();

                Ufo = new UFO();

                Program.game.GetScene <MainScene>().Add(Ufo);

                // Create player and add to scene
                player = new Player();
                Add(player);
                // Gametext for the entire game pretty much
                #region gameText

                var background = new Image("Assets/background.png");
                background.Alpha = 0.4f;
                scene.AddGraphic(background);

                //Setting a default config file for the RichText to use
                var txtConfig = new RichTextConfig()
                {
                    TextAlign = TextAlign.Center,
                    CharColor = Color.Green,
                    FontSize  = 18,
                    SineAmpX  = 1,
                    SineAmpY  = 2,
                    SineRateX = 1,
                    Font      = new Font("Assets/VCR_OSD_MONO.ttf"),
                };
                // Writing the text graphics and setting position
                var livesLeftTxtLabel = new RichText("Lives", txtConfig);
                livesLeftTxtLabel.SetPosition(50, 16);

                scene.livesLeftTxt      = new RichText(scene.player.playerLives.ToString(), txtConfig);
                scene.livesLeftTxt.Name = "livesLeftTxt";
                scene.livesLeftTxt.SetPosition(70, 32);

                var highScoreTxtLabel = new RichText("Highscore", txtConfig);
                highScoreTxtLabel.SetPosition(350, 15);

                highScoreTxt      = new RichText(ReadXML.MainScreenXML(), txtConfig);
                highScoreTxt.Name = "highScoreTxt";
                highScoreTxt.SetPosition(380, 30);

                var curScoreTxtLabel = new RichText("Score", txtConfig);
                curScoreTxtLabel.SetPosition(650, 15);

                scene.curScoreTxt      = new RichText(scene.player.ScoreAmount.ToString(), txtConfig);
                scene.curScoreTxt.Name = "curScoreTxt";
                scene.curScoreTxt.SetPosition(670, 32);
                // Adds Graphic to Scene
                scene.AddGraphic(livesLeftTxtLabel);
                scene.AddGraphic(highScoreTxtLabel);
                scene.AddGraphic(curScoreTxtLabel);

                scene.AddGraphic(scene.livesLeftTxt);
                scene.AddGraphic(scene.highScoreTxt);
                scene.AddGraphic(scene.curScoreTxt);

                #endregion gameText
            };
        }