بتل کد Battle Codeدارد باز می‌شود…

جواب «Everyone Falls» چالش 2 از جلسه‌ی 13

سؤال

سه ستاره داریم، ولی فقط اولی می‌افتد! با for (const s of stars) کاری کن که هر سه ستاره ثانیه‌ای ۱۰۰ پیکسل پایین بیایند.

راهنما

خط stars[0].y = ... را با این عوض کن:
for (const s of stars) { s.y = s.y + 100 * dt; }

یک جواب درست

<script>
  const ctx = salam.canvas(360, 480);
  const stars = [
    { x: 60, y: 0, w: 20, h: 20 },
    { x: 170, y: 40, w: 20, h: 20 },
    { x: 280, y: 80, w: 20, h: 20 },
  ];

  salam.loop(function (dt) {
    for (const s of stars) {
      s.y = s.y + 100 * dt;
    }

    ctx.fillStyle = "midnightblue";
    ctx.fillRect(0, 0, 360, 480);
    ctx.fillStyle = "gold";
    for (const s of stars) {
      ctx.fillRect(s.x, s.y, s.w, s.h);
    }
  });
</script>

اول خودت امتحان کن؛ جواب‌های دیگر هم قبول است. برگرد و خودت حلش کن