# Thread: Makeing a border - Y axis bugging? (Applet)

1. Member
Join Date
Jul 2011
Posts
13
Rep Power
0

## Makeing a border - Y axis bugging? FIXED

Hello, so i'm trying to make a basic border structure for a object, which then should be bounced away when hitting the border. But for some reason i find the Y-axis bugging me alot, i tried changeing my code alot, but each time it keeps doing the same. When the object reaches the top border (and should be bounced away) it keeps going out of sight, and comes back a moment later.

This is the code i have so far.

Define the border coordinates (The applet size is 400x400):
Java Code:
```    public int Leftout = 30;
public int Rightout = 370;
public int Topout = 370;
public int Bottonout = 40;```
The code that checks if the object is out of the "border"
Java Code:
```	public boolean isOut(){

if(x_pos > Rightout){

speedx = (rand.nextInt(2)+1)-4;
return true;

}
else if(x_pos < Leftout){

speedx = rand.nextInt(2)+1;
return true;
}
else if(y_pos > Topout){

speedy = (rand.nextInt(2)+1)-4;
return true;
}
else if(y_pos < Bottonout){

speedy = rand.nextInt(2)+1;
return true;
}
else return false;

}```
I think the problem is here somewhere, i suspect the "speed" randoms.
speed is just how much to move on X and Y axis, per 20 milliseconds.

Regards Naxix
Last edited by Naxix; 10-15-2011 at 08:20 PM. Reason: I got it working

2. Senior Member
Join Date
Oct 2011
Posts
115
Rep Power
0

## Re: Makeing a border - Y axis bugging? (Applet)

Well, if x == any of those values (meaning right on them) wouldn't it work just how you described?

3. Member
Join Date
Jul 2011
Posts
13
Rep Power
0

## Re: Makeing a border - Y axis bugging? (Applet)

I'm not sure i know what you mean, right now it seems that the top border, is around 50 pixels out of the window?

EDIT: I got it working, i think my other class went in and changed the border for some reason.
Last edited by Naxix; 10-15-2011 at 08:20 PM.

4. Senior Member
Join Date
Oct 2011
Posts
115
Rep Power
0

## Re: Makeing a border - Y axis bugging? (Applet)

I was just saying that is you use x_pos > Rightout, then you as I'm sure you know x_pos can equal Rightout.

However, I'm just curious if you have the Random object instantiated?

Java Code:
`Random rand = new Random();`

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•