Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

(Java) Timer objects 'running slow'

Name: Anonymous 2011-03-07 1:33

Hi. I have a java game I made in a course at Uni. It has three Timer objects.
When I run the game from Notepad++ it runs perfectly (sweet-as game if I may say so myself).
I have made executable .jar files so that I can share it with friends. Unfortunately sometimes the game runs 'slow' when run from the .jar.

I have the feeling this has nothing to do with errors in code (due to the randomness of the error's occurence) but rather a runtime problem (if that's the right word..).

Anyone know what the problem might be?
Also plz keep elitism to a minimum

Name: Anonymous 2011-03-07 18:24

Looks like you could improve the collision detection. Right now you have rectangle hit boxes 3/4 the size of the circles they represent. This means you'll have collisions that are false positives and some that aren't detected.

Use the distance formula to get the distance between the two circles. If the distance is less than circleRadius + otherCircleRadius you have a collision.

    public boolean collision(Ball ball_1, Ball ball_2){
        double distance;
        int xDistance, yDistance;
        xDistance =  (ball_2.x-ball_1.x);
        yDistance = (ball_2.y-ball_1.y);
        distance = Math.sqrt(xDistance*xDistance+yDistance*yDistance); //distance formula  sqrt((x2-x1)^2+(y2-y1)^2)
        if(distance<0)//make sure we don't have a negative direction
            distance *= -1;
        if(distance<(ball_1.width+ball_2.width)/2)
            return true; //there was a collision
        else
            return false; //no collision
    }

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List