package graphics;
import java.awt.Point;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import route.Route;
import vehicles.OrdinaryCar;
import _main.Game;
import cross.Cross;
public class GraphicsOrdinaryCar 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 image;
private Icon image1;
private Icon image2;
private Icon image3;
private Icon image4;
private Icon image5;
private Icon image6;
private Icon image7;
private Icon image8;
private int rotation;
private Draw draw;
private OrdinaryCar ord;
/**
* GraphicsOrdinaryCar konstruktora, beolvassuk a felhasznalt kepeket a megfelelo attributumokba
* a kesobbi felhasznalas celjabol
*/
public GraphicsOrdinaryCar(){
// kep beolvasasa
try {
// image = Toolkit.getDefaultToolkit().getImage("images/ordinarycar1.gif");
image = new ImageIcon("images/ordinarycar1.gif","ordinary car"); //egy ilyen imageIcont kell letrehozni
image1 = new ImageIcon("images/ord1.gif","ordinary car"); //egy ilyen imageIcont kell letrehozni
image2 = new ImageIcon("images/ord2.gif","ordinary car"); //egy ilyen imageIcont kell letrehozni
image3 = new ImageIcon("images/ord3.gif","ordinary car"); //egy ilyen imageIcont kell letrehozni
image4 = new ImageIcon("images/ord4.gif","ordinary car"); //egy ilyen imageIcont kell letrehozni
image5 = new ImageIcon("images/ord5.gif","ordinary car"); //egy ilyen imageIcont kell letrehozni
image6 = new ImageIcon("images/ord6.gif","ordinary car"); //egy ilyen imageIcont kell letrehozni
image7 = new ImageIcon("images/ord7.gif","ordinary car"); //egy ilyen imageIcont kell letrehozni
image8 = new ImageIcon("images/ord8.gif","ordinary car"); //egy ilyen imageIcont kell letrehozni
}
catch (Exception e) {
e.printStackTrace();
}
}
/**
* Beallitjuk az Ordinary car-t.
* @param o Ordinary Car
*/
public void setOrdinaryCar(OrdinaryCar o){
ord = o;
}
/**
* Visszaadja az auto adott poziojat
* @return Point: az auto koordinataja
*/
public Point getPosition(){
return new Point(xp,yp);
}
public Icon getImage(){
return image;
}
public void setDraw(Draw d){
draw = d;
}
/**
* kiszamoljuk a megjeleniteshez szukseges valtozokat
*/
public void calcGraphics(){
MainGraphics gr = Game.getInstance().getMap().getGraphics();
Route r = ord.getRoute();
// ha uton vagyunk es nem keresztezodesben
if (r!=null){
// az adott ut ket csomopontjanak koordinatainak lekerdezese
Cross cr1 = r.getStartCross();
Point cr1p = gr.getGraphicsFromObject(cr1).getPosition();
Cross cr2 = r.getEndCross();
Point cr2p = gr.getGraphicsFromObject(cr2).getPosition();
// konkret pozicio kiszamolasa
xp = (cr2p.x-cr1p.x)*ord.getPosition()/r.getLength()+cr1p.x;
yp = (cr2p.y-cr1p.y)*ord.getPosition()/r.getLength()+cr1p.y;
System.out.println(xp+","+yp);
//melyik forgat�st hozzuk be: f�gg a k�t csom�pont helyzet�t�l
setRotateImage(calcRotation(cr1p,cr2p));
}
else{
Point crp = gr.getGraphicsFromObject(ord.getCross()).getPosition();
xp = crp.x;
yp = crp.y;
}
draw.drawing((Object)this,gr.getGraphic());
}
/**
* beallitja az autonal melyik forgatott kepet mutassa
* @param n 1..8-ig az autok kepei
*/
public void setRotateImage(int n){
switch(n){
case 1: image = image1;break;
case 2: image = image2;break;
case 3: image = image3;break;
case 4: image = image4;break;
case 5: image = image5;break;
case 6: image = image6;break;
case 7: image = image7;break;
case 8: image = image8;break;
}
}
}