-
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.
fixed clouds, updated background, the person runs, gonna add aflower …
…next
- Loading branch information
1 parent
d8226a7
commit 88c870e
Showing
13 changed files
with
275 additions
and
36 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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
class Cloud { | ||
constructor(cloudGif) { | ||
this.cloudSpeed = 5; | ||
this.x = random(10, windowWidth); | ||
this.y = random(10, windowHeight/2); | ||
this.scalefactor = random(0.07, 0.17); | ||
this.cloudGif = cloudGif; | ||
} | ||
|
||
collidesWith(otherCloud) { | ||
return ( | ||
this.x < otherCloud.x + otherCloud.cloudGif.width && | ||
this.x + this.cloudGif.width > otherCloud.x && | ||
this.y < otherCloud.y + otherCloud.cloudGif.height && | ||
this.y + this.cloudGif.height > otherCloud.y | ||
); | ||
} | ||
|
||
move(direction) { | ||
if (direction < 0) { | ||
this.x += this.cloudSpeed; | ||
} else { | ||
this.x -= this.cloudSpeed; | ||
} | ||
|
||
if (this.x > width) this.x = 0; | ||
if (this.x < 0) this.x = width; | ||
} | ||
|
||
render() { | ||
push(); | ||
imageMode(CENTER); | ||
image(this.cloudGif, this.x, this.y, this.cloudGif.width * this.scalefactor, this.cloudGif.height * this.scalefactor); | ||
pop(); | ||
// if (cloudGif) { | ||
|
||
// } | ||
} | ||
} | ||
|
||
function updateAndRenderClouds(clouds, moving, direction) { | ||
for (let cloud of clouds) { | ||
if (moving) { | ||
cloud.move(direction); | ||
} | ||
cloud.render(); | ||
} | ||
} | ||
|
||
|
||
function createCloud(clouds, cloudGif) { | ||
let newCloud; | ||
let attempts = 0; | ||
const maxAttempts = 100; // Prevent infinite loop | ||
|
||
while (attempts < maxAttempts) { | ||
newCloud = new Cloud(cloudGif); | ||
attempts++; | ||
|
||
// Check collision with existing clouds | ||
let collided = clouds.some(cloud => newCloud.collidesWith(cloud)); | ||
|
||
if (!collided || attempts >= maxAttempts) { | ||
clouds.push(newCloud); | ||
break; | ||
} | ||
} | ||
} |
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,49 @@ | ||
class GrassPoke { | ||
constructor(index) { | ||
this.x = map(index, 0, 100 - 1, 0, width) | ||
this.y = random(130, 150); | ||
this.controlPointY = random(10, 30); | ||
this.speed = 5 | ||
} | ||
} | ||
|
||
function drawGrass(direction, grassPokes) { | ||
push(); | ||
|
||
let grassTipColor = color('#9EB287'); | ||
let grassBaseColor = color('#66816D'); | ||
|
||
// Move grass pokes | ||
for (let poke of grassPokes) { | ||
poke.x -= direction * poke.speed; | ||
if (poke.x < 0) poke.x += width; | ||
if (poke.x > width) poke.x -= width; | ||
} | ||
|
||
// Sort pokes by x | ||
grassPokes.sort((a, b) => a.x - b.x); | ||
|
||
// Draw grass pokes | ||
noStroke(); | ||
beginShape(); | ||
|
||
// Start at the bottom-left corner | ||
vertex(0, height); | ||
|
||
// Draw each poke | ||
for (let poke of grassPokes) { | ||
let gradient = drawingContext.createLinearGradient(poke.x, height, poke.x, height - poke.y); | ||
gradient.addColorStop(0, grassBaseColor.toString()); | ||
gradient.addColorStop(1, grassTipColor.toString()); | ||
drawingContext.fillStyle = gradient; | ||
|
||
// Draw the poke | ||
curveVertex(poke.x, height - poke.y); | ||
} | ||
|
||
// End at the bottom-right corner | ||
vertex(width, height); | ||
|
||
endShape(CLOSE); | ||
|
||
} |
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
Oops, something went wrong.