好友
阅读权限10
听众
最后登录1970-1-1
|
yy852
发表于 2016-11-17 14:41
1 solarFrame
[Java] 纯文本查看 复制代码 package cn.solar.test;
import java.awt.Graphics;
import java.awt.Image;
import cn.lsz.test1.Constant;
import cn.lsz.test1.GameUtil;
import cn.lsz.test1.MyFrame;
public class solarFrame1 extends MyFrame {
Image bg = GameUtil.getImage("images/bg.jpg");
Star1 sun = new Star1("images/sun.jpg",Constant.GAME_WEIGHT/2,Constant.GAME_HEIGHT/2);//太阳
Planet1 Mercury = new Planet1(sun, "images/Mercury.jpg", 100, 50, 0.1);//水星
Planet1 Venus = new Planet1(sun, "images/Venus.jpg", 140, 80, 0.5);//金星
Planet1 earth = new Planet1(sun, "images/earth.jpg", 170, 110, 0.2);//地球
Planet1 moon = new Planet1(earth, "images/moon.jpg", 30, 20, 0.4,true);
Planet1 Mars = new Planet1(sun, "images/Mars.jpg", 220, 140, 0.3);//火星
Planet1 Jupiter = new Planet1(sun, "images/Jupiter.jpg", 290, 200, 0.08);//木星
Planet1 Saturn = new Planet1(sun, "images/Saturn.jpg", 330, 230, 0.03);//土星
Planet1 Uranus = new Planet1(sun, "images/Uranus.jpg", 370, 270, 0.1);//天王星
Planet1 Neptune = new Planet1(sun, "images/Neptune.jpg", 400, 300, 0.05);//海王星
@Override
public void paint(Graphics g) {
g.drawImage(bg, 0, 0, null);
sun.draw(g);//太阳
Mercury.draw(g);
Venus.draw(g);
earth.draw(g);//地球
Mars.draw(g);//火星
Jupiter.draw(g);
Saturn.draw(g);
Uranus.draw(g);
Neptune.draw(g);
moon.draw(g);
}
public static void main(String[] args) {
new solarFrame1().launchFrame();
}
}
2 Planet1
[Java] 纯文本查看 复制代码 package cn.solar.test;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import cn.lsz.test1.GameUtil;
public class Planet1 extends Star1 {
double longAxis;
double shortAxis;
double speed;
double dreege;
Star1 center;
boolean satellite;//卫星
public void draw(Graphics s) {
super.draw(s);
move();
if(!satellite)
{
drawTrace(s);
}
}
public void drawTrace(Graphics s) {
double _x,_y,_width,_height;
_width = longAxis*2;
_height = shortAxis*2;
_x = (center.x+center.width/2)-longAxis;
_y = (center.y+center.height/2)-shortAxis;
Color c = s.getColor();
s.setColor(Color.blue);
s.drawOval((int)_x,(int)_y,(int)_width, (int)_height);
s.setColor(c);
}
public void move() {
x = (center.x+center.width/2)+longAxis*Math.cos(dreege);
y = (center.y+center.height/2)+shortAxis*Math.sin(dreege);
dreege += speed;
}
public Planet1(Star1 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.width = img.getWidth(null);
this.height = img.getHeight(null);
this.longAxis = longAxis;
this.shortAxis = shortAxis;
this.speed = speed;
}
public Planet1(Star1 center, String imgpath, double longAxis, double shortAxis, double speed,boolean satellite ) {
this(center, imgpath, longAxis, shortAxis, speed);
this.satellite = satellite;
}
public Planet1(Image img, double x, double y) {
super(img, x, y);
// TODO Auto-generated constructor stub
}
public Planet1(String imgpath, double x, double y) {
super(imgpath, x, y);
// TODO Auto-generated constructor stub
}
}
3 Star1
[Java] 纯文本查看 复制代码 package cn.solar.test;
import java.awt.Graphics;
import java.awt.Image;
import cn.lsz.test1.GameUtil;
public class Star1 {
Image img;
double x,y;
int width,height;
public void draw(Graphics s) {
s.drawImage(img, (int)x, (int)y, null);
}
public Star1(Image img) {
this.img = img;
this.width = img.getWidth(null);
this.height = img.getHeight(null);
}
public Star1(Image img,double x,double y) {
this(img);
this.x = x;
this.y = y;
}
public Star1(String imgpath,double x,double y) {
this(GameUtil.getImage(imgpath), x, y);
}
}
|
免费评分
-
查看全部评分
|