|
|
Line 155: |
Line 155: |
| doorImage.src = "magicdoor.png"; | | doorImage.src = "magicdoor.png"; |
| var windowfound = 0; | | var windowfound = 0; |
| + | |
| + | // Game objects |
| + | var avatar = { |
| + | speed: 256 // movement in pixels per second |
| + | }; |
| + | |
| + | var flower = {}; |
| + | var door = {}; |
| + | var flowersCaught = 0; |
| + | |
| + | // Handle keyboard controls |
| + | var keysDown = {}; |
| + | |
| + | addEventListener("keydown", function (e) { |
| + | keysDown[e.keyCode] = true; |
| + | }, false); |
| + | |
| + | addEventListener("keyup", function (e) { |
| + | delete keysDown[e.keyCode]; |
| + | }, false); |
| + | |
| + | // Reset the game when the player catches a flower |
| + | var reset = function () { |
| + | if (start<1) { |
| + | avatar.x=305; |
| + | avatar.y=355; |
| + | } |
| + | flower.x = 32 + (Math.random() * (canvas.width - 64)); |
| + | flower.y = 32 + (Math.random() * (canvas.height - 64)); |
| + | }; |
| + | |
| + | |
| + | // Update game objects |
| + | var update = function (modifier) { |
| + | |
| + | //gelijkvloers |
| + | if (level < 1) { |
| + | if (38 in keysDown) { // Player holding up |
| + | if (avatar.y < 210 && avatar.y > 160) { |
| + | if (avatar.x > 370){ |
| + | avatar.y -= avatar.speed * modifier; |
| + | } |
| + | else if (avatar.x > 260 && avatar.x < 270){ |
| + | avatar.y -= avatar.speed * modifier; |
| + | } |
| + | else if (avatar.x > 130 && avatar.x < 150){ |
| + | avatar.y -= avatar.speed * modifier; |
| + | } |
| + | } |
| + | else if (avatar.y < 280 && avatar.y > 260){ |
| + | if (avatar.x > 370){ |
| + | avatar.y -= avatar.speed * modifier; |
| + | } |
| + | else if (avatar.x > 280 && avatar.x < 360){ |
| + | avatar.y -= avatar.speed * modifier; |
| + | } |
| + | else if (avatar.x < 160){ |
| + | avatar.y -= avatar.speed * modifier; |
| + | } |
| + | } |
| + | else if (avatar.y < 72 && avatar.y > 140){ |
| + | if (avatar.x > 365){ |
| + | avatar.y -= avatar.speed * modifier; |
| + | } |
| + | else if (avatar.x < 320){ |
| + | avatar.y -= avatar.speed * modifier; |
| + | } |
| + | } |
| + | else { |
| + | avatar.y -= avatar.speed * modifier; |
| + | } |
| + | } |
| + | if (40 in keysDown) { // Player holding down |
| + | if (avatar.y < 160 && avatar.y > 150) { |
| + | if (avatar.x > 370){ |
| + | avatar.y += avatar.speed * modifier; |
| + | } |
| + | else if (avatar.x > 260 && avatar.x < 280){ |
| + | avatar.y += avatar.speed * modifier; |
| + | } |
| + | else if (avatar.x > 130 && avatar.x < 150){ |
| + | avatar.y += avatar.speed * modifier; |
| + | } |
| + | } |
| + | else if (avatar.y < 260 && avatar.y > 210){ |
| + | if (avatar.x > 370){ |
| + | avatar.y += avatar.speed * modifier; |
| + | } |
| + | else if (avatar.x > 280 && avatar.x < 315){ |
| + | avatar.y += avatar.speed * modifier; |
| + | } |
| + | else if (avatar.x < 160 && avatar.x > 125){ |
| + | avatar.y += avatar.speed * modifier; |
| + | } |
| + | else if (avatar.x < 75){ |
| + | avatar.y += avatar.speed * modifier; |
| + | } |
| + | } |
| + | else if (avatar.y < 108 && avatar.y > 95){ |
| + | if (avatar.x > 370){ |
| + | avatar.y += avatar.speed * modifier; |
| + | } |
| + | else if (avatar.x < 320){ |
| + | avatar.y += avatar.speed * modifier; |
| + | } |
| + | } |
| + | else { |
| + | avatar.y += avatar.speed * modifier; |
| + | } |
| + | } |
| + | if (37 in keysDown) { // Player holding left |
| + | if (avatar.y < 60) { |
| + | if (avatar.x > 375){ |
| + | avatar.x -= avatar.speed * modifier; |
| + | } |
| + | else if (avatar.x > 210 && avatar.x < 350){ |
| + | avatar.x -= avatar.speed * modifier; |
| + | } |
| + | else if (avatar.x < 200){ |
| + | avatar.x -= avatar.speed * modifier; |
| + | } |
| + | } |
| + | else if (avatar.y < 108) { |
| + | if (avatar.x > 210){ |
| + | avatar.x -= avatar.speed * modifier; |
| + | } |
| + | else if (avatar.x < 200){ |
| + | avatar.x -= avatar.speed * modifier; |
| + | } |
| + | } |
| + | else if (avatar.y < 160) { |
| + | if (avatar.x > 375){ |
| + | avatar.x -= avatar.speed * modifier; |
| + | } |
| + | else if (avatar.x > 210 && avatar.x < 350){ |
| + | avatar.x -= avatar.speed * modifier; |
| + | } |
| + | else if (avatar.x < 200){ |
| + | avatar.x -= avatar.speed * modifier; |
| + | } |
| + | } |
| + | else if (avatar.y <205) { |
| + | if (avatar.x > 375){ |
| + | avatar.x -= avatar.speed * modifier; |
| + | } |
| + | else if (avatar.x < 120){ |
| + | avatar.x -= avatar.speed * modifier; |
| + | } |
| + | } |
| + | else if (avatar.y < 220) { |
| + | avatar.x -= avatar.speed * modifier; |
| + | } |
| + | else if (avatar.y <270) { |
| + | if (avatar.x > 375){ |
| + | avatar.x -= avatar.speed * modifier; |
| + | } |
| + | else if (avatar.x < 120){ |
| + | avatar.x -= avatar.speed * modifier; |
| + | } |
| + | } |
| + | else if (avatar.x > 375){ |
| + | avatar.x -= avatar.speed * modifier; |
| + | } |
| + | else if (avatar.x > 210 && avatar.x < 350){ |
| + | avatar.x -= avatar.speed * modifier; |
| + | } |
| + | else if (avatar.x > 130 && avatar.x < 190){ |
| + | avatar.x -= avatar.speed * modifier; |
| + | } |
| + | else if (avatar.x < 120){ |
| + | avatar.x -= avatar.speed * modifier; |
| + | } |
| + | } |
| + | if (39 in keysDown) { // Player holding right |
| + | if (avatar.y < 60) { |
| + | if (avatar.x > 320){ |
| + | avatar.x += avatar.speed * modifier; |
| + | } |
| + | else if (avatar.x > 160 && avatar.x < 315){ |
| + | avatar.x += avatar.speed * modifier; |
| + | } |
| + | else if (avatar.x < 150){ |
| + | avatar.x += avatar.speed * modifier; |
| + | } |
| + | } |
| + | else if (avatar.y < 108) { |
| + | if (avatar.x > 160){ |
| + | avatar.x += avatar.speed * modifier; |
| + | } |
| + | else if (avatar.x < 150){ |
| + | avatar.x += avatar.speed * modifier; |
| + | } |
| + | } |
| + | else if (avatar.y < 160) { |
| + | if (avatar.x > 320){ |
| + | avatar.x += avatar.speed * modifier; |
| + | } |
| + | else if (avatar.x > 200 && avatar.x < 312){ |
| + | avatar.x += avatar.speed * modifier; |
| + | } |
| + | else if (avatar.x > 150 && avatar.x < 190){ |
| + | avatar.x += avatar.speed * modifier; |
| + | } |
| + | else if (avatar.x < 145){ |
| + | avatar.x += avatar.speed * modifier; |
| + | } |
| + | } |
| + | else if (avatar.y <205) { |
| + | if (avatar.x > 320){ |
| + | avatar.x += avatar.speed * modifier; |
| + | } |
| + | else if (avatar.x < 145){ |
| + | avatar.x += avatar.speed * modifier; |
| + | } |
| + | } |
| + | else if (avatar.y < 220) { |
| + | avatar.x += avatar.speed * modifier; |
| + | } |
| + | else if (avatar.y <270) { |
| + | if (avatar.x > 320){ |
| + | avatar.x += avatar.speed * modifier; |
| + | } |
| + | else if (avatar.x < 70) { |
| + | avatar.x += avatar.speed * modifier; |
| + | } |
| + | } |
| + | else if (avatar.x > 320){ |
| + | avatar.x += avatar.speed * modifier; |
| + | } |
| + | else if (avatar.x > 160 && avatar.x < 312){ |
| + | avatar.x += avatar.speed * modifier; |
| + | } |
| + | else if (avatar.x > 110 && avatar.x < 150){ |
| + | avatar.x += avatar.speed * modifier; |
| + | } |
| + | else if (avatar.x < 70){ |
| + | avatar.x += avatar.speed * modifier; |
| + | } |
| + | } |
| + | |
| + | //checken in welke kamer je bent en de correcte tekst vertonen |
| + | if (avatar.x > 320) { |
| + | //living |
| + | if (avatar.y > 200){ |
| + | document.getElementById("general").style.display = "none"; |
| + | document.getElementById("outreach").style.display = "none"; |
| + | document.getElementById("team").style.display = "block"; |
| + | document.getElementById("project").style.display = "none"; |
| + | document.getElementById("notebook").style.display = "none"; |
| + | document.getElementById("modeling").style.display = "none"; |
| + | document.getElementById("research").style.display = "none"; |
| + | } |
| + | //eettafel |
| + | else { |
| + | document.getElementById("general").style.display = "none"; |
| + | document.getElementById("outreach").style.display = "none"; |
| + | document.getElementById("team").style.display = "none"; |
| + | document.getElementById("project").style.display = "block"; |
| + | document.getElementById("notebook").style.display = "none"; |
| + | document.getElementById("modeling").style.display = "none"; |
| + | document.getElementById("research").style.display = "none"; |
| + | } |
| + | } |
| + | |
| + | else if (avatar.x > 160) { |
| + | //keuken |
| + | if (avatar.y < 205){ |
| + | document.getElementById("general").style.display = "none"; |
| + | document.getElementById("outreach").style.display = "block"; |
| + | document.getElementById("team").style.display = "none"; |
| + | document.getElementById("project").style.display = "none"; |
| + | document.getElementById("notebook").style.display = "none"; |
| + | document.getElementById("modeling").style.display = "none"; |
| + | document.getElementById("research").style.display = "none"; |
| + | } |
| + | else if (avatar.y >270) { |
| + | //inkom |
| + | if (avatar.x > 240){ |
| + | document.getElementById("general").style.display = "block"; |
| + | document.getElementById("outreach").style.display = "none"; |
| + | document.getElementById("team").style.display = "none"; |
| + | document.getElementById("project").style.display = "none"; |
| + | document.getElementById("notebook").style.display = "none"; |
| + | document.getElementById("modeling").style.display = "none"; |
| + | document.getElementById("research").style.display = "none"; |
| + | leveldiscovered=1; |
| + | } |
| + | //trap |
| + | else { |
| + | if (leveldiscovered < 1) { |
| + | document.getElementById("general").style.display = "block"; |
| + | document.getElementById("outreach").style.display = "none"; |
| + | document.getElementById("team").style.display = "none"; |
| + | document.getElementById("project").style.display = "none"; |
| + | document.getElementById("notebook").style.display = "none"; |
| + | document.getElementById("modeling").style.display = "none"; |
| + | document.getElementById("research").style.display = "none"; |
| + | } |
| + | else { |
| + | bgImage.src = "Firstfloor.png"; |
| + | level=1; |
| + | leveldiscovered=0; |
| + | } |
| + | } |
| + | } |
| + | } |
| + | |
| + | else if (avatar.x < 150) { |
| + | //bureau |
| + | if (avatar.y < 205){ |
| + | document.getElementById("general").style.display = "none"; |
| + | document.getElementById("outreach").style.display = "none"; |
| + | document.getElementById("team").style.display = "none"; |
| + | document.getElementById("project").style.display = "none"; |
| + | document.getElementById("notebook").style.display = "none"; |
| + | document.getElementById("modeling").style.display = "block"; |
| + | document.getElementById("research").style.display = "none"; |
| + | } |
| + | //badkamer |
| + | else if (avatar.x < 80) { |
| + | document.getElementById("general").style.display = "none"; |
| + | document.getElementById("outreach").style.display = "none"; |
| + | document.getElementById("team").style.display = "none"; |
| + | document.getElementById("project").style.display = "none"; |
| + | document.getElementById("notebook").style.display = "none"; |
| + | document.getElementById("modeling").style.display = "none"; |
| + | document.getElementById("research").style.display = "block"; |
| + | } |
| + | //toilet |
| + | else if (avatar.x > 80 && avatar.y > 270) { |
| + | document.getElementById("general").style.display = "none"; |
| + | document.getElementById("outreach").style.display = "none"; |
| + | document.getElementById("team").style.display = "none"; |
| + | document.getElementById("project").style.display = "none"; |
| + | document.getElementById("notebook").style.display = "block"; |
| + | document.getElementById("modeling").style.display = "none"; |
| + | document.getElementById("research").style.display = "none"; |
| + | } |
| + | } |
| + | |
| + | |
| + | |
| + | |
| + | // walls |
| + | |
| + | if (avatar.x < 14){ |
| + | avatar.x=14; |
| + | if (avatar.y < 14){ |
| + | avatar.y=14; |
| + | } |
| + | if (avatar.y > canvas.height-65){ |
| + | avatar.y=canvas.height-65; |
| + | } |
| + | } |
| + | |
| + | else if (avatar.y < 14){ |
| + | avatar.y=14; |
| + | if (avatar.x > canvas.width-65){ |
| + | avatar.x=canvas.width-65; |
| + | } |
| + | } |
| + | |
| + | else if (avatar.x > canvas.width-65){ |
| + | avatar.x=canvas.width-65; |
| + | if (avatar.y > canvas.height-65){ |
| + | avatar.y=canvas.height-65; |
| + | } |
| + | } |
| + | |
| + | |
| + | else if (avatar.y > canvas.height-65){ |
| + | if (avatar.x > 290 && avatar.x < 320){ |
| + | avatar.y=0; |
| + | level = 3; |
| + | } |
| + | else { |
| + | avatar.y=canvas.height-65; |
| + | } |
| + | } |
| + | |
| + | } |
| + | |
| + | //eerste verdieping |
| + | else if (level < 2) { |
| + | if (38 in keysDown) { // Player holding up |
| + | if (avatar.y < 210 && avatar.y > 160) { |
| + | if (avatar.x > 210 && avatar.x < 310){ |
| + | avatar.y -= avatar.speed * modifier; |
| + | } |
| + | } |
| + | else if (avatar.y < 150 && avatar.y > 120) { |
| + | if (avatar.x < 160) { |
| + | avatar.y -= avatar.speed * modifier; |
| + | } |
| + | else if (avatar.x > 370) { |
| + | avatar.y -= avatar.speed * modifier; |
| + | } |
| + | } |
| + | else { |
| + | avatar.y -= avatar.speed * modifier; |
| + | } |
| + | } |
| + | if (40 in keysDown) { // Player holding down |
| + | if (avatar.y < 180 && avatar.y > 150) { |
| + | if (avatar.x > 210 && avatar.x < 310){ |
| + | avatar.y += avatar.speed * modifier; |
| + | } |
| + | } |
| + | else if (avatar.y > canvas.height-110) { |
| + | if (avatar.x > 210){ |
| + | avatar.y += avatar.speed * modifier; |
| + | } |
| + | } |
| + | else if (avatar.y < 120 && avatar.y > 90) { |
| + | if (avatar.x < 160) { |
| + | avatar.y += avatar.speed * modifier; |
| + | } |
| + | else if (avatar.x > 370) { |
| + | avatar.y += avatar.speed * modifier; |
| + | } |
| + | } |
| + | else { |
| + | avatar.y += avatar.speed * modifier; |
| + | } |
| + | } |
| + | if (37 in keysDown) { // Player holding left |
| + | if (avatar.y < 70) { |
| + | if (avatar.x > 375){ |
| + | avatar.x -= avatar.speed * modifier; |
| + | } |
| + | else if (avatar.x > 215 && avatar.x < 350){ |
| + | avatar.x -= avatar.speed * modifier; |
| + | } |
| + | else if (avatar.x < 200){ |
| + | avatar.x -= avatar.speed * modifier; |
| + | } |
| + | } |
| + | else if (avatar.y < 95) { |
| + | if (avatar.x > 215){ |
| + | avatar.x -= avatar.speed * modifier; |
| + | } |
| + | else if (avatar.x < 200){ |
| + | avatar.x -= avatar.speed * modifier; |
| + | } |
| + | } |
| + | else if (avatar.y < 145) { |
| + | if (avatar.x < 215 ) { |
| + | avatar.x -= avatar.speed * modifier; |
| + | } |
| + | else if (avatar.x > 375) { |
| + | avatar.x -= avatar.speed * modifier; |
| + | } |
| + | } |
| + | else if (avatar.y < 155) { |
| + | avatar.x -= avatar.speed * modifier; |
| + | } |
| + | else if (avatar.y <205) { |
| + | if (avatar.x < 375 && avatar.x > 215){ |
| + | avatar.x -= avatar.speed * modifier; |
| + | } |
| + | } |
| + | else if (avatar.y < 210) { |
| + | avatar.x -= avatar.speed * modifier; |
| + | } |
| + | else if (avatar.y >215) { |
| + | if (avatar.x > 375){ |
| + | avatar.x -= avatar.speed * modifier; |
| + | } |
| + | else if (avatar.x > 215 && avatar.x < 350){ |
| + | avatar.x -= avatar.speed * modifier; |
| + | } |
| + | else if (avatar.x < 200){ |
| + | avatar.x -= avatar.speed * modifier; |
| + | } |
| + | } |
| + | } |
| + | if (39 in keysDown) { // Player holding right |
| + | if (avatar.y < 70) { |
| + | if (avatar.x > 350){ |
| + | avatar.x += avatar.speed * modifier; |
| + | } |
| + | else if (avatar.x > 180 && avatar.x < 310){ |
| + | avatar.x += avatar.speed * modifier; |
| + | } |
| + | else if (avatar.x < 155){ |
| + | avatar.x += avatar.speed * modifier; |
| + | } |
| + | } |
| + | else if (avatar.y < 95) { |
| + | if (avatar.x > 210){ |
| + | avatar.x += avatar.speed * modifier; |
| + | } |
| + | else if (avatar.x < 155){ |
| + | avatar.x += avatar.speed * modifier; |
| + | } |
| + | } |
| + | else if (avatar.y < 145) { |
| + | if (avatar.x < 155 ) { |
| + | avatar.x += avatar.speed * modifier; |
| + | } |
| + | else if (avatar.x > 350) { |
| + | avatar.x += avatar.speed * modifier; |
| + | } |
| + | } |
| + | else if (avatar.y < 155) { |
| + | avatar.x += avatar.speed * modifier; |
| + | } |
| + | else if (avatar.y <205) { |
| + | if (avatar.x < 310 && avatar.x > 155){ |
| + | avatar.x += avatar.speed * modifier; |
| + | } |
| + | } |
| + | else if (avatar.y < 210) { |
| + | avatar.x += avatar.speed * modifier; |
| + | } |
| + | else if (avatar.y >215) { |
| + | if (avatar.x > 350){ |
| + | avatar.x += avatar.speed * modifier; |
| + | } |
| + | else if (avatar.x > 180 && avatar.x < 310){ |
| + | avatar.x += avatar.speed * modifier; |
| + | } |
| + | else if (avatar.x < 150){ |
| + | avatar.x += avatar.speed * modifier; |
| + | } |
| + | } |
| + | } |
| + | |
| + | // walls |
| + | if (avatar.x < 30){ |
| + | avatar.x=30; |
| + | if (avatar.y < 20){ |
| + | avatar.y=20; |
| + | } |
| + | if (avatar.y > canvas.height-72){ |
| + | avatar.y=canvas.height-72; |
| + | } |
| + | } |
| + | |
| + | else if (avatar.y < 20){ |
| + | avatar.y=20; |
| + | if (avatar.x > canvas.width-70){ |
| + | avatar.x=canvas.width-70; |
| + | } |
| + | } |
| + | |
| + | else if (avatar.x > canvas.width-70){ |
| + | avatar.x=canvas.width-70; |
| + | if (avatar.y > canvas.height-70){ |
| + | avatar.y=canvas.height-70; |
| + | } |
| + | } |
| + | |
| + | |
| + | else if (avatar.y > canvas.height-70){ |
| + | avatar.y=canvas.height-70; |
| + | } |
| + | |
| + | |
| + | |
| + | else if (avatar.y > canvas.height-50){ |
| + | avatar.y=canvas.height-50; |
| + | } |
| + | |
| + | //checken in welke kamer je bent en de correcte tekst vertonen |
| + | if (avatar.x > 320) { |
| + | //living |
| + | if (avatar.y > 200){ |
| + | document.getElementById("general").style.display = "none"; |
| + | document.getElementById("outreach").style.display = "none"; |
| + | document.getElementById("team").style.display = "block"; |
| + | document.getElementById("project").style.display = "none"; |
| + | document.getElementById("notebook").style.display = "none"; |
| + | document.getElementById("modeling").style.display = "none"; |
| + | document.getElementById("research").style.display = "none"; |
| + | } |
| + | //eettafel |
| + | else { |
| + | document.getElementById("general").style.display = "none"; |
| + | document.getElementById("outreach").style.display = "none"; |
| + | document.getElementById("team").style.display = "none"; |
| + | document.getElementById("project").style.display = "block"; |
| + | document.getElementById("notebook").style.display = "none"; |
| + | document.getElementById("modeling").style.display = "none"; |
| + | document.getElementById("research").style.display = "none"; |
| + | } |
| + | } |
| + | |
| + | else if (avatar.x > 160) { |
| + | //keuken |
| + | if (avatar.y < 205){ |
| + | document.getElementById("general").style.display = "none"; |
| + | document.getElementById("outreach").style.display = "block"; |
| + | document.getElementById("team").style.display = "none"; |
| + | document.getElementById("project").style.display = "none"; |
| + | document.getElementById("notebook").style.display = "none"; |
| + | document.getElementById("modeling").style.display = "none"; |
| + | document.getElementById("research").style.display = "none"; |
| + | } |
| + | else if (avatar.y >270) { |
| + | //inkom |
| + | if (avatar.x > 240){ |
| + | document.getElementById("general").style.display = "block"; |
| + | document.getElementById("outreach").style.display = "none"; |
| + | document.getElementById("team").style.display = "none"; |
| + | document.getElementById("project").style.display = "none"; |
| + | document.getElementById("notebook").style.display = "none"; |
| + | document.getElementById("modeling").style.display = "none"; |
| + | document.getElementById("research").style.display = "none"; |
| + | leveldiscovered=1; |
| + | } |
| + | //trap |
| + | else { |
| + | if (leveldiscovered < 1) { |
| + | document.getElementById("general").style.display = "block"; |
| + | document.getElementById("outreach").style.display = "none"; |
| + | document.getElementById("team").style.display = "none"; |
| + | document.getElementById("project").style.display = "none"; |
| + | document.getElementById("notebook").style.display = "none"; |
| + | document.getElementById("modeling").style.display = "none"; |
| + | document.getElementById("research").style.display = "none"; |
| + | } |
| + | else { |
| + | bgImage.src = "plattegrondGelijksvloer.PNG"; |
| + | level=0; |
| + | leveldiscovered=0; |
| + | } |
| + | } |
| + | } |
| + | } |
| + | |
| + | else if (avatar.x < 150) { |
| + | //bureau |
| + | if (avatar.y < 205){ |
| + | document.getElementById("general").style.display = "none"; |
| + | document.getElementById("outreach").style.display = "none"; |
| + | document.getElementById("team").style.display = "none"; |
| + | document.getElementById("project").style.display = "none"; |
| + | document.getElementById("notebook").style.display = "none"; |
| + | document.getElementById("modeling").style.display = "block"; |
| + | document.getElementById("research").style.display = "none"; |
| + | } |
| + | //badkamer |
| + | else if (avatar.x < 80) { |
| + | document.getElementById("general").style.display = "none"; |
| + | document.getElementById("outreach").style.display = "none"; |
| + | document.getElementById("team").style.display = "none"; |
| + | document.getElementById("project").style.display = "none"; |
| + | document.getElementById("notebook").style.display = "none"; |
| + | document.getElementById("modeling").style.display = "none"; |
| + | document.getElementById("research").style.display = "block"; |
| + | } |
| + | //toilet |
| + | else if (avatar.x > 80 && avatar.y > 270) { |
| + | document.getElementById("general").style.display = "none"; |
| + | document.getElementById("outreach").style.display = "none"; |
| + | document.getElementById("team").style.display = "none"; |
| + | document.getElementById("project").style.display = "none"; |
| + | document.getElementById("notebook").style.display = "block"; |
| + | document.getElementById("modeling").style.display = "none"; |
| + | document.getElementById("research").style.display = "none"; |
| + | } |
| + | } |
| + | } |
| + | |
| + | //tuin |
| + | else { |
| + | flowerImage.src = "Bloemen35.gif"; |
| + | bgImage.src = "gras.jpg"; |
| + | |
| + | if (38 in keysDown) { |
| + | avatar.y -= avatar.speed * modifier; |
| + | } |
| + | if (40 in keysDown) { |
| + | avatar.y += avatar.speed * modifier; |
| + | } |
| + | if (37 in keysDown) { |
| + | avatar.x -= avatar.speed * modifier; |
| + | } |
| + | if (39 in keysDown) { |
| + | avatar.x += avatar.speed * modifier; |
| + | } |
| + | if (avatar.x <= (flower.x + 32)){ |
| + | if(flower.x <= (avatar.x + 32)){ |
| + | if(avatar.y <= (flower.y + 32)){ |
| + | if(flower.y <= (avatar.y + 32)){ |
| + | ++flowersCaught; |
| + | avatar.speed=avatar.speed+2; |
| + | start=start+1; |
| + | reset(); |
| + | } |
| + | } |
| + | } |
| + | } |
| + | |
| + | if (flowersCaught > 0) { |
| + | if (avatar.x < 380){ |
| + | if( avatar.x > 285){ |
| + | if(avatar.y > 285){ |
| + | if( avatar.y < 370){ |
| + | if (windowfound < 1) { |
| + | window.alert("you can visit our secret page") |
| + | windowfound = 1; |
| + | reset(); |
| + | } |
| + | } |
| + | } |
| + | } |
| + | } |
| + | } |
| + | |
| + | if (avatar.x < 0){ |
| + | avatar.x=canvas.width; |
| + | if (avatar.y < 0){ |
| + | avatar.y=canvas.height; |
| + | } |
| + | if (avatar.y > canvas.height){ |
| + | avatar.y=0; |
| + | } |
| + | } |
| + | |
| + | else if (avatar.y > canvas.height){ |
| + | avatar.y=0; |
| + | if (avatar.x > canvas.width){ |
| + | avatar.x=0; |
| + | } |
| + | } |
| + | |
| + | else if (avatar.x > canvas.width){ |
| + | avatar.x=0; |
| + | if (avatar.y > canvas.height){ |
| + | avatar.y=0; |
| + | } |
| + | } |
| + | |
| + | else if (avatar.y < 0){ |
| + | if (avatar.x > 290 && avatar.x < 320){ |
| + | avatar.y = canvas.height-65; |
| + | level = 0; |
| + | bgImage.src = "plattegrondGelijksvloer.PNG"; |
| + | } |
| + | else { |
| + | avatar.y=canvas.height; |
| + | } |
| + | } |
| + | |
| + | |
| + | } |
| + | |
| + | }; |
| + | |
| + | // Draw everything |
| + | var render = function () { |
| + | if (bgReady) { |
| + | ctx.drawImage(bgImage, 0, 0); |
| + | } |
| + | |
| + | if (avatarReady) { |
| + | |
| + | ctx.drawImage(avatarImage, avatar.x, avatar.y); |
| + | } |
| + | |
| + | |
| + | |
| + | // Score |
| + | ctx.fillStyle = "rgb(250, 250, 250)"; |
| + | ctx.font = "24px Helvetica"; |
| + | ctx.textAlign = "left"; |
| + | ctx.textBaseline = "top"; |
| + | if (level < 1) { |
| + | ctx.fillText("Groundfloor", 32, 32); |
| + | } |
| + | else if (level < 2) { |
| + | ctx.fillText("Firstfloor", 32, 32); |
| + | } |
| + | else { |
| + | if (flowerReady) { |
| + | ctx.drawImage(flowerImage, flower.x, flower.y); |
| + | } |
| + | if (flowersCaught > 0) { |
| + | if (doorReady) { |
| + | ctx.drawImage(doorImage, 300, 300); |
| + | } |
| + | } |
| + | ctx.fillText("Flowers collected: " + flowersCaught, 32, 32); |
| + | } |
| + | }; |
| + | |
| + | //checkroom |
| + | |
| + | |
| + | // The main game loop |
| + | var main = function () { |
| + | var now = Date.now(); |
| + | var delta = now - then; |
| + | |
| + | update(delta / 1000); |
| + | render(); |
| + | then = now; |
| + | |
| + | // Request to do this again ASAP |
| + | requestAnimationFrame(main); |
| + | }; |
| + | |
| + | // Cross-browser support for requestAnimationFrame |
| + | var w = window; |
| + | requestAnimationFrame = w.requestAnimationFrame || w.webkitRequestAnimationFrame || w.msRequestAnimationFrame || w.mozRequestAnimationFrame; |
| + | |
| + | // Let's play this game! |
| + | var then = Date.now(); |
| + | reset() |
| + | main(); |
| | | |
| } | | } |