【问题标题】:Mixing active and static modes in Processing在处理中混合活动和静态模式
【发布时间】:2014-03-03 07:26:18
【问题描述】:

让太空入侵者淘汰游戏。我的代码无法编译,因为我收到错误消息“看起来您正在混合'活动'和'静态'模式”,但我看不到我在哪里混合它们。有人可以看看我的代码吗?

final  int  SCREENX=400;  
final  int  SCREENY=400;  
final  int  GAP=10;  
final  int  ALIEN_ALIVE=0;  
final  int  ALIEN_DEAD=6;  
final  int  FORWARD=0;  
final  int  BACKWARD=1; 
final int MARGIN=30;

Alien  theAliens[]; 
Bullet bullets[];
Player thePlayer;

void  setup() {  
  PImage  normalImg, explodeImg;
  size(SCREENX, SCREENY);  
  normalImg =loadImage("invader.GIF");  
  explodeImg =loadImage("exploding.GIF");
  theAliens  =  new  Alien[10];
  bullets = new Bullet[20];  
  init_aliens(theAliens, normalImg, explodeImg);
  thePlayer  =  new  Player(SCREENY- 50);
}  

void  init_aliens(Alien  baddies[], PImage  okImg, PImage  
exImg) {  
  for (int  i=0;  i<baddies.length;  i++) {  
    //  This  is  buggy,  what  is  the  problem?  
    baddies[i]  =  new  Alien(i*(okImg.width+GAP), 0, okImg, 
    exImg);
  }
}

void init_bullets() {
  for (int i = 0; i < bullets.size(); i++) {
    Bullet b = (Bullet) bullets.get(i);
    b.move();
    b.draw();
  }
}

void shoot() {
  if (mousePressed)
    Player.shoot();
}

void  draw() {    
  background(0);
  thePlayer.draw(); 
  thePlayer.move(mouseX);
  draw_bullets(myBullets);  
  for (int  i=0;  i<theAliens.length;  i++) {  
    theAliens[i].move();  
    theAliens[i].draw();

    if (random(0, 500)<1)
      theAliens[i].die();
  }
}

////// Player Class //////
Player() {        ///** When I get the error, this line is highlighted**///
  this.x = width/2;
  this.y = height-50;
  this.timeLastShot = 0;
  this.coolDown = 200;
  colour playColour= color(50);

  void draw() {
    fill(playerColour);
    rect(this.x, this.y, 30, 30);
  }

  void move(int x) {
    if (x>SCREENX-50) 
      xpos= SCREENX-50;
    else xpos=x;
  }
    void shoot() {
      if (millis() - timeLastShot > coolDown) {
        Bullet bullet = new Bullet(this.x+12.5, this.y, -5);
        bullets.add(bullet);
        timeLastShot = millis();
      }
    }
  }

【问题讨论】:

  • 这是什么语言?请编辑您的问题以包含完整(和未经编辑的)错误日志,同时指出错误在发布的源中的位置(错误消息确实有源文件名和行号)。
  • 正在处理中。它基于Java。我在我的“标签”中有它。我已经编辑了我的问题。
  • 另外,这是我收到的错误消息,我没有编辑它。@JoachimPileborg

标签: processing


【解决方案1】:

你的 Player 类写得不好。应该是:

class Player {

Player () {
//constructor
}

void functionOfSorts () {

} // Never forget to enclose functions with curly brackets!

}

...与你写的相反:

Player() { 
//yadayada
}

【讨论】:

    猜你喜欢
    • 2011-10-03
    • 2020-05-21
    • 2013-10-06
    • 1970-01-01
    • 1970-01-01
    • 2011-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多