Beispiel #1
0
        // Gets an instance of explosion instead of just the texture. This gives me more options and freedom,
        //   aslong as the variables etc. are public in the class Explosion.
        public Vector2 getVisualCoords(Vector2 logicalCoords, Explosion explosion)
        {
            // (explosion.frameWidth / 2) and (explosion.frameHeight / 2) makes the explosion to be drawn from it's center, not the upper-left corner.
            float visualX = (logicalCoords.X * scaleX) - (explosion.frameWidth / 2);
            float visualY = (logicalCoords.Y * scaleY) - (explosion.frameHeight / 2);

            return new Vector2(visualX, visualY);
        }
        /// <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);

            // TODO: use this.Content to load your game content here
            explosionTexture = Content.Load<Texture2D>("explosion.png");
            camera = new Camera(graphics.GraphicsDevice.Viewport);
            explosion = new Explosion(explosionTexture, camera);
        }
        /// <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();

            // TODO: Add your update logic here
            if (Keyboard.GetState().IsKeyDown(Keys.E))
            {
                explosion = new Explosion(explosionTexture, camera);
            }

            base.Update(gameTime);
        }