package graphics;
import java.awt.Point;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import bunny.Bunny;
import route.Route;
import vehicles.OrdinaryCar;
import _main.Game;
import cross.Cross;
public class GraphicsBunny extends AbstractGraphicsObject {
//TODO: [peti] ezek private mezok es get-set-tel lehet csak rajuk hivatkozni! lathatosagot mindig irjunk, kulonben azert tuti pontlevonas jar
private int xp;
private int yp;
//!! nem image, hanem icon tipus
private Icon image1;
private Icon image2;
public GraphicsBunny(){
// kep beolvasasa
try {
//
image1 = new ImageIcon("images/nyul1.gif","nyul"); //egy ilyen imageIcont kell letrehozni
image2 = new ImageIcon("images/nyul2.gif","nyul"); //egy ilyen imageIcont kell letrehozni
}
catch (Exception e) {
e.printStackTrace();
}
}
/**
* Visszadja a nyuszi kepet, annak megfeleloen, hogy elutottek-e
* @return Icon: nyuszi kepe
*/
public Icon getImage(){
if (Bunny.get().getHit()==true) return image2;
else return image1;
}
public Point getPosition(){return new Point(xp,yp);}
/**
* Kiszamolja a megjeleniteshez szukseges valtozok ertekeit
*/
public void calcGraphics(){
MainGraphics gr = Game.getInstance().getMap().getGraphics();
//meghatarozzuk a bunny poziciojat a terkepen
Route r = Bunny.get().getRoute();
// lekerjuk a ket csomopont koordinatait
Cross cr1 = r.getStartCross();
Point cr1p = gr.getGraphicsFromObject(cr1).getPosition();
Cross cr2 = r.getEndCross();
Point cr2p = gr.getGraphicsFromObject(cr2).getPosition();
//kiszamoljuk a bunny konkret megjeleniteshez hasznalt koordinatajat
xp = (cr2p.x-cr1p.x)*Bunny.get().getPos()/r.getLength()+cr1p.x;
yp = (cr2p.y-cr1p.y)*Bunny.get().getPos()/r.getLength()+cr1p.y;
System.out.println("bunny:"+xp+","+yp);
draw.drawing((Object)this,gr.getGraphic());
}
}