sketch
// 15-104
// SEAN CHEN
// A person running in the rain rushes toward a gathering indoors
// and suddenly the person busts through the window causing panic.
var rain, running, panting, group, intrain, scream, glass;
var note = 0;
var walkImage = [];
var filenames = [];
// various sounds
function preload() {
rain = loadSound ('http://127.0.0.1:5500/handin10/seanc1-10-project/sounds/-combo.wav');
group = loadSound ('http://127.0.0.1:5500/handin10/seanc1-10-project/sounds/-combo-group.wav');
scream = loadSound ('http://127.0.0.1:5500/handin10/seanc1-10-project/sounds/-group-scream.wav');
glass = loadSound ('http://127.0.0.1:5500/handin10/seanc1-10-project/sounds/-glass-smash.wav');
}
function setup() {
createCanvas(600, 300);
frameRate(15);
}
function soundSetup() {}
// apartment building
function house() {
push();
fill(150);
rect(525, 50, 100, 250);
fill(244,202,41);
rect(550, 75, 50, 50);
rect(550, 150, 50, 50);
rect(550, 225, 50, 50);
pop();
}
// rain
function rainfall() {
stroke(255);
strokeWeight(0.5);
for (var x = 0; x < width; x += 5) {
for (var y = 0; y < height; y += 10) {
line(x, y, x, y+5);
}
}
}
// shadowy figure
function figure(x, y) {
push();
fill(0);
rect(x, y+275, 10, 50);
ellipse(x+5, 265, 10, 10);
pop();
}
function draw() {
background(50);
// drawing shadowy figure running through rain, into the 1F window
house();
if (frameCount < 170) {
var xpos = map(frameCount, 0, 170, 0, 550);
figure(xpos, 0);
}
push();
if (frameCount % 3 == 0) {
translate(random(0, 3), 5);
}
rainfall();
pop();
var seq = [rain, group, rain, group, rain, group] // event sequence
var dur = [5, 48, 45, 30, 15, 15]; // event duration
if (frameCount % dur[note] == 0) { // play time based on frames
if (note > 0) {
seq[note-1].stop();
seq[note].play();
}
seq[note].play();
note++;
}
if (note == seq.length) { // final glass smash
glass.play(1);
scream.play(1.3);
seq[note-1].stop(1.5);
var totalFrames = frameCount;
note++;
}
if (frameCount == totalFrames+30) {
noLoop();
}
print(frameCount);
}