{"id":72364,"date":"2022-09-18T22:30:59","date_gmt":"2022-09-19T02:30:59","guid":{"rendered":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/?p=72364"},"modified":"2022-09-19T09:34:43","modified_gmt":"2022-09-19T13:34:43","slug":"assignment-3-game","status":"publish","type":"post","link":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/2022\/09\/18\/assignment-3-game\/","title":{"rendered":"Assignment 3 &#8211; Game"},"content":{"rendered":"<!DOCTYPE html PUBLIC \"-\/\/W3C\/\/DTD HTML 4.0 Transitional\/\/EN\" \"http:\/\/www.w3.org\/TR\/REC-html40\/loose.dtd\">\n<html><body><div class=\"wp-block-file\"><a class=\"p5_sketch_link\" data-width=\"400\" data-height=\"400\" id=\"wp-block-file--media-5c27dd6e-8e90-4e73-acd3-908fac201fc9\" href=\"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-content\/uploads\/2022\/09\/bouncy_ball_game-1.js\">bouncy_ball_game<\/a><iframe src=\"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-content\/plugins\/p5-embedder\/p5_iframe.html\" class=\"p5_exampleFrame\" width=\"400\" height=\"400\"><\/iframe><pre class=\"language-javascript\"><code class=\"p5_editor language-javascript\">\/\/David Vargas dvargas\n\nvar vVelocity =1; \/\/direction and speed of ball\nvar hVelocity =5;\nvar x= 100; \/\/ x position of ball\nvar y= 100; \/\/ y position of ball\nvar diam = 35; \/\/diameter of circle\nvar points=0; \/\/ number of points\nvar title = true; \/\/title screen text variable\n\n\nfunction setup() {\n    createCanvas(200, 200);\n    background(220);\n    \n}\n\nfunction draw() {\n\n    background(220);\n    fill(150,160,240);\n    ellipse(x,y,diam);\n    textSize(15);\n    text(points,width\/2, 20);\n\n    x += hVelocity; \n    y += vVelocity;\n\n    \/\/ this makes ball bounce when it hits vertical walls\n    if(x&gt; width-diam \/ 2){\n        hVelocity= random(-5,-1);\n    } else if (x&lt; diam\/ 2 ) {\n        hVelocity = random(1,5);\n    }\n\n    \/\/ this makes ball bounce when it hits horizontal walls\n    if (y &gt; width -diam\/2){\n        vVelocity= random(-5,-1);\n    } else if (y &lt; diam\/2){\n        vVelocity = random(1,5);\n    }\n\n    if(points&gt;4){ \/\/this creates the \"you win\" screen\n        background(100,250,100,50);\n        textSize(20);\n        fill(255);\n        text('You Win',width\/3 ,height\/2);\n        noLoop();\n\n    } else if(points&lt;-4){ \/\/this creates the \"you lose\" screen\n        background(240,100,100,50);\n        textSize(20);\n        fill(255);\n        text('You Lose',width\/3, height\/2);\n        noLoop();\n    }\n\n    if(title){ \/\/ displays tile screen before mouse is pressed\n        textSize(25);\n        text('Click the Ball',width\/6,height\/2)\n    }\n    print('points='+points);\n\n}\n\n    function mousePressed() {\n        if(dist(mouseX,mouseY,x,y)&lt; diam\/2){ \/\/this changes circle direction after being pressed\n        points+= 1\n        vVelocity=random(-5,5)\n        hVelocity=random(-5,5)\n    } else (points+=-1) \n\n    title= false \/\/ title screen dissappears once mouse is pressed\n    }\n\n\n\n\n<\/code><\/pre><\/div><\/body><\/html>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":767,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[99,55],"tags":[],"_links":{"self":[{"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/posts\/72364"}],"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\/767"}],"replies":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/comments?post=72364"}],"version-history":[{"count":3,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/posts\/72364\/revisions"}],"predecessor-version":[{"id":72462,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/posts\/72364\/revisions\/72462"}],"wp:attachment":[{"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/media?parent=72364"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/categories?post=72364"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/tags?post=72364"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}