Sign in to follow this  
ChristianFrantz

thread error

Recommended Posts

j-locke    945
[i]balls.get(i).x[/i]

ArrayList's .get() documentation: [url="http://docs.oracle.com/javase/6/docs/api/java/util/ArrayList.html#get(int)"]http://docs.oracle.com/javase/6/docs/api/java/util/ArrayList.html#get(int) [/url]

Share this post


Link to post
Share on other sites
Awesome [img]http://public.gamedev.net//public/style_emoticons/default/biggrin.png[/img] this code works perfectly

[source lang="java"]import java.applet.Applet;
import java.awt.Color;
import java.awt.Event;
import java.awt.Graphics;
import java.awt.Image;
import java.util.ArrayList;
import java.util.concurrent.TimeUnit;

public class game extends Applet implements Runnable
{
int xpos = 100;
int ypos = 100;
int radius = 5;
int xspeed = 0;
int yspeed = 0;
static final int WIDTH = 450;
static final int HEIGHT = 450;
private Image dbImage;
private Graphics dbg;

boolean run = true;

public static long NEW_DOT_FREQ = TimeUnit.SECONDS.toMillis(5);
public long lastUpdateTime;
public long timeSinceLastNewDot;

public ArrayList<Ball> Balls;

static final int NUM_OF_BALLS = 4;

int i;
int t;

Thread updateTime = new updateTime();

public void start()
{
lastUpdateTime = System.currentTimeMillis();

Thread th = new Thread(this);
th.start();//start main game

updateTime.start();
}

public void updateGame()
{
//Get the current time
long currentTime = System.currentTimeMillis();
//Calculate how much time has passed since the last update
long elapsedTime = currentTime - lastUpdateTime;
//Store this as the most recent update time
lastUpdateTime = currentTime;

//Create a new dot if enough time has passed
//Update the time since last new dot was drawn
timeSinceLastNewDot += elapsedTime;

if (timeSinceLastNewDot >= NEW_DOT_FREQ)
{
int newX = randomNumber();
int newY = randomNumber();

debugPrint("New dot created at x:" + newX + ", y:" + newY + ".");
Balls.add(new Ball(newX, newY, 20, 20, Color.black));

timeSinceLastNewDot = 0;
}
}

private void debugPrint(String value)
{
System.out.println(value);
}

public class updateTime extends Thread implements Runnable
{
public void run()
{
for(t = 0; ; t++)
{
try
{
Thread.sleep(1000);
}
catch(InterruptedException e){}
}
}
}

public int randomNumber()
{
return (int)(Math.random() * 400);
}

class Ball
{
int x;
int y;
int width;
int height;
Color mycolor;

public Ball(int x, int y, int width, int height, Color mycolor)
{
this.x = x;
this.y = y;
this.width = width;
this.height = height;
this.mycolor = mycolor;
}//end ball

public void paint(Graphics g)
{
g.setColor(mycolor);
g.fillOval(x, y, width, height);
} //end paint

} //ball class

public void update(Graphics g) //double buffer don't touch!!
{
if(dbImage == null)
{
dbImage = createImage(this.getSize().width, this.getSize().height);
dbg = dbImage.getGraphics();
}

dbg.setColor(getBackground());
dbg.fillRect(0, 0, this.getSize().width, this.getSize().height);

dbg.setColor(getForeground());
paint(dbg);

g.drawImage(dbImage, 0, 0, this);
}


/*public class updateBalls extends Thread implements Runnable
{
public void run(Graphics g)
{
for(i = 0; i<NUM_OF_BALLS; i++)
{
ball[i].paint(g);
}
try
{
Thread.sleep(5000);
}catch(InterruptedException e){}
}
}*/

public void init()
{
this.setSize(WIDTH, HEIGHT);

Balls = new ArrayList<Ball>();

Balls.add(new Ball(randomNumber(), randomNumber(), 20, 20, Color.red));
Balls.add(new Ball(randomNumber(), randomNumber(), 20, 20, Color.blue));
Balls.add(new Ball(randomNumber(), randomNumber(), 20, 20, Color.green));
Balls.add(new Ball(randomNumber(), randomNumber(), 20, 20, Color.magenta));

}

public boolean keyDown (Event e, int key)
{
if(key == Event.LEFT)
{
xspeed = -5;
yspeed = 0;
}

if(key == Event.RIGHT)
{
xspeed = 5;
yspeed = 0;
}

if(key == Event.UP)
{
yspeed = -5;
xspeed = 0;
}

if(key == Event.DOWN)
{
yspeed = 5;
xspeed = 0;
}

return true;
}

public void run()
{
while(run)
{
repaint();

if (xpos < 1)
{
xpos = 449;
}

if (xpos > 449)
{
xpos = 1;
}
if (ypos < 1)
{
ypos = 449;
}

if (ypos > 449)
{
ypos = 1;
}
ypos += yspeed;
xpos += xspeed;
try
{
Thread.sleep(20);
}
catch(InterruptedException ex){}
}
}

public void paint(Graphics g)
{

g.setColor(Color.black);
g.fillOval(xpos - radius, ypos - radius, 2 * radius, 2 * radius);

g.drawString("time: " + t, 20, 20);

for (Ball dot : Balls)
{
dot.paint(g);
}

updateGame();
}
}[/source]

next issue tho... collision. i read the link you posted but it didnt help too much. i understood it but i dont even know what to put into the method or how to get the bounds of each ball created. would i have to store each ball created in the array list as a shape? and if so how would i do that?

tweaked it so the balls look cooler [img]http://public.gamedev.net//public/style_emoticons/default/tongue.png[/img]

[source lang="java"] public void paint(Graphics g)
{
g.setColor(color[getRandomColor()]);
g.fillOval(x, y, width, height);
} [/source]

[source lang="java"] public int getRandomColor()
{
return (int)(Math.random() * 6);
}[/source]

[source lang="java"] Color[] color = {Color.red, Color.blue, Color.green, Color.yellow, Color.magenta, Color.black};
int colorIndex;
[/source]

oh lightbulb. since the coordinates of each ball are already stored in the array all id have to do is get the coords from the array and then somehow set the bounds within the getBounds() method Edited by burnt_casadilla

Share this post


Link to post
Share on other sites
j-locke    945
Since you're getting random numbers for more things now, maybe a more general randomNumber method could come in handy.

[source lang="java"]//Returns a random number between 0 and maximum-1
int randomNumber(int maximum)
{
return (int)(Math.random() * maximum);
}[/source]

With that method, you could pass it WIDTH for a yvalue, HEIGHT for an xvalue and 6 (or more cleverly, color.length) for your color stuff.

[quote name='burnt_casadilla' timestamp='1344802282' post='4968815']
next issue tho... collision. i read the link you posted but it didnt help too much. i understood it but i dont even know what to put into the method or how to get the bounds of each ball created. would i have to store each ball created in the array list as a shape? and if so how would i do that?
[/quote]

To your question about needing to create an array list of shapes, you already have one. Through inheritance (one of the core ideas to learn from classes/ object-oriented programming), your Ball class is a shape. The [url="http://docs.oracle.com/javase/6/docs/api/java/awt/geom/Ellipse2D.Float.html"]Ellipse2D documentation[/url] shows what classes it extends and interfaces it implements, and Shape is among them.

Your lightbulb is definitely on the right track. The information is already there; each ball knows information like its x, y coordinates, width and height. The getBounds() method actually already does some of that work for you. Following through the documentation for getBounds, it shows you the return type of the method is Rectangle. Rectangle has an x, y, width and height, so it knows where it's located and it even includes an [url="http://docs.oracle.com/javase/6/docs/api/java/awt/Rectangle.html#intersects(java.awt.Rectangle)"]intersects method[/url] to see if one Rectangle intersects with another Rectangle.

A thought process for what you're trying to accomplish is that every update, you want to get the Rectangle that represents the player's location. And see if that one Rectangle intersects with any of the enemy Rectangles.

Share this post


Link to post
Share on other sites
ok so the getBounds method will return an invisible rectangle around each ball created in the array but how would i pass each ball through the getBounds method? would i need another for loop and call the method when another ball is created in the array list? i think once i figure out how to create the rectangle around the balls the intersects method would be a piece of cake.

this might not make sense but what if i created another arraylist designated for the rectangles around the balls and then used that arraylist in the intersects method? its easier for me to understand but it might not be the easiet way

Share this post


Link to post
Share on other sites
oh and none of my objects implements the Ellipse2d.float class

im going to try to create a Rectangle around the main ball first to see if i can get that to work first

another thought: im thinking about making a simple class for the main ball so i can just call that method inside the getBounds method. would that work? Edited by burnt_casadilla

Share this post


Link to post
Share on other sites
so this is my main ball class

[source lang="java"]class mainBall
{
int x;
int y;
int width;
int height;
int xpos = 100;
int ypos = 100;
int radius = 5;
int xspeed = 0;
int yspeed = 0;

public mainBall(int x, int y, int width, int height)
{
this.x = 100;
this.y = 100;
this.width = 10;
this.height = 10;
this.xpos = 100;
this.ypos = 100;
this.xspeed = 0;
this.yspeed = 0;
}

public boolean keyDown (Event e, int key)
{
if(key == Event.LEFT)
{
xspeed = -5;
yspeed = 0;
}

if(key == Event.RIGHT)
{
xspeed = 5;
yspeed = 0;
}

if(key == Event.UP)
{
yspeed = -5;
xspeed = 0;
}

if(key == Event.DOWN)
{
yspeed = 5;
xspeed = 0;
}

if (xpos < 1)
{
xpos = 449;
}

if (xpos > 449)
{
xpos = 1;
}
if (ypos < 1)
{
ypos = 449;
}

if (ypos > 449)
{
ypos = 1;
}
ypos += yspeed;
xpos += xspeed;
try
{
Thread.sleep(20);
}
catch(InterruptedException ex){}

return true;
}

public void paint(Graphics g)
{
g.setColor(Color.black);
g.fillOval(x, y, width, height);
g.drawString(xpos + ", " + ypos, 20, 40);
}
}//mainBall[/source]

but i cant figure out how to draw it in the main game class. ive tried putting mainBall.paint(g); in the main paint method but that gives me an error

sorry about all the questions lol. my brain is going way too fast and i cant slow down

Share this post


Link to post
Share on other sites
j-locke    945
[quote name='burnt_casadilla' timestamp='1344807075' post='4968838']
oh and none of my objects implements the Ellipse2d.float class
[/quote]

Oh, sorry, I didn't catch that your Ball class changed so it doesn't anymore.

[quote name='burnt_casadilla' timestamp='1344807075' post='4968838']
im going to try to create a Rectangle around the main ball first to see if i can get that to work first
[/quote]

That is a good idea. Write a method named whatever you think is appropriate that returns that invisible rectangle. If you make that an object of the Rectangle class then the Rectangle class will make it quite easy to handle the intersections.

[quote name='burnt_casadilla' timestamp='1344807075' post='4968838']
another thought: im thinking about making a simple class for the main ball so i can just call that method inside the getBounds method. would that work?
[/quote]

Yep, that's a great reason that the main ball should be a class. So you can add functionality to it like that.

[quote name='burnt_casadilla' timestamp='1344806858' post='4968837']
this might not make sense but what if i created another arraylist designated for the rectangles around the balls and then used that arraylist in the intersects method? its easier for me to understand but it might not be the easiet way
[/quote]

That approach would work. I think a more solid approach would be to add a method to your Ball class that returns a Rectangle. Then you could use your existing array to get Rectangles.

[quote name='burnt_casadilla' timestamp='1344806858' post='4968837']
ok so the getBounds method will return an invisible rectangle around each ball created in the array but how would i pass each ball through the getBounds method? would i need another for loop and call the method when another ball is created in the array list?
[/quote]

As you've pointed out, you didn't inherit a getBounds method as you don't extend Ellipse2D but once you write a similar method, yes you would have a for loop iterate through the list of Balls and check if the player intersects with any of them ([i]if ([/i][i]playerRectangle.intersects(enemyRectangle))[/i].

Share this post


Link to post
Share on other sites
j-locke    945
[quote name='burnt_casadilla' timestamp='1344808186' post='4968847']
but i cant figure out how to draw it in the main game class. ive tried putting mainBall.paint(g); in the main paint method but that gives me an error

sorry about all the questions lol. my brain is going way too fast and i cant slow down
[/quote]

I think it is a good time to start following the usual naming conventions for stuff (it helps a lot when all the people looking at the code can quickly know what's going on).
The basics of that would be to name:
[u]classes[/u] start with a capital letter and have a capital letter at the start of each word (public class ThisIsAClass).
[u]variables[/u] start with a lowercase letter and have a capital letter at the start of each word (int whatALongVariableName).
[u]methods[/u] are named like variables (public void cantWeAllJustGetAlong()).

So with that tidbit out of the way, as always, you'll want to post what error you get and what line of code it happens on whenever you code is giving you an error.
As a guess, perhaps your mainBall object isn't named mainBall. I can confirm that that is your class name. So if you have a variable declared [i]mainBall player[/i], you'd want to call player.paint(g). Edited by j-locke

Share this post


Link to post
Share on other sites
My main ball class is now MainBall with the constructor also called MainBall(x, y, width, height). the paint method is public void paintMainBall(Graphics g). How would i call the paintMainBall method in the main paint method? i feel like this should be really simple...

Cannot make a static reference to the non-static method paintMainBall(Graphics) from the type game.MainBall

it gives me this error when i type MainBall.paintMainBall(g); in the main paint method Edited by burnt_casadilla

Share this post


Link to post
Share on other sites
j-locke    945
Nice. That makes it a little more straightforward to look at.

In your game class, you have to declare a MainBall object ([i]MainBall mainBall;[/i]). It also needs initializing somewhere but I'll leave that to you. With that set up, in your game class' paint method, you'd call mainBall.paint(g). Or mainBall.paintMainBall(g) per your newest name.

Share this post


Link to post
Share on other sites
I made the mainBall object based on my MainBall class and put mainBall.paintMainBall(g) in my paint method and now it gives me another error:

Exception in thread "AWT-EventQueue-1" java.lang.NullPointerException
at game.paint(game.java:251)
at game.update(game.java:227)

so its where i put the mainBall.paintMainBall(g) but the compiler doesnt see anything wrong with it

herpderp i forgot to create the object

MainBall mainBall = new MainBall(x, y, width, height);

that worked fine, but now it wont move. good lord this is frusterating

fixed it so that the coordinates of the mainBall change when i press the keys but it isnt being redrawn so the ball stays in one spot. almost!!!! Edited by burnt_casadilla

Share this post


Link to post
Share on other sites
j-locke    945
It's important to keep the mental distinction between updating and drawing/painting. Those are 2 separate things and you should always be treating them as such.

On the drawing/painting side of that question, you'll want to make sure that you're using some variables to determine the current position of the mainBall (which you're doing in mainBall's paint method by passing variables like x and y to the g.fillOval() call).

On the updating side of that question, you'll want to update the mainBall's x and y values based on what the player presses.

Share this post


Link to post
Share on other sites
i added the xpos ypos xspeed and yspeed parameters to the mainBall and changed the variables in the keyDown and run method but it still did nothing

[source lang="java"]import java.applet.Applet;
import java.awt.Color;
import java.awt.Component;
import java.awt.Event;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.concurrent.TimeUnit;

public class game extends Applet implements Runnable
{
static final int WIDTH = 450;
static final int HEIGHT = 450;
private Image dbImage;
private Graphics dbg;

public static long NEW_DOT_FREQ = TimeUnit.SECONDS.toMillis(3);
public long lastUpdateTime;
public long timeSinceLastNewDot;


public ArrayList<Ball> BALLS;

Color[] color = {Color.red, Color.blue, Color.green, Color.yellow, Color.magenta, Color.black};
int colorIndex;

static final int NUM_OF_BALLS = 4;

int i;
int t;

MainBall mainBall = new MainBall(100, 100, 10, 10, 100, 100, 0, 0);

Thread updateTime = new updateTime();

public void start()
{
lastUpdateTime = System.currentTimeMillis();

Thread th = new Thread(this);
th.start();//start main game

updateTime.start();
}

public void updateGame()
{
//Get the current time
long currentTime = System.currentTimeMillis();
//Calculate how much time has passed since the last update
long elapsedTime = currentTime - lastUpdateTime;
//Store this as the most recent update time
lastUpdateTime = currentTime;

//Create a new dot if enough time has passed
//Update the time since last new dot was drawn
timeSinceLastNewDot += elapsedTime;

if (timeSinceLastNewDot >= NEW_DOT_FREQ)
{
int newX = randomNumber();
int newY = randomNumber();

debugPrint("New dot created at x:" + newX + ", y:" + newY + ".");

BALLS.add(new Ball(newX, newY, 20, 20));

timeSinceLastNewDot = 0;
}
}

private void debugPrint(String value)
{
System.out.println(value);
}

public class updateTime extends Thread implements Runnable
{
public void run()
{
for(t = 0; ; t++)
{
try
{
Thread.sleep(1000);
}
catch(InterruptedException e){}
}
}
}

public int randomNumber()
{
return (int)(Math.random() * 400);
}

public int getRandomColor()
{
return (int)(Math.random() * 6);
}

public class MainBall
{
int x;
int y;
int width;
int height;
int xpos = 100;
int ypos = 100;
int xspeed = 0;
int yspeed = 0;

public MainBall(int x, int y, int width, int height, int xpos, int ypos, int xspeed, int yspeed)
{
this.x = 100;
this.y = 100;
this.width = 10;
this.height = 10;
this.xpos = 100;
this.ypos = 100;
this.xspeed = 0;
this.yspeed = 0;
}

public void paintMainBall(Graphics g)
{
g.setColor(Color.black);
g.fillOval(x, y, width, height);
g.drawString(xpos + ", " + ypos, 20, 40);
}
}//mainBall

class Ball
{
int x;
int y;
int width;
int height;

public Ball(int x, int y, int width, int height)
{
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}//end ball

public void paint(Graphics g)
{
g.setColor(color[getRandomColor()]);
g.fillOval(x, y, width, height);
} //end paint


} //ball class

public void update(Graphics g) //double buffer don't touch!!
{
if(dbImage == null)
{
dbImage = createImage(this.getSize().width, this.getSize().height);
dbg = dbImage.getGraphics();
}

dbg.setColor(getBackground());
dbg.fillRect(0, 0, this.getSize().width, this.getSize().height);

dbg.setColor(getForeground());
paint(dbg);

g.drawImage(dbImage, 0, 0, this);
}

public boolean keyDown (Event e, int key)
{
if(key == Event.LEFT)
{
mainBall.xspeed = -5;
mainBall.yspeed = 0;
}

if(key == Event.RIGHT)
{
mainBall.xspeed = 5;
mainBall.yspeed = 0;
}

if(key == Event.UP)
{
mainBall.yspeed = -5;
mainBall.xspeed = 0;
}

if(key == Event.DOWN)
{
mainBall.yspeed = 5;
mainBall.xspeed = 0;
}
return true;
}

public void run()
{
while(true)
{
repaint();

if (mainBall.xpos < 1)
{
mainBall.xpos = 449;
}

if (mainBall.xpos > 449)
{
mainBall.xpos = 1;
}
if (mainBall.ypos < 1)
{
mainBall.ypos = 449;
}

if (mainBall.ypos > 449)
{
mainBall.ypos = 1;
}
mainBall.ypos += mainBall.yspeed;
mainBall.xpos += mainBall.xspeed;
try
{
Thread.sleep(20);
}
catch(InterruptedException ex){}
}
}

public void init()
{
this.setSize(WIDTH, HEIGHT);

BALLS = new ArrayList<Ball>();
}

public void paint(Graphics g)
{

g.drawString("time: " + t, 20, 20);

mainBall.paintMainBall(g);

for (Ball ball : BALLS)
{
ball.paint(g);
}

updateGame();
}


}[/source] Edited by burnt_casadilla

Share this post


Link to post
Share on other sites
j-locke    945
I see the problem in there. But I want to give you a chance to look over the code around the problem.

1. What values are you using to draw the mainBall? Look at the code where you actually handle drawing the mainBall.
2. What values do you update in your key handling code? Then follow those values to see what that values affects and what that value affects and so on.
3. Those are the 2 important actions that happen.. you update the values and then you use those values to draw an object. And you repeat those 2 steps over and over. As you're following through step 1 and 2, you need arrive at the same variable at some point. That is to say, you should ultimately be updating some variable and then using that same variable to draw the object.

So, see what you can find/ figure out about those pieces.

Share this post


Link to post
Share on other sites
1. The values i;m using are the int variables i declared in the constructor. The drawing of the ball is within the class, but im then calling the method through my main paint method with mainBall.paintMainBall(g).

2. The values being updated in the key method are the mainBall.xspeed and mainBall.yspeed. And this part works fine because the coordinates do change when i press a key.

3. Actually i cant really find where im drawing the ball except in the class. and i thought that in the main run method it was being repainted but obviously it isnt.

holy shit youre a genius. i changed the variables in the paintMainBall method to xpos and ypos and it worked [img]http://public.gamedev.net//public/style_emoticons/default/biggrin.png[/img]

i guess i was just repeatedly drawing the ball to x and y, but they never even changed.\

and now i can FINALLY move onto collision. im thinking:

1. create the public Rectangle getBounds() method with a for loop
2. the for loop will run everytime a new ball is created in the arraylist
3. within the for loop i use ballPositionX = balls.get(0).getx(); and ballPositionY = balls.get(0).gety(); to grab the coordinates of the ball
4. then i add return (something) to return the rectangle

i think thatll work for creating the rectangle around the ball, but in order to actually use it, i might store it in an array and then use (if (playerRectangle.intersects(enemyRectangle)) somewhere in order to stop the mainBall when it comes in contact with another ball

oh but in order to make it a little easier at first, im going to create a fixed ball at 250, 250 just so i can try out the method without getting for loops at first

another issue i just realized is that i have no idea how to use the getBounds method -.-

public Rectangle getBounds()
{
//what do i put in here in order to get the bounds of a circle at point 250, 250 and 20 height and 20 width?

// and this returns a value too so im making an arraylist for this too?
} Edited by burnt_casadilla

Share this post


Link to post
Share on other sites
j-locke    945
[quote name='burnt_casadilla' timestamp='1344819144' post='4968902']
i changed the variables in the paintMainBall method to xpos and ypos and it worked
[/quote]
There ya go! And if you're now using xpos and ypos, I'm not sure you even need what you previously called x and y. The last iteration of the code I looked at, you were setting them in the constructor then using them for the draw position, but not using them anywhere else.

1. You say create the method with a for loop. I'm not sure what you're meaning. Do you mean create the method once in the Ball class and then call it in a for loop?
2. It sounds like with this one you're saying, when you add, for example, ball 6, you're gonna run a loop over all of the balls? How does ball 6 being created affect ball 1 (talking in a conversational way, why is the creation of ball 6 related to the long existing ball 1)?
3. Don't forget to grab a width and a height too.
4. Returning a rectangle would be something like [i]return new Rectangle(x, y, width, height);[/i]. Of course the magic happens in you getting the appropriate values into x, y, width and height.

Good idea about trying to get your approach working with 1 item rather than jumping right into it working on a growing array of items. :)

Share this post


Link to post
Share on other sites
alright forget what i said about that for now lol. im gonna start with the simple getBounds of the fixedBall i created.

this is what i have.. but it cant be this simple right?
[source lang="java"] public Rectangle getFixedBallBounds()
{
return new Rectangle (250, 250, 20, 20);
}
[/source]

Share this post


Link to post
Share on other sites
wow ran into an issue already -.-

[source lang="java"] public Rectangle getMainBallBounds()
{
return new Rectangle(mainBall.xpos, mainBall.ypos, 10, 10);
}[/source]

the position of my main ball is always going to be changing. so do i need a while loop or a for loop here to account for the changing xpos and ypos variables?

nevermind fixed that too. i should stop asking questions before i actually try to figure things out lol.

so for collision. oh boy.

-1. should i store each rectangle created as an object for now? before i work on the array part when thatd be hard to do lol
1. create a method checkCollision(). i dont think it needs to return anything but i could be wrong
2. (if (mainBallRectangle.intersects(fixedBallRectangle))
3. if its true, set mainBall.xspeed = 0 and same with the yspeed

will this work? Edited by burnt_casadilla

Share this post


Link to post
Share on other sites
j-locke    945
[b]fixed ball[/b]
Yep it's that simple. Quite simple if nothing is changing. :)

[b]main ball[/b]
Nope, no loop. The position of your ball does change often. But that's why when you return a rectangle you use those very values (xpos, ypos) that are changing.
A way to investigate that mentally is think about what you want to accomplish with this method. Its purpose is to return you the rectangle that encloses the mainBall right now. So it doesn't care if the position changed last frame or if it hasn't changed in 20 minutes. All this method is concerned with is returning you that rectangle that encloses the mainBall [u]right now[/u].

Share this post


Link to post
Share on other sites
this did absolutely nothing lol

[source lang="java"] Rectangle mainBallRectangle = getMainBallBounds();
Rectangle fixedBallRectangle = getFixedBallBounds();[/source]
[source lang="java"] public Rectangle getFixedBallBounds()
{
return new Rectangle (250, 250, 20, 20);
}


public Rectangle getMainBallBounds()
{
return new Rectangle(mainBall.xpos, mainBall.ypos, 10, 10);
}


public void checkCollision()
{
if(mainBallRectangle.intersects(fixedBallRectangle))
{
mainBall.xspeed = 0;
mainBall.yspeed = 0;
}
}[/source]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this