Build combined lasertank.js
This does something that could not be done trivally back when this project started: concatenate all files, which are written as CommonJS modules. I had to write custom code to do this with other projects; Browserify was but an infant back in the day, and I remember SubStack talking about it on freenode.master
parent
2f1967a902
commit
d856fbb957
|
@ -17,3 +17,7 @@
|
|||
|
||||
# npm
|
||||
/node_modules
|
||||
|
||||
#build
|
||||
/lasertank.js
|
||||
|
||||
|
|
|
@ -21,14 +21,18 @@
|
|||
namespaces=$(shell find src -type d)
|
||||
nsindex=$(addsuffix /index.js, $(namespaces))
|
||||
|
||||
.PHONY: FORCE
|
||||
.PHONY: FORCE modindex standalone
|
||||
|
||||
all-am: modindex
|
||||
all-am: standalone
|
||||
|
||||
modindex: $(nsindex)
|
||||
%/index.js: FORCE
|
||||
./build-aux/gen-index "$*" > "$@"
|
||||
|
||||
standalone: lasertank.js
|
||||
lasertank.js: modindex
|
||||
./node_modules/.bin/browserify -s lasertank --debug src/index.js > "$@"
|
||||
|
||||
test: check
|
||||
check:
|
||||
@PATH="$(PATH):$(CURDIR)/node_modules/mocha/bin" \
|
||||
|
|
25
index.html
25
index.html
|
@ -119,31 +119,8 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<!-- these will be concatenated and minified at some point -->
|
||||
<script src="scripts/ease.js"></script>
|
||||
<script src="lasertank.js"></script>
|
||||
<script src="scripts/main.js"></script>
|
||||
<script src="src/TileDfn.js"></script>
|
||||
<script src="src/ClassicTileDfn.js"></script>
|
||||
<script src="src/LtgLoader.js"></script>
|
||||
<script src="src/TileMasker.js"></script>
|
||||
|
||||
<script src="src/MapSet.js"></script>
|
||||
<script src="src/Map.js"></script>
|
||||
<script src="src/MapState.js"></script>
|
||||
<script src="src/MapBounds.js"></script>
|
||||
<script src="src/GameObjectFactory.js"></script>
|
||||
<script src="src/ClassicGameObjectFactory.js"></script>
|
||||
<script src="src/ClassicMap.js"></script>
|
||||
<script src="src/MapRender.js"></script>
|
||||
<script src="src/MapAction.js"></script>
|
||||
|
||||
<script src="src/gameobjs/GameObject.js"></script>
|
||||
<script src="src/gameobjs/Tank.js"></script>
|
||||
|
||||
<script src="src/FileLoader.js"></script>
|
||||
<script src="src/Game.js"></script>
|
||||
<script src="src/ClassicGame.js"></script>
|
||||
<script src="src/ui/MenuBar.js"></script>
|
||||
<script src="scripts/game.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -19,7 +19,8 @@
|
|||
},
|
||||
"devDependencies": {
|
||||
"chai": ">=1.9.1",
|
||||
"mocha": ">=1.18.2"
|
||||
"mocha": ">=1.18.2",
|
||||
"browserify": "~12"
|
||||
},
|
||||
|
||||
"licenses": [
|
||||
|
|
4987
scripts/ease.js
4987
scripts/ease.js
File diff suppressed because it is too large
Load Diff
|
@ -20,10 +20,10 @@
|
|||
( function()
|
||||
{
|
||||
|
||||
var load_ltg = ltjs.FileLoader( document.getElementById( 'ltg' ) ),
|
||||
load_lvl = ltjs.FileLoader( document.getElementById( 'lvl' ) ),
|
||||
var load_ltg = lasertank.FileLoader( document.getElementById( 'ltg' ) ),
|
||||
load_lvl = lasertank.FileLoader( document.getElementById( 'lvl' ) ),
|
||||
|
||||
menu_bar = ltjs.ui.MenuBar( document.getElementById( 'menubar' ) ),
|
||||
menu_bar = lasertank.ui.MenuBar( document.getElementById( 'menubar' ) ),
|
||||
|
||||
ele_game = document.getElementById( 'game' ),
|
||||
ctx = document.getElementById( 'render' ).getContext( '2d' ),
|
||||
|
@ -55,7 +55,7 @@ function gamechk()
|
|||
// temporary
|
||||
if ( ele_game.className.search( 'opening' ) > -1 ) return;
|
||||
|
||||
ltjs.ClassicGame( ltg_data, lvl_data )
|
||||
lasertank.ClassicGame( ltg_data, lvl_data )
|
||||
.on( 'ready', function()
|
||||
{
|
||||
this.renderTo( ctx );
|
||||
|
|
|
@ -17,9 +17,5 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
window.ltjs = { ui: {}, gameobjs: { classic: {} } };
|
||||
window.Class = easejs.Class;
|
||||
window.Interface = easejs.Interface;
|
||||
|
||||
// alert the user on all uncaught errors
|
||||
window.onerror = alert;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Interface representing a facade for a game type
|
||||
*
|
||||
* Copyright (C) 2012 Mike Gerwitz
|
||||
* Copyright (C) 2012, 2015 Mike Gerwitz
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -18,22 +18,34 @@
|
|||
*/
|
||||
|
||||
|
||||
var Class = require( 'easejs' ).Class,
|
||||
Game = require( './Game' ),
|
||||
ClassicGameObjectFactory = require( './ClassicGameObjectFactory' ),
|
||||
ClassicMap = require( './ClassicMap' ),
|
||||
ClassicTileDfn = require( './ClassicTileDfn' ),
|
||||
LtgLoader = require( './LtgLoader' ),
|
||||
MapBounds = require( './MapBounds' ),
|
||||
MapRender = require( './MapRender' ),
|
||||
MapSet = require( './MapSet' ),
|
||||
MapState = require( './MapState' ),
|
||||
TileMasker = require( './TileMasker' );
|
||||
|
||||
/**
|
||||
* Facade for the classic (original) game of LaserTank
|
||||
*/
|
||||
ltjs.ClassicGame = Class( 'ClassicGame' )
|
||||
.implement( ltjs.Game )
|
||||
module.exports = Class( 'ClassicGame' )
|
||||
.implement( Game )
|
||||
.extend(
|
||||
{
|
||||
/**
|
||||
* LTG loader
|
||||
* @type {ltjs.LtgLoader}
|
||||
* @type {LtgLoader}
|
||||
*/
|
||||
'private _ltgLoader': null,
|
||||
|
||||
/**
|
||||
* Tile masker
|
||||
* @type {ltjs.TileMasker}
|
||||
* @type {TileMasker}
|
||||
*/
|
||||
'private _masker': null,
|
||||
|
||||
|
@ -45,7 +57,7 @@ ltjs.ClassicGame = Class( 'ClassicGame' )
|
|||
|
||||
/**
|
||||
* Set of available maps
|
||||
* @type {ltjs.MapSet}
|
||||
* @type {MapSet}
|
||||
*/
|
||||
'private _mapSet': null,
|
||||
|
||||
|
@ -57,13 +69,13 @@ ltjs.ClassicGame = Class( 'ClassicGame' )
|
|||
|
||||
/**
|
||||
* Performs map rendering
|
||||
* @type {ltjs.MapRender}
|
||||
* @type {MapRender}
|
||||
*/
|
||||
'private _render': null,
|
||||
|
||||
/**
|
||||
* Classic game object factory
|
||||
* @type {ltjs.ClassicGameObjectFactory}
|
||||
* @type {ClassicGameObjectFactory}
|
||||
*/
|
||||
'private _gameObjFactory': null,
|
||||
|
||||
|
@ -82,10 +94,10 @@ ltjs.ClassicGame = Class( 'ClassicGame' )
|
|||
{
|
||||
var _self = this;
|
||||
|
||||
this._ltgLoader = ltjs.LtgLoader();
|
||||
this._masker = ltjs.TileMasker( ltjs.ClassicTileDfn() );
|
||||
this._ltgLoader = LtgLoader();
|
||||
this._masker = TileMasker( ClassicTileDfn() );
|
||||
|
||||
this._gameObjFactory = ltjs.ClassicGameObjectFactory();
|
||||
this._gameObjFactory = ClassicGameObjectFactory();
|
||||
|
||||
// load initial tile and map data from the LTG and LVL data
|
||||
this.setTileData( ltg_data, function()
|
||||
|
@ -116,11 +128,11 @@ ltjs.ClassicGame = Class( 'ClassicGame' )
|
|||
}
|
||||
|
||||
var map = this._mapSet.getMapByNumber( 1 ),
|
||||
map_state = ltjs.MapState( map, this._gameObjFactory ),
|
||||
bounds = ltjs.MapBounds( map );
|
||||
map_state = MapState( map, this._gameObjFactory ),
|
||||
bounds = MapBounds( map );
|
||||
|
||||
// render the first map (hardcoded for now)
|
||||
this._render = ltjs.MapRender( ctx, this._tileSet )
|
||||
this._render = MapRender( ctx, this._tileSet )
|
||||
.render( map, map_state );
|
||||
|
||||
// POC
|
||||
|
@ -182,7 +194,7 @@ ltjs.ClassicGame = Class( 'ClassicGame' )
|
|||
*/
|
||||
'public setMapData': function( data, callback )
|
||||
{
|
||||
this._mapSet = ltjs.MapSet( data, ltjs.ClassicMap );
|
||||
this._mapSet = MapSet( data, ClassicMap );
|
||||
|
||||
callback.call( this.__inst );
|
||||
return this;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Creates game objects for the classic game
|
||||
*
|
||||
* Copyright (C) 2012 Mike Gerwitz
|
||||
* Copyright (C) 2012, 2015 Mike Gerwitz
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -17,9 +17,14 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
var Class = require( 'easejs' ).Class,
|
||||
GameObjectFactory = require( './GameObjectFactory' ),
|
||||
GameObject = require( './gameobjs/GameObject' ),
|
||||
Tank = require( './gameobjs/Tank' );
|
||||
|
||||
ltjs.ClassicGameObjectFactory = Class( 'ClassicGameObjectFactory' )
|
||||
.implement( ltjs.GameObjectFactory )
|
||||
|
||||
module.exports = Class( 'ClassicGameObjectFactory' )
|
||||
.implement( GameObjectFactory )
|
||||
.extend(
|
||||
{
|
||||
'private _objs': {},
|
||||
|
@ -33,14 +38,12 @@ ltjs.ClassicGameObjectFactory = Class( 'ClassicGameObjectFactory' )
|
|||
|
||||
'public createObject': function( id )
|
||||
{
|
||||
return ( this._objs[ id ] || ltjs.gameobjs.GameObject )( id );
|
||||
return ( this._objs[ id ] || GameObject )( id );
|
||||
},
|
||||
|
||||
|
||||
'private _initObjs': function()
|
||||
{
|
||||
var o = ltjs.gameobjs;
|
||||
|
||||
this._objs = {
|
||||
dirt: null,
|
||||
base: null,
|
||||
|
@ -49,10 +52,10 @@ ltjs.ClassicGameObjectFactory = Class( 'ClassicGameObjectFactory' )
|
|||
mblock: null,
|
||||
brick: null,
|
||||
|
||||
tup: o.Tank,
|
||||
tright: o.Tank,
|
||||
tdown: o.Tank,
|
||||
tleft: o.Tank,
|
||||
tup: Tank,
|
||||
tright: Tank,
|
||||
tdown: Tank,
|
||||
tleft: Tank,
|
||||
|
||||
atup: null,
|
||||
atright: null,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Represents a classic map (level)
|
||||
*
|
||||
* Copyright (C) 2012 Mike Gerwitz
|
||||
* Copyright (C) 2012, 2015 Mike Gerwitz
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -40,14 +40,17 @@
|
|||
* display.
|
||||
*/
|
||||
|
||||
var Class = require( 'easejs' ).Class,
|
||||
Map = require( './Map' );
|
||||
|
||||
|
||||
/**
|
||||
* Represents a classic map, as they exist in the original game.
|
||||
*
|
||||
* Classic maps are 16x16 tiles in size (for a total of 256 tiles).
|
||||
*/
|
||||
ltjs.ClassicMap = Class( 'ClassicMap' )
|
||||
.implement( ltjs.Map )
|
||||
module.exports = Class( 'ClassicMap' )
|
||||
.implement( Map )
|
||||
.extend(
|
||||
{
|
||||
/**
|
||||
|
@ -139,7 +142,7 @@ ltjs.ClassicMap = Class( 'ClassicMap' )
|
|||
/**
|
||||
* Initialize map with map data and the given id
|
||||
*
|
||||
* @param {ltjs.MapSet} set map set data
|
||||
* @param {MapSet} set map set data
|
||||
* @param {number} id 1-indexed map id
|
||||
*/
|
||||
__construct: function( data, id )
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Contains tile definition for classic (original game) tile sets
|
||||
*
|
||||
* Copyright (C) 2012 Mike Gerwitz
|
||||
* Copyright (C) 2012, 2015 Mike Gerwitz
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -17,12 +17,15 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
var Class = require( 'easejs' ).Class,
|
||||
TileDfn = require( './TileDfn' );
|
||||
|
||||
|
||||
/**
|
||||
* Definition for classic tile sets found in the original game
|
||||
*/
|
||||
ltjs.ClassicTileDfn = Class( 'ClassicTileDfn' )
|
||||
.implement( ltjs.TileDfn )
|
||||
module.exports = Class( 'ClassicTileDfn' )
|
||||
.implement( TileDfn )
|
||||
.extend(
|
||||
{
|
||||
/**
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Loads a file from disk and returns a binary string
|
||||
*
|
||||
* Copyright (C) 2012 Mike Gerwitz
|
||||
* Copyright (C) 2012, 2015 Mike Gerwitz
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -21,6 +21,8 @@
|
|||
* specs, as it depends on FileReader.
|
||||
*/
|
||||
|
||||
var Class = require( 'easejs' ).Class;
|
||||
|
||||
|
||||
/**
|
||||
* Load file into memory as binary string from a given file element
|
||||
|
@ -28,7 +30,7 @@
|
|||
* This class handles the loading of only a single file (as that is all this
|
||||
* project requires).
|
||||
*/
|
||||
ltjs.FileLoader = Class( 'FileLoader',
|
||||
module.exports = Class( 'FileLoader',
|
||||
{
|
||||
/**
|
||||
* DOM file element to watch
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Interface representing a facade for a game type
|
||||
*
|
||||
* Copyright (C) 2012 Mike Gerwitz
|
||||
* Copyright (C) 2012, 2015 Mike Gerwitz
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -17,6 +17,8 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
var Interface = require( 'easejs' ).Interface;
|
||||
|
||||
|
||||
/**
|
||||
* Represents a game type
|
||||
|
@ -24,7 +26,7 @@
|
|||
* The facade should perform all necessary loading for support of a specific
|
||||
* type of game play. All DOM elements should be injected.
|
||||
*/
|
||||
ltjs.Game = Interface( 'Game',
|
||||
module.exports = Interface( 'Game',
|
||||
{
|
||||
/**
|
||||
* Render to the given 2d canvas context
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Interface for handling game object creation
|
||||
*
|
||||
* Copyright (C) 2012 Mike Gerwitz
|
||||
* Copyright (C) 2012, 2015 Mike Gerwitz
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -17,7 +17,9 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
var Interface = require( 'easejs' ).Interface;
|
||||
|
||||
ltjs.GameObjectFactory = Interface( 'GameObjectFactory',
|
||||
|
||||
module.exports = Interface( 'GameObjectFactory',
|
||||
{
|
||||
} );
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Handles the loading of LTG files
|
||||
*
|
||||
* Copyright (C) 2012 Mike Gerwitz
|
||||
* Copyright (C) 2012, 2015 Mike Gerwitz
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -42,11 +42,13 @@
|
|||
* identify the file as a bitmap image.)
|
||||
*/
|
||||
|
||||
var Class = require( 'easejs' ).Class;
|
||||
|
||||
|
||||
/**
|
||||
* Loads tiles and metadata from LTG files
|
||||
*/
|
||||
ltjs.LtgLoader = Class( 'LtgLoader',
|
||||
module.exports = Class( 'LtgLoader',
|
||||
{
|
||||
/** various data segment byte offsets and lengths **/
|
||||
'private const _POS_NAME': [ 0, 40 ],
|
||||
|
|
10
src/Map.js
10
src/Map.js
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Represents a map (level)
|
||||
*
|
||||
* Copyright (C) 2012 Mike Gerwitz
|
||||
* Copyright (C) 2012, 2015 Mike Gerwitz
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -29,6 +29,8 @@
|
|||
* tunnel identified by index 0 is 0x40, index 1 is 0x42, and so on.
|
||||
*/
|
||||
|
||||
var Interface = require( 'easejs' ).Interface;
|
||||
|
||||
|
||||
/**
|
||||
* Represents a map (level)
|
||||
|
@ -40,13 +42,13 @@
|
|||
* Note that this interface specifies a constructor definition; this allows it
|
||||
* to be used in place of a separate Factory class.
|
||||
*/
|
||||
ltjs.Map = Interface( 'Map',
|
||||
module.exports = Interface( 'Map',
|
||||
{
|
||||
/**
|
||||
* Initialize map with map data and the given id
|
||||
*
|
||||
* @param {ltjs.MapSet} set map set data
|
||||
* @param {number} id 1-indexed map id
|
||||
* @param {MapSet} set map set data
|
||||
* @param {number} id 1-indexed map id
|
||||
*/
|
||||
__construct: [ 'set', 'id' ],
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Represents an action being performed on a game object
|
||||
*
|
||||
* Copyright (C) 2012 Mike Gerwitz
|
||||
* Copyright (C) 2012, 2015 Mike Gerwitz
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -17,7 +17,11 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
ltjs.MapAction = Class( 'MapAction',
|
||||
var Class = require( 'easejs' ).Class,
|
||||
MapBounds = require( './MapBounds' );
|
||||
|
||||
|
||||
module.exports = Class( 'MapAction',
|
||||
{
|
||||
// arranged by keycode
|
||||
'const D__MIN': 0,
|
||||
|
@ -39,7 +43,7 @@ ltjs.MapAction = Class( 'MapAction',
|
|||
|
||||
__construct: function( bounds, move_callback )
|
||||
{
|
||||
if ( !( Class.isA( ltjs.MapBounds, bounds ) ) )
|
||||
if ( !( Class.isA( MapBounds, bounds ) ) )
|
||||
{
|
||||
throw TypeError( 'Invalid MapBounds provided' );
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Handles map boundaries for collision detection and movement
|
||||
*
|
||||
* Copyright (C) 2012 Mike Gerwitz
|
||||
* Copyright (C) 2012, 2015 Mike Gerwitz
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -17,6 +17,9 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
var Class = require( 'easejs' ).Class,
|
||||
Map = require( './Map' );
|
||||
|
||||
|
||||
/**
|
||||
* Calculates map bounding box
|
||||
|
@ -24,7 +27,7 @@
|
|||
* This simply encapsulates the process of determining whether a given position
|
||||
* is against an edge of the map.
|
||||
*/
|
||||
ltjs.MapBounds = Class( 'MapBounds',
|
||||
module.exports = Class( 'MapBounds',
|
||||
{
|
||||
/**
|
||||
* Map width (number of tiles)
|
||||
|
@ -46,7 +49,7 @@ ltjs.MapBounds = Class( 'MapBounds',
|
|||
*/
|
||||
__construct: function( map )
|
||||
{
|
||||
if ( !( Class.isA( ltjs.Map, map ) ) )
|
||||
if ( !( Class.isA( Map, map ) ) )
|
||||
{
|
||||
throw TypeError( 'Invalid Map provided' );
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Renders a given map
|
||||
*
|
||||
* Copyright (C) 2012 Mike Gerwitz
|
||||
* Copyright (C) 2012, 2015 Mike Gerwitz
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -17,11 +17,14 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
var Class = require( 'easejs' ).Class,
|
||||
MapState = require( './MapState' );
|
||||
|
||||
|
||||
/**
|
||||
* Renders a map to a canvas
|
||||
*/
|
||||
ltjs.MapRender = Class( 'MapRender',
|
||||
module.exports = Class( 'MapRender',
|
||||
{
|
||||
/**
|
||||
* Property to hold lock bit on canvas element
|
||||
|
@ -171,7 +174,7 @@ ltjs.MapRender = Class( 'MapRender',
|
|||
*/
|
||||
'public render': function( map, map_state )
|
||||
{
|
||||
if ( !( Class.isA( ltjs.MapState, map_state ) ) )
|
||||
if ( !( Class.isA( MapState, map_state ) ) )
|
||||
{
|
||||
throw TypeError( 'Invalid MapState provided' );
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Handles the loading of LVL files
|
||||
*
|
||||
* Copyright (C) 2012 Mike Gerwitz
|
||||
* Copyright (C) 2012, 2015 Mike Gerwitz
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -21,6 +21,9 @@
|
|||
* file.
|
||||
*/
|
||||
|
||||
var Class = require( 'easejs' ).Class;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Handles delegation of LVL data
|
||||
|
@ -29,7 +32,7 @@
|
|||
* Map instance. Consequently, any custom map format would be supported,
|
||||
* provided that the appropriate Map is handling it.
|
||||
*/
|
||||
ltjs.MapSet = Class( 'MapSet',
|
||||
module.exports = Class( 'MapSet',
|
||||
{
|
||||
/**
|
||||
* Raw level set data (binary)
|
||||
|
@ -55,8 +58,8 @@ ltjs.MapSet = Class( 'MapSet',
|
|||
*
|
||||
* The Map constructor is used in place of a separate Map factory.
|
||||
*
|
||||
* @param {string} data binary LVL data
|
||||
* @param {ltjs.Map} map_ctor Map constructor
|
||||
* @param {string} data binary LVL data
|
||||
* @param {Map} map_ctor Map constructor
|
||||
*/
|
||||
__construct: function( data, map_ctor )
|
||||
{
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Represents the current state of a map
|
||||
*
|
||||
* Copyright (C) 2012 Mike Gerwitz
|
||||
* Copyright (C) 2012, 2015 Mike Gerwitz
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -17,15 +17,20 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
var Class = require( 'easejs' ).Class,
|
||||
MapAction = require( './MapAction' ),
|
||||
GameObjectFactory = require( './GameObjectFactory' ),
|
||||
GameObject = require( './gameobjs/GameObject' );
|
||||
|
||||
|
||||
/**
|
||||
* Represents the current state of a map
|
||||
*/
|
||||
ltjs.MapState = Class( 'MapState',
|
||||
module.exports = Class( 'MapState',
|
||||
{
|
||||
/**
|
||||
* Game object factory
|
||||
* @type {ltjs.GameObjectFactory}
|
||||
* @type {GameObjectFactory}
|
||||
*/
|
||||
'private _objFactory': null,
|
||||
|
||||
|
@ -66,7 +71,7 @@ ltjs.MapState = Class( 'MapState',
|
|||
*/
|
||||
__construct: function( map, obj_factory )
|
||||
{
|
||||
if ( !( Class.isA( ltjs.GameObjectFactory, obj_factory ) ) )
|
||||
if ( !( Class.isA( GameObjectFactory, obj_factory ) ) )
|
||||
{
|
||||
throw TypeError( 'Invalid GameObjectFactory provided' );
|
||||
}
|
||||
|
@ -304,7 +309,7 @@ ltjs.MapState = Class( 'MapState',
|
|||
{
|
||||
throw Error( "Invalid tile position: " + pos );
|
||||
}
|
||||
if ( !( Class.isA( ltjs.gameobjs.GameObject, newobj )
|
||||
if ( !( Class.isA( GameObject, newobj )
|
||||
|| ( newobj === null )
|
||||
) )
|
||||
{
|
||||
|
@ -522,7 +527,7 @@ ltjs.MapState = Class( 'MapState',
|
|||
player = this._player;
|
||||
|
||||
// XXX: tightly coupled
|
||||
var action = ltjs.MapAction(
|
||||
var action = MapAction(
|
||||
bounds,
|
||||
this._createMoveCallback( player, this._playerPos, function( pos )
|
||||
{
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Contains tile definition interface
|
||||
*
|
||||
* Copyright (C) 2012 Mike Gerwitz
|
||||
* Copyright (C) 2012, 2015 Mike Gerwitz
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -75,6 +75,8 @@
|
|||
* thinice - thin ice
|
||||
*/
|
||||
|
||||
var Interface = require( 'easejs' ).Interface;
|
||||
|
||||
|
||||
/**
|
||||
* Defines the contents of a tile set
|
||||
|
@ -83,7 +85,7 @@
|
|||
* containing individual tiles (of width w and height h) such that W % w === 0
|
||||
* and H % h === 0. All tiles are expected to share the same dimensions.
|
||||
*/
|
||||
ltjs.TileDfn = Interface( 'TileDfn',
|
||||
module.exports = Interface( 'TileDfn',
|
||||
{
|
||||
/**
|
||||
* Retrieve the tile definition
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Handles the masking of tile sets
|
||||
*
|
||||
* Copyright (C) 2012 Mike Gerwitz
|
||||
* Copyright (C) 2012, 2015 Mike Gerwitz
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -63,10 +63,13 @@
|
|||
* rendering.
|
||||
*/
|
||||
|
||||
var Class = require( 'easejs' ).Class,
|
||||
TileDfn = require( './TileDfn' );
|
||||
|
||||
/**
|
||||
* Slices tiles and applies masks
|
||||
*/
|
||||
ltjs.TileMasker = Class( 'TileMasker',
|
||||
module.exports = Class( 'TileMasker',
|
||||
{
|
||||
/**
|
||||
* Canvas 2D context (used for masking and tile slicing)
|
||||
|
@ -118,11 +121,11 @@ ltjs.TileMasker = Class( 'TileMasker',
|
|||
* allows us to support *any* type of tile set -- not just those that are
|
||||
* defined by the original game.
|
||||
*
|
||||
* @param {ltjs.TileDfn} tile_dfn tile definition object
|
||||
* @param {TileDfn} tile_dfn tile definition object
|
||||
*/
|
||||
__construct: function( tile_dfn )
|
||||
{
|
||||
if ( !( Class.isA( ltjs.TileDfn, tile_dfn ) ) )
|
||||
if ( !( Class.isA( TileDfn, tile_dfn ) ) )
|
||||
{
|
||||
throw TypeError( "Invalid tile definition provided." );
|
||||
}
|
||||
|
@ -151,7 +154,7 @@ ltjs.TileMasker = Class( 'TileMasker',
|
|||
* unwise to continuously invoke methods unnecessarily (who knows what the
|
||||
* developer of the given tile definition did!).
|
||||
*
|
||||
* @param {ltjs.TileDfn} tile_dfn tile definition object
|
||||
* @param {TileDfn} tile_dfn tile definition object
|
||||
*
|
||||
* @return {undefined}
|
||||
*/
|
||||
|
@ -194,7 +197,7 @@ ltjs.TileMasker = Class( 'TileMasker',
|
|||
*
|
||||
* @param {function(Object)} callback function to call with tiles
|
||||
*
|
||||
* @return {ltjs.TileMasker} self
|
||||
* @return {TileMasker} self
|
||||
*/
|
||||
'public getMaskedTiles': function( bmp_game, bmp_mask, callback )
|
||||
{
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Represents a game object
|
||||
*
|
||||
* Copyright (C) 2012 Mike Gerwitz
|
||||
* Copyright (C) 2012, 2015 Mike Gerwitz
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -17,7 +17,10 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
ltjs.gameobjs.GameObject = Class( 'GameObject',
|
||||
var Class = require( 'easejs' ).Class;
|
||||
|
||||
|
||||
module.exports = Class( 'GameObject',
|
||||
{
|
||||
'private _tid': '',
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Represents a tank game object
|
||||
*
|
||||
* Copyright (C) 2012 Mike Gerwitz
|
||||
* Copyright (C) 2012, 2015 Mike Gerwitz
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -17,8 +17,12 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
ltjs.gameobjs.Tank = Class( 'Tank' )
|
||||
.extend( ltjs.gameobjs.GameObject,
|
||||
var Class = require( 'easejs' ).Class,
|
||||
GameObject = require( './GameObject' );
|
||||
|
||||
|
||||
module.exports = Class( 'Tank' )
|
||||
.extend( GameObject,
|
||||
{
|
||||
'override public move': function( direction, c, sc )
|
||||
{
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Represents a classic tank game object, facing down
|
||||
*
|
||||
* Copyright (C) 2012 Mike Gerwitz
|
||||
* Copyright (C) 2012, 2015 Mike Gerwitz
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -17,7 +17,11 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
ltjs.gameobjs.classic.TankDown = Class( 'TankDown' )
|
||||
.extend( ltjs.gameobjs.Tank,
|
||||
var Class = require( 'easejs' ).Class,
|
||||
Tank = require( '../Tank' );
|
||||
|
||||
|
||||
module.exports = Class( 'TankDown' )
|
||||
.extend( Tank,
|
||||
{
|
||||
} );
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Handles CSS-drive menu bar
|
||||
*
|
||||
* Copyright (C) 2012 Mike Gerwitz
|
||||
* Copyright (C) 2012, 2015 Mike Gerwitz
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -17,6 +17,8 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
var Class = require( 'easejs' ).Class;
|
||||
|
||||
|
||||
/**
|
||||
* Basic MenuBar
|
||||
|
@ -24,7 +26,7 @@
|
|||
* This class provides basic scripting for a menu bar; it expected the majority
|
||||
* of the menu bar to be handled via CSS.
|
||||
*/
|
||||
ltjs.ui.MenuBar = Class( 'MenuBar',
|
||||
module.exports = Class( 'MenuBar',
|
||||
{
|
||||
/**
|
||||
* DOM element representing the menu bar
|
||||
|
|
|
@ -75,7 +75,7 @@
|
|||
|
||||
<canvas id="canvas_map" width="512" height="512"></canvas>
|
||||
|
||||
<script src="../scripts/ease.min.js"></script>
|
||||
<script src="../lasertank.js"></script>
|
||||
<script>
|
||||
var ctx = document.getElementById( 'canvas' ).getContext( '2d' ),
|
||||
ctxmap = document.getElementById( 'canvas_map' ).getContext( '2d' ),
|
||||
|
@ -103,8 +103,8 @@
|
|||
|
||||
reader.onload = function( event )
|
||||
{
|
||||
var loader = ltjs.LtgLoader(),
|
||||
masker = ltjs.TileMasker( ltjs.ClassicTileDfn() ),
|
||||
var loader = lasertank.LtgLoader(),
|
||||
masker = lasertank.TileMasker( lasertank.ClassicTileDfn() ),
|
||||
meta = loader.fromString( event.target.result ),
|
||||
|
||||
bmp_game = document.getElementById( 'bmp_game' ),
|
||||
|
@ -201,12 +201,15 @@
|
|||
|
||||
reader.onload = function( event )
|
||||
{
|
||||
var map_set = ltjs.MapSet( event.target.result, ltjs.ClassicMap );
|
||||
var map_set = lasertank.MapSet(
|
||||
event.target.result,
|
||||
lasertank.ClassicMap
|
||||
);
|
||||
|
||||
// clean up any previous render and create a new one to render the
|
||||
// chosen level with our chosen tile set
|
||||
render && render.freeCanvas();
|
||||
render = ltjs.MapRender( ctxmap, tile_set );
|
||||
render = lasertank.MapRender( ctxmap, tile_set );
|
||||
|
||||
var lvlsel = document.getElementById( 'lvl_id' ),
|
||||
count = map_set.getMapCount();
|
||||
|
@ -247,14 +250,5 @@
|
|||
// invoke immediately, as we may have a filename prefilled from a refresh
|
||||
ltgChange();
|
||||
</script>
|
||||
<script src="../scripts/main.js"></script>
|
||||
<script src="../src/TileDfn.js"></script>
|
||||
<script src="../src/ClassicTileDfn.js"></script>
|
||||
<script src="../src/LtgLoader.js"></script>
|
||||
<script src="../src/TileMasker.js"></script>
|
||||
<script src="../src/MapSet.js"></script>
|
||||
<script src="../src/Map.js"></script>
|
||||
<script src="../src/ClassicMap.js"></script>
|
||||
<script src="../src/MapRender.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
Loading…
Reference in New Issue