6 Replies - 520 Views - Last Post: 20 November 2008 - 12:48 PM Rate Topic: -----

#1 yowutup11  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 59
  • Joined: 07-March 08

Multiple pictureboxes moving SIMULTANEOUSLY

Posted 19 November 2008 - 10:49 AM

Hello. So I am doing a project for my C# programming class and I am making a version of Space Invaders. I have everything I need in the game except the movement by the enemy ships. The point of the movement is simple. All ships move at same time from left to right until the edge ships hit the edge of the form. Then it drops a level and moves from right to left etc etc etc until the ships reach the bottom for a game over.

I have put in code for movement of the ships but they dont move in unison but the first ship moves then the second ship moves then the third so on and so on. I have no sample of the code because I have already deleted it off my program but it was very lengthy and did not work as I had planned.

Any help on the topic is appreciated. Thank you in advance


Edit: heres a sample of a thing that sort of works but after a few moves it says the program does not respond and shuts down.

 public void DownMovement()
		{
			picEnemy1.Location = new Point(picEnemy1.Location.X, picEnemy1.Location.Y + 20);
			picEnemy2.Location = new Point(picEnemy2.Location.X, picEnemy2.Location.Y + 20);
			picEnemy3.Location = new Point(picEnemy3.Location.X, picEnemy3.Location.Y + 20);
			picEnemy4.Location = new Point(picEnemy4.Location.X, picEnemy4.Location.Y + 20);
			picEnemy5.Location = new Point(picEnemy5.Location.X, picEnemy5.Location.Y + 20);
			picEnemy6.Location = new Point(picEnemy6.Location.X, picEnemy6.Location.Y + 20);
			picEnemy7.Location = new Point(picEnemy7.Location.X, picEnemy7.Location.Y + 20);
			picEnemy8.Location = new Point(picEnemy8.Location.X, picEnemy8.Location.Y + 20);
			picEnemy9.Location = new Point(picEnemy9.Location.X, picEnemy9.Location.Y + 20);
			picEnemy10.Location = new Point(picEnemy10.Location.X, picEnemy10.Location.Y + 20);
			picEnemy11.Location = new Point(picEnemy11.Location.X, picEnemy11.Location.Y + 20);
			picEnemy12.Location = new Point(picEnemy12.Location.X, picEnemy12.Location.Y + 20);
			picEnemy13.Location = new Point(picEnemy13.Location.X, picEnemy13.Location.Y + 20);
			picEnemy14.Location = new Point(picEnemy14.Location.X, picEnemy14.Location.Y + 20);
			picEnemy15.Location = new Point(picEnemy15.Location.X, picEnemy15.Location.Y + 20);
			picEnemy16.Location = new Point(picEnemy16.Location.X, picEnemy16.Location.Y + 20);
			picEnemy17.Location = new Point(picEnemy17.Location.X, picEnemy17.Location.Y + 20);
			picEnemy18.Location = new Point(picEnemy18.Location.X, picEnemy18.Location.Y + 20);
			picEnemy19.Location = new Point(picEnemy19.Location.X, picEnemy19.Location.Y + 20);
			picEnemy20.Location = new Point(picEnemy20.Location.X, picEnemy20.Location.Y + 20);
		}
		public void LeftMovement()
		{
			picEnemy1.Location = new Point(picEnemy1.Location.X - 20, picEnemy1.Location.Y);
			picEnemy2.Location = new Point(picEnemy2.Location.X - 20, picEnemy2.Location.Y);
			picEnemy3.Location = new Point(picEnemy3.Location.X - 20, picEnemy3.Location.Y);
			picEnemy4.Location = new Point(picEnemy4.Location.X - 20, picEnemy4.Location.Y);
			picEnemy5.Location = new Point(picEnemy5.Location.X - 20, picEnemy5.Location.Y);
			picEnemy6.Location = new Point(picEnemy6.Location.X - 20, picEnemy6.Location.Y);
			picEnemy7.Location = new Point(picEnemy7.Location.X - 20, picEnemy7.Location.Y);
			picEnemy8.Location = new Point(picEnemy8.Location.X - 20, picEnemy8.Location.Y);
			picEnemy9.Location = new Point(picEnemy9.Location.X - 20, picEnemy9.Location.Y);
			picEnemy10.Location = new Point(picEnemy10.Location.X - 20, picEnemy10.Location.Y);
			picEnemy11.Location = new Point(picEnemy11.Location.X - 20, picEnemy11.Location.Y);
			picEnemy12.Location = new Point(picEnemy12.Location.X - 20, picEnemy12.Location.Y);
			picEnemy13.Location = new Point(picEnemy13.Location.X - 20, picEnemy13.Location.Y);
			picEnemy14.Location = new Point(picEnemy14.Location.X - 20, picEnemy14.Location.Y);
			picEnemy15.Location = new Point(picEnemy15.Location.X - 20, picEnemy15.Location.Y);
			picEnemy16.Location = new Point(picEnemy16.Location.X - 20, picEnemy16.Location.Y);
			picEnemy17.Location = new Point(picEnemy17.Location.X - 20, picEnemy17.Location.Y);
			picEnemy18.Location = new Point(picEnemy18.Location.X - 20, picEnemy18.Location.Y);
			picEnemy19.Location = new Point(picEnemy19.Location.X - 20, picEnemy19.Location.Y);
			picEnemy20.Location = new Point(picEnemy20.Location.X - 20, picEnemy20.Location.Y);
		}
		public void RightMovement()
		{
			picEnemy1.Location = new Point(picEnemy1.Location.X + 20, picEnemy1.Location.Y);
			picEnemy2.Location = new Point(picEnemy2.Location.X + 20, picEnemy2.Location.Y);
			picEnemy3.Location = new Point(picEnemy3.Location.X + 20, picEnemy3.Location.Y);
			picEnemy4.Location = new Point(picEnemy4.Location.X + 20, picEnemy4.Location.Y);
			picEnemy5.Location = new Point(picEnemy5.Location.X + 20, picEnemy5.Location.Y);
			picEnemy6.Location = new Point(picEnemy6.Location.X + 20, picEnemy6.Location.Y);
			picEnemy7.Location = new Point(picEnemy7.Location.X + 20, picEnemy7.Location.Y);
			picEnemy8.Location = new Point(picEnemy8.Location.X + 20, picEnemy8.Location.Y);
			picEnemy9.Location = new Point(picEnemy9.Location.X + 20, picEnemy9.Location.Y);
			picEnemy10.Location = new Point(picEnemy10.Location.X + 20, picEnemy10.Location.Y);
			picEnemy11.Location = new Point(picEnemy11.Location.X + 20, picEnemy11.Location.Y);
			picEnemy12.Location = new Point(picEnemy12.Location.X + 20, picEnemy12.Location.Y);
			picEnemy13.Location = new Point(picEnemy13.Location.X + 20, picEnemy13.Location.Y);
			picEnemy14.Location = new Point(picEnemy14.Location.X + 20, picEnemy14.Location.Y);
			picEnemy15.Location = new Point(picEnemy15.Location.X + 20, picEnemy15.Location.Y);
			picEnemy16.Location = new Point(picEnemy16.Location.X + 20, picEnemy16.Location.Y);
			picEnemy17.Location = new Point(picEnemy17.Location.X + 20, picEnemy17.Location.Y);
			picEnemy18.Location = new Point(picEnemy18.Location.X + 20, picEnemy18.Location.Y);
			picEnemy19.Location = new Point(picEnemy19.Location.X + 20, picEnemy19.Location.Y);
			picEnemy20.Location = new Point(picEnemy20.Location.X + 20, picEnemy20.Location.Y);
		}





then I have a keydown event (I dont feel like pasting that whole thing so im just putting specific key)


case Keys.H:
					{
						int j;
						int i;
						for (j = 0; j < 9; i++)
						{
							for (i = 0; i < 9; i++)
							{
								LeftMovement();
							}
							DownMovement();
							for (i = 0; i < 9; i++)
							{
								RightMovement();
							}
						}   
						break;
					}


This post has been edited by yowutup11: 19 November 2008 - 12:51 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Multiple pictureboxes moving SIMULTANEOUSLY

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9381
  • View blog
  • Posts: 35,228
  • Joined: 12-June 08

Re: Multiple pictureboxes moving SIMULTANEOUSLY

Posted 19 November 2008 - 12:48 PM

Well since you punted your code all I can recommend is "Don't use picture boxes.. use bitmaps..".
Was This Post Helpful? 0
  • +
  • -

#3 yowutup11  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 59
  • Joined: 07-March 08

Re: Multiple pictureboxes moving SIMULTANEOUSLY

Posted 19 November 2008 - 01:00 PM

ok I havent dealt with bitmaps yet
do you know of somewhere I can look about them?

This post has been edited by yowutup11: 19 November 2008 - 01:01 PM

Was This Post Helpful? 0
  • +
  • -

#4 zakary  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 27
  • View blog
  • Posts: 427
  • Joined: 15-February 05

Re: Multiple pictureboxes moving SIMULTANEOUSLY

Posted 19 November 2008 - 01:03 PM

here is a good place to start
http://msdn.microsof...582(VS.71).aspx
Was This Post Helpful? 0
  • +
  • -

#5 yowutup11  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 59
  • Joined: 07-March 08

Re: Multiple pictureboxes moving SIMULTANEOUSLY

Posted 19 November 2008 - 01:11 PM

ok...so heres the exact code given on that site

void CreateBitmap()
{
	System.Drawing.Bitmap flag = new System.Drawing.Bitmap(10, 10);
	for( int x = 0; x <  flag.Height; ++x )
		for( int y = 0; y < flag.Width; ++y )
			flag.SetPixel(x, y, Color.White);
	for( int x = 0; x < flag.Height; ++x )
		flag.SetPixel(x, x, Color.Red);
	pictureBox1.Image = flag;
}



how do I change this to fit my needs?
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9381
  • View blog
  • Posts: 35,228
  • Joined: 12-June 08

Re: Multiple pictureboxes moving SIMULTANEOUSLY

Posted 20 November 2008 - 12:41 PM

View Postyowutup11, on 19 Nov, 2008 - 02:11 PM, said:

ok...so heres the exact code given on that site

void CreateBitmap()
{
	System.Drawing.Bitmap flag = new System.Drawing.Bitmap(10, 10);
	for( int x = 0; x <  flag.Height; ++x )
		for( int y = 0; y < flag.Width; ++y )
			flag.SetPixel(x, y, Color.White);
	for( int x = 0; x < flag.Height; ++x )
		flag.SetPixel(x, x, Color.Red);
	pictureBox1.Image = flag;
}



how do I change this to fit my needs?



Ahm, that's called being a programmer - it's what you do. :D
Was This Post Helpful? 0
  • +
  • -

#7 yowutup11  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 59
  • Joined: 07-March 08

Re: Multiple pictureboxes moving SIMULTANEOUSLY

Posted 20 November 2008 - 12:48 PM

View Postmodi123_1, on 20 Nov, 2008 - 11:41 AM, said:

Ahm, that's called being a programmer - it's what you do. :D



I have never worked with bitmaps before...I am trying to research it but I cant really understand it...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1