这个处理基本游戏我一直在努力,我不断得到这个"期待EOF,发现' YoshiXDX'"错误。有人能在我的代码中发现错误吗?我对这整个处理过程都很陌生,我知道我应该把所有变量放在第一位,这样他们才能进入绘图和设置的范围,但我想我一定是搞砸了。
Many thanks,
/* @pjs preload="peach-castle.jpg","Yoshi.png","Fireball.png"; */
int FireballX, FireballY;
int YoshiX, YoshiY;
int YoshiXdX, YoshiYdY;
YoshiXdX= 5;
YoshiYdY = 5;
int FireballXdX, FireballYdY;
FireballXDX = 8;
FireballYdY = 8;
Pimage Fireball, background, Yoshi;
int randompos;
float timeStarted;
int FireballPoints, YoshiPoints;
FireballPoints = 0;
YoshiPoints = 0;
boolean spawn1 = true;
float distance = dist(FireballX, FireballY, YoshiX, YoshiY);
void setup()
{
size(500, 500);
noCursor();
background(0);
timeStarted = millis();
Fireball = loadImage("Fireball.png");
Yoshi = loadImage("Yoshi.png");
background = loadImage("peach-castle.jpg");
imageMode(CENTER);
//image(background, 0, 0, width, height);
}
void draw()
{
long currentTime = millis();
long elapsedTime = (currentTime - timeStarted)/1000;
text("# of Yoshi's points: " YoshiPoints, 20, 15);
text("# of Fireball's points: " FireballPoints, 20, 30);
text("Time played: "+ elapsedTime, 20, 45);
if (spawn1 == true){
Respawn();
image(Fireball, FireballX, FireballY);
image(Yoshi, YoshiX, YoshiY);
spawn1 == false;}
Main();
}
void Wrapcheck() {
if (FireballX> width) {
FireballX = FireballX - width;
}
if (FireballX < 0 ) {
FireballX = height+ FireballX ;
}
if (FireballY > height) {
FireballY = FireballY - height;
}
if (FireballY < 0 ) {
FireballY = height - FireballY;
}
}
void Yoshimoves() {
if ((FireballX - YoshiX)> 0) {
YoshiX -= YoshiXdX;
} else if ((FireballX - YoshiX)<0) {
YoshiX += YoshiXdX;
} else if ((FireballY - YoshiY)>0) {
YoshiY += YoshiYdY;
} else if ((FireballY - YoshiY)<0) {
YoshiY -= YoshiYdY;
}
}
void keyPressed()
{
if (key == 'w') {
FireballY += FireballYdY;
}
if (key == 's') {
FireballY -= FireballYdY;
}
if (key == 'd') {
FireballX += FireballXdX
}
if (key == 'a') {
FireballX -= FireballXdX
}
Yoshimoves();
}
void collision() {
if (distance <= 50) {
FireballPoints ++;
Respawn();
}
}
void Yoshicheck() {
if ((YoshiX> width) || (YoshiX>0) || (YoshiY>height) || (YoshiY<0)) {
YoshiPoints++;
Respawn();
}
}
void Respawn() {
randompos = random(0, 3);
if (randompos == 0) {
FireballX, FireballY = width/2, 25;
} else if (randompos == 1) {
FireballX, FireballY = width-25, height/2
} else if (randompos == 2) {
FireballX, FireballY = width/2, height-25;
} else if (randompos == 3) {
FireballX, FireballY = 25, height/2
}
YoshiX, YoshiY = width/2, height/2;
}
void Main() {
Wrapcheck();
collision();
Yoshicheck();
}
答案 0 :(得分:0)
假设您正在编写Java代码,您是否在“类”中定义了所有这些?
答案 1 :(得分:0)
靠近顶部的线
YoshiXdX = 5;
是错误的来源。这声明YoshiXdX没有类型,而是需要
int YoshiXdX = 5;
声明中有多个缺少类型的实例。如果你只修复了这一行,那么下一行就会给你带来同样的错误。正如bcsb1001所示,这些都需要修复才能尝试运行它。并且所有的线都没有结束;也需要修理。字节码编译器不知道如何处理具有这些语法错误的行。
在processing.org上的前几个教程解释了这些内容,或者在任何开始的Java站点/书籍中都要花很多钱。无论使用何种语言,在每一行上获得正确的语法都是让代码工作的第一步。 Processing使用简化的Java,但不是那么简单。不幸的是,Processing IDE非常简单,在这方面不是很有帮助。像Eclipse一样真正的IDE会在你输入它们时立即警告你这些错误......