Ryan’s Failed Brick Breaker Game

So, initially for this week’s assignment, I wanted to replicate my childhood game, which was called the Brick Breaker, as I really loved this game and played it almost everyday since I was small with my mom’s old Nokia phone.

Arkadroid Brick Breaker - Apps on Google Play

Initially, I sort of drew a sketch for myself to better follow along and code, as shown below. (Excuse the poor quality)

At first, I had no difficulty creating my user bar, the bouncing balls, and the blocks at the top. However, the main obstacle for me was being able to make the balls to be able to bounce off my user bar and also the rectangles (and causing them to disappear upon contact). I tried searching up tutorials, videos, websites, and even other online projects made before in order to help me understand collision detection and how to code it. However, in the end, I still wasn’t able to code the collision detection for my ellipses because I could not quite grasp and fully understand the mechanics behind coding for interactions between two different classes, which in this case would be the ellipses with the user bar and the rectangles. Furthermore, you will notice a lot of hardcoding because I wasn’t quite sure how to use arrays yet and I did not want to mess with something I wasn’t familiar with yet.

So, in the end, I decided to just add a bit more ellipses to make it look less boring as it did.

/***************MAIN SKETCH **************/
int x;
int y;
int blockx;
int blocky;
int rectWidth=50;
int rectHeight=50;


Bar userbar; 
RandomBlocks blocks;
RandomBlocks blocks2;
RandomBlocks blocks3;
RandomBlocks blocks4;
BouncingBall ball;
BouncingBall ball2;
BouncingBall ball3;
BouncingBall ball4;
BouncingBall ball5;
void setup() {
  size(1280, 720); 
  userbar= new Bar(); //calling for a constructor 
  blocks= new RandomBlocks();//constructor always needs two paranthesis ()
  ball= new BouncingBall(random(width), random(height), 50);
  ball2= new BouncingBall(random(width),random(height),50);
  ball3= new BouncingBall(random(width),random(height),50);//ALL OF THIS IS HARDCODING SORRY
  ball4= new BouncingBall(random(width),random(height),50);
  ball5= new BouncingBall(random(width),random(height),50);
  blocks2= new RandomBlocks();  blocks3= new RandomBlocks();
  blocks4= new RandomBlocks();
}



void draw() { 
  background(255);

  userbar.drawbar(); //using dot syntax, it calls a function for the object to do sth built by constructor 
  //Random blocks at the top
  blocks.drawblock();
  blocks2.drawblock2();
  blocks3.drawblock3();
  blocks4.drawblock4();
  //All the five balls 
  ball.bounceBall();
  ball2.bounceBall();
  ball3.bounceBall();
  ball4.bounceBall();
  ball5.bounceBall();
}

/***********Code for the controllable user blue bar***********/ 
class Bar {
  

  Bar() { //this is a constructor with paranthesis ()
  // in a constructor, it doesn't necessarily have to contain anything inside it, it just represents an object
    
  }
    void drawbar(){
    stroke(255, 0, 0);
    fill(0, 0, 255);
    rect(mouseX-250, height-50, 300, 20);
    }
}

/************Code for the five ellipses***************/
class BouncingBall {
  //float ballx=random(width);
  //float bally=random(height);
  float diameter;
  float xspeed;
  float yspeed;
  float x;
  float y;
  color c;

  BouncingBall(float tempX, float tempY, float tempDiameter) {//constructor
    x=tempX;
    y=tempY;    diameter=tempDiameter;
    xspeed=10;
    yspeed=10;
  }
  void bounceBall() {
    stroke(0);
    fill(211, 123, 231);
    ellipse(x, y, 50,50);

    if (x>=width || x<=0) {
      xspeed*=-1;
    }


    if (y>=height || y<=0) {
      yspeed*=-1;
    }

    x=x+xspeed;
    y=y+yspeed;
  }
 
}

/************Code for the rows of shiny blocks at the top**********/ 

class RandomBlocks {//for a class, the first letter has to be capitalized 

  RandomBlocks() {//a constructor
  }
  void drawblock() {

    for (x=0; x<width; x+=rectWidth+50) {
      stroke(0);
      fill(random(255), random(255), random(255));
      rect(x, y, rectWidth, rectHeight);
    }
  }

  void drawblock2() {
    for (x=0; x<width; x+=rectWidth+50) {
      stroke(0);
      fill(random(255), random(255), random(255));
      rect(x+50, y+60, rectWidth, rectHeight);
    }
  }

  void drawblock3() {
    for (x=0; x<width; x+=rectWidth+50) {
      stroke(0);
      fill(random(255), random(255), random(255));
      rect(x+100, y+120, rectWidth, rectHeight);
    }
  }

  void drawblock4() {    for (x=0; x<width; x+=rectWidth+50) {
      stroke(0);
      fill(random(255), random(255), random(255));
      rect(x+50, y+180, rectWidth, rectHeight);
    }
  }
}

 

Week 2 Animation Assignment

For this week’s assignment, we were asked to incorporate both types of loops, specifically for() and while(), to showcase some various animations, loops, and conditionals.

During the process of making this, I had to go back and rewatch all of the previous class videos from the past two weeks, various Youtube videos online (Dan Shiffman’s are really helpful, will definitely watch more of his videos), and also some other coding tutorial websites and practices online in order to get a better understanding.

Originally, I wanted to make it  similar  to  this  sketch  of  mine,  but  I mainly  struggled  with  creating  the  floating  rectangles.  My   original  plan  was  to  use  the  loops  to  create  multiple  rectangles to float in  randomly  generated  directions  as  well  as  its  colors,  but I was  unable  to  do  it.  However,  I  will  make  sure  to  learn  it  in  my  spare  time.

For this particular assignment, my main personal objective was to utilize both for and while loops in my code and to be able to generate random movements and animations as well as colors. Thought it may be extremely bright to look at due to the different colors changing randomly, I hope you guys like it. Another problem I encountered was when I wanted to use a void mousePressed() function where by clicking the mouse, all the colors would change back to grey or black colors as the compiler stated “unexpected token: void”. This can be found at the bottom of my code where a huge section was disabled with the //. I was unable to figure out why it had appeared this error.

float angle = 100;
int linespace=72;
float y=0;
float x;
float xspeed=3;
float yspeed= 3;
float spacing=50;




void setup() {
  size(1280, 1280);
  rectMode(CENTER);
}

void draw() {
  background(170);

  stroke(150);
  strokeWeight(2);

  //Moving background lines
  spacing=spacing+random(-1, 1);
  //Vertical background lines
  for (int x=0; x<width; x=x+20) {
    line(x, 10, x, height);
    x+=spacing;
  }
  //x=0;
  //while(x<width){
  //  line(x,10,x,height);
  //  x+=spacing;
  //}
  y=0;
  while (y<height) {
    line(20, y, width, y);
    y+=spacing;
  }
  //Failed attempt 
  for (int i=0; i<width; i += linespace) {
    stroke(random(255), random(255), random(255));
    line(i, i, i+5, i+height);
    line(i, i+5, i+width, i+5);
    //The retracting rectangle 
    x=0;
    while (x<width) {
      if (mouseX<1) {
        x+=1;
      } else {
        x+=mouseX;
      }
      fill(random(255), random(255), random(255));
      stroke(240);
      rect(x, mouseY, 100, 100);
      //line(i,i,i,i+height);
    }
    //Spining orange rectangles

    pushMatrix();
    //translate(width/2,height/2);
    translate(mouseX, mouseY);
    fill(random(255), random(255), random(255));
    rotate(angle);
    rect(mouseX, mouseY, 100, 100);
    popMatrix();

    fill(random(255), random(255), random(255));
    rect(mouseX, mouseY, 100, 300);
    angle+=.005;
  }


  //If mouse is pressed, make everthing stop changing colors
//  void mousePressed()){ 
//    for (int i=0; i<width; i += linespace) {
//      stroke(150);
//      line(i, i, i+5, i+height);
//      line(i, i+5, i+width, i+5);

//      x=0;
//      while (x<width) {
//        if (mouseX<1) {
//          x+=1;
//        } else {
//          x+=mouseX;
//        }
//        fill(150);
//        stroke(240);
//        rect(x, mouseY, 100, 100);

//        pushMatrix();
//        //translate(width/2,height/2);
//        translate(mouseX, mouseY);
//        fill(150);
//        rotate(angle);
//        rect(mouseX, mouseY, 100, 100);
//        popMatrix();

//        fill(150);
//        rect(mouseX, mouseY, 100, 300);
//        angle+=.005;
      
//      }
//    }
//  }
}

 

Self Portrait Assignment

Within the process of creating my self portrait , I struggled with a lot of different things ranging from simple writings  and ordering of codes to changing various colors, shapes and sizes of different figures, and many more. I have absolutely zero experience with coding, therefore I was only able to create this five-year-old-like-drawing of mine. However, I hope to be able to get better at coding in the future and it would be really appreciated if any of you guys could give me tips or recommendations for websites that could help me with my coding skills so  I wouldn’t  have  to  look  like  a snowman.

int backgroundColor = 255;
int x=200; 
int y=200;
float a= 100;
float b=100;
float start=180;

void setup(){
  size(500,600);
  x=width/2;
  y=height/2;}

void draw() {
  background(backgroundColor);
 //face shape 
ellipse(250, 320, 400, 400);

//nose
triangle(250,380,200,380,250,330);
//spectacles
rect(100,275,100,60);
rect(300,275,100,60);
line(100, 300,50,300);
line (400, 300, 450, 300);
 // Lips 
 pushStyle();
  fill(210, 153, 133);
  arc(250, 400, 80,80,0, PI, PIE);  
  popStyle();
  
// Eye shape 
ellipse(150, 300, 60, 30);
ellipse (350, 300, 60, 30);



//eye color
pushStyle();
fill(0);
ellipse(150, 300, 20, 20);
ellipse (350, 300, 20, 20);
popStyle();
//eyebrow
pushStyle();
fill(0);
rect(100,250,70,20,7);
rect(320,250,70,20,7);
popStyle();


}