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:
Anonymous2011-03-07 1:56
more like sweet as-game hahahaha
Name:
Anonymous2011-03-07 2:08
Upload source code? (I'm not going to run some random jar from 4chawn)
Make sure you're using
System.nanoTime() returns time in nano seconds, so you'll have to convert to milliseconds if your using it to sleep.
something vague happens sometimes
Try hitting the computer on the side with a blunt object!!
Name:
Anonymous2011-03-07 7:46
Yeah seems that way.. But it happens often (on every system I've tested it on) and definitely isn't vague, it appears the Timer objects are firing slower than the set delay period.
Whatevs, just thought someone might've experienced the same thing before working with Timers, maybe even in a similar uni assignment.
>>13
The link between those statements is tentative at best. Remember, not everyone follows the same train of thought as you, especially when it skips several steps and you don't care to explain it.
So fuck off, autist.
Autists likes to line things up and find them exactly where they left them, therefore a proper autist would always sage and throw a tantrum every time someone didn't.
An autist likes patterns, as you can see in the last few posts.
Name:
Anonymous2011-03-07 17:53
public static final int UP = 0;
public static final int LEFT = UP + 1;
public static final int DOWN = LEFT + 1;
public static final int RIGHT = DOWN + 1;
Ugh, I know their constants and it doesn't really matter performance wise, but this is much easier to read.
public static final int UP = 0;
public static final int LEFT = 1;
public static final int DOWN = 2;
public static final int RIGHT = 3;
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
}
>>29
Jesus, that is abysmal. I know it's Java, but you still shouldn't be programming.
Name:
Anonymous2011-03-07 18:43
You should randomize the starting positions of the enemies. That makes it impossible for the player to find an always safe spot.
here's some random fps code that i found in some old test code of mine. Good to get an fps option so you can see if your changes are making improvements.
>Also plz keep elitism to a minimum
sorry, it is java. I can't
>java
>slow
gee, why I am not suprised
Name:
Anonymous2011-03-07 19:23
>>27
Yeah that's pretty anal. Most of the A3Constants class was provided with the assignment. I added a few things in there. >>29
Thanks for the suggestion. My hitbox system is quite roundabout - there's a box 3/4 of the player, as well as a Point on each extremity of the player - The box or points make contact with the box of an enemyball (which are simply boxes around the circles). From all the playing I've done I haven't noticed any obvious false positives/negatives. Of course they're there, but in those cases a collision would happen in the next frame so it's not noticeable. >>31
The enemyballs direction/speed is randomised every time they disappear. So the intial pattern is quickly broken, there is no 'safe spot'. I quite like the effect of them all starting in the corners.
Name:
Anonymous2011-03-07 19:28
>>29
You need to work on your math. That is hideous. Distance formula never returns negative values for real inputs.
Name:
Anonymous2011-03-07 22:50
>>33
They're more noticeable when the player is larger. You still have to look for it. It was interesting looking at how you did it though.
Didn't realize they gave you part of the code.
Did you do all of the graphics programming too? That had to be a bitch!
>>34
Meh, code I was playing around with when I had free time at work. Just giving ideas.