private void Form1_KeyDown(object sender, KeyEventArgs e) { //Graphics g = Graphics.FromImage(doubleBuffer); //timer.Stop(); //Bitmap bip = new Bitmap(FillPic.Properties.Resources.background); g = Graphics.FromImage(doubleBuffer); //label1.Text = ColorMatch(doubleBuffer.GetPixel(Convert.ToInt16(ball3.X) -3, Convert.ToInt16(ball3.Y) - 3), Color.White).ToString(); g.DrawRectangle(pen, bounds); methodRandom(); RecPart part = new RecPart(); part.X = ball3.X; part.Y = ball3.Y; parts.Add(part); ball3.Move(e); ball3.Draw(brush2, g); CheckCollisons(); graphics.DrawImageUnscaled(doubleBuffer, 0, 0); //check collisions }
void methodRandom() { timer.Start(); g = Graphics.FromImage(doubleBuffer); g.Clear(Color.White); g.DrawRectangle(pen, bounds); if (background != null) { g.DrawImage(background, 0, 0); } int min1 = 0; int min2 = 0; for (int i = 0; i < parts.Count; i++) { //label1.Text = "VLAGA LI TUKA???" + i; /*if(i==0) * { * if (ball3.Y == bounds.Top || ball3.Y == bounds.Bottom || ball3.X == bounds.Left || ball3.X == bounds.Right) * { * RecPart rp = new RecPart(); * rp.X = ball3.X; * rp.Y = ball3.Y; * parts.Add(rp); * g.FillRectangle(brush2, ball3.X, ball3.Y, 5, 5); * * } * if (ball3.Y != bounds.Top || ball3.Y != bounds.Bottom || ball3.X != bounds.Left || ball3.X != bounds.Right) * { * g.FillRectangle(brush2, 100, 100, 100, 100); * } * * }*/ //g.FillRectangle(brush2, 85, 10, 5, 5); if (!(ball3.Y == bounds.Bottom - 5) || !(ball3.Y == bounds.Right - 5)) { g.FillRectangle(brush2, parts[i].X, parts[i].Y, 5, 5); } if ((ball3.Y == bounds.Bottom - 5) || (ball3.Y == bounds.Right - 5)) { g.FillRectangle(brush2, parts[i].X, parts[i].Y, 5, 5); } if (i != 0) { if (ball3.Y == bounds.Top || ball3.Y == bounds.Bottom - 5 || ball3.X == bounds.Left || ball3.X >= bounds.Right - 5) { if (parts[0].X != parts[parts.Count - 1].X && parts[0].Y != parts[parts.Count - 1].Y) { RecPart rp = new RecPart(); rp.X = ball3.X; rp.Y = ball3.Y; //g.FillRectangle(brush2, parts[i].X, parts[i].Y, 5, 5); //parts.Add(rp); g.FillRectangle(brush2, rp.X, rp.Y, 5, 5); //g.FillRectangle(brush2, rp.X-5, rp.Y-5, 5, 5); min1 = Convert.ToInt16(Math.Min(parts[0].X, parts[parts.Count - 1].X)); min2 = Convert.ToInt16(Math.Min(parts[0].Y, parts[parts.Count - 1].Y)); flag2 = true; // break; //break; } if (!flag2) { parts.RemoveAt(0); i = 0; } //break; } } } if (flag2) { //label2.Text = min1 + 5 + " MINIMUM " + min2 + 5; float minX = float.MaxValue; float maxX = float.MinValue; float minY = float.MaxValue; float maxY = float.MinValue; foreach (RecPart part in parts) { if (part.X < minX) { minX = part.X; } if (part.X > maxX) { maxX = part.X; } if (part.Y < minY) { minY = part.Y; } if (part.Y > maxY) { maxY = part.Y; } } Random random = new Random(); int floatX = 0; int floatY = 0; doubleBuffer = FloodFill(doubleBuffer, source, new Point(Convert.ToInt16(parts[0].X), Convert.ToInt16(parts[0].Y)), Color.Green, Color.Black, tmp, broj);//ne se koristi black int i = 0; while (true) { i++; floatX = random.Next(Convert.ToInt32(minX), Convert.ToInt32(maxX)); floatY = random.Next(Convert.ToInt32(minY), Convert.ToInt32(maxY)); if (ColorMatch(doubleBuffer.GetPixel(Convert.ToInt32(floatX), Convert.ToInt32(floatY)), Color.White)) { doubleBuffer = FloodFill(doubleBuffer, source, new Point(Convert.ToInt32(floatX), Convert.ToInt32(floatY)), Color.White, Color.Black, tmp, broj); break; } if (i > 55) { break; } } //bitmap = new Bitmap(doubleBuffer); flag2 = false; parts.Clear(); } background = new Bitmap(doubleBuffer); //g.DrawImage(background, 0, 0); ball.Draw(brush, g); ball.Move(); ball2.Draw(brush, g); ball2.Move(); ball3.Draw(brush2, g); CheckCollisons(); graphics.DrawImageUnscaled(doubleBuffer, 0, 0); }