{"id":75578,"date":"2022-11-12T17:01:51","date_gmt":"2022-11-12T22:01:51","guid":{"rendered":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/?p=75578"},"modified":"2022-11-12T17:01:51","modified_gmt":"2022-11-12T22:01:51","slug":"project-10-sanic","status":"publish","type":"post","link":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/2022\/11\/12\/project-10-sanic\/","title":{"rendered":"Project 10 &#8211; SANIC"},"content":{"rendered":"<!DOCTYPE html PUBLIC \"-\/\/W3C\/\/DTD HTML 4.0 Transitional\/\/EN\" \"http:\/\/www.w3.org\/TR\/REC-html40\/loose.dtd\">\n<html><body><p>Sanic make &ldquo;dash&rdquo; noises every now and then<\/p>\n\n\n\n<p>Eggman has &ldquo;intro&rdquo; and &ldquo;escape&rdquo; lines<\/p>\n\n\n\n<p>Rings make sounds when grabbed by sanic<\/p>\n\n\n\n<p>Knuckle makes sounds in the end<\/p>\n\n\n\n<p><a class=\"p5_sketch_link\" data-width=\"600\" data-height=\"300\" href=\"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-content\/uploads\/2022\/11\/sketch-39.js\"><\/a><iframe src=\"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-content\/plugins\/p5-embedder\/p5_iframe.html\" class=\"p5_exampleFrame\" width=\"600\" height=\"300\"><\/iframe><pre class=\"language-javascript\"><code class=\"p5_editor language-javascript\">\/*\n * Andrew J Wang\n * ajw2@andrew.cmu.edu\n * Section A\n *\n * This Program is Sanic\n *\/\n\n\/\/rotation variables for limb movements for sanic and the coins\nvar rot = 0;\n\/\/controls whether the limbs are moving forwards or backwards\nvar forward = true;\n\/\/sanic locations\nvar x=0;\n\/\/eggman image\nvar egg;\n\/\/eggman Ylocation\nvar eggY = -150;\n\/\/uganda knuckle's Ylocation\nvar ugandaY = 450;\n\n\/\/Green Hill Zone notes (BACKGROUND MUSIC)\nvar 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];\nvar 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];\n\n\/\/counter for durations\nvar counter = 0;\n\/\/which note on the pitch list to play\nvar note = 0;\n\n\/\/rings' existance\nvar coin = [true,true,true,true,true];\n\n\/\/sound variables\nvar eggmanIntro;\nvar ringSound;\nvar dawae;\nvar spinDash;\nvar eggmanDefeat\n\n\/\/https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-content\/uploads\/2022\/11\/name-eggman.wav\n\/\/https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-content\/uploads\/2022\/11\/Sonic_Ring_Sound_Effect.wav\n\/\/https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-content\/uploads\/2022\/11\/do-you-know-the-way.wav\n\/\/https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-content\/uploads\/2022\/11\/Spin.wav\n\/\/https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-content\/uploads\/2022\/11\/no.wav\n\n\n\/\/loading the images and sounds\nfunction preload() {\n    egg = loadImage(\"https:\/\/i.imgur.com\/Wy46mQF.png\");\n    uganda = loadImage (\"https:\/\/i.imgur.com\/HRB5kdy.png\");\n    eggmanIntro = loadSound(\"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-content\/uploads\/2022\/11\/name-eggman.wav\");\n    ringSound = loadSound(\"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-content\/uploads\/2022\/11\/Sonic_Ring_Sound_Effect.wav\");\n    dawae = loadSound(\"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-content\/uploads\/2022\/11\/do-you-know-the-way.wav\");\n    spinDash = loadSound(\"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-content\/uploads\/2022\/11\/Spin.wav\");\n    eggmanDefeat = loadSound ('https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-content\/uploads\/2022\/11\/no.wav');\n}\n\n\/\/setups Don't think I need to elaborate\nfunction setup() {\n    createCanvas(600,300);\n    useSound();\n    frameRate(20);\n}\n\nfunction soundSetup() { \n    osc = new p5.Oscillator();\n    osc.amp(0.25);\n    eggmanIntro.setVolume(1.0);\n    ringSound.setVolume(0.5);\n    dawae.setVolume(0.5);\n    spinDash.setVolume(0.5);\n    eggmanDefeat.setVolume(1.0);\n    osc.setType('square');\n    osc.start();\n}\n\n\n\nfunction draw() {\n\n    background(255);\n    \/\/rotation till 1 then change directions\n    if (rot&gt;=1 || rot &lt;=-1)\n    {\n        forward = !forward;\n    }\n    if (forward)\n    {\n        rot+=0.1;\n    }\n    else\n    {\n        rot-=0.1;\n    }\n\n    \/\/move sanic by 1 per frame\n    x+=1;\n\n    \/\/check whether sanic ran pass through those rings or not\n    for (var k=0; k&lt;5; k++)\n    {\n        if (x&gt;(100+k*100))\n        {\n            coin[k] = false;\n        }\n    }\n\n    \/\/if sanic is on the ring play ring sound\n    if (x%100==0 & x<600 && x>0)\n    {\n        ringSound.play();\n    }\n\n    \/\/sanic spins every now and then if he's on the screen\n    if (x%100==50 & x<=600 && x>=0)\n    {\n        spinDash.play();\n    }\n\n    \/\/rings\n    ring(100,170,rot,coin[0]);\n    ring(200,170,rot,coin[1]);\n    ring(300,170,rot,coin[2]);\n    ring(400,170,rot,coin[3]);\n    ring(500,170,rot,coin[4]);\n\n    \/\/eggman shows up\n    if (eggY&lt;50)\n    {eggY+=2;}\n\n    \/\/eggman \"escapes\"\n    if (x&gt;300 & eggY<1000)\n    {\n        eggY = 50 + (x-300) * (x-300);\n    }\n\n    \/\/eggman intro right before he stops\n    if (eggY==48)\n    {\n        eggmanIntro.play();\n    }\n\n    \/\/eggman says no moment after he's defeated\n    if (eggY==54)\n    {\n        eggmanDefeat.play();\n    }\n    \/\/eggman image\n    eggman(300,eggY);\n\n    \/\/sanic\n    sanicLimbs(x,100,rot);\n    sanic(x,100);\n\n    \/\/uganda knuckle shows up\n    if (x&gt;700 & ugandaY > 200)\n    {\n        ugandaY -=2;\n    }\n\n    \/\/\"DO YOU KNOW DA WAE\" before stoping\n    if (ugandaY==202)\n    {\n        dawae.play();\n    }\n\n    \/\/kunckle\n    knuckle(300,ugandaY);\n\n\n    \/\/if pitch is 0 stop playing\n    if (pitch[note] == 0)\n    {\n        osc.stop();\n    }\n\n    \/\/if pitch before is 0 but this note isn't restart\n    else if (pitch[note-1] == 0 & pitch[note] != 0)\n    {\n        osc.start();\n    }\n\n    \/\/play notes\n    osc.freq(midiToFreq(pitch[note]));\n\n    \/\/duration counter ++\n    if (counter &lt; duration[note] & note < pitch.length)\n    {\n        counter++\n    }\n    \/\/if reach max duration change note and reset\n    else if (counter >= duration[note] && note < pitch.length)\n    {   \n        counter = 0;\n        note++;\n    }\n    \/\/if reach the end restart from the beginning to loop\n    else\n    {\n        note=0;\n    }\n\n}\n\n\/\/drawing sanic\nfunction sanic(xL,yL)\n{   \n    push();\n    translate(xL,yL);\n    noStroke();\n    stroke(0);\n    fill(\"blue\");\n    curve(-10,100,-7,-10,-50,-30,-50,50);\n    curve(-10,100,-7,10,-50,10,-50,50);\n    curve(-10,100,-7,30,-65,20,-50,100);\n    curve(-10,100,-7,40,-50,30,-50,50);\n    curve(-10,100,-7,90,-75,70,-50,200);\n    strokeWeight(1);\n    ellipse(0,25,10,20);\n    ellipse(0,0,50,45);\n    ellipse(0,70,70,75);\n    fill(255,255,170);\n    ellipse(0,70,40,45);\n    ellipse(3,15,25,10);\n    fill(255);\n    ellipse(10,0,15,13);\n    ellipse(-8,0,15,10);\n    fill(0);\n    ellipse(12,0,3,3);\n    ellipse(-6,0,3,3);\n    ellipse(0,8,4,4);\n    stroke(5);\n    curve(-7,5,-7,15,16,15,16,5);\n    pop();\n}\n\n\/\/drawing sanic's llimbs \nfunction sanicLimbs (xL,yL,r)\n{\n    push();\n    translate(xL,yL);\n\n        push();\n        translate(15,50);\n        rotate(r);\n        fill(\"blue\");\n\n        beginShape();\n        vertex(0, 0);\n        bezierVertex(0,0,30,-50,60,0);\n        bezierVertex(60,0,30,-25,0,0);\n        endShape();\n\n        fill(255);\n        ellipse(60,0,20,20);\n        pop();\n\n\n        push();\n        translate(-15,60);\n        rotate(r);\n        fill(\"blue\");\n\n        beginShape();\n        vertex(0, 0);\n        bezierVertex(0,0,-30,-55,-60,0);\n        bezierVertex(-60,0,-30,-15,0,0);\n        endShape();\n\n        fill(255);\n        ellipse(-60,0,30,25);\n        pop();\n\n        push();\n        translate(0,100);\n        rotate(r);\n        fill(\"blue\");\n\n        beginShape();\n        vertex(0, 0);\n        bezierVertex(0,0,-60,0,-60,60);\n        bezierVertex(-60,60,-60,40,0,0);\n        endShape();\n\n        fill(\"red\");\n        ellipse(-70,60,40,20);\n        pop();\n\n        push();\n        translate(20,100);\n        rotate(r);\n        fill(\"blue\");\n\n        beginShape();\n        vertex(0, 0);\n        bezierVertex(0,0,0,40,60,60);\n        bezierVertex(60,60,0,80,0,0);\n        endShape();\n\n        fill(\"red\");\n        ellipse(70,60,40,20);\n        pop();\n\n\n    pop();\n}\n\n\/\/ring spins through scalling\nfunction ring (xR,yR,sc,sh)\n{\n    if (sh==true)\n    {\n    push();\n    translate(xR,yR);\n    scale(sc,1.0);\n    fill(\"gold\");\n    ellipse(0,0,50,50);\n    fill(255);\n    ellipse(0,0,30,30);\n    pop();\n    }\n\n}\n\nfunction eggman (xE,yE)\n{\n    image(egg,xE,yE,150,150);\n}\n\nfunction knuckle (xU, yU)\n{\n    push();\n    imageMode(CENTER);\n    image(uganda,xU, yU, 250,250);\n    pop();\n}<\/code><\/pre><\/p><\/body><\/html>\n","protected":false},"excerpt":{"rendered":"<p>Sanic make &ldquo;dash&rdquo; noises every now and then Eggman has &ldquo;intro&rdquo; and &ldquo;escape&rdquo; lines Rings make sounds when grabbed by sanic Knuckle makes sounds in the end \/* * Andrew J Wang * ajw2@andrew.cmu.edu * Section A * * This Program is Sanic *\/ \/\/rotation variables for limb movements for sanic and the coins var &hellip; <a href=\"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/2022\/11\/12\/project-10-sanic\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Project 10 &#8211; SANIC&#8221;<\/span><\/a><\/p>\n","protected":false},"author":768,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[113,55],"tags":[],"_links":{"self":[{"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/posts\/75578"}],"collection":[{"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/users\/768"}],"replies":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/comments?post=75578"}],"version-history":[{"count":3,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/posts\/75578\/revisions"}],"predecessor-version":[{"id":75848,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/posts\/75578\/revisions\/75848"}],"wp:attachment":[{"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/media?parent=75578"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/categories?post=75578"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/tags?post=75578"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}