HTML and CSS Reference
In-Depth Information
Classified intel
This is a special case since we have only two lanes.
It seems redundant to have three funcions: changeLane , moveToLeftLane ,
and moveToRightLane , for this simple task. This makes sense when we have
more than two lanes, where the move left and right logic can't be hardcoded anymore.
Determining a collision between the
player and tiles
In this task, we will determine the collision between the player and obstacles iles.
Prepare for lift off
We need an array to store the ile IDs (obstacles). Let's put the following code in the
setting.js ile:
game.BLOCKS = [100];
Engage thrusters
Let's add collision detecion with the following steps:
1. Inside the constructor of the Tile deiniion, we store a Boolean value
to determine whether this ile is an obstacle. Since most of the iles aren't
obstacles, we iniialize this variable with false :
this.isBlock = false;
for (var i = 0, len=game.BLOCKS.length; i < len; i++) {
if (type === game.BLOCKS[i]) {
this.isBlock = true;
}
};
2. The following code inside the moveDown funcion of a ile, checks whether
the ile collides with the player, when the ile itself is an obstacle:
if (this.isBlock) {
this.checkCollison();
}
 
Search WWH ::




Custom Search