This is a prototype game about a goose who has to keep the temperature right or else the world ends. I’m trying to add in more mechanics in but I really can’t move on because the lag gets worse the more you play. Is there anything I can reduce or simplify?
let gabHeatColor = 0;
let gabThermoStat = 30;
var gooseHonk;
let laserHue = 0;
//denaplesk2 game timer
let timerValue = 30;
let startButton;
let timerBar = 0; //will appear @ top screen
function preload() {
soundFormats('wav');
gooseHonk = loadSound('spacejoe_bird-honk-2.wav');
}
function mousePressed() { //plays goose honk
gooseHonk.play();
}
function setup() {
createCanvas(windowWidth, windowHeight);
// textAlign(CENTER);
setInterval(timeIt, 1000);
}
function timeIt() {
if (timerValue > 0) {
timerValue--;
}
}
function draw() {
// frameRate(20);
background(140, 140, 72);
strokeWeight(0);
fill(107, 94, 43); //floor background
rect(0, windowHeight/1.3, windowWidth, windowHeight);
fill(140, 213, 237); //window
rect(windowWidth/3, windowHeight/7, 200, 450);
//timer > winstate or gameover
fill(0);
if (timerValue <= 60) {
text(timerValue + " SECONDS", width / 3, height / 10);
} else {
text(timerValue + " SECONDS, You WIN!", width / 3, height / 10);
frameRate(0);
}
if (gabThermoStat > 100) {
gabThermoStat = 999;
text("oops world heated", 50, 50);
text("Oh no SECONDS, You LOSE!", width / 3, height / 10);
} if (gabThermoStat <= 0) {
gabThermoStat = -99;
textSize(windowWidth/20);
text("oops world frozen", 50, 50);
text("NO SECONDS, You LOSE!", width / 3, height / 10);
frameRate(2);
}
gabFan();
gabGooseBod();
}
function gabGooseBod() {
push(); //goose neck
stroke(240);
strokeWeight(30);
line(0, windowHeight, mouseX-(mouseX/2), mouseY-25);
pop();
fill(240); //goose torso
circle(0, windowHeight, 300);
fill(300); //gooseHead
rect(mouseX-(mouseX/2), mouseY-25, 50, 50);
circle(mouseX-(mouseX/2), mouseY-25, 100);
fill(0);
circle(mouseX-(mouseX/2), mouseY-25, 40); //eye
fill(255,166,0);
circle(mouseX-(mouseX/2)+50, mouseY, 50); //goose bill & mouth
fill(300,0,0,laserHue);
rect(mouseX-(mouseX/2), mouseY-40, mouseX-(mouseX/2), 30);
if (mouseIsPressed === true) {
laserHue = laserHue + 40;
} else {
laserHue = 0;
}
}
function gabFan() {
fill(220);
rect(windowWidth/2,windowWidth/2,windowWidth/2,windowHeight/2);
fill(0);
textSize(windowWidth/20);
text("Thermostat: " + gabThermoStat + "/100", windowWidth/2+25, windowHeight/2)
gabThermoStat = gabThermoStat + 1;
let button0 = createButton("-1"); //heats up
// button.mouseClicked(fanButton[0]);
button0.size(90, 70);
button0.position(windowWidth/2, windowHeight/2);
button0.style("font-size", "48px");
let button3 = createButton("3"); //3 button
button3.mousePressed(fanButton);
print(button3.mousePressed(fanButton));
button3.size(90, 70);
button3.position(windowWidth/2, windowHeight/2 + 70);
button3.style("font-size", "48px");
let button2 = createButton("2"); //2 button
// button.mouseClicked(fanButton[1]);
button2.size(90, 70);
button2.position(windowWidth/2, windowHeight/2 + 140);
button2.style("font-size", "48px");
let button1 = createButton("1"); //1 button
// button.mouseClicked(fanButton[2]);
button1.size(90, 70);
button1.position(windowWidth/2, windowHeight/2 + 210);
button1.style("font-size", "48px");
}
function fanButton() {
gabThermoStat = gabThermoStat - 20;
print("-20, temp lowered");
}
I was thinking it was the timer slowing things down but the lag still happened. Then maybe it could be the goose’s neck? Nope not that.