OSDN Git Service

GameStageおよびStageObjectはclassesの中に移動しました
[h58pcdgame/GameScriptCoreLibrary.git] / www / corelib / core.js
index eaf3415..78838a8 100755 (executable)
@@ -271,163 +271,8 @@ GameManager.prototype = {
        },
 };
 
-//
-//ゲームステージ
-//
-
-function GameStage(){
-       //****コンストラクタ****
-       //**インスタンス変数宣言・初期化**
-       //タイマーカウントを初期化
-       this.tickCount = 0;
-       //GameManagerから渡されるプロパティ
-       this.manager = null;
-       this.mainCanvas = null;
-       this.debugCanvas = null;
-       this.mainContext = null;
-       this.debugContext = null;
-       //StageObjectのリスト
-       this.stageObjectList = new Array();
-       //オーバーライドされる可能性のある関数の保存
-       //this.super = new Object();
-       //上記の方法では、thisがsuperになってしまい動作しないので、同一階層に関数の参照を作成することになった。
-       this.super_keyDown = this.keyDown;
-       this.super_keyUp = this.keyUp;
-       this.super_timerTick = this.timerTick;
-       this.super_runStage = this.runStage;
-       this.super_stopStage = this.stopStage;
-       this.super_addStageObject = this.addStageObject;
-       this.super_removeStageObject = this.removeStageObject;
-       //衝突判定用canvas
-       this.collisionMapCanvas = null;
-       this.collisionMapContext = null;
-}
-GameStage.prototype = {
-       //以下の関数をオーバーライドしてステージを作成する。
-       keyDown: function(event){
-               //キー入力
-       },
-       keyUp: function(event){
-               //キー入力
-       },
-       timerTick: function(){
-               //タイマー
-               
-               this.tickCount++;
-               drawText(this.debugContext, "tick:" + this.tickCount, 0, 20);
-               
-               //キャンバスを全消去
-               this.mainContext.clearRect(0, 0, this.mainCanvas.width, this.mainCanvas.height);
-               this.collisionMapContext.clearRect(0, 0, this.collisionMapCanvas.width * 8, this.collisionMapCanvas.height * 8);
-               //全てのオブジェクトを再描画
-               
-               for(i = 0; i < this.stageObjectList.length; i++){
-                       this.stageObjectList[i].display();
-               }
-       },
-       runStage: function(){
-               //ステージ初期化処理
-               this.tickCount = 0;
-               //衝突マップ初期化
-               this.collisionMapCanvas = createCanvas("collisionMapCanvas", this.mainCanvas.width, this.mainCanvas.height, this.mainCanvas.width, 0, 1, "MainArea");
-               this.collisionMapContext = this.collisionMapCanvas.getContext('2d');
-               this.collisionMapContext.fillStyle = "rgba(0,0,0, 0.2)";
-               this.collisionMapContext.strokeStyle = "rgba(0,0,0, 0.2)";
-               this.collisionMapContext.scale(1, 1);
-       },
-       stopStage: function(){
-               //ステージ終了処理
-               destroyDOMObjectByID(this.collisionMapCanvas.id);
-               this.collisionMapCanvas = null;
-               this.collisionMapContext = null;
-               this.stageObjectList = null;
-       },
-       addStageObject: function(aStageObject){
-               //StageObject追加処理
-               this.stageObjectList.push(aStageObject);
-       },
-       removeStageObject: function(aStageObject){
-               //StageObject削除処理
-               removeObjectFromArray(this.stageObjectList, aStageObject);
-       }
-}
 
-//
-//キャラクター
-//
 
-function StageObject(aStage){
-       this.stage = aStage;
-       this.origin = new Point2D(10, 10);
-       //originを中心とした座標でのオブジェクトの描画面のサイズ
-       this.frame = new Rectangle(-8, -8, 16, 16);
-       this.movingSpeed = new Point2D(0, 0);
-       //2 * hysteresis >= movingFrictionであることを推奨する。
-       //そうでない場合、摩擦での減速後に完全に停止できない可能性がある。
-       this.movingFriction = 90;
-       this.hysteresis = this.movingFriction / 2;
-       //実体を持たない、つまり衝突判定が必要ない場合はtrue.
-       this.isPhantom = false;
-       //console.log("StageObject:Init");
-}
-StageObject.prototype = {
-       display: function(){
-               //再描画時に呼ばれる。
-               this.computeTickMoving();
-               this.computeTickFriction();
-               this.computeTickBounding();
-               //弧の描画
-               this.stage.mainContext.save();
-               this.stage.mainContext.fillStyle = "rgba(" + (((11*this.frame.size.x) & 0x7f) + 0x80) + "," + (((19*this.frame.size.x) & 0x7f) + 0x80) + "," + (((17*this.frame.size.x) & 0x7f) + 0x80) + ",0.5)";
-               drawArcDegree(this.stage.mainContext, this.frame.size.x / 2, 0, 360, this.origin.x, this.origin.y, false);
-               this.stage.mainContext.restore();
-               //衝突マップに描画
-               strokeRect(this.stage.collisionMapContext, this.origin.x + this.frame.origin.x, this.origin.y + this.frame.origin.y, this.frame.size.x, this.frame.size.y);
-       },
-       computeTickFriction: function(){
-               //摩擦処理
-               if(this.movingSpeed.x < -this.hysteresis){
-                       this.movingSpeed.x += this.movingFriction / this.stage.manager.tickPerSecond;
-               } else if(this.movingSpeed.x > this.hysteresis){
-                       this.movingSpeed.x -= this.movingFriction / this.stage.manager.tickPerSecond;
-               } else{
-                       this.movingSpeed.x = 0;
-               }
-               if(this.movingSpeed.y < -this.hysteresis){
-                       this.movingSpeed.y += this.movingFriction / this.stage.manager.tickPerSecond;
-               } else if(this.movingSpeed.y > this.hysteresis){
-                       this.movingSpeed.y -= this.movingFriction / this.stage.manager.tickPerSecond;
-               } else{
-                       this.movingSpeed.y = 0;
-               }
-       },
-       computeTickMoving: function(){
-               //運動処理
-               this.origin.x += this.movingSpeed.x / this.stage.manager.tickPerSecond;
-               this.origin.y += this.movingSpeed.y / this.stage.manager.tickPerSecond;
-       },
-       computeTickBounding: function(){
-               //壁面跳ね返り処理
-               if(this.origin.x < -this.frame.origin.x){
-                       //左壁面
-                       this.origin.x = -this.frame.origin.x;
-                       this.movingSpeed.x = -this.movingSpeed.x;
-               } else if(this.origin.x > this.stage.mainCanvas.width - (this.frame.origin.x + this.frame.size.x)){
-                       //右壁面
-                       this.origin.x = this.stage.mainCanvas.width - (this.frame.origin.x + this.frame.size.x);
-                       this.movingSpeed.x = -this.movingSpeed.x;
-               }
-               if(this.origin.y < -this.frame.origin.y){
-                       //上壁面
-                       this.origin.y = -this.frame.origin.y;
-                       this.movingSpeed.y = -this.movingSpeed.y;
-               } else if(this.origin.y > this.stage.mainCanvas.height - (this.frame.origin.y + this.frame.size.y)){
-                       //下壁面
-                       this.origin.y = this.stage.mainCanvas.height - (this.frame.origin.y + this.frame.size.y);
-                       this.movingSpeed.y = -this.movingSpeed.y;
-               }
-       },
-}
 
 //
 //その他のクラス