Sanic make “dash” noises every now and then
Eggman has “intro” and “escape” lines
Rings make sounds when grabbed by sanic
Knuckle makes sounds in the end
var rot = 0;var forward = true;var x=0;var egg;var eggY = -150;var ugandaY = 450;
var pitch = [72,69,72,71,72,71,67, 0, 69,76,74,72,71,72,71,67, 0, 72,69,72,71,72,71,67, 0, 69,69,65,69,67,69,67,60, 0];
var duration = [3,9,3,9,3,9,12, 15, 3,3,9,3,9,3,9,12, 15, 3,9,3,9,3,9,12, 15, 3,3,9,3,9,3,9,12, 15];
var counter = 0;var note = 0;
var coin = [true,true,true,true,true];
var eggmanIntro;
var ringSound;
var dawae;
var spinDash;
var eggmanDefeat
function preload() {
egg = loadImage("https://i.imgur.com/Wy46mQF.png");
uganda = loadImage ("https://i.imgur.com/HRB5kdy.png");
eggmanIntro = loadSound("https://courses.ideate.cmu.edu/15-104/f2022/wp-content/uploads/2022/11/name-eggman.wav");
ringSound = loadSound("https://courses.ideate.cmu.edu/15-104/f2022/wp-content/uploads/2022/11/Sonic_Ring_Sound_Effect.wav");
dawae = loadSound("https://courses.ideate.cmu.edu/15-104/f2022/wp-content/uploads/2022/11/do-you-know-the-way.wav");
spinDash = loadSound("https://courses.ideate.cmu.edu/15-104/f2022/wp-content/uploads/2022/11/Spin.wav");
eggmanDefeat = loadSound ('https://courses.ideate.cmu.edu/15-104/f2022/wp-content/uploads/2022/11/no.wav');
}
function setup() {
createCanvas(600,300);
useSound();
frameRate(20);
}
function soundSetup() {
osc = new p5.Oscillator();
osc.amp(0.25);
eggmanIntro.setVolume(1.0);
ringSound.setVolume(0.5);
dawae.setVolume(0.5);
spinDash.setVolume(0.5);
eggmanDefeat.setVolume(1.0);
osc.setType('square');
osc.start();
}
function draw() {
background(255);
if (rot>=1 || rot <=-1)
{
forward = !forward;
}
if (forward)
{
rot+=0.1;
}
else
{
rot-=0.1;
}
x+=1;
for (var k=0; k<5; k++)
{
if (x>(100+k*100))
{
coin[k] = false;
}
}
if (x%100==0 & x<600 && x>0)
{
ringSound.play();
}
if (x%100==50 & x<=600 && x>=0)
{
spinDash.play();
}
ring(100,170,rot,coin[0]);
ring(200,170,rot,coin[1]);
ring(300,170,rot,coin[2]);
ring(400,170,rot,coin[3]);
ring(500,170,rot,coin[4]);
if (eggY<50)
{eggY+=2;}
if (x>300 & eggY<1000)
{
eggY = 50 + (x-300) * (x-300);
}
if (eggY==48)
{
eggmanIntro.play();
}
if (eggY==54)
{
eggmanDefeat.play();
}
eggman(300,eggY);
sanicLimbs(x,100,rot);
sanic(x,100);
if (x>700 & ugandaY > 200)
{
ugandaY -=2;
}
if (ugandaY==202)
{
dawae.play();
}
knuckle(300,ugandaY);
if (pitch[note] == 0)
{
osc.stop();
}
else if (pitch[note-1] == 0 & pitch[note] != 0)
{
osc.start();
}
osc.freq(midiToFreq(pitch[note]));
if (counter < duration[note] & note < pitch.length)
{
counter++
}
else if (counter >= duration[note] && note < pitch.length)
{
counter = 0;
note++;
}
else
{
note=0;
}
}
function sanic(xL,yL)
{
push();
translate(xL,yL);
noStroke();
stroke(0);
fill("blue");
curve(-10,100,-7,-10,-50,-30,-50,50);
curve(-10,100,-7,10,-50,10,-50,50);
curve(-10,100,-7,30,-65,20,-50,100);
curve(-10,100,-7,40,-50,30,-50,50);
curve(-10,100,-7,90,-75,70,-50,200);
strokeWeight(1);
ellipse(0,25,10,20);
ellipse(0,0,50,45);
ellipse(0,70,70,75);
fill(255,255,170);
ellipse(0,70,40,45);
ellipse(3,15,25,10);
fill(255);
ellipse(10,0,15,13);
ellipse(-8,0,15,10);
fill(0);
ellipse(12,0,3,3);
ellipse(-6,0,3,3);
ellipse(0,8,4,4);
stroke(5);
curve(-7,5,-7,15,16,15,16,5);
pop();
}
function sanicLimbs (xL,yL,r)
{
push();
translate(xL,yL);
push();
translate(15,50);
rotate(r);
fill("blue");
beginShape();
vertex(0, 0);
bezierVertex(0,0,30,-50,60,0);
bezierVertex(60,0,30,-25,0,0);
endShape();
fill(255);
ellipse(60,0,20,20);
pop();
push();
translate(-15,60);
rotate(r);
fill("blue");
beginShape();
vertex(0, 0);
bezierVertex(0,0,-30,-55,-60,0);
bezierVertex(-60,0,-30,-15,0,0);
endShape();
fill(255);
ellipse(-60,0,30,25);
pop();
push();
translate(0,100);
rotate(r);
fill("blue");
beginShape();
vertex(0, 0);
bezierVertex(0,0,-60,0,-60,60);
bezierVertex(-60,60,-60,40,0,0);
endShape();
fill("red");
ellipse(-70,60,40,20);
pop();
push();
translate(20,100);
rotate(r);
fill("blue");
beginShape();
vertex(0, 0);
bezierVertex(0,0,0,40,60,60);
bezierVertex(60,60,0,80,0,0);
endShape();
fill("red");
ellipse(70,60,40,20);
pop();
pop();
}
function ring (xR,yR,sc,sh)
{
if (sh==true)
{
push();
translate(xR,yR);
scale(sc,1.0);
fill("gold");
ellipse(0,0,50,50);
fill(255);
ellipse(0,0,30,30);
pop();
}
}
function eggman (xE,yE)
{
image(egg,xE,yE,150,150);
}
function knuckle (xU, yU)
{
push();
imageMode(CENTER);
image(uganda,xU, yU, 250,250);
pop();
}