2014-02-06 42 views
0

让太空侵略者击倒游戏。我的代码不会编译,因为我收到错误消息“它看起来像是在混合”活动“和”静态“模式”,但我看不到我在混合它们。有人可以看看我的代码吗?混合处理中的活动和静态模式

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

这是什么语言?并且请编辑您的问题以包含完整(和未编辑)的错误日志,同时指出发布源中错误的位置(错误消息确实包含源文件名和行号)。 –

+2

正在处理中。它基于Java。我把它放在我的'标签'中。我编辑了我的问题。 – user3241910

+0

此外,这是我得到的错误消息,我没有编辑它。@ JoachimPileborg – user3241910

回答

3

球员类写的不好。它应该是:

class Player { 

Player() { 
//constructor 
} 

void functionOfSorts() { 

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

} 

...至于反对你写的:

Player() { 
//yadayada 
} 
相关问题