Addition to Game

This week I struggled with coming up with an idea on which of my processing designs I could combine with arduino. I ended up going with my game, popping balloons. But which aspect would I change? I played around with a button to pop them, a potentiometer to change the speed in which they moved, but then settled on using a potentiometer to change how many circles would appear at the start of the game.

My biggest challenge with this was rearranging certain aspects of my code in order to fit how I had defined the sensor. Then, once I had done that, I struggled with the sensor reading being on a loop. Jack helped me add in a boolean to have it only read once at the start of the game.

Here’s some video:

https://vimeo.com/333083714

Here’s my code from arduino:

int sensor;

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

void loop() {
  sensor = analogRead(A0);
  Serial.write(sensor);

}

and from processing:

import processing.serial.*;

Serial myPort;

int sensor;
int totBall = 0;
float xPos;
float yPos;
float spd;
boolean ugh = false;

//int counter = 30;
//boolean timer = true;
//int x = 1;
//boolean time = false;




Ball[] ball; 


boolean timeIsUp=false;
float timeTillOver;

void setup() {
  size(640, 360);

  printArray(Serial.list());
  String portname=Serial.list()[0];
  println(portname);
  myPort = new Serial(this, portname, 9600);

  noStroke();
  timeTillOver=millis()+random(10000, 30000);
}


void draw() {


  background(0);
for (int i = 0; i < totBall; i++) {
    ball[i].run();
  }


  fill(0);
  rect(0, 0, width, 50); 
}

void serialEvent(Serial myPort) {


  sensor=myPort.read();




  if (ugh == false) {
    totBall = int(map(sensor, 0, 1023, 1, 40));
    ball = new Ball[totBall];
    ugh = true;

    for (int i = 0; i < totBall; i++) {
      ball[i] = new Ball(random(0, width), random(0, height), random(1, 5), random(1, 5));
    }
  }
}

(note that I also used a ball class, but that’s the same as my last upload)

Leave a Reply