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

• 10-15-2011, 07:59 PM
Naxix
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):
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"
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
• 10-15-2011, 08:13 PM
kraigballa
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?
• 10-15-2011, 08:17 PM
Naxix
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.
• 10-15-2011, 08:32 PM
kraigballa
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?

Code:

`Random rand = new Random();`