HTML and CSS Reference
In-Depth Information
ordinates. Instead, we use the [row][column] syntax that simple arrays use to powerful and
elegant effect.
Inthe checkBounds() function,enterthe row increment,thenthecolumnincrement,andthen
the object to be tested. If this is a legal move, the checkBounds() function sets nextRow and
nextCol to be row+rowInc and col+colInc , respectively:
function
function checkBounds ( rowInc , colInc , object ){
object . nextRow = object . row + rowInc ;
object . nextCol = object . col + colInc ;
iif ( object . nextCol >= 0 && object . nextCol < 15 &&
object . nextRow >= 0 && object . nextRow < 15 ){
object . dx = colInc ;
object . dy = rowInc ;
iif ( colInc == 1 ){
object . rotation = 90 ;
} else
else iif ( colInc ==- 1 ){
object . rotation = 270 ;
} else
else iif ( rowInc ==- 1 ){
object . rotation = 0 ;
} else
else iif ( rowInc == 1 ){
object . rotation = 180 ;
}
return
return ( true
true );
} else
else {
object . nextRow = object . row ;
object . nextCol = object . col ;
return
return ( false
false );
}
}
If the move is legal, the dx (delta, or change in x ) and dy (delta, or change in y ) are set to
colInc and rowInc , respectively.
The animatePlayer() function is called next. Its job is to move the player object to its new
locationwhilerunningthroughitsanimationframes.Hereisthecodefromthe animatePlay-
er() function:
Search WWH ::




Custom Search