Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8752721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:17:22+00:00 2026-06-13T13:17:22+00:00

I get this error message in the Draw method of the Map class. What

  • 0

I get this error message in the Draw method of the Map class. What is wrong?
I want to draw the bullets which I create in the Enemy class.
Cannot implicitly convert type ‘WindowsGame24.Bullet’ to ‘WindowsGame24.Enemy’

public class Map
{
    Texture2D myEnemy, myBullet ;
    Player Player;
    List<Enemy> enemieslist = new List<Enemy>();
    List<Bullet> bulletslist = new List<Bullet>();     

    float fNextEnemy = 0.0f;
    float fEnemyFreq = 3.0f;
    int fMaxEnemy = 3 ;

    Vector2 Startposition = new Vector2(200, 200);

    GraphicsDeviceManager graphicsDevice; 

    public Map(GraphicsDeviceManager device) 
    { 
        graphicsDevice = device;
    } 

    public void Load(ContentManager content)
    {
    myEnemy = content.Load<Texture2D>("enemy");
    myBullet = content.Load<Texture2D>("bullet");
    Player = new Player(graphicsDevice);
    Player.Load(content);
    }

    public void Update(GameTime gameTime)
    {
        Player.Update(gameTime);
        float delta = (float)gameTime.ElapsedGameTime.TotalSeconds;

         for(int i = enemieslist.Count - 1; i >= 0; i--) 
        {
        // Update Enemy
        Enemy enemy = enemieslist[i];
        enemy.Update(gameTime, this.graphicsDevice, Player.playershape.Position, delta);
        // Try to remove an enemy
        if (enemy.Remove == true)
        {
            enemieslist.Remove(enemy);
            enemy.Remove = false;
        }
        }

        this.fNextEnemy += delta;
        //New enemy
        if (fMaxEnemy > 0)
        {
        if ((this.fNextEnemy >= fEnemyFreq) && (enemieslist.Count < 3))
        {
            Vector2 enemyDirection = Vector2.Normalize(Player.playershape.Position - Startposition) * 100f;
            enemieslist.Add(new Enemy(Startposition, enemyDirection, Player.playershape.Position));
            fMaxEnemy -= 1;
            fNextEnemy -= fEnemyFreq;
        }
        }

  }

    public void Draw(SpriteBatch batch)
    {
    Player.Draw(batch);
    for (int i = enemieslist.Count - 1; i >= 0; i--) 
        {
            Enemy enemy = enemieslist[i];
            enemy.Draw(batch, myEnemy);
        }
     Enemy bullets;
     for (int i = bullets.bulletslist.Count - 1; i >= 0; i--)
        {
            Enemy bullet = bullets.bulletslist[i];
            bullet.Draw(batch, myBullet);
        } 
    }         
}

public class Enemy
{
    public List<Bullet> bulletslist = new List<Bullet>();

    private float nextShot = 0;
    private float shotFrequency = 2.0f;  
    Vector2 vPos;
    Vector2 vMove;
    Vector2 vPlayer;
    public bool Remove;
    public bool Shot;

    public Enemy(Vector2 Pos, Vector2 Move, Vector2 Player)
    {
        this.vPos = Pos;
        this.vMove = Move;
        this.vPlayer = Player;
        this.Remove = false;
        this.Shot = false;
    }

    public void Update(GameTime gameTime, GraphicsDeviceManager graphics, Vector2 PlayerPos, float delta)
    {           
        nextShot += delta;

        for (int i = bulletslist.Count - 1; i >= 0; i--)
        {
            // Update Bullet
            Bullet bullets = bulletslist[i];
            bullets.Update(gameTime, graphics, delta);

            // Try to remove a bullet... Collision, hit, or outside screen.
            if (bullets.Remove == true)
            {
                bulletslist.Remove(bullets);
                bullets.Remove = false;
            }
        }

        if (nextShot >= shotFrequency)
        {
            this.Shot = true;
            nextShot -= shotFrequency;
        }

        // Does the enemy shot?
        if ((Shot == true) && (bulletslist.Count < 1))
        // New bullet
        {
            Vector2 bulletDirection = Vector2.Normalize(PlayerPos - this.vPos) * 200f;
            bulletslist.Add(new Bullet(this.vPos, bulletDirection, PlayerPos));
            Shot = false;
        }


        if (!Remove)
        {
            this.vMove = Vector2.Normalize(PlayerPos - this.vPos) * 100f;
            this.vPos += this.vMove * delta;

            if (this.vPos.X > graphics.PreferredBackBufferWidth + 1)
            {
                this.Remove = true;
            }

            else if (this.vPos.X < -20)
            {
                this.Remove = true;
            }

            if (this.vPos.Y > graphics.PreferredBackBufferHeight + 1)
            {
                this.Remove = true;
            }

            else if (this.vPos.Y < -20)
            {
                this.Remove = true;
            }
        }
    }

    public void Draw(SpriteBatch batch, Texture2D myTexture)
    {
        if (!Remove)
        {
            batch.Draw(myTexture, this.vPos, Color.White);
        }           
    }
}

public class Bullet
{
    Vector2 vPos;
    Vector2 vMove;
    Vector2 vPlayer;
    public bool Remove;

    public Bullet(Vector2 Pos, Vector2 Move, Vector2 Player)
    {
        this.Remove = false;
        this.vPos = Pos;
        this.vMove = Move;
        this.vPlayer = Player;
    }


    public void Update(GameTime gameTime, GraphicsDeviceManager graphics, float delta)
    {
            if (!Remove)
            {
                this.vPos += this.vMove * delta;                  

                if (this.vPos.X > graphics.PreferredBackBufferWidth +1)
                {
                    this.Remove = true;
                }

                else if (this.vPos.X < -20)
                {
                    this.Remove = true;
                }

                if (this.vPos.Y > graphics.PreferredBackBufferHeight +1)
                {
                    this.Remove = true;
                }

                else if (this.vPos.Y < -20)
                {
                    this.Remove = true;
                }
            }         
    }

    public void Draw(SpriteBatch spriteBatch, Texture2D myTexture)
    {
        if (!Remove)
        {
            spriteBatch.Draw(myTexture, this.vPos, Color.White);
        }
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T13:17:23+00:00Added an answer on June 13, 2026 at 1:17 pm
    Enemy bullet = bullets.bulletslist[i];
    

    Your bullets are Enemy now?

    You are assigning a Bullet object into a Enemy variable.

    Shouldn’t it be :

    Bullet bullet = bullets.bulletslist[i];
    

    EDIT: Oh, for Christ sake! Now, why you put the bullets in the enemy class, I just don’t know.

    for (int i = enemieslist.Count - 1; i >= 0; i--) 
    {
        Enemy enemy = enemieslist[i];
        enemy.Draw(batch, myEnemy);
    
        for (int i = enemy.bulletslist.Count - 1; i >= 0; i--)
        {
            Enemy bullet = enemy.bulletslist[i];
            bullet.Draw(batch, myBullet);
        } 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I get this error message pageContext cannot be resolved but I have no variable
I get this error message when running rake db:create Could not find gem 'sqlite3
I get this error message on my server: Method 'GetVirtualPath' in type 'System.Web.Http.WebHost.Routing.HostedHttpRoute' from
I get this error message in LogCat: 06-25 15:17:34.495: E/AndroidRuntime(5891): java.lang.RuntimeException: Unable to start
I get this error message in Eclipse: Access restriction: The type DirectoryWalker is not
I get this error message from a Ghostscript call: Error: /syntaxerror in -file- Operand
I get this error in my app { error: { message: Missing client_id parameter.,
Why do I get this error message with this code? Use of undeclared identifier
I'm using websphere and Java EE and get this error message: Exception reading propertiesfile
When invoking a query on the data service I get this error message inside

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.