Workshop › Angry Birds-style Slingshot › Step 36 of 47
Cracks
What we are doing
A block that has lost more than half its hp shows a dark crack down its middle, so the player can see it is about to
break.
```js
ctx.fillRect(b.x, b.y, b.w, b.h)
// Cracks show how hurt a block is.
if (b.hp < m.hp / 2) {
ctx.fillStyle = 'rgba(0, 0, 0, 0.35)'
ctx.fillRect(b.x + b.w / 2 - 1, b.y, 2, b.h)
}
```
What it means
m.hp is the material's full hp, so b.hp < m.hp / 2 means "lost more than half".
- The crack is a 2-pixel, see-through black line down the middle, as tall as the block.
Your turn
In draw, under the block's ctx.fillRect(b.x, b.y, b.w, b.h) (inside else), write the crack lines.
Skills: Drawing on a canvas
← Show the score Three birds →
All steps
- The sling
- Sky and ground
- Draw it again and again
- The aim: an angle and a pull
- A bird in the sling
- Pull the bird back
- The rubber band
- Aim with the arrow keys
- Bodies
- Launch!
- Move by the velocity
- Gravity
- Land on the ground
- Aiming or flying
- An empty sling in flight
- Gone off the screen
- Wait for calm
- The next bird
- See the path before you shoot
- From a point to an aim
- Grab the sling
- Drag and let go
- Wood and stone
- A level as data
- Push overlapping boxes apart
- Bounce by mass
- Every pair meets
- Friction
- Smaller steps
- Hit points
- Hard hits hurt
- Things break
- Pigs
- Score
- Show the score
- Cracks
- Three birds
- Count the birds
- Won or lost
- The end panel
- Play again
- Three levels of data
- Start any level
- On to the next level
- The best score
- The right words
- Build it yourself: the yellow bird