-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
i added the flower, the score is a bit buggy but need to fix - i also…
… about to add music and then a ending and start screen
- Loading branch information
1 parent
1a0913d
commit 04470cb
Showing
7 changed files
with
90 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
# norainnoflower | ||
Art 173 Game Design Midterm Project | ||
|
||
run python3 -m http.server to play locally | ||
play at http://localhost:8000/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.