0

今天我偶然发现了所有错误中最致命的错误。处理没有看到我的课程......我不知道为什么它没有,因为我对此很陌生。

这是我的主要课程:

Player thePlayer = new Player();
Guard theGuard = new Guard();
SpeedPWRUP speedPowerUp = new SpeedPWRUP();
Keyboard theKeyboard = new Keyboard();

void setup() {
  size(1000, 500);
  theGuard.init();
  thePlayer.init();
  speedPowerUp.init();
}

void updateGame() {
  theGuard.update();
  thePlayer.update();
  speedPowerUp.update();
}

void drawGame() {
  thePlayer.draw();
  theGuard.draw();
  speedPowerUp.draw();
  fill(color(0, 0, 0));
  text(("Score:"), 10, 20);
}

void draw() {
  background(255);
  fill (0, 0, 0);
  rect(-10, 401, 1100, 100);
  noFill();

  updateGame();
  drawGame();
  Keyboard();
}

这是我的播放器类:

  class Player {

  public float playerX, playerY;
  float vx, vy;
  int fillColor;
  float diameterPlayer;
  float jumpTime;
  float jumpHeight;
  boolean isJumping;
  float collisionGuard;
  boolean speedUpActive;
  boolean facingRight;

void init() {
  diameterPlayer = 40;
  fillColor = color(0, 0, 0);
  jumpTime = 200;
  jumpHeight = 100;
  isJumping = false;
  collisionGuard = 80;
  speedUpActive = false;
  facingRight = false;

  playerX = 100;
  playerY = 400-diameterPlayer;

  vx = 0;
  vy = 0;
}

void update() {

  if(theKeyboard.holdingUp == true && isOnGround == true) {
    vx = 5;
    isOnGround = false;
  }

  if(theKeyboard.holdingDown == true) {
    diameterPlayer = 40;
  }

  if(theKeyboard.holdingLeft == true) {
    vx = -2;
  }

  if(theKeyboard.holdingRight == true) {
    vx = 2;
  }

  if (playerY < (400-diameterPlayer/2)) {
  vy = vy + 2.5;
  }

  if (playerY < (80-diameterPlayer/2)) {
  vy = 2.5;
  }

  if (playerX < (0+diameterPlayer/2)) {
  vx = 0.1;
  }

  if(vx>0) {
    facingRight = true;
  } else if(vx<0) { facingRight = false;
  } else facingRight = false;

  playerX += vx;
  playerY += vy;

}

void draw() {
  fill(fillColor);
  ellipse(playerX, playerY, diameterPlayer, diameterPlayer);
  noFill();
}
}

错误发生在我的主类的第一行(“Player thePlayer = new Player();”),错误显示“找不到类或键入“播放器””。有人请帮助我:(提前谢谢!

4

4 回答 4

0

将您的 Player 类放在代码中的主类之上。然后它将起作用。

于 2013-10-29T10:34:22.743 回答
0

将您的 Player 类与 Main 类放在同一目录中,否则使用存储 Player 类的完整包名导入......或者可能存在小的或大写差异......

于 2013-10-29T10:36:08.223 回答
0

您是否已将您的类 Player 导入到与 Main 类相同的包中?

将 Player 设为公开,然后重试:

公共类播放器 { ... }

于 2013-10-29T10:47:58.453 回答
0

如果Player类与类不在同一个包中Main。然后您需要在 Main 类中导入 Player 类,如下所示。

import XXX.Player;

// 你的主类代码放在这里。

于 2013-10-29T10:28:13.780 回答