Ciao a tutti![]()
Durante la creazione del gioco è sorto un altro problema, quello del fuoco nemico e quindi della gestione dell' IA...qualcuno può darmi una mano???
Io avevo pensato una cosa di questo tipo:
il fuoco parte però non va verso sinistra come dovrebbe fare in :codice:private JLabel fuocon; private class Game extends Thread { @Override public void run() { Energia.setValue(100); boolean control=true; boolean attacco=false; while (control) { for (int c = 0; c < h; c++) { if (nemico[c].getLocation().x <= 0) { nemico[c].setLocation(800, nemico[c].getLocation().y); } nemico[c].setLocation(nemico[c].getLocation().x - 1 , nemico[c].getLocation().y); FuocoNemico(nemico[c]); } try { sleep(10);//velocità aerei nemici } catch (InterruptedException ex) { } /*if(Winner()) { win.setVisible(true); control=false; }*/ } } } private void FuocoNemico(JLabel nem) { boolean attacco=false; int vof = (int) ((1-0+1)*Math.random()); switch (vof) { case 0:attacco=true; break; case 1:attacco=false; break; } if (attacco) { fuocon = new JLabel(new ImageIcon(getClass().getResource("/game/graphics/images/fuoco nemico.png"))); fuocon.setLocation(nem.getLocation().x-40, nem.getLocation().y); fuocon.setSize(60, 100); jPanel1.add(fuocon); fuocon.setVisible(true); Point loc = fuocon.getLocation(); for (int i = 0; i < 400; i++) { fuocon.setLocation(fuocon.getLocation().x - 2, fuocon.getLocation().y); } } }
ma rimane vicino all' aereo per tutto il suo proseguiemnto...codice:for (int i = 0; i < 400; i++) { fuocon.setLocation(fuocon.getLocation().x - 2, fuocon.getLocation().y); }
L'errore forse sta nel passare le coordinate dellaereo, dato che quest'ultimo essendo in movimento le fà variare continuamente ? Come potrei risolvere nel caso questo problema?
Oppure non c'entrano niente le coordinate e il problema è da tutt'altra parte?
Comunque se avete un consiglio/idea per una migliore gestione dell IA ditemi sono tutto orecchie![]()



Rispondi quotando