diff --git a/TurkeyTrotNoArrays/Turkey.pde b/TurkeyTrotNoArrays/Turkey.pde index deb60f1..a224c9b 100644 --- a/TurkeyTrotNoArrays/Turkey.pde +++ b/TurkeyTrotNoArrays/Turkey.pde @@ -14,6 +14,13 @@ public Turkey(int x, int y) { turkey.resize(size,size); } +public Turkey(int x, int y, String turkeyImage) { + this.x = x; + this.y = y; + this.turkey = loadImage(turkeyImage); + turkey.resize(size,size); +} + public void draw() { image (turkey, x, y); } diff --git a/TurkeyTrotNoArrays/TurkeyTrotNoArrays.pde b/TurkeyTrotNoArrays/TurkeyTrotNoArrays.pde index d2b1a48..00e8dc1 100644 --- a/TurkeyTrotNoArrays/TurkeyTrotNoArrays.pde +++ b/TurkeyTrotNoArrays/TurkeyTrotNoArrays.pde @@ -38,11 +38,10 @@ void setup() { void draw() { + // Draw the background (farmyard) if (!gameOver) { - // Draw the background (farmyard) - background(farmyard); - + drawLaneMarkers(); // This method draws the lines between each racing lane drawTurkeys(); // This method draws each turkey moveTurkeys(); // This method moves the turkeys during the race @@ -60,7 +59,8 @@ void draw() { if (gameOver) { fill(0); textSize(50); - text ("RACE OVER", width/4, height/2); + text ("RACE OVER", width/4, height/2); + drawConfetti(); } } @@ -93,4 +93,40 @@ void drawLaneMarkers() { text(""+i, width-50, laneWidth*i - 30); } } - + +class Confetti { + int x; + int y; + + public Confetti(int x, int y) { + this.x = x; + this.y = y; + } +} + +ArrayList confettis = new ArrayList(500); + +public void drawConfetti() { + // Add 3 new confettis + for (int i = 0; i < 3; i++) { + confettis.add( new Confetti( int(random(width)), int(random(height) ) ) ); + } + + // Draw the confettis. Loop backwards as quick way to remove in loop. + for (int i = confettis.size() - 1; i >= 0; i--) { + Confetti eachConfetti = confettis.get(i); + + // Draw a single confetti + noStroke(); + fill(random(255), random(150), random(50)); + ellipse(eachConfetti.x, eachConfetti.y, 8, 8); + + // Move confetti down the screen + eachConfetti.y += 2; + + // Remove confettis that go below the bottom of the screen + if (eachConfetti.y > height) { + confettis.remove(i); + } + } +} diff --git a/TurkeyTrotWithArrays/Turkey.pde b/TurkeyTrotWithArrays/Turkey.pde index deb60f1..a224c9b 100644 --- a/TurkeyTrotWithArrays/Turkey.pde +++ b/TurkeyTrotWithArrays/Turkey.pde @@ -14,6 +14,13 @@ public Turkey(int x, int y) { turkey.resize(size,size); } +public Turkey(int x, int y, String turkeyImage) { + this.x = x; + this.y = y; + this.turkey = loadImage(turkeyImage); + turkey.resize(size,size); +} + public void draw() { image (turkey, x, y); } diff --git a/TurkeyTrotWithArrays/TurkeyTrotWithArrays.pde b/TurkeyTrotWithArrays/TurkeyTrotWithArrays.pde index 15b81c4..5a55baf 100644 --- a/TurkeyTrotWithArrays/TurkeyTrotWithArrays.pde +++ b/TurkeyTrotWithArrays/TurkeyTrotWithArrays.pde @@ -28,10 +28,10 @@ void setup() { } -void draw() { +void draw() { + // Draw the background (farmyard) if (!gameOver) { - // Draw the background (farmyard) drawLaneMarkers(); // This method draws the lines between each racing lane drawTurkeys(); // This method draws each turkey @@ -49,7 +49,8 @@ void draw() { if (gameOver) { fill(0); textSize(50); - text ("RACE OVER", width/4, height/2); + text ("RACE OVER", width/4, height/2); + drawConfetti(); } } @@ -77,3 +78,40 @@ void drawLaneMarkers() { // Put code here to draw lines to show the lanes of the racing course // Add text in each lane to show which turkey # is racing in it } + +class Confetti { + int x; + int y; + + public Confetti(int x, int y) { + this.x = x; + this.y = y; + } +} + +ArrayList confettis = new ArrayList(500); + +public void drawConfetti() { + // Add 3 new confettis + for (int i = 0; i < 3; i++) { + confettis.add( new Confetti( int(random(width)), int(random(height) ) ) ); + } + + // Draw the confettis. Loop backwards as quick way to remove in loop. + for (int i = confettis.size() - 1; i >= 0; i--) { + Confetti eachConfetti = confettis.get(i); + + // Draw a single confetti + noStroke(); + fill(random(255), random(150), random(50)); + ellipse(eachConfetti.x, eachConfetti.y, 8, 8); + + // Move confetti down the screen + eachConfetti.y += 2; + + // Remove confettis that go below the bottom of the screen + if (eachConfetti.y > height) { + confettis.remove(i); + } + } +}