基本信息
源码名称:java 星球转动效果
源码大小:0.08M
文件格式:.zip
开发语言:Java
更新时间:2015-12-30
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍


package cn.bjsxt.solar;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;

import cn.bjsxt.util.GameUtil;



public class Planet extends Star {

	//除了图片,坐标。 行星沿着某个椭圆运行:长轴、短轴、速度、角度。 绕着某个Star飞。
	double longAxis;  //椭圆的长轴
	double shortAxis;  //椭圆的短轴
	double speed;     //飞行的速度
	double degree;    
	Star center;
	
	boolean satellite;
	
	
	public void draw(Graphics g){
		super.draw(g);
		move();
		if(!satellite){
			drawTrace(g);
		}
	}
	
	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 c=g.getColor();
		g.setColor(Color.blue);
		g.drawOval((int)OvalX,(int)OvalY, (int)OvalWidth,(int)OvalHeight);
		g.setColor(c);
		
	}	

	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 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;
		
		//this.width = img.getWidth(null);
		//this.height = img.getHeight(null);

	}
	
	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);
	}
	
	
}