package graphics;
import java.awt.*;
import javax.swing.ImageIcon;
import javax.swing.Icon;
import _main.Game;
import vehicles.*;
import route.Route;
import cross.*;
public class GraphicsPoliceCar extends AbstractGraphicsObject {
int xp;
int yp;
Icon image;
Icon image1;
Icon image2;
Icon image3;
Icon image4;
Icon image5;
Icon image6;
Icon image7;
Icon image8;
int rotation;
Draw draw;
PoliceCar ord;
/**
* GraphicsPoliceCar konstruktora, beolvassuk a felhasznalt kepeket a megfelelo attributumokba
* a kesobbi felhasznalas celjabol
*/
public GraphicsPoliceCar(){
try {
image = new ImageIcon("images/police1.gif","ordinary car"); //egy ilyen imageIcont kell letrehozni
image1 = new ImageIcon("images/police1.gif","ordinary car"); //egy ilyen imageIcont kell letrehozni
image2 = new ImageIcon("images/police2.gif","ordinary car"); //egy ilyen imageIcont kell letrehozni
image3 = new ImageIcon("images/police3.gif","ordinary car"); //egy ilyen imageIcont kell letrehozni
image4 = new ImageIcon("images/police4.gif","ordinary car"); //egy ilyen imageIcont kell letrehozni
image5 = new ImageIcon("images/police5.gif","ordinary car"); //egy ilyen imageIcont kell letrehozni
image6 = new ImageIcon("images/police6.gif","ordinary car"); //egy ilyen imageIcont kell letrehozni
image7 = new ImageIcon("images/police7.gif","ordinary car"); //egy ilyen imageIcont kell letrehozni
image8 = new ImageIcon("images/police8.gif","ordinary car"); //egy ilyen imageIcont kell letrehozni
}
catch (Exception e) {
e.printStackTrace();
}
}
/**
* Beallitjuk a PoliceCar-t
* @param o PoliceCar
*/
public void setPoliceCar(PoliceCar o){
ord = o;
}
/**
* Elkerjuk a Policecar poziciojat
* @return Point: a rendorauto pozicioja
*/
public Point getPosition(){
return new Point(xp,yp);
}
/**
* Elkerjuk a kepet
* @return Icon kep
*/
public Icon getImage()
{
return image;
}
/**
* Beallitjuk a draw-t
* @param d: adott Draw
*/
public void setDraw(Draw d){
draw = d;
}
/**
* kiszamoljuk a megjeleniteshez szuksegse valtozok ertekeit
*/
public void calcGraphics(){
MainGraphics gr = Game.getInstance().getMap().getGraphics();
Route r = ord.getRoute();
//ha nem keresztezodesben van az auto
if (r!=null)
{
// ket csompont koordinatinak lekerdezese
Cross cr1 = r.getStartCross();
Point cr1p = gr.getGraphicsFromObject(cr1).getPosition();
Cross cr2 = r.getEndCross();
Point cr2p = gr.getGraphicsFromObject(cr2).getPosition();
// konkret koordinata kiszamolasa
xp = (cr2p.x-cr1p.x)*ord.getPosition()/r.getLength()+cr1p.x;
yp = (cr2p.y-cr1p.y)*ord.getPosition()/r.getLength()+cr1p.y;
setRotateImage(calcRotation(cr1p,cr2p));
System.out.println("police:"+xp+","+yp);
}
// ha keresztezodesben van az auto
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;
}
}
}