Workshop › Angry Birds-style Slingshot › Step 34 of 47

Score

What we are doing

Every pig or block that goes away (broken or knocked off the screen) scores: 500 for a pig, 100 for a block. The bird scores nothing.

```js
let score

  score = 0

  // Broken or fallen off the world: gone. Every pig and block that goes scores.
  bodies = bodies.filter((b) => {
    if (b.hp > 0 && b.x < canvas.width + 50 && b.x + b.w > -50) return true
    if (b === bird) bird = null
    else score += b.kind === 'pig' ? 500 : 100
```

What it means

Your turn

  1. Under let dragging write let score; in reset, under state = 'aiming', write score = 0.
  2. In step, update the comment above the filter and add the else score line under if (b === bird) bird = null.

Skills: Game states

All steps

  1. The sling
  2. Sky and ground
  3. Draw it again and again
  4. The aim: an angle and a pull
  5. A bird in the sling
  6. Pull the bird back
  7. The rubber band
  8. Aim with the arrow keys
  9. Bodies
  10. Launch!
  11. Move by the velocity
  12. Gravity
  13. Land on the ground
  14. Aiming or flying
  15. An empty sling in flight
  16. Gone off the screen
  17. Wait for calm
  18. The next bird
  19. See the path before you shoot
  20. From a point to an aim
  21. Grab the sling
  22. Drag and let go
  23. Wood and stone
  24. A level as data
  25. Push overlapping boxes apart
  26. Bounce by mass
  27. Every pair meets
  28. Friction
  29. Smaller steps
  30. Hit points
  31. Hard hits hurt
  32. Things break
  33. Pigs
  34. Score
  35. Show the score
  36. Cracks
  37. Three birds
  38. Count the birds
  39. Won or lost
  40. The end panel
  41. Play again
  42. Three levels of data
  43. Start any level
  44. On to the next level
  45. The best score
  46. The right words
  47. Build it yourself: the yellow bird