A Pixel-Art Squirrel 🐿️ that lives in the Forest 🌳 and searches for Acorns 🌰. Written in P5JS using P5.Play
Squirrel: Elthen / Elthen on Patreon License: CC BY-NC 4.0 / Forest-Assets: Ansimuz License Acorn: Ansimuz License: CC0 Birds: "[LPC] Birds" by bluecarrot16, commissioned by castelonia. Licenses: CC BY 4.0 & CC BY 3.0 & CC BY-SA 4.0 & CC BY-SA 3.0 & GPL 3.0 & GPL 2.0 & OGA-BY 3.0
The Code is written in P5JS. It makes use of the P5.Play-Library. The P5.Play-Library opens up some cool possibilities, because it gives us an easy way to use the Planck Physics Engine! This is the Physics Engine used by other popular games, like Angry Birds!
- Generate the Background out of 3 different Forest-Tiles
- Generate the Ground out of Earth-Tiles
- Generate Moss out of 2 different Moss-Tiles
- Generate Plants
- Generate the Squirrel
- Generate Birds 🐦 out of 3 different Bird-Sprites
- When there are no Acorns, the Squirrel idles
- After some time, the regular Idle-Animation switches to a second Idle-Animation for a short while, and the Squirrel starts looking around
- If a Acorn drops from a Tree 🌳, the Squirrel will jump up!
- When the Acorn lies still, the Squirrel will run to it
- At the Acorn, there's an 80% Chance the Squirrel will eat it, and a 20 % Chance the Squirrel will bury it
- Yes, that Emoji is not an Acorn 🙄
- The Acorn is where the Planck Physics Engine comes into play!
- When generating the Acorn, several things happen:
- A random Sprite is picked, out of 3 different Acorn-Sprites
- A random Speed is given to the Acorn. It doesn't just drop on the floor in a straight line, it has a direction when it falls
- The Acorn will collide with the floor, and bounce off of it
- On the Ground, the Acorn will roll around a bit
- All these things are made possible by using the Planck Physics Engine which is used by P5.Play-Library
- The Forest consists of 3 different Tiles:
- Two repeating Background-Tiles (Back & Far)
- The third Tile (Middle) can be repeated, but we pick a random distance between them, to make the Forest look more natural
- Since we have 3 layered Background-Tiles, we use them to create a Parallax-Effect
- This Parallax-Effect creates an Illusion of depth, making the Forest look a bit "3D"
- There are 2 different Moss-Sprites and 1 Plant-Sprite
- We just scatter them around randomly on the Ground for some Eye-Candy
- Finally, there are 3 kinds of Birds 🐦 flying around
- These birds get generated on-the-fly
- Each time a Bird gets generated, a random Sprite gets picked out of a pool of 3 Sprites
- When a Bird is too far from the Squirrel 🐿️ (which is what the Camera is centered on) it gets removed and a new Bird gets generated
I also coded a Chicken Coop 🐔 using pure P5JS goodness.