Okay, I've had this error for days and I just cannot place how to fix it.
To pinpoint where the error was I put in debug messages in my code so that I knew where in the code it was freezing. However, it seems to freeze at different points:
My game involves a spaceship shooting lasers at enemies (original, I know) and this is my code for the collision check:"Start of second loop: 5, 6"
"Start of second loop: 12, 11"
"Made dead enemy"
"Start of second loop: 2, 36"
"Start of second loop: 10, 17"
"Start of first loop loop: 0"
"Start of first loop loop: 5"
//collisions // - laser and enemy // i = current laser // ii = current enemy //cycles through all lasers for (i=0; i<totallasers; i++) { //debug messages are drawn to screen message = "Start of first loop: " + i; //if current laser is active (lasers become inactive when they leave the screen or collide with an enemy if (laser[i].active) //cycles through all enemies for (ii=0; ii<totalenemies; ii++) { //if current enemy is active (enemies become inactive when they leave the screen or collide with a laser if (enemy[ii].active) { message = "Start of second loop: " + i + ", " + ii; //if the centre point of the laser is in the enemies rectangular boundary if (scr.PointCheck(laser[i].x+12,laser[i].y+2,enemy[ii].x,enemy[ii].y,enemy[ii].width,enemy[ii].height)) { message = "Testing collision between " + i + " and " + ii; //creates a "dead" enemy of the same type and in the same position as the current enemy that has just been hit deadEnemy[totaldeadenemies] = new DeadEnemy(enemy[ii].type,enemy[ii].x,enemy[ii].y); message = "Made deadenemy"; totaldeadenemies++; //"destroys" current laser and enemy laser[i].active=false; enemy[ii].active=false; } } message = "End of second loop"; } message = "End of first loop"; }
The code for PointCheck() is this:
public boolean PointCheck(int x, int y, int x2, int y2, int width, int height) { if (x>x2 && x<x2+width && y>y2 && y<y2+height) return true; else return false; }
The error seems to happen randomly so I can't really pinpoint what is wrong with the code. I added the "message = "blahblahblah"" which gets drawn to the screen so that I can see which part of the loops it freezes in, but it isn't the same one each time (it's frozen at first loop, second loop, testing collisions...).
Any help would be really really appreciated. I've tried for days but I can't solve this problem and it's preventing me from working on the rest of the game
If you need me to explain the code a bit more just say and I'll try to tell you what means what etc (some things I've done might not be fully self-explanatory).
Thanks in advance ;D