Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions TurkeyTrotNoArrays/Turkey.pde
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
46 changes: 41 additions & 5 deletions TurkeyTrotNoArrays/TurkeyTrotNoArrays.pde
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
}
}

Expand Down Expand Up @@ -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<Confetti> confettis = new ArrayList<Confetti>(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);
}
}
}
7 changes: 7 additions & 0 deletions TurkeyTrotWithArrays/Turkey.pde
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
44 changes: 41 additions & 3 deletions TurkeyTrotWithArrays/TurkeyTrotWithArrays.pde
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
}
}

Expand Down Expand Up @@ -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<Confetti> confettis = new ArrayList<Confetti>(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);
}
}
}