Probably a very basic Java problem but I have two variables in a entity class:
public class Entity {
int posX;
int posY;
public Entity(int posX, int posY){
this.posX = posX;
this.posY = posY;
}
public void update(){
}
public void draw(Graphics2D g2d){
}
}
My player and enemy class extend it and then render off of the two variables. Like so:
public void draw(Graphics2D g2d) {
g2d.drawImage(getPlayerImg(), posX, posY, null);
if (showBounds == true) {
g2d.draw(getBounds());
}
}
I need to access these variables like this (This is in my enemy class):
public static void moveFemale(){
if(posX <= Player.posX){
//do AI code
}
}
posX And Player.posX throw an error saying I need to change the modifier of posX in Entity.java to static. But when I change it to static, my renderer for the enemy class stops working and the enemies no longer show up on screen. How could I go about creating a variable that allowed me to do this:
public static void moveFemale(){
if(posX <= Player.posX){
//do AI code
}
}
And still render my enemies? Sorry for the wall of text and any answers would help a lot!