drive/js/drive.js
function _build_object( game, x, y, speed ) {	

	var car_asset = game.carAssets[parseInt(Math.random()*game.carAssets.length)]
	var framex = car_asset.w * parseInt(Math.random() * car_asset.count);
	
	return {
		collided: 0,
		width: car_asset.w,
		height: car_asset.h,
		img: car_asset.img,
		framex: framex,
		pos: {
			x: x,
			y: y
		},
		speed: speed,
		cleanup: function() {
			if (this.bubble) {
				this.bubble.remove();
			}
		},
		update: function( t ) {
			if (this.collided > 2  && !this.bubble) {
				this.collided = 0;
				this.bubble = $('<div class="bubble">'+BLURB_TBL[parseInt(Math.random()*BLURB_TBL.length)]+'</div>').appendTo('#area');
				this.bubble.css({
					left: this.pos.x - 30,
					top: this.pos.y - 20
				})
				this.bubbleEnd = t + 1000;
			} else if (this.bubbleEnd < t) {
				this.bubble.remove();
			} else if (this.bubble) {
				this.bubble.css({
					left: this.pos.x - 30,
					top: this.pos.y - 20
				})
			}
		},
		clear: function( ctx ) {
			ctx.clearRect( this.pos.x - 1, this.pos.y - 1, this.width + 1 , this.height + 1 );
		},
		draw: function( ctx ) {
			ctx.drawImage( this.img, this.framex, 0, this.width, this.height,
						   this.pos.x, this.pos.y, this.width, this.height );
		}
	}
}
function _build_object( game, x, y, speed ) {	

	var car_asset = game.carAssets[parseInt(Math.random()*game.carAssets.length)]
	var framex = car_asset.w * parseInt(Math.random() * car_asset.count);
	
	return {
		collided: 0,
		width: car_asset.w,
		height: car_asset.h,
		img: car_asset.img,
		framex: framex,
		pos: {
			x: x,
			y: y
		},
		speed: speed,
		cleanup: function() {
			if (this.bubble) {
				this.bubble.remove();
			}
		},
		update: function( t ) {
			if (this.collided > 2  && !this.bubble) {
				this.collided = 0;
				this.bubble = $('<div class="bubble">'+BLURB_TBL[parseInt(Math.random()*BLURB_TBL.length)]+'</div>').appendTo('#area');
				this.bubble.css({
					left: this.pos.x - 30,
					top: this.pos.y - 20
				})
				this.bubbleEnd = t + 1000;
			} else if (this.bubbleEnd < t) {
				this.bubble.remove();
			} else if (this.bubble) {
				this.bubble.css({
					left: this.pos.x - 30,
					top: this.pos.y - 20
				})
			}
		},
		clear: function( ctx ) {
			ctx.clearRect( this.pos.x - 1, this.pos.y - 1, this.width + 1 , this.height + 1 );
		},
		draw: function( ctx ) {
			ctx.drawImage( this.img, this.framex, 0, this.width, this.height,
						   this.pos.x, this.pos.y, this.width, this.height );
		}
	}
}
function _build_object ( game , x , y , speed ) { var car_asset = game . carAssets [ parseInt ( Math . random ( ) * game . carAssets . length ) ] var framex = car_asset . w * parseInt ( Math . random ( ) * car_asset . count ) ; return { collided : 0 , width : car_asset . w , height : car_asset . h , img : car_asset . img , framex : framex , pos : { x : x , y : y } , speed : speed , cleanup : function ( ) { if ( this . bubble ) { this . bubble . remove ( ) ; } } , update : function ( t ) { if ( this . collided > 2 && ! this . bubble ) { this . collided = 0 ; this . bubble = $ ( '<div class="bubble">' + BLURB_TBL [ parseInt ( Math . random ( ) * BLURB_TBL . length ) ] + '</div>' ) . appendTo ( '#area' ) ; this . bubble . css ( { left : this . pos . x - 30 , top : this . pos . y - 20 } ) this . bubbleEnd = t + 1000 ; } else if ( this . bubbleEnd < t ) { this . bubble . remove ( ) ; } else if ( this . bubble ) { this . bubble . css ( { left : this . pos . x - 30 , top : this . pos . y - 20 } ) } } , clear : function ( ctx ) { ctx . clearRect ( this . pos . x - 1 , this . pos . y - 1 , this . width + 1 , this . height + 1 ) ; } , draw : function ( ctx ) { ctx . drawImage ( this . img , this . framex , 0 , this . width , this . height , this . pos . x , this . pos . y , this . width , this . height ) ; } } }
Add car in game
Add car in game