我有一个java项目谁制作了"windows'迷宫"并使用光线投射算法.这是一个截图:
就像你可以看到所有的墙都有相同的高度.我想做同样的事,但身高不同
private void castRay(int xOnScreen,double angle,double direction) {
R rx = castRayInX(angle,direction);
R ry = castRayInY(angle,direction);
// In case of out-of-space rays
if (rx.getDistance()==Double.MAX_VALUE && ry.getDistance()==Double.MAX_VALUE) {
graphics.setColor(BACKGROUND);
graphics.drawLine(xOnScreen,0,xOnScreen,this.image.getHeight());
return;
}
double distance = rx.getDistance();
double normal = rx.getNormal();
Color c = rx.getColor();
double coef = Math.cos((angle+direction+Math.PI)-normal);
Plot collision = rx.getPlot();
if (ry.getDistance()<rx.getDistance()) {
distance = ry.getDistance();
normal = ry.getNormal();
c = ry.getColor();
coef = Math.cos((angle+direction+Math.PI)-normal);
collision = ry.getPlot();
}
coef = Math.abs(coef);
int factor = map.length*SQUARE_SIZE;
double d …
Run Code Online (Sandbox Code Playgroud) 我想像这样调用父构造函数:
Character::Character(int x, int y, int h, int s, int a, char dir) : health(h), strength(s), armor(a), direction(dir){
if(direction == 'N') {
Visual('^', x, y);
} else if(direction == 'S') {
Visual('v', x, y);
} else if(direction == 'W') {
Visual('<', x, y);
} else if(direction == 'E') {
Visual('>', x, y);
}
}
Run Code Online (Sandbox Code Playgroud)
但它不能很好地工作,因为它调用父项的默认构造函数 private
class Visual {
private:
Visual();
Visual(const Visual &);
protected:
Position coordinate;
char chara;
public:
Visual(char c, int x, int y);
};
Run Code Online (Sandbox Code Playgroud)