Arrays
[1,2,3,4]
- Square brackets for arrays- Zero based indexing
.length
to get the number of elements- Demo - Create an array of words and display one at a time by mousePressed()
- Demo - Display multiple objects with an array and a for loop.
- Demo - Use mouse press to push() new objects onto the screen
Particles
- This is Motion 101
- Add velocity to location
- Draw object at location
- Demo - move a particle around with velocity and wrap it’s position around the canvas
- Add Acceleration
- Example: Gravity
- Example: Accelerate to mouse position
- Add lifespan
- Animate display attributes like alpha based off of lifespan
- Particle Emitter - to emit a collection of particles and create some kind of effect
Exercise - Velocity Particles Array
Utilizing arrays, make a sketch that creates a simple explosion explosion effect wherever the mouse is pressed.
Reference : Coding Math: Episode 8 - Velocity
Exercise Checklist
- [core] Everywhere the mouse clicked particles spawn and create a velocity based explosion effect.
- Create a Particle class in it’s own file with the ES6 syntax
- [core] Created an array of particles to update and draw.
Image/Sound Media
preload()
- Set images as the background
- Load and Display an Image
- Links to get some game art
- Play a Sound
- Tools to generate sound effects
Exercise - Space Ship
Utilizing p5.js sound library, create a physics based space ship with sound effects and images.
Reference : Coding Math: Episode 10 - Advanced Acceleration
Exercise Checklist
- [core] Image for the space ship
- [core] Implemented SFX for thrusting and teleporting across the screen.
- [core] Implemented background music.
- Created physics based space ship.
Make a simple game project together
Follow along as we try to recreate the following game :