hey.

I am trying to add a menuscreen to my game using the enumeration method.

I get 4 errors:

No overload for method 'UpdateMenu' takes '0' arguments (at L: 161 C: 25)
No overload for method 'UpdatePlay' takes '0' arguments (at L: 166 C: 25)
No overload for method 'DrawMenu' takes '0' arguments (at L: 212 C: 25)
No overload for method 'DrawPlay' takes '0' arguments (at L: 217 C: 25)
"L" as in line
"C" as in column

My Code:

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace UFO
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        Texture2D backgroundTexture;
        Texture2D mTitleScreenBackground;
        enum ScreenState
        {
            Title,
            Play
        }
        ScreenState mCurrentScreen;
        Rectangle viewportRect;
        GameObject cannon;
        const int maxCannonBalls = 3;
        GameObject[] cannonBalls;
        KeyboardState previousKeyboardState = Keyboard.GetState();
        private int maxEnemies = 3;
        GameObject[] enemies;
        const float maxEnemyHeight = 0.1f;
        const float minEnemyHeight = 0.5f;
        const float maxEnemyVelocity = 5.0f;
        const float minEnemyVelocity = 1.0f;
        Random random = new Random();
        int score;
        SpriteFont font;
        Vector2 scoreDrawPoint = new Vector2(0.1f, 0.1f);
        float interval = 1000f / 25f;
        int frameCount = 16;
        int spriteWidth = 64;
        int spriteHeight = 64;
        Explosion[] explosions;
        AudioEngine audioEngine;
        SoundBank soundbank;
        WaveBank wavebank;



        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }

        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here

            base.Initialize();
        }

        /// <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
            mTitleScreenBackground = Content.Load<Texture2D>("Sprites//titel");
            mCurrentScreen = ScreenState.Title;

            backgroundTexture =
          Content.Load<Texture2D>("Sprites\\background");
            viewportRect = new Rectangle(0, 0,
                            graphics.GraphicsDevice.Viewport.Width,
                            graphics.GraphicsDevice.Viewport.Height);

            cannon = new GameObject(
   Content.Load<Texture2D>("Sprites\\cannon"));
            cannon.position = new Vector2(120,
               graphics.GraphicsDevice.Viewport.Height - 80);

            cannonBalls = new GameObject[maxCannonBalls];
            for (int i = 0; i < maxCannonBalls; i++)
            {
                cannonBalls[i] = new
                          GameObject(Content.Load<Texture2D>(
                                "Sprites\\cannonball"));
            }

            enemies = new GameObject[maxEnemies];
            for (int i = 0; i < maxEnemies; i++)
            {
                enemies[i] = new GameObject(
                    Content.Load<Texture2D>("Sprites\\enemy"));
            }
            font = Content.Load<SpriteFont>("Fonts\\GameFont");
            enemies = new GameObject[maxEnemies];
            explosions = new Explosion[maxEnemies];
            for (int i = 0; i < maxEnemies; i++)
            {
                enemies[i] = new GameObject(
                         Content.Load<Texture2D>("Sprites\\enemy"));
                explosions[i] = new Explosion(
                         Content.Load<Texture2D>(
                         "Sprites\\sprite_sheet"));
                
            }
            audioEngine = new
     AudioEngine("Content\\Audio\\audio.xgs");
            wavebank = new WaveBank(audioEngine,
                 "Content\\Audio\\Wave Bank.xwb");
            soundbank = new SoundBank(audioEngine,
                 "Content\\Audio\\Sound Bank.xsb");


        }

        /// <summary>
        /// UnloadContent will be called once per game and is the place to unload
        /// all content.
        /// </summary>
        protected override void UnloadContent()
        {
            // TODO: Unload any non ContentManager content here
        }

        /// <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)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            // TODO: Add your update logic here
            switch (mCurrentScreen)
            {
                case ScreenState.Title:
                    {
                        UpdateMenu();
                        break;
                    }
                case ScreenState.Play:
                    {
                        UpdatePlay();
                        break;
                    }
            }
 

            KeyboardState keyboardState = Keyboard.GetState();
            if (keyboardState.IsKeyDown(Keys.Left))
            {
                cannon.rotation -= 0.1f;
            }
            if (keyboardState.IsKeyDown(Keys.Right))
            {
                cannon.rotation += 0.1f;
            }

            cannon.rotation = MathHelper.Clamp(cannon.rotation, -MathHelper.PiOver2, 0);

            if (keyboardState.IsKeyDown(Keys.Space) &&
            previousKeyboardState.IsKeyUp(Keys.Space))
            {
                FireCannonBall();
            }
            previousKeyboardState = keyboardState;

            UpdateCannonBalls();
            UpdateEnemies();
            UpdateExplosions((float)gameTime.ElapsedGameTime.TotalMilliseconds);

            base.Update(gameTime);
        }

        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            // TODO: Add your drawing code here
            spriteBatch.Begin();
            switch (mCurrentScreen)
            {
                case ScreenState.Title:
                    {
                        DrawMenu();
                        break;
                    }
                case ScreenState.Play:
                    {
                        DrawPlay();
                        break;
                    }
            }

            spriteBatch.Draw(backgroundTexture, viewportRect,
                            Color.White);

            foreach (GameObject ball in cannonBalls)
            {
                if (ball.alive)
                {
                    spriteBatch.Draw(ball.sprite,
                        ball.position, Color.White);
                }
            }

            

            spriteBatch.Draw(cannon.sprite,
                cannon.position,
                null,
                Color.White,
                cannon.rotation,
                cannon.center, 1.0f,
           SpriteEffects.None, 0);

            foreach (GameObject enemy in enemies)
            {
                if (enemy.alive)
                {
                    spriteBatch.Draw(enemy.sprite,
                             enemy.position, Color.White);
                }
            }
            spriteBatch.DrawString(font,
                "Score: " + score.ToString(),
new Vector2(scoreDrawPoint.X * viewportRect.Width,
                 scoreDrawPoint.Y * viewportRect.Height),
            Color.Yellow);

            foreach (Explosion explosion in explosions)
            {
                if (explosion.alive)
                {
                    spriteBatch.Draw(explosion.sprite, explosion.position, explosion.sourceRect, Color.White, 0f, Vector2.Zero, 1.5f, SpriteEffects.None, 0);
                }
            }


            base.Draw(gameTime);
            spriteBatch.End();
        }

        public void FireCannonBall()
        {
            foreach (GameObject ball in cannonBalls)
            {
                if (!ball.alive)
                {
                    ball.alive = true;
                    soundbank.PlayCue("missilelaunch");
                    ball.position = cannon.position -
                         ball.center;
                    ball.velocity = new Vector2(
                        (float)Math.Cos(cannon.rotation),
                        (float)Math.Sin(cannon.rotation)) *
                            5.0f;
                    return;
                }
            }
        }
        public void UpdateCannonBalls()
        {
            foreach (GameObject ball in cannonBalls)
            {
                if (ball.alive)
                {
                    ball.position += ball.velocity;
                    if (!viewportRect.Contains(new Point(
                        (int)ball.position.X,
                        (int)ball.position.Y)))
                    {
                        ball.alive = false;
                        continue;
                    }
                    Rectangle cannonBallRect = new Rectangle(
                           (int)ball.position.X,
                           (int)ball.position.Y,
                           ball.sprite.Width,
                           ball.sprite.Height);

                    foreach (GameObject enemy in enemies)
                    {
                        Rectangle enemyRect = new Rectangle(
                           (int)enemy.position.X,
                           (int)enemy.position.Y,
                           enemy.sprite.Width,
                           enemy.sprite.Height);

                        if (cannonBallRect.Intersects(enemyRect))
                        {
                            ball.alive = false;
                            enemy.alive = false;
                            explosions[1].alive = true;
                            explosions[1].timer = 0; explosions[1].currentFrame = 0;
                            explosions[1].position = enemy.position;
                            score += 1;
                            soundbank.PlayCue("explosion");
                            break;
                        }
                    }
                }
            }
        }
        public void UpdateEnemies()
        {
            foreach (GameObject enemy in enemies)
            {
                if (enemy.alive)
                {
                    enemy.position += enemy.velocity;
                    if (!viewportRect.Contains(new Point(
                        (int)enemy.position.X,
                        (int)enemy.position.Y)))
                    {
                        enemy.alive = false;
                    }
                }
                else
                {
                    enemy.alive = true;
                    enemy.position = new Vector2(
                        viewportRect.Right,
                        MathHelper.Lerp(
                        (float)viewportRect.Height *
                             minEnemyHeight,
                        (float)viewportRect.Height *
                             maxEnemyHeight,
                        (float)random.NextDouble()));
                    enemy.velocity = new Vector2(
                        MathHelper.Lerp(
                        -minEnemyVelocity,
                        -maxEnemyVelocity,
                        (float)random.NextDouble()), 0);
                }

            }
        }
        public void UpdateExplosions(float timertijd)
        {
            foreach (Explosion explosion in explosions)
            {
                if (explosion.alive)
                {
                  
                    explosion.timer += timertijd;
                    if (explosion.timer > interval)
                    {
                        explosion.currentFrame++;
                        if (explosion.currentFrame > frameCount - 1)
                        {
                            explosion.alive = false;
                        }
                        explosion.timer = 0f;
                    }
                    explosion.sourceRect = new
                    Rectangle(explosion.currentFrame * spriteWidth,
                    0, spriteWidth, spriteHeight);
                    

                }
            }
        }
        public void UpdatePlay(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            // TODO: Add your update logic here
            KeyboardState keyboardState = Keyboard.GetState();
            if (keyboardState.IsKeyDown(Keys.Left))
            {
                cannon.rotation -= 0.1f;
            }
            if (keyboardState.IsKeyDown(Keys.Right))
            {
                cannon.rotation += 0.1f;
            }

            cannon.rotation = MathHelper.Clamp(cannon.rotation, -MathHelper.PiOver2, 0);

            if (keyboardState.IsKeyDown(Keys.Space) &&
            previousKeyboardState.IsKeyUp(Keys.Space))
            {
                FireCannonBall();
            }
            previousKeyboardState = keyboardState;

            UpdateCannonBalls();
            UpdateEnemies();
            UpdateExplosions((float)gameTime.ElapsedGameTime.TotalMilliseconds);

            base.Update(gameTime);
        }
        public void UpdateMenu(GameTime gameTime)
        {
            // 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
            {
                if (Keyboard.GetState().IsKeyDown(Keys.A) == true)
                {
                    mCurrentScreen = ScreenState.Play;
                    maxEnemies = 9;
                    return;
                }
            }

            backgroundTexture =
          Content.Load<Texture2D>("Sprites\\background");
            viewportRect = new Rectangle(0, 0,
                            graphics.GraphicsDevice.Viewport.Width,
                            graphics.GraphicsDevice.Viewport.Height);

            cannon = new GameObject(
   Content.Load<Texture2D>("Sprites\\cannon"));
            cannon.position = new Vector2(120,
               graphics.GraphicsDevice.Viewport.Height - 80);

            cannonBalls = new GameObject[maxCannonBalls];
            for (int i = 0; i < maxCannonBalls; i++)
            {
                cannonBalls[i] = new
                          GameObject(Content.Load<Texture2D>(
                                "Sprites\\cannonball"));
            }

            enemies = new GameObject[maxEnemies];
            for (int i = 0; i < maxEnemies; i++)
            {
                enemies[i] = new GameObject(
                    Content.Load<Texture2D>("Sprites\\enemy"));
            }
            font = Content.Load<SpriteFont>("Fonts\\GameFont");
            enemies = new GameObject[maxEnemies];
            explosions = new Explosion[maxEnemies];
            for (int i = 0; i < maxEnemies; i++)
            {
                enemies[i] = new GameObject(
                         Content.Load<Texture2D>("Sprites\\enemy"));
                explosions[i] = new Explosion(
                         Content.Load<Texture2D>(
                         "Sprites\\sprite_sheet"));

            }
            audioEngine = new
     AudioEngine("Content\\Audio\\audio.xgs");
            wavebank = new WaveBank(audioEngine,
                 "Content\\Audio\\Wave Bank.xwb");
            soundbank = new SoundBank(audioEngine,
                 "Content\\Audio\\Sound Bank.xsb");


        }
        public void DrawPlay(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            // TODO: Add your drawing code here
            spriteBatch.Begin();
            spriteBatch.Draw(backgroundTexture, viewportRect,
                            Color.White);

            foreach (GameObject ball in cannonBalls)
            {
                if (ball.alive)
                {
                    spriteBatch.Draw(ball.sprite,
                        ball.position, Color.White);
                }
            }



            spriteBatch.Draw(cannon.sprite,
                cannon.position,
                null,
                Color.White,
                cannon.rotation,
                cannon.center, 1.0f,
           SpriteEffects.None, 0);

            foreach (GameObject enemy in enemies)
            {
                if (enemy.alive)
                {
                    spriteBatch.Draw(enemy.sprite,
                             enemy.position, Color.White);
                }
            }
            spriteBatch.DrawString(font,
                "Score: " + score.ToString(),
new Vector2(scoreDrawPoint.X * viewportRect.Width,
                 scoreDrawPoint.Y * viewportRect.Height),
            Color.Yellow);

            foreach (Explosion explosion in explosions)
            {
                if (explosion.alive)
                {
                    spriteBatch.Draw(explosion.sprite, explosion.position, explosion.sourceRect, Color.White, 0f, Vector2.Zero, 1.5f, SpriteEffects.None, 0);
                }
            }


            base.Draw(gameTime);
            spriteBatch.End();
        }
        public void DrawMenu(GameTime gameTime)
        {
            spriteBatch.Draw(mTitleScreenBackground, Vector2.Zero, Color.White);
        }
            
    }
}

Recommended Answers

All 2 Replies

Well, if you take a look at the method UpdateMenu you find public void UpdateMenu(GameTime gameTime) . Your call to it doesn't pass a gameTime object, thus the error.

The rest of your errors are similar in nature. When a method needs an object, you have to pass that object to them.

hey,

Thanks alot for your help, didn't notice the GameTime. just pasted the methods from another method

thanks again :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.