-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdraw.js
1 lines (1 loc) · 4.03 KB
/
draw.js
1
function drawBackground(){let e=document.getElementById("backgroundLayer"),t=new Image;t.src="assets/gameboy-80-center.png",e.style.background=`url('${t.src}')`,e.style.backgroundSize="contain",e.style.backgroundPosition="center",e.style.backgroundRepeat="no-repeat"}const fps=60;let now,then=Date.now();const interval=16.666666666666668;let delta;function draw(){if((delta=(now=Date.now())-then)>16.666666666666668){then=now-delta%16.666666666666668,ctx.clearRect(0,0,width,height);let e=new Image;e.src="assets/tyson_tiger.png",ctx.drawImage(e,tigerX,tigerY,tigerSize,tigerSize);let t=new Image;if(isRob=level%3==0,t.src=isRob?"assets/big-rob.png":"assets/mike_tyson.png",document.getElementById("bigMike").src=isRob?"assets/big-rob.png":"assets/big_mike_tyson.png",ctx.drawImage(t,tysonX,tysonY,tysonSize,tysonSize),isLeftArrowPressed&&tigerX>0&&(tigerX-=5),isRightArrowPressed&&tigerX<width-tigerSize&&(tigerX+=5),tysonX>=-5&&"left"===tysonDirection&&(isTimePowerupActive?tysonX-=1:tysonX-=5),tysonX<width-tysonSize+20&&"right"===tysonDirection&&(isTimePowerupActive?tysonX+=1:tysonX+=5),tysonX<=-5&&(tysonDirection="right"),tysonX>=width-tysonSize+20&&(tysonDirection="left"),setTimeout(()=>{createObstaclesIfNeeded()},[1250]),!gamePaused){.0025>Math.random()&&createPowerupsIfNeeded();let n=powerups[0];if(powerups.length>0){let o=new Image;"slowTime"===n.type&&(o.src="assets/clock.png"),"shrinkTiger"===n.type&&(o.src="assets/blue_shroom.png"),ctx.drawImage(o,n.x,n.y,n.width,n.height),n.y+=n.speed}n&&(tigerX<n.x+n.width&&tigerX+tigerSize>n.x&&tigerY<n.y+n.height&&tigerY+tigerSize>n.y&&("slowTime"===n.type&&(isTimePowerupActive=!0),"shrinkTiger"===n.type&&(tigerSize=15),playPowerUpSound(),n.x=-9999,setTimeout(()=>{"slowTime"===n.type&&(isTimePowerupActive=!1),"shrinkTiger"===n.type&&(tigerSize=30),powerups=[]},5e3)),n.y>height-n.height&&(powerups=[])),obstacles.forEach(e=>{let t=[{src:"boxing_glove_main.png",height:17,width:12},{src:"beer.png",height:29,width:7},{src:"belt.png",height:13,width:31}],n=(level-1)%t.length,o=new Image,s=t[n];o.src=`assets/${s.src}`,ctx.drawImage(o,e.x,e.y,s.width,s.height),e.y+=e.speed,tigerX<e.x+e.width&&tigerX+tigerSize>e.x&&tigerY<e.y+e.height&&tigerY+tigerSize>e.y&&(playGameOverSound(),document.getElementById("finalScore").textContent=getScore(),document.getElementById("gameOverPopup").style.display="flex",document.getElementById("bigMikeSpeechContainer").style.display="none",document.getElementById("hourglass").classList.remove("spin"),document.getElementById("speech-bubble-bottom").textContent="",gamePaused=!0,clearInterval(timerInterval),clearInterval(speedIncreaseInterval),cancelAnimationFrame(drawInterval))})}}drawInterval=requestAnimationFrame(draw)}const mikeTysonQuotes=["Everyone has a plan until they get punched in the mouth.","I'm the best ever. I'm the most brutal and vicious, and most ruthless champion there's ever been.","I just want to conquer people and their souls.","Everyone has a plan until they get punched in the mouth.","I just want to conquer people and their souls.","I'm not a tycoon. I'm just a small guy from Brooklyn.","I could feel his muscle tissues collapse under my force. It's ludicrous these mortals even attempt to enter my realm.","I'm not Mother Teresa, but I'm not Charles Manson, either.","I don't try to intimidate anybody before a fight. That's nonsense. I intimidate people by hitting them.","I refuse to be beaten by people who believe in luck.","I just want to do what I do best, and that's fight. I love it.","Hard times fall upon everybody. Whatever it is, we're going to get out of it.","Everybody you fight is not your enemy and everybody that helps you is not your friend."],robQuotes=["Why am I the only one wearing a high-vis vest?","Breakfast will be in about 10 minutes guys.","Why are you taking a picture of my face?","Anyone got any rubbish for me?","Hi, I'm Rob."];function displayRandomQuote(){let e=isRob?Math.floor(Math.random()*robQuotes.length):Math.floor(Math.random()*mikeTysonQuotes.length),t=isRob?robQuotes[e]:mikeTysonQuotes[e],n=document.getElementById("speech-bubble-bottom");n.textContent=t}