I'm making hit detection in Eclipse and I need to check for specific TileType enum classes, AND certain actors in my game, however I can't seem to put them in the same array. What should I do?
package data;
import static helpers.Clock.*;
import org.newdawn.slick.opengl.Texture;
import data.World.*;
public class Matter extends Actor{
double xmove=0, ymove=0;
public Matter(Texture texture, float x, float y, int width, int height){
super(texture, x, y, width, height);
}
//Physics Stuff
static double g = 1; //gravitational acceleration
static String gravityDirection = "down";
boolean reaction = false;
int hw = getWidth()/2; //half of the hit box's width
int hh = getHeight()/2; //half of the hit box's height
String collided = "";
public void physics(){
collided = ""; //reset variable collided
//Gravity acceleration
if (gravityDirection.equals("down")){ymove += g;}
if (gravityDirection.equals("up")){ymove -= g;}
if (gravityDirection.equals("left")){xmove -= g;}
if (gravityDirection.equals("right")){xmove += g;}
//Hit detection
float deltaX=(float) (xmove*Delta()); //actual distance moved in the x coordinate
float deltaY=(float) (ymove*Delta()); //actual distance moved in the y coordinate
//if (xmove!=0||ymove!=0){System.out.println(World.getTileAt((int)getX()+getWidth()/2, (int)getY()+getHeight()/2));}
//Collision Detection
TileType[] solids = {TileType.TileB}; //all classes that can be collided with
for (int c = 0; c<solids.length; c++){//This for statement handles all of the tile collisions
//Vertical Collisions
for (int x=0; x<hw*2-1; x+=hw/2-2){
if (deltaY==0){break;} //if there is no vertical movement, then don't check for vertical collisions
//Down
for (int y=0; y<=deltaY; y++){//If ymove is negative, then the loop wont activate in the first place
TileType tile = World.getTileAt((int) getX()+x+1, (int) getY()+hh*2+y);
if ((int)getY()+hh*2+y > World.getHeight()-1 || tile!=null && tile.equals(solids[c])){
setLocation(getX(),getY()+y);
collided += "down";
if (reaction){
deltaY/=3;
ymove/=3;
}else{
deltaY=0;
ymove=0;
}
break;
}
}
if (ymove==0){break;} //if there is no vertical movement, then don't check for vertical collisions
//Up
for (int y=0; y>=deltaY; y--){
TileType tile = World.getTileAt((int) getX()+x+1, (int) getY()+y-1);
if ((int)getY()+y-1 < 0 || tile!=null && tile.equals(solids[c])){
setLocation(getX(),getY()+y);
collided += "up";
if (reaction){
deltaY/=3;
ymove/=3;
}else{
deltaY=0;
ymove=0;
}
break;
}
}
}
//Horizontal Collisions
for (int y=0; y<hh*2-1; y+=hh/2-2){
if (deltaX==0){break;} //if there is no horizontal movement, then don't check for horizontal collisions
//left
for (int x=0; x>=deltaX; x--){
TileType tile = World.getTileAt((int) getX()+x-1, (int) getY()+y+1);
if ((int)getX()+x-1 < 0 || tile!=null && tile.equals(solids[c])){
setLocation(getX()+x,getY());
collided += "left";
if (reaction){
deltaX/=3;
xmove/=3;
}else{
deltaX=0;
xmove=0;
}
break;
}
}
if (deltaX==0){break;} //if there is no horizontal movement, then don't check for horizontal collisions
//right
for (int x=0; x<=deltaX; x++){
TileType tile = World.getTileAt((int) getX()+hw*2+x, (int) getY()+y+1);
if ((int)getX()+hw*2+x > World.getWidth()-1 || tile!=null && tile.equals(solids[c])){
setLocation(getX()+x,getY());
collided += "right";
if (reaction){
deltaX/=3;
xmove/=3;
}else{
deltaX=0;
xmove=0;
}
break;
}
}
}
}
setLocation(getX()+deltaX,getY()+deltaY);
System.out.println(collided);
}
static public void setGravityDirection(String s){
gravityDirection = s;
}
static public void setGravitationalAcceleration(int i){
g = i;
}
}// this Object[] solids = ...; // instead of TileType[] solids = ...;