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

  • Home
  • SEARCH
  • 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 6858369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:09:00+00:00 2026-05-27T02:09:00+00:00

i am developing a space invader game, and i am new to this game

  • 0

i am developing a space invader game, and i am new to this game programming thing.

i need the invaders to move from left to right.

i have 4 rows of pictureboxes,10 invaders per row.

the problem i am having is that only 1 of the rows are moving.

please help!

Thank you

private void Form1_Load(object sender, EventArgs e)
    {
        Cursor.Dispose();

        objsp.gsImage = Image.FromFile(@"C:\Users\kuven\Desktop\SpaceInvader\SpaceInvader\Space Shooter.png");
        objsp.gsImage = Resized(objsp.gsImage, 2);

        objsp.gsPos = new Point(660, 650);


        Cursor.Hide();


        Cursor.Position = new Point(660 + objsp.gsImage.Width / 2, 650 + objsp.gsImage.Height / 2);
        Cursor.Clip = new Rectangle(this.Location, this.Size);

        objsp.invader = new PictureBox[invaderrow,invadercol];

        for(int r = 0; r <= invaderrow-1; r++)
        {
            for( int c = 0; c<=invadercol-1; c++)
            {
                objsp.invader[r,c] = new PictureBox();
                objsp.invader[r,c].Image= pictureBox2.Image;
                objsp.invader[r,c].Image = Resized(pictureBox2.Image, 2);
                objsp.invader[r,c].BackColor = Color.Transparent;
                objsp.invader[r,c].Location= new Point((c * 100) + 10, 10 + r * 50);
                this.Controls.Add(objsp.invader[r,c]);
            }
        }
        invadermove.Enabled = true;

    }

//moving invaders

private void invadermove_Tick(object sender, EventArgs e)
    {
        for (int r = 0; r <= invaderrow-1 ; r++)
        {
            for (int c = 0; c <= invadercol - 1; c++)
            {
                if (level == 0)
                    dir = "r";
                if (objsp.invader[r,9].Left >= ClientSize.Width)
                    dir = "l";

                if (dir == "r")
                {
                    if (c < 9)
                    {
                        objsp.invader[r,c].Location = new Point(objsp.invader[r,c].Left + 10, level * 5 + 25);
                    }

                    if (c > 8)
                    {
                        objsp.invader[r,c].Location = new Point(objsp.invader[r,c].Left + 10, level * 5 + 61);
                        if (objsp.invader[r,9].Left >= ClientSize.Width)
                        {
                            level += 1;
                        }
                    }
                }

                if (dir == "l")
                {
                    if (c < 9)
                    {
                        objsp.invader[r,c].Location = new Point(objsp.invader[r,c].Left - 10, level * 5 + 25);
                    }

                    if (c > 8)
                    {
                        objsp.invader[r,c].Location = new Point(objsp.invader[r,c].Left - 10, level * 5 + 61);
                        if (objsp.invader[r,0].Left <=0)
                        {
                            dir = "r";
                            level += 1;
                        }
                    }
                }
            }
        }
    }
  • 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-05-27T02:09:00+00:00Added an answer on May 27, 2026 at 2:09 am
    for(int r = 0; r <= invaderrow-1; r++)
        {
            for( int c = 0; c<=invadercol-1; c++)
            {
                objsp.invader[c] = new PictureBox();
                objsp.invader[c].Image= pictureBox2.Image;
                objsp.invader[c].Image = Resized(pictureBox2.Image, 2);
                objsp.invader[c].BackColor = Color.Transparent;
                objsp.invader[c].Location= new Point((c * 100) + 10, 10 + r * 50);
                this.Controls.Add(objsp.invader[c]);
            }
        }
    

    Here you are creating invaderrow times invadercol count invaders, I assume 4 and 10 respectively, but storing only in an invadercol sized array, so each iteration of the outer for loop will override the result of the previous iteration. So you won’t have the references for the previous ones, only the new ones, that’s why the move method only moves those for which you have the reference.
    You should use maybe a 2-dimension array (objsp.invader[r,c] (corrected according to kendfrey’s comment)) or something similar.

    Then in your move method make sure, to move all of the PictureBox instances.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am developing a space invader game which has a mouse_move event. it works
Developing a project of mine I realize I have a need for some level
I am developing a space shooter game with customizable ships. You can increase the
I'm developing a 3-column website using a layout like this: <div id='left' style='left: 0;
I`m developing this application that need to read every key stroke while the application
I am developing an android application where i need to determine the free space
I'm developing a ASP.NET MVC application. There is little space for me to put
Developing a C# .NET 2.0 WinForm Application. Need the application to close and restart
I am using C language and Linux as my programming platform. I am developing
I'm developing some sort of air mouse application for iPhone platform. This applications connects

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.