School assignment. Completely lost.
in
Core Library Questions
•
1 year ago
Dear members of the processing forum,
I have been given the assignment to make a webcam game which keeps score en reacts to movement.
I've been going around the internet, looking for examples and I've ended up with this big mess of mixed codes I hardly understand anymore.
The Assignment:
Make a webcam game where if you move, the game will register your movement and fill up a blue bar.
The game will last for 10 seconds. A timer needs to be displayed on screen to show you how much time you have left.
The game will keep score, the more you move, the more points you get. This score needs to be displayed on screen aswell.
So far I have this:
---------------------
import processing.video.*;
Capture video;
PImage prevFrame;
float previous;
float current;
float threshold = 50;
void setup() {
size(320,240);
video = new Capture(this, width, height, 15);
prevFrame = createImage(video.width,video.height,RGB);
}
void draw() {
background(0);
int s = second();
text(s,40,40);
image(video,0,0);
if (video.available()) {
prevFrame.copy(video,0,0,video.width,video.height,0,0,video.width,video.height);
prevFrame.updatePixels();
video.read();
}
loadPixels();
video.loadPixels();
prevFrame.loadPixels();
float totalMotion = 0;
for (int i = 0; i < video.pixels.length; i ++ ) {
if ((video.pixels[i] ) > previous) {
current = (video.pixels[i]);
}
color current = video.pixels[i];
color previous = prevFrame.pixels[i];
float r1 = red(current);
float g1 = green(current);
float b1 = blue(current);
float r2 = red(previous);
float g2 = green(previous);
float b2 = blue(previous);
float diff = dist(r1,g1,b1,r2,g2,b2);
totalMotion += diff;
}
float avgMotion = totalMotion / video.pixels.length;
fill(200,0,100);
rect(260,20,20,150,5,5,5,5);
smooth();
noStroke();
fill(0,0,255);
float r = avgMotion;
rect(260,170,20,-r,5,5,5,5);
fill(255);
text("Score: ",30,30);
text("Timer: ",30,50);
}
----------------------------
As you can see it will fill up the blue bar the more I move, so that's working.
Now I need to find out how to make a counting down timer which will end the game (either freeze the frame or reset the game I guess).
And I need to find out how to add score which increases the more you move.
I've only had 4 lessons in processing, so this is a real challange for me. Any help would be greatly appreciated.
Kind regards,
-Ghost
p.s. If you require any more information, please by all means let me know, and I'll try to clarify.
1