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

A level as data

What we are doing

A level is just data: a list of rows [kind, x, y, width, height]. reset turns each row into a body with map. Two posts, a beam across them and a stone block.

```js
// The level: [kind, x, y, width, height], x and y the top left corner.
const LEVEL = [
  ['wood', 380, 230, 12, 60], ['wood', 440, 230, 12, 60], ['wood', 370, 218, 94, 12], ['stone', 480, 250, 40, 40],
]

  bodies = LEVEL.map(([kind, x, y, w, h]) => body(kind, x, y, w, h))
```

What it means

Your turn

  1. Under the MATERIALS block (after its }), write the comment and LEVEL.
  2. In reset, replace bodies = [] with the map line.

Skills: Arrays and objects

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