2016-05-12 3 views
1

私はコーディングが初めてです(私は確信しているかもしれません)。プログラムが実行され、1つのTubbleが生成されますが、追加のオブジェクトは表示されません。配列は変数の全量の代わりに1つのオブジェクトしか表示していません

ここに私のクラスです:

class Tubble { 

    float x; 
    float y; 
    float diameter; 
    float yspeed; 
    float tempD = random(2,86); 

    Tubble() { 
    x = random(width); 
    y = height-60; 
    diameter = tempD; 
    yspeed = random(0.1, 3); 
    } 

    void ascend() { 
    y -= yspeed; 
    x = x + random(-2, 2); 
    } 

    void dis() { 
    stroke(0); 
    fill(127, 100); 
    ellipse(x, y, diameter, diameter); 
    } 

    void top() { 
    if (y < -diameter/2) { 
     y = height+diameter/2; 
    } 
    } 
} 

クラス

class Particle { 
    float x, y; 
    float r; 
    float speed = 2.2; 
    int direction = 1; 
    PImage pbubbles; 
    Particle(float x_, float y_, float r_) { 
    x = x_; 
    y = y_; 
    r = r_; 
    } 

    void display() { 
    stroke(#F5D7D7); 
    strokeWeight(2.2); 
    noFill(); 
    ellipse(x, y, r*2, r*2); 
    } 

    boolean overlaps(Particle other) { 
    float d = dist(x, y, other.x, other.y); 
    if (d < r + other.r) { 
     return true; 
    } else { 
     return false; 
    } 
    } 
    void move() { //testing 
    x += (speed * direction); 
    if ((x > (width - r)) || (x < r)) { 
     direction *= -1; 
    } 
    }  
    void updown() { 
    y += (speed * direction); 
    if ((y > (height - r)) || (y < r)) { 
     direction *= -1; 
    } 
    } 
} 

主なスケッチ:

Tubble[] tubbles = new Tubble [126]; 
PImage bubbles; 

Particle p1; 
Particle p2; 
Particle p3; 
Particle p4; 
Particle p5; 

float x,y; 
float speed; 
int total = 0; 
int i; 


//int direction = 1; 

void setup() { 
    size(800, 925); 

    bubbles = loadImage("purple_bubbles.png"); 
    p1 = new Particle (100, 100, 50); 
    p2 = new Particle (500, 200, 100); 
    p3 = new Particle (600, 600, 82); 
    p4 = new Particle (height/2, width/2, 200); 
    p5 = new Particle ((height/3), (width/3), 20); 

    for (int i = 0; i < tubbles.length; i++); { 
    tubbles[i] = new Tubble(); 
    } 
} 

void mousePressed() { 
    total = total + 1; 
} 

void keyPressed() { 
    total = total - 1; 
} 

void draw() { 
    image(bubbles, 0, 0, 800, 925); 
    //background(0); 

for (int i = 0; i < tubbles.length; i++); { 
    tubbles[i].ascend(); 
    tubbles[i].dis(); 
    tubbles[i].top(); 
    } 

    if ((p2.overlaps(p1)) && (p2.overlaps(p4))) { 
    background(#BF55AB, 25); 
    } 
    if ((p3.overlaps(p2)) && (p3.overlaps(p4))) { 
    background(#506381, 80); 
    } 

    p2.x = mouseX; 
    p3.y = mouseY; 


    p1.display(); 
    p2.display(); 
    p3.display(); 
    p4.display(); 
    p5.display(); 

    p4.move(); 
    p5.updown(); 

// for (int i = 0; i < tubbles.length; i++); { 
    // tubbles[i].dis(); 
    // tubbles[i].ascend(); 
    // tubbles[i].top(); 
// } 
} 

答えて

4

ライン

for (int i = 0; i < tubbles.length; i++); { 
for (int i = 0; i < tubbles.length; i++); { 
// for (int i = 0; i < tubbles.length; i++); { 
0に余分なセミコロンがあります。

ループは実質的に何もしません。 の後のブロックforループでは、グローバル変数iが読み込まれ、アクションは1回だけ実行されます。

このようなセミコロンを削除して、ブロックをループに入れます。ループはです。

for (int i = 0; i < tubbles.length; i++) { 
for (int i = 0; i < tubbles.length; i++) { 
// for (int i = 0; i < tubbles.length; i++) { 
関連する問題