here it is:
Player collision (collision box in the middle of screen):
public static void Collision(){
for (int i=0;i<e.size();i++){
if (bounds().intersects(e.get(i).bounds())){
//collision stuff here
if(e.get(i).enNum==5){
System.out.println("hit a wall");
if(direction==1){
goRight=false;
goUp=false;
goLeft=false;
goDown=false;
speedx=0;
x-=1;
canChange=false;
}
else if(direction==2){
goRight=false;
goUp=false;
goLeft=false;
goDown=false;
x+=5;
speedx=0;
canChange=false;
}
else if(direction==3){
goRight=false;
goUp=false;
goLeft=false;
goDown=false;
speedy=0;
y-=5;
canChange=false;
}
else if(direction==4){
goRight=false;
goUp=false;
goLeft=false;
goDown=false;
speedy=0;
y+=1;
canChange=false;
}
}
else{
goRight=true;
goUp=true;
goDown=true;
goLeft=true;
//speed=8;
}
}
}
}
here is the collision to the tiles:
public Rectangle bounds(){
return (new Rectangle(-Player.x+x,-Player.y+-y, size,size));
}
and finally the player collision box:
public static Rectangle bounds(){
return (new Rectangle(Main.width/2*Main.Scale, Main.height/2*Main.Scale,32,32));
}