Workshop › Flappy-style Bird › Step 3 of 30
Draw the bird
What we are doing
The bird is a gold circle. We keep what we know about it (where it is, how big it is) in one object, bird, and
draw the circle from that object.
```js
let bird = { x: 100, y: 300, r: 14 }
ctx.fillStyle = 'gold'
ctx.beginPath()
ctx.arc(bird.x, bird.y, bird.r, 0, Math.PI * 2)
ctx.fill()
```
What it means
{ x: 100, y: 300, r: 14 } is an object: named values in one package. r is the radius.
let makes a variable whose value can change later: the bird will move.
- Canvas has no "fill a circle" command.
beginPath starts a new shape, arc describes a full circle around
(bird.x, bird.y), fill paints it.
- Angles are in radians: a full turn is
Math.PI * 2, not 360.
Your turn
- Under
const ctx = ..., leave an empty line and write the bird line.
- At the very end, leave an empty line and write the four circle lines. Press Run.
Skills: Drawing on a canvas, Game states
← Paint the sky A function that draws →
All steps
- Get the canvas and the pen
- Paint the sky
- Draw the bird
- A function that draws
- A function that moves
- The game loop
- Gravity
- A flap
- Space, Up arrow or a tap
- Wait for the first flap
- The ground and the sky
- Tell the player
- A pipe as data
- Draw the pipes
- The world moves, not the bird
- A new pipe at a random height
- A pipe every 90 frames
- Remove the pipes you passed
- Is the bird level with a pipe?
- Through the opening
- Score each pipe once
- Show the score
- A function for a fresh start
- Try again
- One place where the game ends
- Remember the best score
- Show the best score
- The same speed on every screen
- No catching up after a pause
- Build it yourself: a medal