Progress to Infinity

For my final project, I made another game. There were about 4 factors that went into this game idea.

  1. Unlike my other games, I wanted to challenge myself and not be reliant on PImages for the actual graphics and physically draw shapes and lines myself.
  2. Since we  so recently wrote our blog post on Computational Media, I think I was still very oriented towards that meditation on computers and their capabilities, etc.
  3. I wanted to incorporate the first part of our class that focused on the Arduino because it was so integral to our course with its scope on the physical world of computing.

So with all those factors in mind, I thought about the circle and how basically it is a polygon with an infinite amount of sides. This topic of “infinity” reminded me of David Deutsch’s Beginning of Infinity , where  he claims that progress is boundless – or infinite. So by somehow weirdly merging the those thoughts in my mind, the game where the goal was to become a circle (that represented infinity with its “infinite” number of sides) became its own ” progress towards infinity”.

This is my first multiplayer game (woohooo, double the fun!) and the movement of the players are controlled by the  ASDW and the arrow keys. In each level, there are foreign words floating around that mean the number of the next shape the player must become. To advance, the player must retrieve all of his respective words. For example, for a square to become a polygon, the player must collect all 5 words that mean “5”. The words are also the same color as the player so it makes the game easier than just a mere translation exercise and actually possible to finish within a more reasonable amount of time.

Here is the tutorial demo video: https://www.youtube.com/watch?v=4atf-fCveh0

 

Twist the dials to change your color!
Twist the dials to change your color!

 

I did throw in one last surprise so unfortunately the file needs to be in the data folder along with the fonts in order for the code to run correctly.

So to download everything: https://drive.google.com/folderview?id=0B9jm5VZVC2_oNFZtVUdCZ1hXMVk&usp=sharing

And here is the scary code. The switch statements got very repetitive but I wasn’t able to modularize the actual level changing function because then it ended up being that I would have to return an array and somehow pass it back into the same function (all because I have so many switches within each level).

import processing.serial.*;
Serial myPort;

int pot1;
int pot2;
int pot3;
int converted1;
int converted2;
int converted3;

Shape player_1;
Shape player_2;
Text opening;

ArrayList<Text>player1text;
ArrayList<Text>player2text;

//OPENING:

PFont type;

//Beginning: 
boolean start;

boolean player_1_choice;
boolean player_2_choice;
int final_red1;
int final_green1;
int final_blue1;
int final_red2;
int final_green2;
int final_blue2;

//GAME
boolean game_on;
int level_count1= 1; 
int level_count2 = 1;
boolean level_start;
boolean level_start2;

//WINNING:
boolean finish;
Boolean win1;
Boolean win2;
boolean win_keys;
boolean win_reset1;
boolean win_reset2;
boolean win_text1;
boolean win_text2;

void setup() {
  size(1000, 700,P2D);

  //Beginning:
  start = true;
  game_on = false; 
  type = loadFont("Cochin-48.vlw");
  boolean player_1_choice = true;
  boolean player_2_choice = false;
  int final_red1=0;
  int final_green1=0;
  int final_blue1=0;
  int final_red2=0;
  int final_green2=0;
  int final_blue2=0;

  //Gameplay:
  level_start = false;
  level_start2 = false;
  player_1 = new Shape();
  player_1.set_Position(200,300,4);
  player_2 = new Shape();
  player_2.set_Position(800,300,-4);

  player1text = new ArrayList<Text>();
  player2text = new ArrayList<Text>();
  //Only for level 1:
  for (int i = 0;i<2;i++) {
    player1text.add(new Text((int)random(1, 11), 1));
    player1text.get(i).set_text_color(final_red1, final_green1, final_blue1);
    player2text.add(new Text((int)random(1, 11), 1));
    player2text.get(i).set_text_color(final_red2, final_green2, final_blue2);
  }
  //Winning:
  finish = false;
  win1 = false;
  win2=  false;
  win_keys = false;
  win_reset1 = false;
  win_reset2 = false;
  win_text1 = false;
  win_text2 = false;

 //ARDUINO --> PROCESSING: 
  println(Serial.list());
  String portName = Serial.list()[5];
  myPort = new Serial(this, portName, 9600);
 myPort.readStringUntil('\n');
}//End of setup

void draw() {
  background(255);

  if (start) {
    background(255);
    fill(0);
    textFont(type, 36);
    text("Welcome to the beginning of infinity.\n Please press the '1' to begin color selection for player 1.\n Mouse click to re-orient the dial inputs.", width/10, height /4);

    if (player_1_choice) {
      background(255);
      text("Player 1: please select color by turning each dial. \n Press '2' to save your selection and let Player 2 choose.", width/9, height/4);
      final_red1 = converted1;
      final_green1 = converted3;
      final_blue1 = converted2;
      fill(final_red1, final_green1, final_blue1);
      rect(100, height/2, 200, 200);
    }
    else if (player_2_choice) {
      background(255);
      text("Player 2: please select your color by turning the dial.\n To begin the game press 'ENTER'", width/8, height/4);
      final_red2 = converted1;
      final_green2 = converted3;
      final_blue2 = converted2;
      fill(final_red2,final_green2, final_blue2);
      rect(700, height/2, 200, 200);
    }
  }

  //game start
  if (game_on) {

    //PLAYER 1 SWITCH
    switch (level_count1) {
    case 1:
      player_1.drawShape1();
       ;
      player_1.moveShape();
      if (player_1.checkBoundaries()) {
        player_1.move_back();
      }
      //TEXT
      for (int i = 0;i<player1text.size();i++) {
        player1text.get(i).set_text_color(final_red1, final_green1, final_blue1);
        player1text.get(i).drawText();
        player1text.get(i).moveText();
        if (player1text.get(i).checkBoundaries()) {
          player1text.get(i).move_back_text();
        }
        if (player1text.get(i).check_Collision(player_1)) {
          player1text.remove(i);
          i--;

          if (player1text.isEmpty()) {
            level_count1++;
            level_start = true;
          }
        }
      }

      break;
    case 2:
      player_1.drawLine();
       ;
      player_1.moveShape();
      if (player_1.checkBoundaries()) {
        player_1.move_back();
      }
      //Text
      if (level_start) {
        for (int i = 0;i<3;i++) {
          player1text.add(new Text((int)random(1, 11), 2));
        }
        for (int i = 0; i<3; i++) {
          player1text.get(i).set_text_color(final_red1, final_green1,final_blue1);
      }
        level_start = false;
      }
      for (int i = 0;i<player1text.size();i++) {
        player1text.get(i).drawText();
        player1text.get(i).moveText();
        if (player1text.get(i).checkBoundaries()) {
          player1text.get(i).move_back_text();
        }
        if (player1text.get(i).check_Collision(player_1)) {
          player1text.remove(i);
          i--;

          if (player1text.isEmpty()) {
            level_count1++;
            level_start = true;
          }
        }
      }
      break;
    case 3:
      player_1.drawShape2(3);
      player_1.moveShape();
      if (player_1.checkBoundaries()) {
        player_1.move_back();
      }
      //Text
      if (level_start) {
        for (int i = 0;i<4;i++) {
          player1text.add(new Text((int)random(1, 11), 3));
        }
        for (int i = 0; i<4; i++) {
          player1text.get(i).set_text_color(final_red1, final_green1,final_blue1);
      }
        level_start = false;
      }

      for (int i = 0;i<player1text.size();i++) {
        player1text.get(i).drawText();
        player1text.get(i).moveText();
        if (player1text.get(i).checkBoundaries()) {
          player1text.get(i).move_back_text();
        }
        if (player1text.get(i).check_Collision(player_1)) {
          player1text.remove(i);
          i--;
          if (player1text.isEmpty()) {
            level_count1++;
            level_start = true;
          }
        }
      }
      break;
    case 4:
      player_1.drawShape2(4);
       ;
      player_1.moveShape();
      if (player_1.checkBoundaries()) {
        player_1.move_back();
      }
      //Text
      if (level_start) {
        for (int i = 0;i<5;i++) {
          player1text.add(new Text((int)random(1, 11), 4));
        }
        for (int i = 0; i<5; i++) {
          player1text.get(i).set_text_color(final_red1, final_green1,final_blue1);
      }
        level_start = false;
      }
      for (int i = 0;i<player1text.size();i++) {
        player1text.get(i).drawText();
        player1text.get(i).moveText();
        if (player1text.get(i).checkBoundaries()) {
          player1text.get(i).move_back_text();
        }
        if (player1text.get(i).check_Collision(player_1)) {
          player1text.remove(i);
          i--;

          if (player1text.isEmpty()) {
            level_count1++;
            level_start = true;
          }
        }
      }
      break;
    case 5:
      player_1.drawShape2(5);
       ;
      player_1.moveShape();
      if (player_1.checkBoundaries()) {
        player_1.move_back();
      }
      //Text
      if (level_start) {
        for (int i = 0;i<6;i++) {
          player1text.add(new Text((int)random(1, 11), 5));
        }
        for (int i = 0; i<6; i++) {
          player1text.get(i).set_text_color(final_red1, final_green1,final_blue1);
      }
        level_start = false;
      }
      for (int i = 0;i<player1text.size();i++) {
        player1text.get(i).drawText();
        player1text.get(i).moveText();
        if (player1text.get(i).checkBoundaries()) {
          player1text.get(i).move_back_text();
        }
        if (player1text.get(i).check_Collision(player_1)) {
          player1text.remove(i);
          i--;

          if (player1text.isEmpty()) {
            level_count1++;
            level_start = true;
          }
        }
      }
      break;
    case 6:
      player_1.drawShape2(6);
       ;
      player_1.moveShape();
      if (player_1.checkBoundaries()) {
        player_1.move_back();
      }
      //Text
      if (level_start) {
        for (int i = 0;i<7;i++) {
          player1text.add(new Text((int)random(1, 11), 6));
        }
        for (int i = 0; i<7; i++) {
          player1text.get(i).set_text_color(final_red1, final_green1,final_blue1);
      }
        level_start = false;
      }
      for (int i = 0;i<player1text.size();i++) {
        player1text.get(i).drawText();
        player1text.get(i).moveText();
        if (player1text.get(i).checkBoundaries()) {
          player1text.get(i).move_back_text();
        }
        if (player1text.get(i).check_Collision(player_1)) {
          player1text.remove(i);
          i--;

          if (player1text.isEmpty()) {
            level_count1++;
            level_start = true;
          }
        }
      }
      break;
    case 7:
      player_1.drawShape2(7);
      player_1.moveShape();
      if (player_1.checkBoundaries()) {
        player_1.move_back();
      }
      //Text
      if (level_start) {
        for (int i = 0;i<8;i++) {
          player1text.add(new Text((int)random(1, 11), 7));
        }
        for (int i = 0; i<8; i++) {
          player1text.get(i).set_text_color(final_red1, final_green1,final_blue1);
      }
        level_start = false;
      }
      for (int i = 0;i<player1text.size();i++) {
        player1text.get(i).drawText();
        player1text.get(i).moveText();
        if (player1text.get(i).checkBoundaries()) {
          player1text.get(i).move_back_text();
        }
        if (player1text.get(i).check_Collision(player_1)) {
          player1text.remove(i);
          i--;
          if (player1text.isEmpty()) {
            level_count1++;
            level_start = true;
          }
        }
      }
      break;
    case 8:
      player_1.drawShape2(8);
       ;
      player_1.moveShape();
      if (player_1.checkBoundaries()) {
        player_1.move_back();
      }
      //Text
      if (level_start) {
        for (int i = 0;i<9;i++) {
          player1text.add(new Text((int)random(1, 11), 8));
        }
        for (int i = 0; i<9; i++) {
          player1text.get(i).set_text_color(final_red1, final_green1,final_blue1);
      }
        level_start = false;
      }
      for (int i = 0;i<player1text.size();i++) {
        player1text.get(i).drawText();
        player1text.get(i).moveText();
        if (player1text.get(i).checkBoundaries()) {
          player1text.get(i).move_back_text();
        }
        if (player1text.get(i).check_Collision(player_1)) {
          player1text.remove(i);
          i--;
          if (player1text.isEmpty()) {
            level_count1++;
            level_start = true;
          }
        }
      }
      break;
    case 9:
      player_1.drawShape2(9);
      player_1.moveShape();
      if (player_1.checkBoundaries()) {
        player_1.move_back();
      }
      //Text
      if (level_start) {
        for (int i = 0;i<10;i++) {
          player1text.add(new Text((int)random(1, 11), 9));
        }
        for (int i = 0; i<10; i++) {
          player1text.get(i).set_text_color(final_red1, final_green1,final_blue1);
      }
        level_start = false;
      }
      for (int i = 0;i<player1text.size();i++) {
        player1text.get(i).drawText();
        player1text.get(i).moveText();
        if (player1text.get(i).checkBoundaries()) {
          player1text.get(i).move_back_text();
        }
        if (player1text.get(i).check_Collision(player_1)) {
          player1text.remove(i);
          i--;
          if (player1text.isEmpty()) {
            level_count1++;
            level_start = true;
          }
        }
      }
      break;
    case 10:
      game_on = false;
      finish = true;
      win1 = true;
      win_keys = true;
      win_reset1 = true;
      break;
    } // End of player 1

    //PLAYER 2
    switch (level_count2) {
    case 1:
      player_2.drawShape1();
      player_2.moveShape();
      if (player_2.checkBoundaries()) {
        player_2.move_back();
      }
      //TEXT
      for (int i = 0;i<player2text.size();i++) {
       player2text.get(i).set_text_color(final_red2, final_green2, final_blue2);
        player2text.get(i).drawText();
        player2text.get(i).moveText();
        if (player2text.get(i).checkBoundaries()) {
          player2text.get(i).move_back_text();
        }
        if (player2text.get(i).check_Collision(player_2)) {
          player2text.remove(i);
          i--;
          if (player2text.isEmpty()) {
            level_count2++;
            level_start2 = true;
          }
        }
      }
      break;
    case 2:
      player_2.drawLine();
      player_2.moveShape();
      if (player_2.checkBoundaries()) {
        player_2.move_back();
      }
      //Text
      if (level_start2) {
        for (int i = 0;i<3;i++) {
          player2text.add(new Text((int)random(1, 11), 2));
        }
        for (int i = 0; i<3; i++) {
          player2text.get(i).set_text_color(final_red2, final_green2,final_blue2);
      }
        level_start2 = false;
      }
      for (int i = 0;i<player2text.size();i++) {
        player2text.get(i).drawText();
        player2text.get(i).moveText();
        if (player2text.get(i).checkBoundaries()) {
          player2text.get(i).move_back_text();
        }
        if (player2text.get(i).check_Collision(player_2)) {
          player2text.remove(i);
          i--;

          if (player2text.isEmpty()) {
            level_count2++;
            level_start2 = true;
          }
        }
      }
      break;
    case 3:
      player_2.drawShape2(3);

      player_2.moveShape();
      if (player_2.checkBoundaries()) {
        player_2.move_back();
      }
      //Text
      if (level_start2) {
        for (int i = 0;i<4;i++) {
          player2text.add(new Text((int)random(1, 11), 3));
        }
        for (int i = 0; i<4; i++) {
          player2text.get(i).set_text_color(final_red2, final_green2,final_blue2);
      }
        level_start2 = false;
      }
      for (int i = 0;i<player2text.size();i++) {
        player2text.get(i).drawText();
        player2text.get(i).moveText();
        if (player2text.get(i).checkBoundaries()) {
          player2text.get(i).move_back_text();
        }
        if (player2text.get(i).check_Collision(player_2)) {
          player2text.remove(i);
          i--;
          if (player2text.isEmpty()) {
            level_count2++;
            level_start2 = true;
          }
        }
      }
      break;
    case 4:
      player_2.drawShape2(4);

      player_2.moveShape();
      if (player_2.checkBoundaries()) {
        player_2.move_back();
      }
      //TEXT
      //Text
      if (level_start2) {
        for (int i = 0;i<5;i++) {
          player2text.add(new Text((int)random(1, 11), 4));
        }
        for (int i = 0; i<5; i++) {
          player2text.get(i).set_text_color(final_red2, final_green2,final_blue2);
      }
        level_start2 = false;
      }
      for (int i = 0;i<player2text.size();i++) {
        player2text.get(i).drawText();
        player2text.get(i).moveText();
        if (player2text.get(i).checkBoundaries()) {
          player2text.get(i).move_back_text();
        }
        if (player2text.get(i).check_Collision(player_2)) {
          player2text.remove(i);
          i--;

          if (player2text.isEmpty()) {
            level_count2++;
            level_start2 = true;
          }
        }
      }
      break;
    case 5:
      player_2.drawShape2(5);
      player_2.moveShape();
      if (player_2.checkBoundaries()) {
        player_2.move_back();
      }
      //TEXT
      //Text
      if (level_start2) {
        for (int i = 0;i<6;i++) {
          player2text.add(new Text((int)random(1, 11), 5));
        }
        for (int i = 0; i<6; i++) {
          player2text.get(i).set_text_color(final_red2, final_green2,final_blue2);
      }
        level_start2 = false;
      }
      for (int i = 0;i<player2text.size();i++) {
        player2text.get(i).drawText();
        player2text.get(i).moveText();
        if (player2text.get(i).checkBoundaries()) {
          player2text.get(i).move_back_text();
        }
        if (player2text.get(i).check_Collision(player_2)) {
          player2text.remove(i);
          i--;

          if (player2text.isEmpty()) {
            level_count2++;
            level_start2 = true;
          }
        }
      }
      break;
    case 6:
      player_2.drawShape2(6);

      player_2.moveShape();
      if (player_2.checkBoundaries()) {
        player_2.move_back();
      }
      //Text
      if (level_start) {
        for (int i = 0;i<7;i++) {
          player2text.add(new Text((int)random(1, 11), 6));
        }
        for (int i = 0; i<7; i++) {
          player2text.get(i).set_text_color(final_red2, final_green2,final_blue2);
      }
        level_start2 = false;
      }
      for (int i = 0;i<player2text.size();i++) {
        player2text.get(i).drawText();
        player2text.get(i).moveText();
        if (player2text.get(i).checkBoundaries()) {
          player2text.get(i).move_back_text();
        }
        if (player2text.get(i).check_Collision(player_2)) {
          player2text.remove(i);
          i--;
          if (player2text.isEmpty()) {
            level_count2++;
            level_start2 = true;
          }
        }
      }
      break;
    case 7:
      player_2.drawShape2(7);
      player_2.moveShape();
      if (player_2.checkBoundaries()) {
        player_2.move_back();
      }
      //Text
      if (level_start) {
        for (int i = 0;i<8;i++) {
          player2text.add(new Text((int)random(1, 11), 7));
        }
        for (int i = 0; i<8; i++) {
          player2text.get(i).set_text_color(final_red2, final_green2,final_blue2);
      }
        level_start2 = false;
      }
      for (int i = 0;i<player2text.size();i++) {
        player2text.get(i).drawText();
        player2text.get(i).moveText();
        if (player2text.get(i).checkBoundaries()) {
          player2text.get(i).move_back_text();
        }
        if (player2text.get(i).check_Collision(player_2)) {
          player2text.remove(i);
          i--;
          if (player2text.isEmpty()) {
            level_count2++;
            level_start2 = true;
          }
        }
      }
      break;
    case 8:
      player_2.drawShape2(8);
      player_2.moveShape();
      if (player_2.checkBoundaries()) {
        player_2.move_back();
      }
      //Text
      if (level_start2) {
        for (int i = 0;i<9;i++) {
          player2text.add(new Text((int)random(1, 11), 8));
        }
        for (int i = 0; i<9; i++) {
          player2text.get(i).set_text_color(final_red2, final_green2,final_blue2);
      }
        level_start2 = false;
      }
      for (int i = 0;i<player2text.size();i++) {
        player2text.get(i).drawText();
        player2text.get(i).moveText();
        if (player2text.get(i).checkBoundaries()) {
          player2text.get(i).move_back_text();
        }
        if (player2text.get(i).check_Collision(player_2)) {
          player2text.remove(i);
          i--;
          if (player2text.isEmpty()) {
            level_count2++;
            level_start2 = true;
          }
        }
      }
      break;
    case 9:
      player_2.drawShape2(9);
      player_2.moveShape();
      if (player_2.checkBoundaries()) {
        player_2.move_back();
      }
      //Text
      if (level_start2) {
        for (int i = 0;i<10;i++) {
          player2text.add(new Text((int)random(1, 11), 9));
        }
        for (int i = 0; i<10; i++) {
          player2text.get(i).set_text_color(final_red2, final_green2,final_blue2);
      }
        level_start2 = false;
      }
      for (int i = 0;i<player2text.size();i++) {
        player2text.get(i).drawText();
        player2text.get(i).moveText();
        if (player2text.get(i).checkBoundaries()) {
          player2text.get(i).move_back_text();
        }
        if (player2text.get(i).check_Collision(player_2)) {
          player2text.remove(i);
          i--;
          if (player2text.isEmpty()) {
            level_count2++;
            level_start2 = true;
          }
        }
      }
      break;
    case 10:
      game_on = false;
      finish = true;
      win2 = true;
      win_keys = true;
      win_reset2 = true;
      break;
    } // End of player 2
  }// End of game_on

  //WINNERS: 
  else if (finish) {
    //player 1 win:
    if (win1) {
      if (win_reset1) {
        player_1.win_reset();
        win_reset1 = false;
      }
      player_1.win_animation();
      if (player_1.get_win()) {
        textFont(type, 32);
        fill(255);
        text("To Infinity and Beyond", 500, 300);
      }
    }//play1win

    //player 2 win:

    if (win2) {
      if (win_reset2) {
        player_2.win_reset();
        win_reset1 = false;
      }
      player_2.win_animation();
      if (player_2.get_win()) {
        textFont(type, 32);
        fill(255);
        text("To Infinity and Beyond", 500, 300);
      }
    }//play1win
  }//end of finish
}// End of Draw

void keyPressed() {
  if (start) {
    if (key=='1'){
      player_1_choice = true;
    }
    if (key=='2') {
      player_1.set_color(final_red1, final_green1, final_blue1);
      player_1_choice = false;
      player_2_choice = true;
    }
    else if (key==ENTER && player_2_choice == true) {
      player_2.set_color(final_red2, final_green2, final_blue2);
      start = false;
      game_on = true;
    }
  }//end of if start

  if (win_keys==false) {
    if (key==CODED) {
      if (keyCode == UP) {
        player_1.set_y_velocity(-2);
        player_1.set_x_velocity(0);
      }
      else if (keyCode == DOWN) {
        player_1.set_y_velocity(2);
        player_1.set_x_velocity(0);
      }
      else if (keyCode == RIGHT) {
        player_1.set_x_velocity(2);
        player_1.set_y_velocity(0);
      }
      else if (keyCode == LEFT) {
        player_1.set_x_velocity(-2);
        player_1.set_y_velocity(0);
      }
    } //end of key code

    else if (key=='a') {
      player_2.set_x_velocity(-2);
      player_2.set_y_velocity(0);
    }
    else if (key=='d') {
      player_2.set_x_velocity(2);
      player_2.set_y_velocity(0);
    }
    else if (key=='w') {
      player_2.set_y_velocity(-2);
      player_2.set_x_velocity(0);
    }
    else if (key=='s') {
      player_2.set_y_velocity(2);
      player_2.set_x_velocity(0);
    }
  }
}//End of keyPress

void serialEvent(Serial _port) { //this is a callback function
  if (myPort == null) return;  //this is a hack to cover a bug where the port does not get set up in time.  
  ///this says if the port is not set up yet, bail (for now.) 
  String input = myPort.readStringUntil('\n');
  if (input != null) {  //if a '\n' character has in fact now arrived
    String [] dual_inputs = split(input, ",");
   input = input.trim();  //Take off the '\n' character
    pot1 = int(dual_inputs[0]);  //Turn it into number
    pot2 = int(dual_inputs[1]); 
    pot3 = int(dual_inputs[2]);
    converted1 = (int)map(pot1, 0, 1024, 0, 256);
   converted2 = (int)map(pot2, 0, 1024, 0, 256);
    converted3= (int)map(pot3, 0, 1024, 0, 256);
    println(converted1, converted3, converted2);
    myPort.write("Go");
  }
}//END OF KEY EVENT

void mousePressed(){
myPort.write("A");
}

Here is the SHAPE class:

class Shape {
  float x;
  float y;
  int velocity_x;
  int velocity_y;
  int radius; 
  float new_x;
  float new_y;
  int magnitude = 2;
  int shape_height = radius * 2;
  int shape_width = radius * 2; 
  int red;
  int green;
  int blue;

  PShape player;

  //Stages of Win:
  boolean win = false;

  //Constructor: 
  Shape() {
    velocity_x = 4;
    velocity_y=0;
    radius = 60;
    shape_height = radius * 2;
    shape_width = radius * 2;
  }
  void drawShape1() {
    fill(red,green,blue);
    ellipse(x, y, 8, 8);
  }
void drawLine(){
  fill(red, green, blue);
  line(x-(radius/2), y,x+(2 * radius),y);
  ellipse(x,y, 2,2);
}
  void drawShape2(int number_of_sides) {
    FloatList new_x_coords;
    new_x_coords = new FloatList();
    FloatList new_y_coords;
    new_y_coords = new FloatList();
    float angle = 0;

//FILL ARRAY WITH VERTEXES 
    for (int i=0;i<number_of_sides; i++) {
      new_x = cos(angle) * radius;
      new_y = sin(angle) * radius;
      new_x_coords.append(new_x);
      new_y_coords.append(new_y);
      angle+= ((2*PI)/(number_of_sides));
    }

    player = createShape();
    player.beginShape();
    for (int i = 0; i<new_x_coords.size(); i++){
    player.vertex(new_x_coords.get(i), new_y_coords.get(i));}
    player.endShape();
    player.setStroke(color(0));
    player.setFill((color(red,green,blue)));
    shapeMode(CENTER);
    shape(player, x, y);

  } //End of drawing shape again

  //Set velocity:
  void set_x_velocity(int direction ) {
    velocity_x = direction * magnitude;
  }

  void set_y_velocity(int direction ) {
    velocity_y = direction * magnitude;
  }

  void set_magnitude(int potentiometer_input) {
    magnitude = potentiometer_input;
  }

  //MOVEMENT
  void moveShape() {
    x+= velocity_x;
    y+= velocity_y;
  }

  boolean checkBoundaries() {
    boolean out_of_bounds = false;
    //Out of screen (horizontal)
    if (x>(width+(shape_width))|| x < (0 - (shape_width))) {
      out_of_bounds = true;
    }

    //Out of screen (vertical)
    if (y>(height+(shape_height)) || y < (0 - (shape_height))) {
      out_of_bounds = true;
    }
    return out_of_bounds;
  }

  void move_back() {
    if (y < 0 - shape_height) {
      y = height;
    }
    else if (y > height+shape_height) {
      y = 0;
    }

    else if (x < 0 - shape_width) {
      x = width;
    }
    else if (x>width+shape_width) {
      x = 0;
    }
  }

  //Getters:
  float get_X_Position() {
    return x;
  }
  float get_Y_Position() {
    return y;
  }
  int get_shape_Height() {
    return shape_height;
  }

  int get_shape_Width() {
    return shape_width;
  }

  boolean get_win() {
    return win;
  }

  //Setters: 
  void set_Position(float x, float y, int x_v) {
    this.x  = x;
    this.y =y;
    this.velocity_x = x_v;
  }

void set_color(int _red, int _green, int _blue){
  red = _red;
  green = _green;
  blue = _blue;
}
  //WINNER:
  void win_reset() {
    x = 0+shape_width;
    y = height / 2;
    velocity_x = 2;
    velocity_y = 0;
  }

  void drawCircle() {
    fill(red, green, blue);
    ellipse(x, y, radius*2, radius*2);
  }

  void win_animation() {
    if (x < width / 5) {
      this.drawShape2(10);
      this.moveShape();
    }
    else if (x < (2*(width / 5)) && x >= (width / 5)) {
      this.drawShape2(14);
      this.moveShape();
    }

    else if (x < (3*(width / 5)) && x >= (2*width) / 5) {
      this.drawShape2(18);
      this.moveShape();
    }

    else if (x < (4*(width / 5)) && x >= (3*width) / 5) {
      this.drawShape2(22);
      this.moveShape();
    }
    else if (x < width && x >=  (4*(width / 5))) {
      this.drawCircle();
      this.moveShape();
      if (x == width - 60) {
        velocity_x=0;
        if (radius< 1010) {
          radius+=10;
        }
        else if (radius == 1010) {
          win = true;
        }//end of win sign
      }//side of screen
    }//end of last else-if
  }//win animation
}//End of class

Here is the TEXT class:

class Text {

  //Different languages arrays that must be converted into stringsList
  String [] EnglishArray = {
    "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"
  };
  StringList English = new StringList(EnglishArray);
  String [] GermanArray = {
    "eins", "zwei", "drei", "vier", "funf", "sechs", "sieben", "acht", "neun", "zehn"
  };
  StringList German = new StringList(GermanArray);
  String [] FrenchArray = {
    "un", "deux", "trois", "quatre", "cinq", "six", "sept", "huit", "neuf", "dix"
  };
  StringList French = new StringList(FrenchArray);
  String [] HindiArray = {
    "ek", "do", "teen", "char", "panch", "chech", "saat", "aath", "nau", "das"
  };
  StringList Hindi = new StringList(HindiArray);
  String [] JapaneseArray = {
    "ichi", "ni", "san", "yon", "go", "roku", "nana", "hatchi", "kyu", "ju"
  };
  StringList Japanese = new StringList(JapaneseArray);
  String [] MandarinArray= {
    "yi", "er", "san", "si", "wu", "liu", "qi", "ba", "jiu", "shi"
  };
  StringList Mandarin = new StringList(MandarinArray);
  String [] ItalianArray = {
    "uno", "due", "tre", "quattro", "cinque", "sei", "sette", "otto", "nove", "dieci"
  };
  StringList Italian = new StringList(ItalianArray);
  String [] SpanishArray = {
    "uno", "dos", "tres", "cuatro", "cinco", "seis", "siete", "ocho", "nueve", "diez"
  };
  StringList Spanish = new StringList(SpanishArray);
  String [] RegularNumbersArray = {
    "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"
  };
  StringList RegularNumbers = new StringList(RegularNumbersArray);
  String [] BinaryArray = {
    "1", "10", "11", "100", "101", "110", "111", "1000", "1001", "1010"
  };
  StringList Binary = new StringList(BinaryArray);
  String [] SwahiliArray = {
    "moja", "mbili", "tatu", "nne", "tano", "sita", "saba", "nane", "tisa", "kumi"
  };

  PFont basic_font = loadFont("ACaslonPro-Regular-32.vlw");

  float x;
  float y;
  float velocity_x;
  float velocity_y;
  float text_height;
  float text_width;
  String words;
  int which_language;
  int index;
  int red;
  int green;
  int blue;

  //Constructor for load screen/win
  Text(String input, int fontsize) {
    x = width / 2;
    y = height / 4;
    textFont(basic_font);
    words = input;
    textSize(fontsize);
    textAlign(LEFT);
  }

  //Constructor for regular game:
  Text(int language, int number) {
    x = random(0,width+1 - text_width);
    y = random(0, height+1 - text_height);
    velocity_x = random(0,6);
    velocity_y = random(1,6);

    which_language = language;
    index = number;
  }

  void drawText() {
    fill(red, green, blue);
    String word="";
    switch(which_language) {
    case 1: 
      word = EnglishArray[index];
      break;
    case 2:
      word = GermanArray[index];
      break;
    case 3:
      word = FrenchArray[index];
      break;
    case 4:
      word = HindiArray[index];
      break;
    case 5:
      word = MandarinArray[index];
      break;
    case 6:
      word = ItalianArray[index];
      break;
    case 7:
      word = SpanishArray[index];
      break;
    case 8:
      word = RegularNumbersArray[index];
      break;
    case 9:
      word = BinaryArray[index];
      break;
    case 10:
      word = SwahiliArray[index];
      break;
    }
    text(word, x,y);
    textFont(basic_font);
    textSize(25);
    textAlign(LEFT);
    text_height = textDescent() + textAscent();
    text_width = textWidth(word);

  } // End of Draw

  void moveText() {
    x+= velocity_x;
    y+= velocity_y;
  }

  //MOVEMENT 
  boolean checkBoundaries() {
    boolean out_of_bounds = false;
    //Out of screen (horizontal)
    if (x>(width+(text_width))|| x < (0 - (text_width))) {
      out_of_bounds = true;
    }

    //Out of screen (vertical)
    if (y>(height+(text_height)) || y < (0 - (text_height))) {
      out_of_bounds = true;
    }
    return out_of_bounds;
  }

  void move_back_text() {
    //Will randomize the side from which the text returns
    //Will maintain the same magnitude of velocity
    /* Must figure out magnitude from original x and y velocities
     Then use magnitude to determine the new velocities 
     Use random to find new angle of reentry (radians)
     magintude SIN (theta) = y
     magnitude COS (theta) = X
     */

    float theta = random(.1*PI, .9*PI);
    float magnitude = 0;
    magnitude = sqrt((float)(Math.pow(velocity_x, 2))+(float)(Math.pow(velocity_y, 2)));
    int side = (int) random(1, 5);
    switch (side) {
      //Top
    case 1: 
      y = 0 - text_height; 
      x = width/2;
      velocity_y = (magnitude * sin(theta)); 
      velocity_x = (magnitude * cos(theta)); 
      break;

      //Bottom
    case 2:
      y = height + text_height;
      x = 450;
      velocity_y = -(magnitude * sin(theta)); 
      velocity_x = (magnitude * cos(theta));
      break;

      //Left
    case 3:
      y = 375;
      x = 0 - text_width;
      velocity_y = (magnitude * sin(theta)); 
      velocity_x = (magnitude * cos(theta));
      break;
      //Right
    case 4:
      y = 375;
      x = width + text_width;
      velocity_y = (magnitude * sin(theta)); 
      velocity_x = -(magnitude * cos(theta));
      break;
    }
  }

  //COLLISION

boolean check_Collision(Shape temporary) {
    boolean signal = false;

    int temp_shape_height = temporary.get_shape_Height();
    int temp_shape_width = temporary.get_shape_Width();
    float temp_x = temporary.get_X_Position()-temp_shape_width/2;
    float temp_y = temporary.get_Y_Position()-temp_shape_height/2;
    if (x < (temp_x + temp_shape_width) && (x+text_width) > (temp_x )) {   
      if (y < (temp_y + temp_shape_height) && (y+text_height) > (temp_y )) {
        signal = true;
      }
      else {
        signal = false;
      }
    }
    return signal;
  }

void set_text_color(int _red, int _green, int _blue){
  red = _red; 
  green = _green;
  blue = _blue;
}

}//End of text

To improve on this game, and to progress on this further, I’d maybe think about venturing into the third dimension for the shapes, making it more interactive (with the video tracking) so it can be a team game, and making obstacles!

I had a really fun time this class  and I had a lotta fun with you all, through bugs of frustration to sheer hilarity to coding successes! : )

 

Leave a Reply