Game Development Reference
In-Depth Information
If the left or right keys are pressed, we calculate the next rotation by multiplying the
player's velocity times the turnSpeed for the player. We add that to the rotation for
rotating right and subtract it for rotating left.
The render functions
The render process is broken up into two parts: rendering the screen ( drawCamera ) and rendering
the player car ( drawPlayer ).The render function simply calls these on order.
private function render():void {
drawCamera();
drawPlayer();
}
private function drawCamera():void {
//calculate starting tile position
if (player.move) {
camera.x = camera.nextX;
camera.y = camera.nextY;
}
//find starting tiles
var tileCol:int=int(camera.x/mapTileWidth);
var tileRow:int = int(camera.y / mapTileHeight);
var rowCtr:int=0;
var colCtr:int=0;
var tileNum:int;
//camera buffer is 1 tile larger (51 rows).
//For last tile row, make sure to only copy 50
//here we simply catch the exception
for (rowCtr = 0; rowCtr <= camera.rows; rowCtr++) {
if (rowCtr+tileRow == worldRows) break;
for (colCtr = 0; colCtr <= camera.cols; colCtr++) {
if (colCtr + tileCol ==worldCols ) break;
tileNum = world[rowCtr + tileRow][colCtr + tileCol];
tilePoint.x=colCtr*mapTileWidth;
tilePoint.y=rowCtr*mapTileHeight;
tileRect.x = int((tileNum % tileSheet.tilesPerRow))*mapTileWidth;
tileRect.y = int((tileNum / tileSheet.tilesPerRow)) * mapTileHeight;
camera.bufferBD.copyPixels(tileSheet.sourceBitmapData,
tileRect, tilePoint);
}
}
Search WWH ::




Custom Search