From 8eaeefc51a0c9a9b6e2d240d62fab1c786cbcd4e Mon Sep 17 00:00:00 2001 From: sam Date: Wed, 6 Dec 2023 15:30:32 +0100 Subject: [PATCH] Created button function and fixed timer issue --- web/game.js | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/web/game.js b/web/game.js index bcbc1a2..6a53e39 100644 --- a/web/game.js +++ b/web/game.js @@ -170,6 +170,7 @@ function draw() { pop(); } if (hasMoved == false) { + time = 0; push(); score(); textSize(10); @@ -332,8 +333,39 @@ function spawnRandomBullet() { function homescreen() { - push() - square(width/2, height/2, 100) - color(255, 0, 255, 200) - pop() + // push() + // fill(0, 0, 0, 200) + // square(0, 0, 1600) + // pop() + + // push() + // fill(255, 0, 0) + // let buttonHeight = height/2 + // rect(width/2-90, buttonHeight, 200, 40 , 20, 20, 20, 20) + // textSize(25) + // fill(0,0,0) + // text("Start Game", width/2+10, buttonHeight+30) + // if (mouseX > width/2-90 && mouseX < width/2+110 && mouseY > height/2 && mouseY < buttonHeight+40) { + // if (mouseIsPressed) { + // homescreenOn = false; + // } + // } + // pop() + button(0,0,0 ,width/2-90, height/2, 200, 40, "Start Game") + } + +function button(r, g, b, buttonX, buttonY, buttonWidth, buttonHeight, buttonText) { + push() + fill(255, 0, 0) + rect(buttonX, buttonY, buttonWidth, buttonHeight, 20, 20, 20, 20) + textSize(25) + fill(r,g,b) + text(buttonText, buttonX+100, buttonY+30) + if (mouseX > buttonX-90 && mouseX < width/2+110 && mouseY > height/2 && mouseY < buttonY+40) { + if (mouseIsPressed) { + homescreenOn = false; + } + } + pop() +}