java星球动画制作_java 星球转动效果

【实例简介】

【实例截图】

【核心代码】

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

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值