If you're behind a web filter, please make sure that the domains *.kastatic.org and *.kasandbox.org are unblocked.

# 森林环境

``````draw = function() {
background(227, 254, 255);
fill(130, 79, 43);
rect(0, height*0.90, width, height*0.10);
// ...
}``````

``````var grassXs = [];
for (var i = 0; i < 25; i++) {
grassXs.push(i*20);
}``````

``````for (var i = 0; i < grassXs.length; i++) {
image(getImage("cute/GrassBlock"), grassXs[i], height*0.85, 20, 20);
}``````

``````for (var i = 0; i < grassXs.length; i++) {
image(getImage("cute/GrassBlock"), grassXs[i], height*0.85, 20, 20);
grassXs[i] -= 1;
}``````

``````for (var i = 0; i < grassXs.length; i++) {
image(getImage("cute/GrassBlock"), grassXs[i], height*0.85, 20, 20);
grassXs[i] -= 1;
if (grassXs[i] <= -20) {
grassXs[i] = width;
}
}``````

• 每一个木棍都有一个 xy 坐标。我们大概需要 x 坐标分布在一定范围内（可以是恒定的或在一定范围内随机的），然后我们需要 y 坐标随机分布在一定范围内，这样玩家就必须控制海狸的跳跃。
• 木棍应该看起来和草一起在移动，但它们 不应该 被循环使用。一旦一个木棍离开屏幕，它就应该永远消失。
• 每关应该有一些固定数量的木棍 -- 在某个时刻，木棍应该不再出现。

``````var Stick = function(x, y) {
this.x = x;
this.y = y;
};

Stick.prototype.draw = function() {
fill(89, 71, 0);
rect(this.x, this.y, 5, 40);
};``````

``````var sticks = [];
for (var i = 0; i < 40; i++) {
sticks.push(new Stick(i * 40 + 300, random(20, 260)));
}``````

``````for (var i = 0; i < sticks.length; i++) {
sticks[i].draw();
sticks[i].x -= 1;
}``````