我正在尝试在Processing中制作一个游戏,其中用户必须击中一系列多米诺骨牌的射弹,一旦命中发生,所有多米诺骨牌在它开始下降之后。
示例:http://www.fallingdominoes.com/
也就是说,所有的多米诺骨牌关键词最初是笔直的:| | | | | | | | | |
有一次,弹丸击中了第一张多米诺骨牌,然后:/ / / / / / / / / /
说,弹丸击中第6个多米诺骨牌,然后:| | | | | / / / / / / /
射弹的代码和游戏在这里:http://www.openprocessing.org/sketch/28940
这一切都发生在处理中。
有人可以帮助我们完成什么事情吗?以及如何做?
答案 0 :(得分:1)
在这里,我为你做了一个小测试!它不是一个完全实现的物理引擎,但我猜它足够接近......
int numberOdominos = 60;
Domino [] myDominos = new Domino[numberOdominos];
int currentDropDomino = -1;
void setup() {
size(600, 100);
myDominos[0] = new Domino(null);
for (int i = 1; i < myDominos.length; i++) {
myDominos[i] = new Domino(myDominos[i-1]);
}
}
void draw() {
background(0);
String s = getDominoState();
fill(255,0,0);
text("press any button from 0 to " + myDominos.length + " to drop that domino and all subsequent ones!!!! (r to reset)",20,10,width,height);
fill(255);
text(s, 5, 40, width, 100);
}
String getDominoState() {
String result = "";
for (int i = 1; i < myDominos.length; i++) {
if(currentDropDomino != -1 && i == currentDropDomino) {
myDominos[i].push();
}
result += myDominos[i].state;
}
if(currentDropDomino != -1) currentDropDomino += 1;
if(currentDropDomino > myDominos.length)
currentDropDomino = -1;
return result;
}
class Domino {
Domino previous;
char state = '|';
Domino(Domino previous) {
this.previous = previous;
}
void reset() {
state = '|';
}
char checkPrevious() {
if (previous.state == '/') push();
return state;
}
void push() {
state = '/';
}
}
void reset() {
for(int i = 0; i < myDominos.length; i++)
myDominos[i].reset();
}
void keyPressed() {
if(key == 'r' || key == 'R') {
reset();
return;
}
int pushDomino = 0;
try {
pushDomino = Integer.parseInt(""+key);
}
catch(NumberFormatException e) {
println("thats not a number...");
return;
}
if(pushDomino < myDominos.length) currentDropDomino = pushDomino;
}
您只需要使用您选择的一个更改keyPressed()方法;像throwProjectileAt(int position) {}