From 36d1281698d355dd17d2533ee3aa085eec7c91e4 Mon Sep 17 00:00:00 2001 From: Daniel Commins Date: Wed, 18 Nov 2020 15:26:15 -0800 Subject: [PATCH 1/2] Add confetti effect on game over --- TurkeyTrotNoArrays/Turkey.pde | 7 ++++ TurkeyTrotNoArrays/TurkeyTrotNoArrays.pde | 42 +++++++++++++++++-- TurkeyTrotWithArrays/Turkey.pde | 7 ++++ TurkeyTrotWithArrays/TurkeyTrotWithArrays.pde | 40 +++++++++++++++++- 4 files changed, 92 insertions(+), 4 deletions(-) diff --git a/TurkeyTrotNoArrays/Turkey.pde b/TurkeyTrotNoArrays/Turkey.pde index deb60f1..1eb2b6d 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; + turkey.resize(size,size); + this.turkey = loadImage(turkeyImage); +} + public void draw() { image (turkey, x, y); } diff --git a/TurkeyTrotNoArrays/TurkeyTrotNoArrays.pde b/TurkeyTrotNoArrays/TurkeyTrotNoArrays.pde index d2b1a48..c1eb6c7 100644 --- a/TurkeyTrotNoArrays/TurkeyTrotNoArrays.pde +++ b/TurkeyTrotNoArrays/TurkeyTrotNoArrays.pde @@ -41,7 +41,6 @@ void draw() { if (!gameOver) { // Draw the background (farmyard) - background(farmyard); drawLaneMarkers(); // This method draws the lines between each racing lane drawTurkeys(); // This method draws each turkey @@ -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..1eb2b6d 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; + turkey.resize(size,size); + this.turkey = loadImage(turkeyImage); +} + public void draw() { image (turkey, x, y); } diff --git a/TurkeyTrotWithArrays/TurkeyTrotWithArrays.pde b/TurkeyTrotWithArrays/TurkeyTrotWithArrays.pde index 15b81c4..9fccf01 100644 --- a/TurkeyTrotWithArrays/TurkeyTrotWithArrays.pde +++ b/TurkeyTrotWithArrays/TurkeyTrotWithArrays.pde @@ -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); + } + } +} From 27da4c4c4d64e4a0990e1d6dfdf43b44009be493 Mon Sep 17 00:00:00 2001 From: Daniel Commins Date: Thu, 19 Nov 2020 19:07:21 -0800 Subject: [PATCH 2/2] Fixed resize --- TurkeyTrotNoArrays/Turkey.pde | 2 +- TurkeyTrotNoArrays/TurkeyTrotNoArrays.pde | 4 ++-- TurkeyTrotWithArrays/Turkey.pde | 2 +- TurkeyTrotWithArrays/TurkeyTrotWithArrays.pde | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/TurkeyTrotNoArrays/Turkey.pde b/TurkeyTrotNoArrays/Turkey.pde index 1eb2b6d..a224c9b 100644 --- a/TurkeyTrotNoArrays/Turkey.pde +++ b/TurkeyTrotNoArrays/Turkey.pde @@ -17,8 +17,8 @@ public Turkey(int x, int y) { public Turkey(int x, int y, String turkeyImage) { this.x = x; this.y = y; - turkey.resize(size,size); this.turkey = loadImage(turkeyImage); + turkey.resize(size,size); } public void draw() { diff --git a/TurkeyTrotNoArrays/TurkeyTrotNoArrays.pde b/TurkeyTrotNoArrays/TurkeyTrotNoArrays.pde index c1eb6c7..00e8dc1 100644 --- a/TurkeyTrotNoArrays/TurkeyTrotNoArrays.pde +++ b/TurkeyTrotNoArrays/TurkeyTrotNoArrays.pde @@ -38,10 +38,10 @@ void setup() { 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 moveTurkeys(); // This method moves the turkeys during the race diff --git a/TurkeyTrotWithArrays/Turkey.pde b/TurkeyTrotWithArrays/Turkey.pde index 1eb2b6d..a224c9b 100644 --- a/TurkeyTrotWithArrays/Turkey.pde +++ b/TurkeyTrotWithArrays/Turkey.pde @@ -17,8 +17,8 @@ public Turkey(int x, int y) { public Turkey(int x, int y, String turkeyImage) { this.x = x; this.y = y; - turkey.resize(size,size); this.turkey = loadImage(turkeyImage); + turkey.resize(size,size); } public void draw() { diff --git a/TurkeyTrotWithArrays/TurkeyTrotWithArrays.pde b/TurkeyTrotWithArrays/TurkeyTrotWithArrays.pde index 9fccf01..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