{"id":69515,"date":"2021-12-05T23:44:37","date_gmt":"2021-12-06T04:44:37","guid":{"rendered":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/?p=69515"},"modified":"2021-12-05T23:44:37","modified_gmt":"2021-12-06T04:44:37","slug":"final-project-21","status":"publish","type":"post","link":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/2021\/12\/05\/final-project-21\/","title":{"rendered":"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\" href=\"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/wp-content\/uploads\/2021\/12\/wpf-final.js\" data-width=\"480\" data-height=\"480\">wpf-final.js<\/a><iframe src=\"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/wp-content\/plugins\/p5-embedder\/p5_iframe.html\" class=\"p5_exampleFrame\" width=\"480\" height=\"480\"><\/iframe><pre class=\"language-javascript\"><code class=\"p5_editor language-javascript\">\/\/Patrick Fisher, section B, wpf assignment - 13\n\nvar bear; \/\/object for the bear\nvar icebergs = []; \/\/array of objects of icebergs\nvar middleIce; \/\/variable the stores the position of the platform that is under the bear\nvar clouds = []; \/\/array of objects of clouds\nvar score = 0; \/\/score counter based on frame count and the amount of platforms passed\n\nfunction setup() {\n    createCanvas(480,480);\n    background(113,147,231);\n    bear = makeBear();\n    var ib = newBerg(-60,0,120) \/\/creates the starting platform which is the same everytime\n    icebergs.push(ib);\n\n    for(var i = 1; i &lt;= 5; i++){ \/\/creates new, random platofrms,\n        icebergs.push(newBerg(-60 + (i * 250),floor(random(-20,0)),random(90,150)))\n    }\n\n    for(var i = 0; i &lt;= 7; i++){ \/\/aesthetic clouds at the top\n        clouds.push(makeCloud(-60 + (i * 250)));\n    }\n    middleIce = {end: 60, y: 0}; \/\/starting info for the platform that will have colision\n}\n\nfunction draw() {\n    background(113,147,231); \/\/sky\n    fill(63,181,207);\n    rect(0,300,width,height); \/\/ocean\n\n    fill(255,246,2); \/\/sun\n    circle(100,75, 50);\n    \n    push();\n    fill(0);\n    translate(width\/2-75, 300);\n    for(var i = 0; i &lt;= 5; i ++){ \/\/for loop to draw the icebergs\n        if(icebergs[i].x &lt;= 30 & icebergs[i].end >= -30){ \/\/checks to see if theres a platform under the bear and if so stores it as middle ice\n            middleIce.y = floor(icebergs[i].y);\n            middleIce.end = floor(icebergs[i].end);\n        }\n\n        icebergs[i].draw();\n    \n\n        if(icebergs[i].x &lt;= -600){ \/\/deletes a iceberg from the array when it gets too far off screen and makes a new one\n            icebergs.shift();\n            icebergs.push(newBerg(900,random(-20,0),random(90,150)));\n\n        }\n\n    }\n    if(middleIce.end &lt;= -25){ \/\/gets rid of middle ice after its gone past the bear\n        middleIce.y = 200;\n        score ++;\n\n    }\n\n    for(var i = 0; i &lt;= 7; i++){ \/\/draws clouds\n        clouds[i].draw();\n    }\n\n    if(clouds.x &lt;= -600){ \/\/deletes a cloud from the array when it gets too far off screen and makes a new one\n            clouds.shift();\n            clouds.push(makeCloud(600));\n\n        }\n\n    if (bear.y &gt;= 200) { \/\/checks to see if the bear has fallen and if so starts the game over sequence\n        bear.isAlive = false;\n    }\n\n    if(frameCount &lt; 240){ \/\/4 seconds of the text\n        text(\"Press Space to Jump\", 10, 30);\n    }\n\n    bear.draw(); \n    pop();\n\n    if(bear.isAlive == false){ \/\/game over sequencse\n        background(0);\n        fill(63,181,207);\n        stroke(255);\n        textSize(50);\n        textAlign(CENTER);\n        text(\"GAME OVER\", width\/2, height\/2);\n        textSize(40);\n        text(\"SCORE: \" + score.toString(), width\/ 2, height\/2 + 75);\n        noLoop();\n    }\n}\n\nfunction newBerg(bx,by,bw) { \/\/constructor funtion to create icebergs\n    var b = {x: bx, y: by, w: bw, end: bx+bw, half: bx + (bw \/ 2), draw: drawIce, speed: iceSpeed};\n    return b;\n}\n\nfunction makeBear() { \/\/constructor to make the bear\n    var b = {x: 0, y: 0, dy: 0, isAlive: true, vestOn: false, draw: drawBear}\n    return b;\n}\n\nfunction drawBear(){\n    push();\n    \n    this.y += this.dy; \/\/moves the bear down\n    if(this.y &gt;= middleIce.y - 3 & this.y <= middleIce.y){ \/\/checks if the bear is over a platform\n        this.dy = 0;\n    }\n    else{ \n        this.dy ++;\n    }\n\n    fill(214,207,193); \/\/draws the bear\n    legAni(this.x,this.y);\n    ellipse(this.x,this.y-17,50,30);\n    legAni(this.x + 2,this.y);\n    ellipse(this.x+20,this.y-38,5,10);\n    ellipse(this.x+30,this.y-38,5,10);\n    circle(this.x+25,this.y-30,20);\n\n    \n    fill(0);\n    circle(this.x+30,this.y-32,5);\n\n    pop();\n}\n\nfunction drawIce() { \/\/draws the ice\n    push();\n    fill(95,145,150);\n    triangle(this.x,this.y,this.end,this.y,this.half, this.y + 160);\n    fill(228,224,221);\n    triangle(this.x,this.y,this.end,this.y,this.half, this.y - 90);\n    push();\n    strokeWeight(5);\n    line(this.x,this.y,this.end,this.y);\n    pop();\n    pop();\n\n    this.speed();\n\n}\n\nfunction keyPressed() { \/\/ press spacebar to jump\n    if(keyCode ==  32){\n        bear.dy = -10;\n    }\n}\n\nfunction iceSpeed() { \/\/function that moves and continually speeds up the icebergs every 30 seconds\n    var o = floor(frameCount \/ (30*60));\n\n    this.x -= o+1;\n    this.end -= o+1;\n    this.half -= o+1;\n}\n\nfunction makeCloud(cx){ \/\/constructor for the clouds\n    var c = {x: cx, y: (-350,-250), draw: drawCloud}\n    return c;\n}\n\nfunction drawCloud(){ \/\/function to draw the clouds\n    push();\n    fill(255);  \/\/series of ellipses that draws the cloud\n    ellipse(this.x,this.y,60,50);\n    ellipse(this.x+30,this.y-10,60,50);\n    ellipse(this.x+80,this.y,60,50);\n    ellipse(this.x+20,this.y+20,60,50);\n    ellipse(this.x+60,this.y+15,60,50);\n    push();\n    noStroke();\n    ellipse(this.x+40,this.y+10,100,55)\n    pop();\n    pop();\n\n    if(frameCount % 2 == 0){\n        this.x --;\n    }\n}\n\nfunction legAni(x,y){ \/\/simple leg moving animation\n    \n    if(frameCount % 4 == 0){\n        ellipse(x-18,y-8,10,20);\n        ellipse(x+22,y-8,10,20);\n    }\n\n    if(frameCount % 4 == 1){\n        ellipse(x-18,y-8,10,20);\n        ellipse(x+21,y-8,10,20);\n    }\n\n    if(frameCount % 4 == 2){\n        ellipse(x-17,y-8,10,20);\n        ellipse(x+20,y-8,10,20);\n    }\n\n    if(frameCount % 4 == 3){\n        ellipse(x-15,y-8,10,20);\n        ellipse(x+19,y-8,10,20);\n    }\n}\n\n\n<\/code><\/pre><\/div>\n\n\n\n<p>For my project what inspired me was the polar ice caps melting and seeing pictures of polar bears literally having to jump across water to get to safety. So I decided to create a platform game that was that. It&rsquo;s pretty simple, just press space to repeatedly jump and land on the next iceberg. The collision detection for the icebergs is very hit or miss, unfortunately. If I had more time I would want to figure out what is going wrong with it as when debugging I could see that the values for the bear and the iceberg I was comparing were equal and yet the bear did not stop falling. Additionally, I had more time I would add a sort of extra life feature, described in my design documents as a life preserver, make the icebergs sink once landed on, and make the bear fully controllable rather than the game being an auto scroller.<\/p><\/body><\/html>\n","protected":false},"excerpt":{"rendered":"<p>wpf-final.js \/\/Patrick Fisher, section B, wpf assignment &#8211; 13 var bear; \/\/object for the bear var icebergs = []; \/\/array of objects of icebergs var middleIce; \/\/variable the stores the position of the platform that is under the bear var clouds = []; \/\/array of objects of clouds var score = 0; \/\/score counter based &hellip; <a href=\"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/2021\/12\/05\/final-project-21\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Final Project&#8221;<\/span><\/a><\/p>\n","protected":false},"author":648,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[116,56],"tags":[],"_links":{"self":[{"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/wp-json\/wp\/v2\/posts\/69515"}],"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\/648"}],"replies":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/wp-json\/wp\/v2\/comments?post=69515"}],"version-history":[{"count":2,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/wp-json\/wp\/v2\/posts\/69515\/revisions"}],"predecessor-version":[{"id":69518,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/wp-json\/wp\/v2\/posts\/69515\/revisions\/69518"}],"wp:attachment":[{"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/wp-json\/wp\/v2\/media?parent=69515"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/wp-json\/wp\/v2\/categories?post=69515"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/wp-json\/wp\/v2\/tags?post=69515"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}