I am currently in the process in making a modified version of capture the flag and a quarter way though the process I ran into a weird issue. For some reason when moving player 2, the yellow player, around the board the entire game freezes at times. This is odd because for several minutes I tested player one by only moving that one and there was no freezing. There are no error messages nothing either.
Edit: I found an issue:holding down the arrow keys to move is fine, using the wasd keys however holding them down causes it to freeze they must be single pressed?
int[] player1;
int[] player2;
int[] player1chicken1;
int[] player1chicken2;
int[] player1chicken3;
int[] player2chicken1;
int[] player2chicken2;
int[] player2chicken3;
int p1chicken1width = 50;
int p1chicken1height = 50;
int p1chicken2width = 50;
int p1chicken2height = 50;
int p1chicken3width = 50;
int p1chicken3height = 50;
int p2chicken1width = 50;
int p2chicken1height = 50;
int p2chicken2width = 50;
int p2chicken2height = 50;
int p2chicken3width = 50;
int p2chicken3height = 50;
int p1width = 50;
int p1height = 50;
int p2width = 50;
int p2height = 50;
void setup(){
size(1200, 600);
player1= new int[] {250, 250};
player2= new int[] {950, 250};
player1chicken1= new int[] {40, 250};
player1chicken2= new int[] {40, 50};
player1chicken3= new int[] {40, 500};
player2chicken1= new int[] {1110, 250};
player2chicken2= new int[] {1110, 50};
player2chicken3= new int[] {1110, 500};
}
void draw(){
//draw players
fill(0);
rect(0,0,width/2,height);
fill(255,0,0);
rect(600,0,width/2,height);
//move players
fill(255);
rect(player1[0], player1[1], p1width, p1height);
if (keyPressed) {
switch(keyCode) {
case LEFT:
player1[0] -=10;
break;
case RIGHT:
player1[0] +=10;
break;
case UP:
player1[1] -=10;
break;
case DOWN:
player1[1] +=10;
break;
}
}
fill(255,255,0);
rect(player2[0], player2[1], p2width, p2height);
if (keyPressed) {
if (key=='a'){
player2[0] -=10;
}
if (key=='s'){
player2[0] +=10;
}
if (key=='w'){
player2[1] -=10;
}
if (key=='d'){
player2[1] +=10;
}
}
if(player1[0]+25>1150){
player1[0]-=25;
}
if(player1[0]-25<0){
player1[0]+=50;
}
if(player2[0]+25>1150){
player2[0]-=25;
}
if(player2[0]-25<0){
player2[0]+=50;
}
if(player1[1]+25>550){
player1[1]-=25;
}
if(player1[1]-25<0){
player1[1]+=50;
}
if(player2[1]+25>550){
player2[1]-=25;
}
if(player2[1]-25<0){
player2[1]+=50;
}
////////////////////////////////chickens
fill(0,0,255);
rect(player1chicken1[0],player1chicken1[1],p1chicken1width,p1chicken1height);
fill(0,0,255);
rect(player1chicken2[0],player1chicken2[1],p1chicken2width, p1chicken2height);
fill(0,0,255);
rect(player1chicken3[0],player1chicken3[1],p1chicken3width,p1chicken3width);
fill(0,0,255);
rect(player2chicken1[0],player2chicken1[1],p2chicken1width,p2chicken1width);
fill(0,0,255);
rect(player2chicken2[0],player2chicken2[1],p2chicken2width,p2chicken2width);
fill(0,0,255);
rect(player2chicken3[0],player2chicken3[1],p2chicken3width,p2chicken3width);
//move chickens
if(player1[0] + p1width/2 > player2chicken1[0] - p2chicken1width/2
&& player1[0] - p1width/2 < player2chicken1[0] + p2chicken1width/2
&& player1[1] + p1width/2 > player2chicken1[1] - p2chicken1height/2
&& player1[1] - p1width/2 < player2chicken1[1] + p2chicken1height/2 ){
player2chicken1[0]=player1[0];
player2chicken1[1]=player1[1];
}
if(player1[0] + p1width/2 > player2chicken2[0] - p2chicken2width/2
&& player1[0] - p1width/2 < player2chicken2[0] + p2chicken2width/2
&& player1[1] + p1width/2 > player2chicken2[1] - p2chicken2height/2
&& player1[1] - p1width/2 < player2chicken2[1] + p2chicken2height/2){
player2chicken2[0]=player1[0];
player2chicken2[1]=player1[1];
}
if(player1[0] + p1width/2 > player2chicken3[0] - p2chicken3width/2
&& player1[0] - p1width/2 < player2chicken3[0] + p2chicken3width/2
&& player1[1] + p1width/2 > player2chicken3[1] - p2chicken3height/2
&& player1[1] - p1width/2 < player2chicken3[1] + p2chicken3height/2){
player2chicken3[0]=player1[0];
player2chicken3[1]=player1[1];
}
//
//
//
if(player2[0] + p2width/2 > player1chicken1[0] - p1chicken1width/2
&& player2[0] - p2width/2 < player1chicken1[0] + p1chicken1width/2
&& player2[1] + p2width/2 > player1chicken1[1] - p1chicken1height/2
&& player2[1] - p2width/2 < player1chicken1[1] + p1chicken1height/2){
player1chicken1[0]=player2[0];
player1chicken1[1]=player2[1];
}
if(player2[0] + p2width/2 > player1chicken2[0] - p1chicken2width/2
&& player2[0] - p2width/2 < player1chicken2[0] + p1chicken2width/2
&& player2[1] + p2width/2 > player1chicken2[1] - p1chicken2height/2
&& player2[1] - p2width/2 < player1chicken2[1] + p1chicken2height/2){
player1chicken2[0]=player2[0];
player1chicken2[1]=player2[1];
}
if(player2[0] + p2width/2 > player1chicken3[0] - p1chicken3width/2
&& player2[0] - p2width/2 < player1chicken3[0] + p1chicken3width/2
&& player2[1] + p2width/2 > player1chicken3[1] - p1chicken3height/2
&& player2[1] - p2width/2 < player1chicken3[1] + p1chicken3height/2){
player1chicken3[0]=player2[0];
player1chicken3[1]=player2[1];
}
}