え〜〜い!いっそうのこと、ブロック崩しを作れ!
きっと長くなるなぁ〜!そして、これは作りかけ&暇なときにやります!きっと
//@cc_on
//___
//計算時間のかかる sin, cos をテーブルにして関数化
var Math2 = new Function ( ) {
var sinTable = [ ];
var cosTable = [ ];
var radian = Math.PI / 180;
var d, t;
for( d = 0; d < 360; d++ ) {
t = d * radian;
sinTable[ d ] = Math.sin( t );
cosTable[ d ] = Math.cos( t );
}
this.sinDegree = function ( deg ) {
return sinTable[ deg % 360 |0 ];
};
this.cosDegree = function ( deg ) {
return cosTable[ deg % 360 | 0 ];
};
this.randomInt = function ( num ) {
return Math.random() * num | 0;
};
};
//___
//移動物体を定義する
var MovingParts = new Function;
//移動部品の状態を設定
MovingParts.prototype.set = function ( position, vctor, timing ) {
this.position = position || { x: 0, y: 0 };
this.vector = vector || { v: 0, s: 0 };
this.timing = timing || 25;
this.scale = this.timing / 10;
};
//状態を返す
MovingParts.prototype.get = function ( ) {
return { position: this.position, vector: this.vector };
};
//物体に運動を与える
MovingParts.prototype.attack = function ( vector ) {
var v = this.vector;
if( 0 == v.s |0 )
this.start();
else {
this.vector.s += vector.s || 0;
if( 0 < v.v - vector.v )
this.vector.v += 180 + ( 90 - v.v + vector.v ) * 2;
else
this.vector.v += 180 - ( 90 - v.v + vector.v ) * 2;
}
};
MovingParts.prototype.start = function ( ) {
if( this.tmid === null )
this.tmid = setInterval(
(function ( that ) {
return function ( ) { that.move(); };
})( this ), this.timing );
};
MovingParts.prototype.stop = function ( ) {
clearInterval( this.tmid );
this.tmid = null;
};
MovingParts.prototype.move = (function( sin, cos ) {
return function ( ) {
if( 0 == this.vector.s | 0 ) {
this.stop();
this.vector.s = 0;
} else {
this.position.x += sin( this.vector.v ) * this.vector.s * this.scale;
this.position.y += cos( this.vector.v ) * this.vector.s * this.scale;
}
return this.position;
};
})( Math2.sinDegree, Math2.cosDegree, Math2.randomInt )
//___
var Coart = function( x, y ) {
this.x = x;
this.y = y;
};
Coart.prototype.isOutSide = function ( p ) {
if( p.y < 0 ) return 1;
if( this.x < p.x ) return 2;
if( this.y < p.y ) return 3;
if( p.x < 0 ) return 4;
return 0;
};
//___
//ラケットもボールも「動く物」と考えてしまえば、
動くところだけ、付け足せばいいのかも?!
var Ball = new Function;
Ball.prototype = new MovingParts;
Ball.prototype.constructor = Ball;
//___
var Racket = new Function;
Racket.prototype = new MovingParts;
Racket.prototype.constructor = Racket;