I have two picture boxs that move around and are meant to bounce off the sides of the form they are on. This is part of the code i have for that:
private void timer1_Tick(object sender, EventArgs e)
{
if (clicked)
{
Point p = bball.Location;
p.X += 1;
p.Y += 1;
bball.Location = p;
Point p2 = rball.Location;
p2.X += 1;
p2.Y += 1;
rball.Location = p2;
}
if (moving)
{
if (bball.Y > bball)
vy = Math.Abs(vy) * -1;
else if (bball.Y vy = Math.Abs(vy);
if (bball.X > bounceright)
vx = Math.Abs(vx) * -1;
else if (bball.X vx = Math.Abs(vx);
}
}
X and Y are throwing lots of errors if "if (moving)". Even if i made a point like the first part of the timer, it says cant be used. bball is a picture box on the form already made. Shouldn't the picture box already have and x and y to it...? I'm having trouble finding what code works for this.
Alex4 pointsPosted Sep 13, 2009, 1:23 PM EDT
if (bball.Y > bball)
bball.y can not be compared to bball the object.
Normally when I do something like this i would start with x,y direction variables...
int xDirection=1;
int yDirection=1;
int xMin=0;
int yMin=0;
int xMax=100;
int yMax=100;
bball.x = bball.x + xDirection;
bball.y = bball.y + yDirection;
if (bball.x < xMin) {xDirection = 1;}
if (bball.x > xMax) {xDirection = -1;}
if (bball.y < yMin) {yDirection = 1;}
if (bball.y > yMax) {yDirection = -1;}
shena forga5 pointsPosted Sep 13, 2009, 6:16 PM EDT