Java - AWT: Making objects point to other objects -
i begginer java programmer awt, , i'm wondering how make enemy()
point player()
. here code far:
player.java:
import java.awt.color; import java.awt.graphics; public class player extends gameobject { public player(int x, int y, color color) { super(x, y, color); } @override public void tick() { x += velx; y += vely; } @override public void render(graphics g) { g.setcolor(color); g.fillrect(x, y, 32, 32); } }
enemy.java:
import java.awt.color; import java.awt.graphics; public class enemy extends gameobject { public enemy(int x, int y, color color) { super(x, y, color); } @override public void tick() { x += velx; y += vely; } @override public void render(graphics g) { g.setcolor(color); g.fillrect(x, y, 32, 32); } }
so how can begin moving enemy()
towards player()
game works?
you need reference gameobject somehow. you're missing in design. somewhere, in these 2 classes, or class, should keeping track of reference gameobject variable can set enemy player. there's no way arbitrarily make 1 class another.
Comments
Post a Comment