{"id":68926,"date":"2021-11-08T22:43:50","date_gmt":"2021-11-09T03:43:50","guid":{"rendered":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/?p=68926"},"modified":"2021-11-09T08:52:33","modified_gmt":"2021-11-09T13:52:33","slug":"project-10-4","status":"publish","type":"post","link":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/2021\/11\/08\/project-10-4\/","title":{"rendered":"Project 10"},"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>\/\/This is a original ball game where two players play against each other<br>\/\/by trying their best to get the ball to the other side<br>\/\/Crowds are cheering whenever a player gets the ball to the other side<br>\/\/as time past, players become tired.Play suffering sound instead of &lsquo;haha&rsquo;<br>\/\/the game ends with a player not able to get the ball to the other side<br>\/\/canvas turns black and the last sound is the man suffering.<\/p>\n\n\n\n<div class=\"wp-block-file\"><a class=\"p5_sketch_link\" data-width=\"&ldquo;400&rdquo;\" data-height=\"&ldquo;400&rdquo;\" href=\"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/wp-content\/uploads\/2021\/11\/sketch-41.js\">sketch<\/a><iframe src=\"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/wp-content\/plugins\/p5-embedder\/p5_iframe.html\" class=\"p5_exampleFrame\" width=\"&ldquo;400&rdquo;\" height=\"&ldquo;400&rdquo;\"><\/iframe><pre class=\"language-javascript\"><code class=\"p5_editor language-javascript\">\/\/This is a original ball game where two players play against each other\n\/\/by trying their best to get the ball to the other side\n\/\/Crowds are cheering whenever a player gets the ball to the other side\n\/\/as time past, players become tired.Play suffering sound instead of 'haha'\n\/\/the game ends with a player not able to get the ball to the other side\n\/\/canvas turns black and the last sound is the man suffering.\n\nvar manSuffering;\nvar ballBouncing;\nvar crowdCheering;\nvar womanHaha;\nvar womanSuffering;\nvar manHaha;\nvar x = 50\nvar y = 170\nvar vx = 100\nvar vy = 1\n\/\/loading the sounds\nfunction preload() {\n    manSuffering = loadSound(\"http:\/\/localhost:8000\/man suffering.wav\");\n    ballBouncing = loadSound(\"http:\/\/localhost:8000\/ball bouncing.wav\");\n    crowdCheering = loadSound(\"http:\/\/localhost:8000\/crowd cheering.wav\");\n    womanHaha = loadSound(\"http:\/\/localhost:8000\/woman haha.wav\");\n    manHaha = loadSound(\"http:\/\/localhost:8000\/man haha.wav\");\n    womanSuffering = loadSound(\"http:\/\/localhost:8000\/woman suffering.wav\");\n}\nfunction setup() {\n    createCanvas(400, 400);\n    createDiv(\"p5.dom.js library is loaded.\");\n    useSound();\n    frameRate(10)\n}\nfunction soundSetup() { \/\/ setup for audio generation\n    manSuffering.setVolume(0.5);\n    ballBouncing.setVolume(0.5)\n    crowdCheering.setVolume(0.5)\n    womanHaha.setVolume(0.5)\n    womanSuffering.setVolume(0.5)\n    manHaha.setVolume(0.5)\n}\nfunction draw() {\n    background(192,100,150)\n    \/\/draws the court\n    court()\n    \/\/draws a moving male player\n    playerMale(20,random(100,220))\n    \/\/draws a moving female player\n    playerFemale(380,random(100,220))\n    \/\/draws a moving ball\n    ball()\n    \/\/draws 7 spectators\n    for (var i = 0; i &lt; 4; i++){\n        push()\n        fill(random(170,255))\n        spectator(50+100*i,300)\n        pop()    \n    }\n    for (var i = 0; i &lt; 3; i++){\n        push()\n        fill(random(170,255))\n        spectator(100+100*i,320)   \n        pop() \n    }\n    \/\/when the ball hits the edge and time is a 15 seconds, one player screams and game ends\n    if (frameCount &gt; 150 & x+25 >= width){\n        manSuffering.play()\n        background(0)\n        noLoop();\n    }\n}\nfunction playerMale(x,y){\n    push()\n    strokeWeight(3)\n    ellipse(x,y,18,25)\n    \/\/body\n    line(x,y+12,x,y+50)\n    line(x,y+30,x-10,y+15)\n    line(x,y+30,x+10,y+15)\n    line(x,y+50,x+10,y+65)\n    line(x,y+50,x-10,y+65)\n    \/\/eyes\n    ellipse(x-3,y-2,1,1)\n    ellipse(x+3,y-2,1,1)\n    arc(x, y, 12, 15, 1, PI-1)\n    \/\/hair\n    line(x,y-12,x,y-22)\n    line(x-3,y-11,x-10,y-18)\n    line(x+3,y-13,x+10,y-18)\n    pop()  \n}\nfunction playerFemale(x,y){\n    push()\n    strokeWeight(3)\n    ellipse(x,y,18,25)\n    \/\/body\n    line(x,y+12,x,y+50)\n    line(x,y+30,x-10,y+15)\n    line(x,y+30,x-20,y+30)\n    line(x,y+50,x+10,y+65)\n    line(x,y+50,x-10,y+65)\n    \/\/eyes\n    ellipse(x-3,y-2,1,1)\n    ellipse(x+3,y-2,1,1)\n    arc(x, y, 12, 15, 1, PI-1)\n    \/\/hair\n    line(x,y-12,x-10,y)\n    line(x-2,y-12,x-12,y+2)\n    line(x+2,y-12,x+12,y+2)\n    pop()\n}\nfunction court(){\n    push()\n    fill(0,130,0)\n    beginShape();\n    vertex(70, 50);\n    vertex(330, 50);\n    vertex(380, 320);\n    vertex(20, 320);\n    endShape(CLOSE);\n    pop()\n}\nfunction spectator(x,y){\n    push()\n    noStroke()\n    ellipse(x,y+120,100,200)\n    ellipse(x,y,50,70)\n    pop()\n\n}\nfunction ball(){\n    push()\n    ellipse(x,y,10,10) \/\/draws the ball\n    x = x + vx \/\/x-coordinate of ball moves according to x-velocity\n    y = y + vy \/\/y-coordinate of ball moves according to y-velocity\n    if (x+25 &gt;= width){ \/\/when ball touches right side, bounces back\n        vx = random(-80,-30)\n        vy = random(-5,5)\n        \/\/crowd cheers when a player gets the ball to the other side\n        \/\/as time past, players become tired.Play suffering sound instead of 'haha'\n        ballBouncing.play()\n        if (frameCount &lt; 125){\n            crowdCheering.play()\n        }\n        if (frameCount &lt; 75){\n            womanHaha.play() \n        }else{\n            womanSuffering.play()\n        }\n    }\n    if (x-25 &lt;= 0){ \/\/when ball touches left side, bounces back\n        vx = random(30,80)\n        vy = random(-5,5)\n        ballBouncing.play()\n        if (frameCount &lt; 125){\n            crowdCheering.play()\n        }\n        if (frameCount &lt; 75){\n            manHaha.play() \n        }else{\n            manSuffering.play()\n        }\n    }\n    \/\/ball doesn't go off the court\n    y = constrain(y,50,320)\n    pop()\n}\n\n<\/code><\/pre><\/div>\n\n\n\n<p><\/p><\/body><\/html>\n","protected":false},"excerpt":{"rendered":"<p>\/\/This is a original ball game where two players play against each other\/\/by trying their best to get the ball to the other side\/\/Crowds are cheering whenever a player gets the ball to the other side\/\/as time past, players become tired.Play suffering sound instead of &lsquo;haha&rsquo;\/\/the game ends with a player not able to get &hellip; <a href=\"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/2021\/11\/08\/project-10-4\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Project 10&#8221;<\/span><\/a><\/p>\n","protected":false},"author":667,"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\/f2021\/wp-json\/wp\/v2\/posts\/68926"}],"collection":[{"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/wp-json\/wp\/v2\/users\/667"}],"replies":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/wp-json\/wp\/v2\/comments?post=68926"}],"version-history":[{"count":4,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/wp-json\/wp\/v2\/posts\/68926\/revisions"}],"predecessor-version":[{"id":68940,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/wp-json\/wp\/v2\/posts\/68926\/revisions\/68940"}],"wp:attachment":[{"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/wp-json\/wp\/v2\/media?parent=68926"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/wp-json\/wp\/v2\/categories?post=68926"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/wp-json\/wp\/v2\/tags?post=68926"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}