diff --git a/.DS_Store b/.DS_Store index 306cbd0..81338d9 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/README.md b/README.md index 869bfaf..726cd1a 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,5 @@ # norainnoflower Art 173 Game Design Midterm Project + +run python3 -m http.server to play locally +play at http://localhost:8000/ \ No newline at end of file diff --git a/background/flower.js b/background/flower.js new file mode 100644 index 0000000..89a8592 --- /dev/null +++ b/background/flower.js @@ -0,0 +1,75 @@ +class Flower { + constructor(flowerGif) { + this.x = width + 50; + this.y = windowHeight/2 + this.flowerGif = flowerGif; + this.collected = false; + this.speed = 3; + } + + collidesWith(charX, charWidth) { + let flowerWidth = this.flowerGif.width * 0.5; + return ( + this.x < charX + charWidth && + this.x + flowerWidth > charX + ); + } + + move(direction) { + if (direction < 0) { + this.x += this.speed; + } else { + this.x -= this.speed; + } + } + + render() { + if (!this.collected) { + image(this.flowerGif, this.x, this.y, this.flowerGif.width * 0.1, this.flowerGif.height * 0.1); + } + } + + isOffScreen() { + return this.x < -50; // Check if flower has moved off-screen to the left + } +} + +let timeSinceLastFlower = 0; +let flowerInterval = 450; + +function updateAndRenderFlowers(rain, flowers, flowerGif, direction) { + if (!rain.isRaining) { + timeSinceLastFlower++ + + if (flowers.length === 0 && timeSinceLastFlower >= flowerInterval) { + flowers.push(new Flower(flowerGif)); + timeSinceLastFlower = 0 + flowerInterval = random(100, 240) + } + } + + for (let i = flowers.length - 1; i >= 0; i--) { + let flower = flowers[i]; + flower.move(direction); + flower.render(); + + // Remove flowers that have gone off-screen + if (flower.isOffScreen()) { + flowers.splice(i, 1); + } + } +} + +function updateScoreFlower(charX, charWidth) { + for (let i = flowers.length - 1; i >= 0; i--) { + if (flowers[i].collidesWith(charX, charWidth)) { + flowers.splice(i, 1); + flowers.collected = true + return score += 2; + } + else { + return score + } + } + return score +} \ No newline at end of file diff --git a/background/rain.js b/background/rain.js index f866971..b9dc231 100644 --- a/background/rain.js +++ b/background/rain.js @@ -57,12 +57,12 @@ function updateScoreRain(rain, charX, charWidth, showUmbrella, score, currentTim let collided = collidesWith(rain, charX, charWidth) if (showUmbrella) { - return score; // No score decrease if umbrella is shown + return score; } if (collided && rain.isRaining && !showUmbrella && currentTime - lastScoreDecrease >= scoreDecreaseInterval) { lastScoreDecrease = currentTime; - return Math.max(0, score - 1); // Ensure score doesn't go below 0 + return Math.max(0, score - 1); } else { return score diff --git a/index.html b/index.html index 4388800..be0e23f 100644 --- a/index.html +++ b/index.html @@ -10,6 +10,7 @@