📄 fallingbox.java
字号:
package net.java.gamebase.sample.boxes.v3;
import java.awt.Color;
import java.awt.Graphics;
import net.java.gamebase.core.GameCharMovable;
public class FallingBox extends GameCharMovable {
public static final Color [] colors ={
Color.BLACK,
Color.BLUE,
Color.CYAN,
Color.DARK_GRAY,
Color.GRAY,
Color.GREEN,
Color.LIGHT_GRAY,
Color.MAGENTA};
private int color;
private int position;
private boolean falling;
private int horizontalSpace;
private BoxesGame3 base;
public FallingBox(int color, int x, int y, BoxesGame3 base) {
super("", x, y, 32, 32);
this.color = color;
this.position = 0;
this.falling = true;
this.base = base;
}
public void paint(Graphics g) {
super.paint(g);
g.setColor(colors[color]);
g.fillRect(0, 0, getWidth()-1, getHeight()-1);
g.setColor(Color.BLACK);
g.drawRect(0, 0, getWidth()-1, getHeight()-1);
}
public void tick(){
// if its falling
if( falling ){
// check if its at the last lane
if( ! base.isLastLane(this) ){
setY((position * getWidth()+ horizontalSpace) + horizontalSpace);
position ++;
}
}
}
public void stopFalling(){
falling = false;
}
public int getPosition() {
return position;
}
public void setHorizontalSpace(int horizontalSpace) {
this.horizontalSpace = horizontalSpace;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -