Final Project: Falling Berries by Carlo (Marcela)

Date: May 20th, 2017

Partner: Ryan Yee

Instructor: Marcela Godoy

Description: 

For our final project, we created a game called Falling Berries. Our concept for this game is basically about food. We made everything about this game food-related; started from the game interface to its controllers. In addition to that, we also bring more enjoyment and excitement to the users by providing a punishment system should one of the two players lose. We created a slapping machine that will slap the “loser” right in their face, with cream.

Basically, the rules of this game are quite simple. The players have to catch the berries with the bucket that corresponds with the color of the controllers. For example, the players have to catch the blue berry with blue controller and so on and so forth. The players have three life to play this game. If a players fail to catch the berries or press the controller when the berries are not yet in the area of the bucket, they will lose one life. When their life is finally 0, then they will lose the game and will receive the punishment from the slapping machine, with cream. As one of the players lose, the winner can watch them with satisfaction. To achieve this goal, my partner and I separated our work into two parts: Arduino part and Processing part. Being in charge of Processing, I was really challenged to design the game and created the technical systems of the game. Here is a screenshot of our game interface.

 

Screen Shot 2017-05-20 at 9.28.49 PM

Motivation: 

Our motivation to create this game actually derives from a problem that most of the students encounter when they stay in Shanghai over the break. They often face boredom. Some conventional games such as card games and boardgames are getting more boring over time. So, from this problem, we are attempting to give another kind of game for them to play with their friends during the break. By creating this game, we also solve their problem of boredom by proving another game option.

The users: all people who love to play games are our targeted users.

We believe that our game is really interactive and fun. Our punishment system in which the users will be slapped by our slapping machine will give the users more pleasure especially the winners.

Process: 

Software:

  1. Arduino
  2. Processing
  3. Adobe Photoshop

Materials:

  1. Arduino kit
  2. Servo
  3. Cables
  4. Grove Q touch sensor

I first created the design of the game from a really simple sketch. I calculated the size of the canvas and divided it into four columns. Each column, I calculated the coordinate of the middle point as the berry’s track. After that, I also calculated the coordinate for the bucket.

new doc 2017-05-20 22.40.49_2

The first interface looked pretty much like the picture below. The interface was quite rough and needed some improvements.

Screen Shot 2017-04-19 at 11.16.31 PM

After I got the first interface on the screen, I keep on developing the design by adding some pictures. My partner suggested that we used the Sprite images to support our game interface. Here are the sprites images that we used in our game. All images below are example of Sprite images except for the apple tree. I really like Sprites images when it comes to design. In fact, Sprites images are really useful and easy to use. Their size is just about right: not too small nor too big.  TS path seasonal_grass_by_nsora_96-d3ferof copy seasonal_grass_by_nsora_96-d3ferof grass berries_by_skitticko-d92i2j3 copy 2 berries_by_skitticko-d92i2j3 copy 3 berries_by_skitticko-d92i2j3 copy berries_by_skitticko-d92i2j3 Apple barrel

When I downloaded these sprite images, I didn’t use it directly. I had to make some changes to the images by using Adobe Photoshop. It is because these downloaded images weren’t formatted in .png but .jpg. As a result, when you directly put these images into your game with processing, it will look like the picture below. Therefore, you have to make sure that you clear crop out the white background of the image.

 

Screen Shot 2017-05-20 at 11.29.50 PM

To put all these sprites images in the right place I use the coordinates that I have calculated in the beginning. However, when I put all these sprites images in its respective coordinates, I did a really stupid mistake that I hope none of the students in the future will do this since it really consumed so much of my time. I literally did not know that there’s this one built-in function that can help me automatically place these images in the same coordinates. As a result I had to repeat doing the same thing over and over again. So, when my professor, Learning Assistants and some of my friends helped me, they all were complaining about the number of images that I upload.

Screen Shot 2017-05-20 at 11.34.56 PM Screen Shot 2017-05-20 at 11.35.02 PM

After I was done with all the sprites images, finally now our game interface looks so much better than the first one and I am really glad to say that this game interface is really cute and entertaining. Additionally, now we already have two screens for 2 players.

Screen Shot 2017-05-20 at 9.28.49 PM

After polishing the design, I had to move on to the most challenging part of this game: functions. First, I had to determine all the functions that I needed. I had to make the logic of the game so that it would work according to our initial plans. First, I had to determine the rules of the games:

 

  1. The players have to catch each berry with corresponding controller.

2. The players have three life to play this game.

3 If  the players fail to catch the berries they will lose one life

4. If the players press the controller when the berries are not yet in the area of the bucket, they will lose one life.

5. When their life is finally 0, then they will lose the game and will receive the punishment from the slapping machine, with cream.

Those are basically the five things that I have to made in my game. When I first tried making those functions, I had a hard time figuring it out. However, when I got a help from my instructor Marcela, she gave a really helpful method to solve this. We created a tree diagram. This kind of method is really helpful because it is stated clearly. Here is the tree diagram that my instructor and I made.

new doc 2017-05-20 22.40.49_1

However, our first attempt was not as successful as we expected, we still had some issues with this. The issue that we faced was that the 3rd and 4th rules I mentioned above did not run properly. So, I needed to make some changes to the code. Then, I asked some help from the Learning Assistants, Jiwon and Tyler, to figure out these problems. It turns out that we had to use Boolean variable to perform the action we want. It is common to use Boolean values with control statements to determine the flow of a program. To avoid any crashes, I made different Boolean variable for each berry and buckets. I also learned how to use the dist() function to perform an action based on two objects’ distance. Finally, we successfully fixed this issue. I’m really thankful for having them two as part of my project.

To give a better gaming experience, I also added a music into this game by using minim library. The music that I used in this game is from Five Nights at Freddy’s Sister Location cupcake minigame. I decided to use this sound because it is really catchy and sounds fun. Here is the link in case some students want to use it in the future:

After, we’re done with the processing part, finally we connected the game with the controllers that my partner has built. We basically use the Q touch sensor and connected it to the controllers. As I said in the beginning that we want to make this game food-related, I meant to say that we use the real food which is fruits as our controllers and we chose banana. The its mechanism works is the players have to touch the banana in order to perform the action. Here is a video of our first test

We also built the slapping machine that connects to the game and controllers. The machine works when one of the players lose. All the boxes that we use in this project are done by laser cut.

IMG_3419IMG_3418

The problem that we encountered when we were working on the Arduino part was that it’s somehow not that responsive. Besides that, it also sometimes printed more than one frame. For example, when the I touched the controller once, on the screen it said that I touched the controller more than once and therefore, it made the game crashed. However, with a help of our instructor and learning assistant we finally solved this problem.

After we are done with both part, finally our game works!

Conclusion:

From this final project, I learned how to be more efficient in working with Processing. In fact, I found so many codes that help me to be more efficient. Besides that, another thing that I learned is that I have to be more meticulous when I code. It is because during the process of coding, I made so many silly mistakes such as missing punctuations such as “;” “;”, and {}. This may look trivial but missing one of these signs in the code literally will stop your whole code from running. In addition to that, I also got to improve my logic skill. When I build the game with bunch of function that requires logic skill, I was seriously confused and often time got stressed of my non- responding code. When Marcela taught me to draw tree diagram before creating the function, I find that method to be really useful for me.

In this project too, I am really glad that I got to finish the game with all the functions on time. I am truly happy that I successfully integrate all keyboard keys with the game and properly run the game according to our plan. Another thing that I think I successfully achieved is that the game that I created look nice in term of its interface. Especially the music sound and the interface received so much good feedback from people when I held users testing.

Things I wish I Could Do Better: 

Two things that I wish I could do better is that first, I did not create the point and life board on the screen. This somehow makes the players confused since they do not know how many life they have left. If I had more time to work on this project, I would really like to fix this issue.

Another thing is that, I wish that my group could create a banana-looking controller. We really like the idea of using the actual fruits as our controllers, however, one fact about this is that we can’t keep these fruits for long-term use since it will rot as the time goes by. When we worked on this project, we truly felt so bad that we eventually threw the bananas away. We feel that it is such a waste of food. Therefore, we wish we had more time to create something similar to bananas but it is reusable.

 

 

 

 

//processing 

import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;
import ddf.minim.signals.*;
import ddf.minim.spi.*;
import ddf.minim.ugens.*;

import processing.serial.*;

//player1
int lifeCounter = 3;
boolean prevPress = false;
boolean die=true;
boolean early=true;

boolean die1=true;
boolean early1=true;

boolean die2=true; 
boolean early2=true; 

float dist; 

float x0 = 30;
float y0 = 0;
float y0_speed = 4;

float x1 = 150;
float y1 = 0;
float y1_speed = 3;

float x2 = 258;
float y2 = 0;
float y2_speed = 2;

//player2
int lifeCounter2 = 3;
boolean die3=true;
boolean early3=true;

boolean die4=true; 
boolean early4=true;

boolean die5=true;
boolean early5=true; 

float x3 = 380;
float y3 = 0;
float y3_speed = 4;

float x4 = 480;
float y4 = 0;
float y4_speed = 3;

float x5 = 595;
float y5 = 0;
float y5_speed = 2;


//background

PImage bucket;
PImage BB;
PImage RB;
PImage GB;
PImage YB;
PImage TSprite1; 
PImage PSprite;
PImage GSprite;
PImage grass;
PImage grey;
PImage apple;
PImage orange;
PImage blue;
PImage red;
PImage yellow; 
PImage green;
float i; 
float j;
float k;
float l;
float m; 
float n;

Serial myPort1;
Serial myPort2;

AudioPlayer player;
Minim minim;
int inByte1;
int inByte2;

void setup() {
  size(680, 750);  
  printArray(Serial.list());
  myPort1 = new Serial(this, Serial.list()[3], 9600);
  myPort2 = new Serial(this, Serial.list()[4], 9600);

  //y0 = -15;
  //x0 = 35;
  //y0_speed = random(3, 7);
  //y0 += y0_speed;

  orange = loadImage("orange.png");
  TSprite1 = loadImage("TS.png"); 
  image(TSprite1, 10, 10);
  apple = loadImage("Apple.png");
  PSprite = loadImage("path2.png");
  GSprite = loadImage("grass2.png");
  grass = loadImage("grass3.png");
  grey = loadImage("grey.png");
  bucket = loadImage("barrel.png"); 
  image(bucket, 0, 700);
  bucket.resize(60, 60);
  BB = loadImage("BB.png");
  blue = loadImage("blue.png");
  red = loadImage("red.png"); 
  yellow = loadImage("yellow.png");
  green = loadImage("green.png");

  minim = new Minim(this);
  player = minim.loadFile("music.mp3");
  player.loop();

  line(450, 0, 450, 750);

  inByte1 = inByte2 = -1;
}

//player1-------------------------------------------------------------------------

void berry1() {
  i = i+5;
  //if (y0>=0) {
  die=true;
  early=true;
  //}
  image(blue, x0, y0, 50, 50);
}

void berry2() {
  j = j+5;
  die1=true;
  early1=true;
  image(red, x1, y1, 50, 50);
}

void berry3() {
  k = k+5;
  die2=true;
  early2=true;
  image(yellow, x2, y2, 50, 50);
}

//player2---------------------------------------------------------------------------

void berry4() {
  l = l+5;
  die3=true;
  early3=true;
  image(blue, x3, y3, 50, 50);
}

void berry5() {
  m = m+5;
  die4=true;
  early4=true;
  image(red, x4, y4, 50, 50);
}

void berry6() {
  n= n +5;
  die5=true;
  early5=true;
  image(yellow, x5, y5, 50, 50);
}

//----------------------------------------------------------------------------------
void line() {
  pushStyle();
  stroke(0, 0, 0);
  strokeWeight(6);
  line(112.5, 0, 112.5, 800);
  line(225, 0, 225, 800);
  line(337.5, 0, 337.5, 800); 
  line(0, 700, 450, 700);
  popStyle();
}

void draw() {
  //println(frameCount);
  background(255);
  while ( myPort1.available() > 0) {
    inByte1 = myPort1.read();
    if (inByte1 != 10) {
      println("1: " + inByte1);
    }
  }
  while ( myPort2.available() > 0) {
    inByte2 = myPort2.read();
    if (inByte2 != 10) {
      println("2: " + inByte2);
    }
  }
  //println(inByte2);

  if (lifeCounter2<=0) {
    myPort1.write(2);
  } 
  else if (lifeCounter<=0) {
    myPort1.write(1);
  }
  else {
    myPort1.write(0);
  }


  //println(lifeCounter);
  image(PSprite, -10, -25);
  image(PSprite, -10, 10);
  image(PSprite, -10, 45);
  image(PSprite, -10, 80);
  image(PSprite, -10, 115);
  image(PSprite, -10, 150);
  image(PSprite, -10, 185);
  image(PSprite, -10, 220);
  image(PSprite, -10, 255);
  image(PSprite, -10, 290);
  image(PSprite, -10, 325);
  image(PSprite, -10, 360);
  image(PSprite, -10, 395);
  image(PSprite, -10, 430);
  image(PSprite, -10, 465);
  image(PSprite, -10, 500);
  image(PSprite, -10, 535);
  image(PSprite, -10, 570);
  image(PSprite, -10, 605); 
  image(PSprite, -10, 640);
  image(PSprite, -10, 675);
  image(PSprite, -10, 710);
  image(PSprite, -10, 745);

  image(PSprite, 70, -25);
  image(PSprite, 70, 10);
  image(PSprite, 70, 45);
  image(PSprite, 70, 80);
  image(PSprite, 70, 115);
  image(PSprite, 70, 150);
  image(PSprite, 70, 185);
  image(PSprite, 70, 220);
  image(PSprite, 70, 255);
  image(PSprite, 70, 290);
  image(PSprite, 70, 325);
  image(PSprite, 70, 360);
  image(PSprite, 70, 395);
  image(PSprite, 70, 430);
  image(PSprite, 70, 465);
  image(PSprite, 70, 500);
  image(PSprite, 70, 535);
  image(PSprite, 70, 570);
  image(PSprite, 70, 605); 
  image(PSprite, 70, 640);
  image(PSprite, 70, 675);
  image(PSprite, 70, 710);
  image(PSprite, 70, 745);

  image(PSprite, 30, -25);
  image(PSprite, 30, 10);
  image(PSprite, 30, 45);
  image(PSprite, 30, 80);
  image(PSprite, 30, 115);
  image(PSprite, 30, 150);
  image(PSprite, 30, 185);
  image(PSprite, 30, 220);
  image(PSprite, 30, 255);
  image(PSprite, 30, 290);
  image(PSprite, 30, 325);
  image(PSprite, 30, 360);
  image(PSprite, 30, 395);
  image(PSprite, 30, 430);
  image(PSprite, 30, 465);
  image(PSprite, 30, 500);
  image(PSprite, 30, 535);
  image(PSprite, 30, 570);
  image(PSprite, 30, 605); 
  image(PSprite, 30, 640);
  image(PSprite, 30, 675);
  image(PSprite, 30, 710);
  image(PSprite, 30, 745);

  image(GSprite, 110, -25);
  image(GSprite, 110, 10);
  image(GSprite, 110, 45);
  image(GSprite, 110, 80);
  image(GSprite, 110, 115);
  image(GSprite, 110, 150);
  image(GSprite, 110, 185);
  image(GSprite, 110, 220);
  image(GSprite, 110, 255);
  image(GSprite, 110, 290);
  image(GSprite, 110, 325);
  image(GSprite, 110, 360);
  image(GSprite, 110, 395);
  image(GSprite, 110, 430);
  image(GSprite, 110, 465);
  image(GSprite, 110, 500);
  image(GSprite, 110, 535);
  image(GSprite, 110, 570);
  image(GSprite, 110, 605); 
  image(GSprite, 110, 640);
  image(GSprite, 110, 675);
  image(GSprite, 110, 710);
  image(GSprite, 110, 745);

  image(GSprite, 150, -25);
  image(GSprite, 150, 10);
  image(GSprite, 150, 45);
  image(GSprite, 150, 80);
  image(GSprite, 150, 115);
  image(GSprite, 150, 150);
  image(GSprite, 150, 185);
  image(GSprite, 150, 220);
  image(GSprite, 150, 255);
  image(GSprite, 150, 290);
  image(GSprite, 150, 325);
  image(GSprite, 150, 360);
  image(GSprite, 150, 395);
  image(GSprite, 150, 430);
  image(GSprite, 150, 465);
  image(GSprite, 150, 500);
  image(GSprite, 150, 535);
  image(GSprite, 150, 570);
  image(GSprite, 150, 605); 
  image(GSprite, 150, 640);
  image(GSprite, 150, 675);
  image(GSprite, 150, 710);
  image(GSprite, 150, 745);

  image(GSprite, 190, -25);
  image(GSprite, 190, 10);
  image(GSprite, 190, 45);
  image(GSprite, 190, 80);
  image(GSprite, 190, 115);
  image(GSprite, 190, 150);
  image(GSprite, 190, 185);
  image(GSprite, 190, 220);
  image(GSprite, 190, 255);
  image(GSprite, 190, 290);
  image(GSprite, 190, 325);
  image(GSprite, 190, 360);
  image(GSprite, 190, 395);
  image(GSprite, 190, 430);
  image(GSprite, 190, 465);
  image(GSprite, 190, 500);
  image(GSprite, 190, 535);
  image(GSprite, 190, 570);
  image(GSprite, 190, 605); 
  image(GSprite, 190, 640);
  image(GSprite, 190, 675);
  image(GSprite, 190, 710);
  image(GSprite, 190, 745);

  image(grass, 225, -25);
  image(grass, 225, 10);
  image(grass, 225, 45);
  image(grass, 225, 80);
  image(grass, 225, 115);
  image(grass, 225, 150);
  image(grass, 225, 185);
  image(grass, 225, 220);
  image(grass, 225, 255);
  image(grass, 225, 290);
  image(grass, 225, 325);
  image(grass, 225, 360);
  image(grass, 225, 395);
  image(grass, 225, 430);
  image(grass, 225, 465);
  image(grass, 225, 500);
  image(grass, 225, 535);
  image(grass, 225, 570);
  image(grass, 225, 605); 
  image(grass, 225, 640);
  image(grass, 225, 675);
  image(grass, 225, 710);
  image(grass, 225, 745);

  image(grass, 265, -25);
  image(grass, 265, 10);
  image(grass, 265, 45);
  image(grass, 265, 80);
  image(grass, 265, 115);
  image(grass, 265, 150);
  image(grass, 265, 185);
  image(grass, 265, 220);
  image(grass, 265, 255);
  image(grass, 265, 290);
  image(grass, 265, 325);
  image(grass, 265, 360);
  image(grass, 265, 395);
  image(grass, 265, 430);
  image(grass, 265, 465);
  image(grass, 265, 500);
  image(grass, 265, 535);
  image(grass, 265, 570);
  image(grass, 265, 605); 
  image(grass, 265, 640);
  image(grass, 265, 675);
  image(grass, 265, 710);
  image(grass, 265, 745);

  image(grass, 305, -25);
  image(grass, 305, 10);
  image(grass, 305, 45);
  image(grass, 305, 80);
  image(grass, 305, 115);
  image(grass, 305, 150);
  image(grass, 305, 185);
  image(grass,305, 220);
  image(grass, 305, 255);
  image(grass, 305, 290);
  image(grass, 305, 325);
  image(grass, 305, 360);
  image(grass, 305, 395);
  image(grass, 305, 430);
  image(grass, 305, 465);
  image(grass, 305, 500);
  image(grass, 305, 535);
  image(grass, 305, 570);
  image(grass, 305, 605); 
  image(grass, 305, 640);
  image(grass, 305, 675);
  image(grass, 305, 710);
  image(grass, 305, 745);

  image(TSprite1, 65, -40);
  image(TSprite1, 65, 10);
  image(TSprite1, 65, 60);
  image(TSprite1, 65, 110); 
  image(TSprite1, 65, 160);
  image(TSprite1, 65, 210);
  image(TSprite1, 65, 260); 
  image(TSprite1, 65, 310); 
  image(TSprite1, 65, 360);
  image(TSprite1, 65, 410);
  image(TSprite1, 65, 460);
  image(TSprite1, 65, 510);
  image(TSprite1, 65, 560);
  image(TSprite1, 65, 610);
  image(TSprite1, 65, 660);
  image(TSprite1, 65, 710);
  image(TSprite1, 65, 760);
  image(TSprite1, 178, -40);
  image(TSprite1, 178, 10);
  image(TSprite1, 178, 60);
  image(TSprite1, 178, 110);
  image(TSprite1, 178, 160);
  image(TSprite1, 178, 210);
  image(TSprite1, 178, 260);
  image(TSprite1, 178, 310);
  image(TSprite1, 178, 360);
  image(TSprite1, 178, 410);
  image(TSprite1, 178, 460);
  image(TSprite1, 178, 510);
  image(TSprite1, 178, 560);
  image(TSprite1, 178, 610);
  image(TSprite1, 178, 660);
  image(TSprite1, 178, 710);
  image(TSprite1, 178, 760);

  for (int i = 0; i < 750; i = i+35) {
    image(PSprite, 335, i);
  }
  for (int i = 0; i < 750; i = i+35) {
    image(PSprite, 375, i);
  }
  for (int i = 0; i < 750; i = i+35) {
    image(PSprite, 415, i);
  }
  for (int i = 0; i < 750; i = i+35) {
    image(GSprite, 450, i);
  }
  for (int i = 0; i < 750; i = i+35) {
    image(GSprite, 490, i);
  }

  for (int i = 0; i < 750; i = i+35) {
    image(GSprite, 530, i);
  }
  for (int i = 0; i < 750; i = i+35) {
    image(grass, 560, i);
  }
  for (int i = 0; i < 750; i = i+35) {
    image(grass, 600, i);
  }
  for (int i = 0; i < 750; i = i+35) {
    image(grass, 640, i);
  }

  image(TSprite1, 515, -40);
  image(TSprite1, 515, 10);
  image(TSprite1, 515, 60);
  image(TSprite1, 515, 110); 
  image(TSprite1, 515, 160);
  image(TSprite1, 515, 210);
  image(TSprite1, 515, 260); 
  image(TSprite1, 515, 310); 
  image(TSprite1, 515, 360);
  image(TSprite1, 515, 410);
  image(TSprite1, 515, 460);
  image(TSprite1, 515, 510);
  image(TSprite1, 515, 560);
  image(TSprite1, 515, 610);
  image(TSprite1, 515, 660);
  image(TSprite1, 515, 710);
  image(TSprite1, 515, 760);
  image(TSprite1, 628, -40);
  image(TSprite1, 628, 10);
  image(TSprite1, 628, 60);
  image(TSprite1, 628, 110);
  image(TSprite1, 628, 160);
  image(TSprite1, 628, 210);
  image(TSprite1, 628, 260);
  image(TSprite1, 628, 310);
  image(TSprite1, 628, 360);
  image(TSprite1, 628, 410);
  image(TSprite1, 628, 460);
  image(TSprite1, 628, 510);
  image(TSprite1, 628, 560);
  image(TSprite1, 628, 610);
  image(TSprite1, 628, 660);
  image(TSprite1, 628, 710);
  image(TSprite1, 628, 760);
  image(TSprite1, 741, -40); 
  image(TSprite1, 741, 10);
  image(TSprite1, 741, 60);
  image(TSprite1, 741, 110);
  image(TSprite1, 741, 160);
  image(TSprite1, 741, 210);
  image(TSprite1, 741, 360);
  image(TSprite1, 741, 260);
  image(TSprite1, 741, 310);
  image(TSprite1, 741, 360);
  image(TSprite1, 741, 410);
  image(TSprite1, 741, 460);
  image(TSprite1, 741, 510);
  image(TSprite1, 741, 560);
  image(TSprite1, 741, 610);
  image(TSprite1, 741, 660);
  image(TSprite1, 741, 710);
  image(TSprite1, 741, 760);

  ////Player 1------------------------------------------------------

  if (y0 > height + 15) {
    y0 = -15;
    x0 = 35;
    y0_speed = random(3, 7);
  }

  y0 += y0_speed;


  if (y1 > height + 15) {
    y1 = -15;
    x1 = 150;
    y1_speed = random(3, 7);
  }

  y1 += y1_speed;

  if (y2 > height + 15) {
    y2 = -15;
    x2 = 258;
    y2_speed = random(3, 7);
  }

  y2 += y2_speed;

  //player2----------------------------------------------------------

  if (y3 > height + 10) {
    y3 = -15;
    x3 = 380;
    y3_speed = random(3, 7);
  }

  y3 += y3_speed;


  if (y4 > height + 15) {
    y4 =-15;
    x4 = 480;
    y4_speed = random(3, 7);
  }

  y4 += y4_speed;

  if (y5 > height + 15) {
    y5 = -15;
    x5 = 595;
    y5_speed = random(3, 7);
  }

  y5 += y5_speed;


  berry1();
  berry2();
  berry3();
  berry4();
  berry5();
  berry6();
  image(bucket, 30, 680); 
  image(bucket, 152, 680); 
  image(bucket, 268, 680); 
  image(bucket, 384, 680); 
  image(bucket, 485, 680);
  image(bucket, 601, 680);
  bucket.resize(40, 50);

  for (int i = -40; i < 600; i = i+80) {
    image(apple, i, -80);
  }

  line(345, 0, 345, 750);
  strokeWeight(9);

  //player1-----------------------------------------------------------------------

  //println("player1: " + lifeCounter);
  //if (y0<=450 && y0>=151 && (keyPressed && (key=='v'|| key == 'V') ) && early && inByte1==1) {
  if (y0<=450 && y0>=151 && (keyPressed && (key=='v'|| key == 'V') ) && early) {
    println("C - too early");
    lifeCounter-=1;
    if (lifeCounter <=0) {
      y0= -15;
      x0 = 35;
      y0_speed = 0;
    } else {
      y0=0;
    }
    early=false;
  }
  if (y0 >= 500) {
    if (inByte1 == 0 || (keyPressed && (key=='v'|| key == 'V') )) {
      println("C!!! " + inByte1); 
      y0 = -15;
      x0 = 35;
      y0_speed = random(3, 7);
    }
    if (y0>=750) {
      println("C - no hit");

      y0 = -15;
      x0 = 35;
      y0_speed = random(3, 7);
      loseLife();
    }
  }


  if (y1<=450 && y1>=151 && (keyPressed && (key=='b'|| key == 'B') ) && early1) {
    println("B - too early1");
    lifeCounter-=1;
    if (lifeCounter <=0) {
      y1=-15;
      x1 = 150;
      y1_speed = 0;
    } else {
      y1=0;
    }
    early1=false;
  }

  if (y1 >= 500) {
    if (inByte1 == 0 || (keyPressed && (key=='b'|| key == 'B') )) {
      println("B!!!"); 
      y1 = -15;
      x1 = 150;
      y1_speed = random(3, 7);
    }
    if (y1>=750) {
      println("B - no hit");
      y1 = -15;
      x1 = 150;
      y1_speed = random(3, 7);
      loseLife();
    }
  }

  if (y2<=450 && y2>=151 && (keyPressed && (key=='n'|| key == 'N') ) && early2) {
    println("N - too early");
    lifeCounter-=1;
    if (lifeCounter <=0) {
      y2=-15;
      x2 = 258;
      y2_speed = 0;
    } else {
      y2=0;
    }
    early2=false;
  }
  if (y2 >= 500) {
    if (inByte1 == 0 || (keyPressed && (key=='n'|| key == 'N') )) {

      println("N!!!"); 
      y2 = -15;
      x2 = 258;
      y2_speed = random(3, 7);
    }
    if (y2>=750) {
      println("N - no hit");

      y2 = -15;
      x2 = 258;
      y2_speed = random(3, 7);
      loseLife();
    }
  }

  //player2------------------------------------------------------------------------
  //println("player2: " + lifeCounter2);
  if (y3<=450 && y3>=151 && (keyPressed && (key=='a'|| key == 'A') ) && early3) {
    println("F - too early");
    lifeCounter2-=1;
    if (lifeCounter2<=0) {
      y3=-15;
      x3 = 380;
      y3_speed = 0;
    } else {
      y3=0;
    }
    early3=false;
  }
  if (y3 >= 500) {
    if (inByte2 == 0 || (keyPressed && (key=='a'|| key == 'A') )) {

      println("F!!! " + inByte2); 
      y3 = -15;
      x3 = 380;
      y3_speed = random(3, 7);
    }
    if (y3>=750) {
      println("F - no hit");

      y3 = -15;
      x3 = 380;
      y3_speed = random(3, 7);
      loseLife2();
    }
  }

  if (y4<=450 && y4>=151 && (keyPressed && (key=='s'|| key == 'S') ) && early4) {
    println("G - too early");
    lifeCounter2-=1;
    if (lifeCounter2<=0) {
      y4=-15;
      x4 = 480;
      y4_speed = 0;
    } else {
      y4=0;
    }
    early4=false;
  }
  if (y4 >= 500) {
    if (inByte2 == 1 || (keyPressed && (key=='s'|| key == 'S') )) {

      println("G!!!"); 
      y4 = -15;
      x4 = 480;
      y4_speed = random(3, 7);
    }
    if (y4>=750) {
      println("G - no hit");

      y4 = -15;
      x4 = 480;
      y4_speed = random(3, 7);
      loseLife2();
    }
  }

  if (y5<=450 && y4>=151 && (keyPressed && (key=='d'|| key == 'D') ) && early5) {
    println("H - too early");
    lifeCounter2-=1;
    if (lifeCounter2<=0) {
      y5=-15;
      x5 = 595;
      y5_speed = 0;
    } else {
      y5=0;
    }
    early5=false;
  }
  if (y5 >= 500) {
    if (inByte2 == 2 || (keyPressed && (key=='h'|| key == 'H') )) {

      println("H!!!"); 
      y5 = -15;
      x5 = 595;
      y5_speed = random(3, 7);
    }
    if (y5>=750) {
      println("H - no hit"); 
      y5 = -15;
      x5 = 595;
      y5_speed = random(3, 7);
      loseLife2();
    }
  }
}




void loseLife() {

  //player 1 


  if (die) {
    lifeCounter= lifeCounter-1;
    die=false;
    if (lifeCounter <= 0) {
      println("die - gameover");
      y0 = -15;
      x0 = 0;
      y0_speed = 0;
    }
  }

  if (die1) {
    lifeCounter= lifeCounter-1;
    die1=false;
    if (lifeCounter <= 0) {
      println("die1 - gameover");
      y1 = -15;
      x1 = 150;
      y1_speed = 0;
    }
  }

  if (die2) {
    lifeCounter= lifeCounter-1;
    die2=false;
    if (lifeCounter <= 0) {
      println("die2 - gameover");
      y2 = -15;
      x2 = 258;
      y2_speed = 0;
    }
  }
  //if (die && die1 && die2) {

  //  println("player 1 game over");
  //}
}

void loseLife2() {
  //player2 

  if (die3) {
    lifeCounter2= lifeCounter2-1;
    die3=false;
    if (lifeCounter2 < 0) {
      println("die3 - gameover");
      y3 = -15;
      x3 = 380;
      y3_speed = 0;
    }
  }

  if (die4) {
    lifeCounter2= lifeCounter2-1;
    die4=false;
    if (lifeCounter2 < 0) {
      println("die4 - gameover");
      y4 = -15;
      x4 = 480;
      y4_speed = 0;
    }
  }

  if (die5) {
    lifeCounter2= lifeCounter2-1;
    die5=false;
    if (lifeCounter2 < 0) {
      println("die5 - gameover");
      y5 = -15;
      x5 = 595;
      y5_speed = 0;
    }
  }

  //if (die3 && die4 && die5) {   
  //println("player 2 game over");
  //}
}  

//ArduinoPlayer1

#include <Wire.h>
#include "Seeed_QTouch.h"

void setup()
{   
    Serial.begin(9600);
}

void loop()
{
    if(QTouch.isTouch(0))
    {
        Serial.write(0);
        Serial.print(0);
        delay(10);
    }
    
    else if(QTouch.isTouch(1))
    {                      
        Serial.write(1);
        Serial.print(1);
        delay(10);
    }
    
    else if(QTouch.isTouch(2))
    {
        Serial.write(2);
        Serial.print(2);
        delay(10);
        
    }
    
    else if(QTouch.isTouch(3))
    {
        Serial.write(3);
        Serial.print(3);
        delay(10);
    }

    delay(10);
}

//ArduinoPlayer2

#include <Wire.h>
#include "Seeed_QTouch.h"

void setup()
{   
    Serial.begin(9600);
}

void loop()
{
    if(QTouch.isTouch(0))
    {
        Serial.write(0);
        Serial.print(0);
        delay(10);
    }
    
    else if(QTouch.isTouch(1))
    {                      
        Serial.write(1);
        Serial.print(1);
        delay(10);
    }
    
    else if(QTouch.isTouch(2))
    {
        Serial.write(2);
        Serial.print(2);
        delay(10);
        
    }
    
    else if(QTouch.isTouch(3))
    {
        Serial.write(3);
        Serial.print(3);
        delay(10);
    }

    delay(10);
}

One thought on “Final Project: Falling Berries by Carlo (Marcela)

  1. great documentation Carlo!
    I am pretty happy with the improvements you did during the semester, I hope you finally enjoyed the class and feel more confident with what you learned 🙂
    IMA is a collaborative program, so you can take advantage of this and ask anything to anyone.
    I’d have liked to see your project running, but I understand you spent your time working on the code. It was a great job though!

    Congrats Carlo!

Leave a Reply