package cn.com.solar;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import cn.com.util.GameUtil;
public class Planet extends Star{
//除了图片,坐标。行星沿着某个椭圆运行:长轴、短轴、速度。绕着某个Strat飞。
double longAxis;//椭圆的长轴
double shortAxis;//椭圆的短轴
double speed;
double degree;
Star center;
boolean satellite;//判断是否是卫星,若是,则不画轨迹
//重写父类的draw方法
public void draw(Graphics g){
super.draw(g);
move();
if(!satellite){
drawTrace(g);
}
}
public void move(){
//沿着椭圆轨迹飞行
x=center.x+center.width/2+longAxis*Math.cos(degree);
y=center.y+center.height/2+shortAxis*Math.sin(degree);
degree+=speed;
}
public void drawTrace(Graphics g){
double ovalX,ovalY,ovalWidth,ovalHeight;
ovalWidth=longAxis*2;
ovalHeight=shortAxis*2;
ovalX=(center.x+center.width/2)-longAxis;
ovalY=(center.y+center.height/2)-shortAxis;
Color color=g.getColor();
g.setColor(Color.BLUE);
g.drawOval((int)ovalX, (int)ovalY, (int)ovalWidth, (int)ovalHeight);
g.setColor(color);
}
public Planet(Star center,String imgpath,double longAxis,double shortAxis,double speed){
super(GameUtil.getImage(imgpath));
this.center=center;
this.x=center.x+longAxis;
this.y=center.y;
this.longAxis =longAxis;
this.shortAxis=shortAxis;
this.speed=speed;
}
public Planet(Star center,String imgpath,double longAxis,double shortAxis,double speed,boolean satellite){
this(center, imgpath, longAxis, shortAxis, speed);
this.satellite=satellite;
}
public Planet(Image img,double x,double y){
super(img, x, y);
}
public Planet(String imgpath,double x,double y){
super(imgpath, x, y);
}
}