problem is that picture is not being printed on screen from enemy_1 class.
i have a class enemy where i am setting up main enemy stuff. for ex collision and move bc all enemy will have the same move and collision.
than i want to create another class called enemy_1 where i will upload different images.
my goal is to set variable from Enemy class to Enemy_1 class.
first here is a Enemy class
public class Enemy { private int x; private int y; private int width = 30; private int height = 40; public Enemy(int ix, int iy) { x = ix; y = iy; } public int getX() { return x; } public void setX(int value) { this.x = value; } public int getY() { return y; } public void setY(int value) { this.y = value; } public int getWIDTH() { return width; } public void setWIDTH(int value) { this.width = value; } public int getHEIGHT() { return height; } public void setHEIGHT(int value) { this.height = value; } /*** update method ****/ /*** player move ***/ public void ENEMY_MOVE(Main m, Sprite_Sheet s) { Random r = new Random(); //x -= 1; if(x+width < 0) { x = m.getWidth() + r.nextInt(200); } } /*** player + enemy collion ***/ public void PLAYER_ENEMY_COLLISION(Main m, Player p, Enemy e) { int playerX = p.getX(); int playerY = p.getY(); int playerW = p.getWIDTH(); int playerH = p.getHEIGHT(); if(playerX + playerW >= x && playerX <= x + width) { if(playerY+playerH >= y && playerY <= y+height) { if (playerX <= x) //player on left { //player has to be touching enemy and player has to be on left of enemy p.setX(x - playerW); } else if(playerX >= x)//player on right { //player has to be touch enemy and player has to be on right of enemy p.setX(x + width); } } } }/*** end of PlAYER_ENEMY_COLLISION METHOD ***/ /*** paint method ***/ public void paint(Graphics g, Enemy e) { }/*** paint method ***/ }
now i am extending the main enemy class.
public class Enemy_1 extends Enemy { private static ImageIcon enemy_image = new ImageIcon("Image/enemy/ch2.png"); public Enemy_1(int ix, int iy) { super(ix,iy); } /*** get/set methods ***/ public static Image getEIMAGE() { return enemy_image.getImage(); } @Override public void enemy_action(Player p, Score s) { } @Override public void paint(Graphics g, Enemy e) { g.drawImage(this.getEIMAGE(), e.getX(), e.getY(), e.getWIDTH(), e.getHEIGHT(), null); super.paint(g, e); //call enemy paint method } }
when i put every thing in enemy class than it works fine but when i create two class it doesnt work.
problem is in enemy_1 class. when i run this picture is not being printed. i am not sure but i think i am not sure paint method in enemy_1 class.
paint from enemy
/*** paint method ***/ public void paint(Graphics g, Enemy e) { }/*** paint method ***/
paint from enemy_1
@Override public void paint(Graphics g, Enemy e) { g.drawImage(this.getEIMAGE(), e.getX(), e.getY(), e.getWIDTH(), e.getHEIGHT(), null); super.paint(g, e); //call enemy paint method }
let me now if you need more information