1
0
Fork 0

Game object tile mappings and tunnel colors are now part of the ClassicMap

master
Mike Gerwitz 2012-03-16 20:04:52 -04:00
parent e4f678919b
commit 6af5adddb8
3 changed files with 70 additions and 38 deletions

View File

@ -141,5 +141,43 @@ ltjs.ClassicMap = Class( 'ClassicMap' )
'public getDimensions': function() 'public getDimensions': function()
{ {
return [ 16, 16 ]; return [ 16, 16 ];
},
/**
* Retrieve map of object codes to their appropriate tiles
*
* @return {Array.<string>}
*/
'public getObjectTileMap': function()
{
// we return these values here instead of returning, say, a constant,
// because we would have to clone it to ensure that our inner state
// would not be altered
return [
'dirt', 'tup', 'base', 'water', 'block', 'mblock', 'brick',
'atup', 'atright', 'atdown', 'atleft', 'mirrorul', 'mirrorur',
'mirrordr', 'mirrordl', 'owup', 'owright', 'owdown', 'owleft',
'cblock', 'rmirrorul', 'rmirrorur', 'rmirrordr', 'rmirrordl',
'ice', 'thinice'
];
},
/**
* Retrieve tunnel colors
*
* These colors will be rendered in the background and will bleed through
* the transparent portions of the tile. We use explicit HEX codes rather
* than CSS color names because environments may vary the colors used.
*
* @return {Array.<string>}
*/
'public getTunnelColors': function()
{
return [
'#ff0000', '#00ff00', '#0000ff', '#00ffff', // r g b c
'#ffff00', '#ff00ff', '#ffffff', '#808080' // y m w b
];
} }
} ); } );

View File

@ -69,5 +69,27 @@ ltjs.Map = Interface( 'Map',
* *
* @return {Array.<number>} width and height in tiles * @return {Array.<number>} width and height in tiles
*/ */
'public getDimensions': [] 'public getDimensions': [],
/**
* Retrieve map of object codes to their appropriate tiles
*
* @return {Array.<string>}
*/
'public getObjectTileMap': [],
/**
* Retrieve tunnel colors
*
* These colors will be rendered in the background and will bleed through
* the transparent portions of the tile. A total of eight colors should be
* returned. They may be specified in any CSS format, but explicit values
* are recommended since color names (e.g. 'green') can vary between
* environments.
*
* @return {Array.<string>}
*/
'public getTunnelColors': []
} ); } );

View File

@ -54,38 +54,6 @@ ltjs.MapRender = Class( 'MapRender',
*/ */
'private _tiles': {}, 'private _tiles': {},
/**
* Maps each "game object" in the map to a tile id
* TODO: abstract
* @type {Array.<string>}
*/
'private _objMap': [
'dirt', 'tup', 'base', 'water', 'block', 'mblock', 'brick',
'atup', 'atright', 'atdown', 'atleft', 'mirrorul', 'mirrorur',
'mirrordr', 'mirrordl', 'owup', 'owright', 'owdown', 'owleft',
'cblock', 'rmirrorul', 'rmirrorur', 'rmirrordr', 'rmirrordl',
'ice', 'thinice'
],
/**
* Colors used to identify tunnels
*
* These colors will be rendered in the background and will bleed through
* the transparent portions of the tile. We use explicit HEX codes rather
* than CSS color names because environments may vary the colors used.
*
* Taken from ColorList in LTANK2.C in the original sources. Note that there
* is an endianness difference.
*
* TODO: abstract
*
* @type {Array.<string>}
*/
'private _tunnelColors': [
'#ff0000', '#00ff00', '#0000ff', '#00ffff', // r g b c
'#ffff00', '#ff00ff', '#ffffff', '#808080' // y m w b
],
/** /**
* Initialize renderer with a canvas context and a tile set * Initialize renderer with a canvas context and a tile set
@ -202,7 +170,9 @@ ltjs.MapRender = Class( 'MapRender',
var objs = map.getObjects(), var objs = map.getObjects(),
size = map.getDimensions(), size = map.getDimensions(),
i = objs.length, i = objs.length,
tiles = this._tiles, omap = map.getObjectTileMap(),
tunnel_colors = map.getTunnelColors(),
// get the width and height from one of the tiles // get the width and height from one of the tiles
t = this._tiles.dirt.data, t = this._tiles.dirt.data,
@ -214,14 +184,14 @@ ltjs.MapRender = Class( 'MapRender',
while ( i-- ) while ( i-- )
{ {
var oid = objs[ i ], var oid = objs[ i ],
tid = this._objMap[ oid ], tid = omap[ oid ],
x = ( Math.floor( i / size[ 0 ] ) * w ), x = ( Math.floor( i / size[ 0 ] ) * w ),
y = ( ( i % size[ 1 ] ) * h ); y = ( ( i % size[ 1 ] ) * h );
// tunnels are handled a bit differently than other objects // tunnels are handled a bit differently than other objects
if ( this._isTunnel( oid ) ) if ( this._isTunnel( oid ) )
{ {
this._renderTunnel( oid, x, y ); this._renderTunnel( oid, x, y, tunnel_colors );
continue; continue;
} }
@ -283,14 +253,16 @@ ltjs.MapRender = Class( 'MapRender',
* @param {number} x left position * @param {number} x left position
* @param {number} y top position * @param {number} y top position
* *
* @param {Array.<string>} colors tunnel colors
*
* @return {undefined} * @return {undefined}
*/ */
'private _renderTunnel': function( oid, x, y ) 'private _renderTunnel': function( oid, x, y, colors )
{ {
// get the tunnel id by stripping off the tunnel bitmask and grab the // get the tunnel id by stripping off the tunnel bitmask and grab the
// associated color // associated color
var tunnel_id = ( ( +oid ^ this.__self.$( '_TMASK' ) ) / 2 ), var tunnel_id = ( ( +oid ^ this.__self.$( '_TMASK' ) ) / 2 ),
color = this._tunnelColors[ tunnel_id ] || 'black', color = colors[ tunnel_id ] || 'black',
tdata = this._tiles.tunnel.data; tdata = this._tiles.tunnel.data;
// fill tile with the appropriate background color for this tile // fill tile with the appropriate background color for this tile