xxxxxxxxxx
56
let player;
let blobs = [];
let score = 0;
let minScore = 0;
function setup() {
let cnv = createCanvas(800, 250);
cnv.parent('canvasContainer'); // Make sure to add this line if you have a container element in your HTML
player = new Player();
}
function keyPressed() {
if (keyCode === UP_ARROW) {
player.jump();
}
}
function draw() {
background(220);
score += .05;
fill(0, 102, 153);
textSize(30);
text(round(score), 10, 32);
player.show();
player.move();
if (random(1) < 0.03) {
if (score > minScore) {
blobs.push(new Blob());
minScore = score + 2 + random(1);
}
}
for (blob of blobs) {
blob.setSpeed(8 + sqrt(score) / 5);
blob.move();
blob.show();
if (player.hits(blob)) {
print("GAME OVER");
noLoop();
}
if (blob.getX() < -50) {
blobs.shift();
print("Removed");
}
}
}