{"id":76220,"date":"2022-12-10T12:58:01","date_gmt":"2022-12-10T17:58:01","guid":{"rendered":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/?p=76220"},"modified":"2022-12-10T12:59:10","modified_gmt":"2022-12-10T17:59:10","slug":"76220","status":"publish","type":"post","link":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/2022\/12\/10\/76220\/","title":{"rendered":"My final project"},"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=\"800\" data-height=\"600\" href=\"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-content\/uploads\/2022\/12\/sketch-3.js\">sketch<\/a><iframe src=\"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-content\/plugins\/p5-embedder\/p5_iframe.html\" class=\"p5_exampleFrame\" width=\"800\" height=\"600\"><\/iframe><pre class=\"language-javascript\"><code class=\"p5_editor language-javascript\">\/\/hfroling\n\/\/section c\n\n\nvar level = 1;\nvar spot;\nvar a;\nvar b;\nvar lilies = [];\nvar fishies = [];\nvar turtles = [];\nvar heights = [80,140,200,260,320,380,440,500];\nvar bunny;\n\nfunction preload() {\n  bunnyStopped = loadImage(\"https:\/\/i.imgur.com\/ASG9W87.png\"); \/\/loads image\n  bunnySitting = loadImage(\"https:\/\/i.imgur.com\/fouQhgx.png\"); \/\/loads image\n  bunnyDead = loadImage(\"https:\/\/i.imgur.com\/9d2vjo4.png\");\n  lilyPadImg = loadImage(\"https:\/\/i.imgur.com\/Z69HCHs.png\");\n  killerFishImg = loadImage(\"https:\/\/i.imgur.com\/mRGD4oC.png\");\n  turtleImg = loadImage(\"https:\/\/i.imgur.com\/4JEWEFk.png\");\n}\n\nfunction setup() {\n    createCanvas(800,600);\n    background(120, 150, 81);\n    imageMode(CENTER)\n    a = width\/2-35;\n    b = 295;\n    noStroke();\n    print(bunnyStopped.width);       \/\/ displays in console\n    print(bunnyStopped.height);\n\n\n        for(j=0;j&lt;8;j++){               \/\/lily pad object setup\n            lilies[j] = new Object();\n            lilies[j].x = (floor(random(60,width-60)\/60)*60)-20;\n            lilies[j].y = heights[j];\n        }\n\n        for(k=0;k&lt;8;k++){               \/\/fish set up\n            fishies[k] = new Object();\n            fishies[k].x = random(width-50);\n            fishies[k].y = heights[k];\n            fishies[k].dx = random(1,6);\n        }\n\n        for(l=0;l&lt;8;l++){           \/\/turtles set up\n            turtles[l] = new Object();\n            turtles[l].x = random(width-50);\n            turtles[l].y = heights[l];\n            turtles[l].dx = random(-3,3);\n        }\n\n    bunny = makeBunny(width\/2,320,0);\n}\n\nfunction draw() { \/\/draw the image\n    background(120, 150, 81);\n    textSize(18);\n    textAlign(CENTER, CENTER);\n    fill('white');\n        if(frameCount &lt; 150){\n            text('PRESS UP ARROW KEYS TO HOP ACROSS THE RIVER', width\/2, 30);\n        }\n\n    river();\n    bunny.draw();\n    bunny.collideLily();\n    bunny.onTurtle = false;\n\n\n    for(i=0;i&lt;8;i++){\n        bunny.collideTurtle(turtles[i])\n    }\n\n    for(i=0;i&lt;8;i++){\n        bunny.collideWater(fishies[i],turtles[i],lilies[i])\n    }\n\n    bunny.dieBunny();\n}\n\n\nfunction river(){ \/\/make river\n    var depth = 60;\n    spot = 50;\n        if(level == 1){\n            text('LEVEL 1',100, height-30);\n                for(var i=1; i&lt;3; i++){\n                    fill('lightblue');\n                    rect(0,spot,width,depth);\n                    fill(208,228,247);\n                    rect(0,spot+depth,width,depth);\n                    spot += depth*2;\n                }\n\n\n                for(k=0;k&lt;4;k++){           \/\/fishies on river\n                    drawFish(fishies[k]);\n                    fishies[k].x += fishies[k].dx\n                        if (fishies[k].x &gt; width) {\n                            fishies[k].x = -40;\n                            fishies[k].dx = random(1,6);\n                        }\n                }\n\n                for(l=0; l&lt;4; l++){             \/\/turtles on river\n                    drawTurtle(turtles[l]);\n                    turtles[l].x  += turtles[l].dx\n                        if (turtles[l].x &gt;= width -25 & turtles[l].dx > 0) {\n                            turtles[l].dx = -turtles[l].dx;\n                        }\n                        if (turtles[l].x &lt;= 25 & turtles[l].dx < 0) {\n                            turtles[l].dx = -turtles[l].dx;\n                        }\n                }\n        }\n\n        for(j=0;j&lt;4;j++){           \/\/lilies on river\n            drawLily(lilies[j]);\n        }\n    \n    if(level == 2){\n        text('LEVEL 2',100, height-30);\n            for(var i=1; i&lt;4; i++){\n                fill('lightblue');\n                rect(0,spot,width,depth);\n                fill(208,228,247);\n                rect(0,spot+depth,width,depth);\n                spot += depth*2;\n            }\n\n            for(k=0;k&lt;6;k++){           \/\/fishies on river\n                drawFish(fishies[k]);\n                fishies[k].x += fishies[k].dx\n                    if (fishies[k].x &gt; width) {\n                        fishies[k].x = -40;\n                        fishies[k].dx = random(1,6);\n                    }\n            }\n\n            for(l=0; l&lt;6; l++){             \/\/turtles on river\n                drawTurtle(turtles[l]);\n                turtles[l].x  += turtles[l].dx\n                    if (turtles[l].x &gt;= width -25 & turtles[l].dx > 0) {\n                        turtles[l].dx = -turtles[l].dx;\n                    }\n\n                    if (turtles[l].x &lt;= 25 & turtles[l].dx < 0) {\n                        turtles[l].dx = -turtles[l].dx;\n                    }\n            }\n\n            for(j=0;j&lt;6;j++){          \/\/lilies on river\n                drawLily(lilies[j])\n            }\n    }\n\n    if(level == 3){\n        text('LEVEL 3',100, height-30);\n        for(var i=1; i&lt;5; i++){\n            fill('lightblue');\n            rect(0,spot,width,depth);\n            fill(208,228,247);\n            rect(0,spot+depth,width,depth);\n            spot += depth*2;\n        }\n        for(k=0;k&lt;8;k++){           \/\/fishies on river\n            drawFish(fishies[k]);\n            fishies[k].x += fishies[k].dx\n            if (fishies[k].x &gt; width) {\n                fishies[k].x = -40;\n                fishies[k].dx = random(1,6);\n            }\n        }\n\n        for(l=0; l&lt;8; l++){             \/\/turtles on river\n            drawTurtle(turtles[l]);\n            turtles[l].x  += turtles[l].dx\n                if (turtles[l].x &gt;= width -25 & turtles[l].dx > 0) {\n                    turtles[l].dx = -turtles[l].dx;\n                }\n\n                if (turtles[l].x &lt;= 25 & turtles[l].dx < 0) {\n                    turtles[l].dx = -turtles[l].dx;\n                }\n\n            for(j=0;j&lt;8;j++){          \/\/lilies on river\n                drawLily(lilies[j])\n            }   \n        }\n    }\n\n    if(level == 4){\n        fill('lightblue');\n        rect(0,0,width,450)\n        textSize(36);\n        fill('white')\n        text('YOU WON!',width\/2, height\/2-50);\n        image(bunnySitting,(width\/2),450,200,200);\n        textSize(12);\n        text('PRESS RELOAD TO PLAY AGAIN!',100, 30);\n        noLoop();\n        \n    }\n}\n\nfunction makeBunny(a,b,da){ \/\/ make bunny\n    var bunny = {ba: a, bb: b, bda: da,\n        draw: drawBunny,\n        step: stepBunny,\n        collideLily: collideLily,\n        onLily: false,\n        collideTurtle: collideTurtle,\n        onTurtle: false,\n        collideWater: collideWater,\n        dieBunny: dieBunny\n    }\n    return bunny;\n}\n\nfunction drawBunny(){\n    image(bunnyStopped,this.ba,this.bb,50,50);\n        if(this.bb&lt;=0){\n            level+=1;\n            this.bb +=level*120 + 240\n        }\n}\n\n\nfunction stepBunny(keyCode){ \/\/\/ add this .y\n    if (keyCode === UP_ARROW){\n        this.bb -= 60;\n    }\n\n    if (keyCode === DOWN_ARROW){\n        this.bb += 60;\n    }\n\n    if (keyCode === RIGHT_ARROW){\n        this.ba += 60;\n    }\n\n    if (keyCode === LEFT_ARROW){\n        this.ba -= 60;\n    }\n}\n\nfunction collideLily(lily){\n    this.onLily=false;\n        for(i=0;i&lt;lilies.length;i++){\n            if(dist(lilies[i].x,lilies[i].y,this.ba,this.bb)&lt;=10){\n                this.onLily = true;\n                this.bda = 0;\n                console.log(\"should be on a lily\")\n            }\n        }\n\n}\n\nfunction collideWater(fish,turtle,lily){ \/\/work on\n    if(this.onLily == false & this.onTurtle==false && this.bb < 180+(level*120) && this.bb > 60){\n        if(dist(this.ba,this.bb,turtle.x,turtle.y)>15||(dist(lily.x,lily.y,this.ba,this.bb)>10)){\n            this.ba += 1;\n        }\n    }\n}\n\n\nfunction collideTurtle(turtle){\n    if (this.onLily == false){\n        if(dist(turtle.x,turtle.y,this.ba,this.bb)&lt;=20){\n            this.ba += turtle.dx\n            console.log(\"on a turtle\")\n            this.onTurtle = true;\n        }\n    }\n}\n\nfunction dieBunny(){\n    if(this.ba &gt; width){\n        fill(135, 6, 4);\n        rect(0,0,width,height);\n        fill(82, 25, 21);\n        rect(0,330,width,height);\n        textSize(36);\n        fill('white')\n        text('YOU LOST!',width\/2, 100);\n        image(bunnyDead,(width\/2),350,200,150);\n        textSize(12);\n        text('PRESS RELOAD TO PLAY AGAIN!',100, 30);\n        noLoop();\n    }\n}\n\nfunction keyPressed() {\n  bunny.step(keyCode);\n}\n\nfunction drawLily(lily){\n    image(lilyPadImg, lily.x,lily.y, 50,50);\n}\n\nfunction drawFish(fish){\n    image(killerFishImg, fish.x, fish.y,50,50);\n}\n\nfunction drawTurtle(turtle){\n    if(turtle.dx &lt; 0){\n        push()\n        translate(turtle.x, turtle.y);\n        rotate(radians(180));\n        image(turtleImg, 0, 0, 50,50);\n        pop()\n\n    }\n    else{\n            image(turtleImg, turtle.x, turtle.y, 50,50);\n    }\n}\n\n<\/code><\/pre><\/div><\/body><\/html>\n","protected":false},"excerpt":{"rendered":"<p>sketch \/\/hfroling \/\/section c var level = 1; var spot; var a; var b; var lilies = []; var fishies = []; var turtles = []; var heights = [80,140,200,260,320,380,440,500]; var bunny; function preload() { bunnyStopped = loadImage(&#8220;https:\/\/i.imgur.com\/ASG9W87.png&#8221;); \/\/loads image bunnySitting = loadImage(&#8220;https:\/\/i.imgur.com\/fouQhgx.png&#8221;); \/\/loads image bunnyDead = loadImage(&#8220;https:\/\/i.imgur.com\/9d2vjo4.png&#8221;); lilyPadImg = loadImage(&#8220;https:\/\/i.imgur.com\/Z69HCHs.png&#8221;); killerFishImg = loadImage(&#8220;https:\/\/i.imgur.com\/mRGD4oC.png&#8221;); turtleImg &hellip; <a href=\"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/2022\/12\/10\/76220\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;My final project&#8221;<\/span><\/a><\/p>\n","protected":false},"author":720,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[116,57],"tags":[],"_links":{"self":[{"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/posts\/76220"}],"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\/720"}],"replies":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/comments?post=76220"}],"version-history":[{"count":3,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/posts\/76220\/revisions"}],"predecessor-version":[{"id":76224,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/posts\/76220\/revisions\/76224"}],"wp:attachment":[{"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/media?parent=76220"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/categories?post=76220"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/tags?post=76220"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}