From 3ec25aac82ade42db23b7a140a91792ab9e2d390 Mon Sep 17 00:00:00 2001 From: Subarked <68792391+Subarked@users.noreply.github.com> Date: Tue, 12 Oct 2021 12:56:01 -0500 Subject: [PATCH] Add the ability to pause the game --- virus/virus.pde | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/virus/virus.pde b/virus/virus.pde index 9a463c0..4e34680 100644 --- a/virus/virus.pde +++ b/virus/virus.pde @@ -398,8 +398,8 @@ void drawUI(){ fill(255); textFont(font,48); textAlign(LEFT); - text(framesToTime(frameCount)+" start",25,60); - text(framesToTime(frameCount-lastEditTimeStamp)+" edit",25,108); + text(framesToTime(framesPaused(frameCount))+" start",25,60); + text(framesToTime(framesPaused(frameCount)-lastEditTimeStamp)+" edit",25,108); textFont(font,36); text("Healthy: "+cellCounts[0]+" / "+START_LIVING_COUNT,360,50); text("Tampered: "+cellCounts[1]+" / "+START_LIVING_COUNT,360,90); @@ -712,3 +712,31 @@ int[] stringToInfo(String str){ } return info; } +double framePaused = 0; +double framesPaused = 0; +double frameLastCalled = 0; +boolean isPaused = false; +double framesPaused(double f) { + + if (isPaused == true) { + framesPaused += f-frameLastCalled; + } + frameLastCalled = f; + return f-framesPaused; +} +float UNPAUSED_PLAY_SPEED = PLAY_SPEED; +void keyPressed() { + if (key == ' ') { + if (isPaused == false) { + framePaused = frameCount; + + PLAY_SPEED = 0; + isPaused = true; + } else { + framePaused = 0; + PLAY_SPEED = UNPAUSED_PLAY_SPEED; + isPaused = false; + + } + } +}