在Processing中混合活动和静态模式

时间:2014-02-06 11:18:23

标签: processing

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

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();
      }
    }
  }

1 个答案:

答案 0 :(得分:3)

您的播放器类编写得很糟糕。它应该是:

class Player {

Player () {
//constructor
}

void functionOfSorts () {

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

}

...与你所写的相反:

Player() { 
//yadayada
}