Faster Every Catch چالش 1 از جلسهی 15، آسان
ستاره را با لمس میگیری. کاری کن که با هر امتیاز، ستاره تندتر شود: بعد از گرفتن، speed = 100 + score * 20.
یعنی با امتیاز ۱ سرعت ۱۲۰ است، با ۲ سرعت ۱۴۰ و …
<script>
const ctx = salam.canvas(360, 480);
const star = { x: 160, y: 0, w: 40, h: 40 };
let score = 0;
let speed = 100;
salam.tap(function (x, y) {
if (salam.hit({ x: x, y: y, w: 1, h: 1 }, star)) {
score = score + 1;
star.y = 0;
}
});
salam.loop(function (dt) {
star.y = star.y + speed * dt;
if (star.y > 480) star.y = 0;
ctx.fillStyle = "midnightblue";
ctx.fillRect(0, 0, 360, 480);
ctx.fillStyle = "gold";
ctx.fillRect(star.x, star.y, star.w, star.h);
ctx.fillStyle = "white";
ctx.font = "20px sans-serif";
ctx.fillText("Score: " + score, 10, 30);
});
</script>
راهنما و جواب این چالش · برگشت به درس جلسهی 15: سطح سختی · چالش بعدی: Level 2
بیشتر بخوان: دیکشنری در پایتون: آموزش کامل کلید و مقدار با مثال