Пример #1
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            //Laddar in spelaren
            player = new Player(Content.Load <Texture2D>("xwing"), Content.Load <Texture2D>("bullet4"), new Vector2((int)PlayerStartPos.X, (int)PlayerStartPos.Y), new Rectangle(300, 700, 50, 50));

            //Laddar in fiendetexturerna
            EnemyListClass.bulletTexture = Content.Load <Texture2D>("bullet4");
            EnemyListClass.enemyTexture  = Content.Load <Texture2D>("xwingRotated");
            EnemyListClass.StartTimer();

            //Laddar in item-texturer
            ItemListClass.lifeTexture        = Content.Load <Texture2D>("heart3");
            ItemListClass.multiBulletTexture = Content.Load <Texture2D>("star2");
            ItemListClass.shieldTexture      = Content.Load <Texture2D>("shield");
            ItemListClass.StartTimer();

            //Laddar in värden för poängräknaren
            Points.pointsPosition    = new Vector2(660, 50);
            Points.highScorePosition = new Vector2(660, 70);
            Points.font = Content.Load <SpriteFont>("Text");
            Points.ReadHighScore();

            //Position och typsnitt för Livräknaren
            Lives.position = new Vector2(660, 30);
            Lives.font     = Content.Load <SpriteFont>("Text");

            // TODO: use this.Content to load your game content here
        }
Пример #2
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            //Uppdaterar spelaren, fienderna och itemsen
            player.Update();

            EnemyListClass.Update();
            ItemListClass.Update();

            //Tar bort fiende och skadar spelaren om en fiende kolliderar med spelaren
            foreach (EnemyClass element in EnemyListClass.enemyList)
            {
                element.Update();

                if (element.Rectangle.Intersects(player.Rectangle))
                {
                    element.Die();
                    player.Damage();

                    if (Lives.lives <= 0)
                    {
                        Points.WriteHighScore();
                        Exit();
                    }
                }
            }

            //Lägger till item i item-kön om den kolliderar med spelaren
            foreach (Item element in ItemListClass.itemList)
            {
                element.Update();

                if (element.Rectangle.Intersects(player.Rectangle))
                {
                    element.Remove();
                    ItemListClass.AddItem(element);
                }
            }

            //Om ett skott kolliderar med en fiende dödas fienden
            foreach (Bullet element in player.BulletList)
            {
                element.Update();

                foreach (EnemyClass enemyElement in EnemyListClass.enemyList)
                {
                    if (element.Rectangle.Intersects(enemyElement.Rectangle))
                    {
                        element.Damage();
                        enemyElement.Damage();
                        player.AddPoint();
                        EnemyListClass.DecreaseSpawnTime();
                    }
                }
            }

            //Fiendens skott skadar spelaren
            foreach (Bullet element in Enemy3.BulletList)
            {
                element.Update();

                if (element.Rectangle.Intersects(player.Rectangle))
                {
                    element.Damage();
                    player.Damage();

                    if (Lives.lives <= 0)
                    {
                        Points.WriteHighScore();
                        Exit();
                    }
                }
            }


            // TODO: Add your update logic here

            base.Update(gameTime);
        }