Javafx, how do I create Node/objects that are meant to represent a wave of mobs/turrets? -


tower defense game:

public class main extends application { ....... private node turret6; private int turretcount = 0;  @override public void start(stage stage) throws exception {     mob1image = new image(mob1_image_loc);     ............     turretimage = new image(turret_image_loc);     mob1 = new imageview(mob1image);     ............     turret1 = new imageview(turretimage);     group group = new group(mob1, mob2, mob3, mob4, mob5, home);     movemobto(1 * w / 10, h / 2, mob1);      ...............................     movemobto(5 * w / 10, h / 2, mob5);     movehometo(w * 9 / 10, h * 1 / 2);     scene scene = new scene(group, w, h, color.blue);      scene.setonmousepressed(new eventhandler<mouseevent>() {     @override     public void handle(mouseevent event) {         if (turretcount == 0) {         group.getchildren().add(turret1);         moveturretto( event.getscenex(), event.getsceney(), turret1);         turretcount = turretcount + 1;         score = score - 10;         }         else if (turretcount == 1) {}         .............................         else if (turretcount == 5) {}   }     });     stage.setscene(scene);     stage.show();     goeast = true;      animationtimer timer = new animationtimer() {         @override         public void handle(long now) {             int dx = 0, dy = 0;             if (goeast)  dx += 1;             movemobby(dx, dy, mob1);             ........................             movemobby(dx, dy, mob5); }     }; timer.start();}  private void movemobby(int dx, int dy, node mobs) {} private void movemobto(double x, double y, node mobs) {} private void moveturretto(double x, double y, node turret) {}  public static void main(string[] args) { launch(args); }  } 

so in class have 6 mob nodes , 6 turret nodes, mobs created , move east, , 6 turrets place mouse event. problem of course don't want limited writing group.getchildren.add(turret1), etc. 6 times each node want placed. , want each mob have health bar property associated it, or @ least health number, , see no way of doing node.

is there way make copies of node each own thing? have single private node turret, , can place many times? , there way can associate nodes class mob has health properties? i'm sure there is, can't figure out.

thanks can provide!

that's little bit answered on stackoverflow. however, toyed around tower defense last weekend , wrote blog post if interested. can full source there. it's prototype, ask in question. can place many turrets code. turrets rotate towards enemy, fire @ them , health displayed , reduced.

you may interested in a* algorithm need next step in tower defense game. enemies move top bottom. of course should find path start end, when place towers right in front of them move.

screenie:

enter image description here

and youtube link.


Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -