中脉虚假宣传APP不存在,从设计到研发过程解析
该文件定义了一个Circle类,用以生成每个球的对象。
属性有圆的半径、x坐标、y坐标、x方向的偏移量、y方向的偏移量、id。
方法有移动和获取每个属性的接口
package com.hust.game;
import java.awt.*;
import java.util.Random;
public class Circle {
protected int radius,x,y,dx,dy;
private int id;
protected GUI gui;
String color;
public Circle(int X,int Y,int R,int id,String color,GUI gui,int dx,int dy){
x = X;
y = Y;
radius = R;
Random random = new Random();
this.dx = random.nextBoolean() ? dx : -dx;
this.dy = random.nextBoolean() ? dy : -dy;
this.gui = gui;
this.id = id;
this.color = color;
draw();
}
public Circle(int X,int Y,int R,int id,String color,GUI gui){
x = X;
y = Y;
radius = R;
this.gui = gui;
this.id = id;
this.color = color;
}
public void draw(){
gui.updateCircle(this);
}
public void move(){
// clearcircle()
x += dx;
y += dy;
if(x + radius > gui.graphWidth || x - radius < 0){
dx = -dx;
}
if(y + radius > gui.graphHeight || y - radius < GUI.PROGRESSWIDTH){
dy = -dy;
}
draw();
}
public int getX(){
return x;
}
public int getY(){
return y;
}
public int getR(){
return radius;
}
public int getD(){
return radius << 1;
}
public int getID(){
return id;
}
}
中脉虚假宣传APP不存在,从设计到研发过程解析
import java.util.Random;
public class Bee extends FlyingObject implements Award{
private int xSpeed = 1; //x坐标移动速度
private int ySpeed = 2; //y坐标移动速度
private int awardType; //奖励类型
public Bee(){
this.image = ShootGame.bee;
width = image.getWidth();
height = image.getHeight();
y = -height;
Random rand = new Random();
x = rand.nextInt(ShootGame.WIDTH - width);
awardType = rand.nextInt(2); //初始化时给奖励
}
public int getType(){
return awardType;
}
@Override
public boolean outOfBounds() {
return y>ShootGame.HEIGHT;
}
@Override
public void step() {
x += xSpeed;
y += ySpeed;
if(x > ShootGame.WIDTH-width){
xSpeed = -1;
}
if(x < 0){
xSpeed = 1;
}
}
}
好了不扯蛋了,认真回答问题。
0.用java写小游戏需要知道什么,明白什么?
首先需要知道游戏的本质,其实是图片(像)的显示以及图片的移动(图片坐标的改变)。
明白了这两点以后,问题就变得简单了,把问题变成,如何用java显示一张图片与如何动态的改变图片的坐标。
到这里回答题主的第二个问题。
1.需要初学者做的步骤有哪些
展示一张图片,需要一个容器,容器的种类有很多, 这里不一一列举,以上述游戏中使用的java原生javax.swing包中的类容为例,不需要再引入其它jar包。
public class Bullet extends FlyingObject {
private int speed = 3; //移动的速度
public Bullet(int x,int y){
this.x = x;
this.y = y;
this.image = ShootGame.bullet;
}
@Override
public void step(){
y-=speed;
}
@Override
public boolean outOfBounds() {
return y<-height;
}
}



