Click here to Skip to main content
15,887,436 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hello,

i am trying to make some game, and i need your help. I have panel control and in that panel i put two images:
Background image: black with one blue line on middle
Movable image: Red image whick can be moved left,right,up,down.

I want to move image throw black picture but when it hit blue line it stop, movable image should not pass throw blue line...
How to do that, to read pixel color or any other way?


Thanks!
Posted

1 solution

Here you can find a good solution for your problem.

Bitmap.GetPixel Method[^]

C#
// Create a Bitmap object from an image file.
Bitmap myBitmap = new Bitmap("Grapes.jpg");

// Get the color of a pixel within myBitmap.
Color pixelColor = myBitmap.GetPixel(50, 50);
}
 
Share this answer
 
Comments
[no name] 17-Sep-13 19:35pm    
Yes, i know that, but how to stop moving foward movable image, how to stop it to come out on the other side of blue line? Thanks for the respond.
[no name] 17-Sep-13 19:43pm    
Here is key down event and form load an panel_paint

private void Form1_Load(object sender, EventArgs e)
{
//background img
panel1.BackgroundImage = img;
}

private void panel1_Paint(object sender, PaintEventArgs e)
{
//player img sa koordinatama x i y
e.Graphics.DrawImage(img_player, new Point(x, y));
}

private void Form1_KeyDown(object sender, KeyEventArgs e)
{

if (e.KeyData == Keys.Up)
{
x = x + 0;
y = y - 2;

if (x > 590 || x < 0 || y > 590 || y < 0)
{
y = y + 2;//za gresku kad ode u - tj +
}
else
panel1.Invalidate();//prosledjuje x i y u paint event
}
if (e.KeyData == Keys.Down)
{
x = x + 0;
y = y + 2;
if (x > 590 || x < 0 || y > 590 || y < 0)
{
y = y - 2;//za gresku kad ode u - tj +
}
else
panel1.Invalidate();//prosledjuje x i y u paint event
}
if (e.KeyData == Keys.Left)
{
x = x - 2;
y = y + 0;
if (x > 590 || x < 0 || y > 590 || y < 0)
{
x = x + 2;//za gresku kad ode u - tj +
}
else
panel1.Invalidate();//prosledjuje x i y u paint event
}
if (e.KeyData == Keys.Right)
{
x = x + 2;
y = y + 0;
if (x > 590 || x < 0 || y > 590 || y < 0)
{
x = x - 2;//za gresku kad ode u - tj +
}
else
panel1.Invalidate();//prosledjuje x i y u paint event
}
BillWoodruff 17-Sep-13 20:28pm    
Do you have a solution now ? If you don't: in your game does the black rectangle always stay the same size ? the blue-line is horizontal or vertical ? are you familiar with hit-detection in regions ?
[no name] 18-Sep-13 9:13am    
I have black image with vertical blue line on middle from top to bottom of the image, movable image can move only in left side of blue line in black area. Can you give me some tutorial or explanation of hit detection in regions, to read and learn? Thnaks!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900