OSDN Git Service

キャラの動きの調整と当たり判定bug fix
authorttwilb <ttwilb@users.sourceforge.jp>
Thu, 8 Aug 2013 02:10:48 +0000 (11:10 +0900)
committerttwilb <ttwilb@users.sourceforge.jp>
Thu, 8 Aug 2013 02:10:48 +0000 (11:10 +0900)
www/corelib/classes/GameStageClass.js
www/corelib/classes/MovableStageObjectClass.js
www/corelib/classes/OperatedCharacterClass.js
www/corelib/core.js
www/index_local_debug.html

index f7fc623..093877c 100644 (file)
@@ -144,39 +144,43 @@ GameStage.prototype = {
                //\96{\97\88\82Í\82±\82±\82É\93\96\82½\82è\94»\92è\8f\88\97\9d\82ð\93ü\82ê\82é
                var sx = obj.origin.x, sy = obj.origin.y;
                var lx = x - sx, ly = y - sy;
+               var rx = x, ry = y;
                if(lx == 0 && ly == 0) return;
                var dx, dy, ct;
+               var collideDirection = 0;       //\89º\88Ê4bit : \8fã \89º \8d¶ \89E
                ct = Math.max(Math.abs(lx), Math.abs(ly));
                dx = lx / ct; dy = ly / ct;
-               for(var i = 1; i <= ct; i++)
+               var fx = dx == 0, fy = dy == 0;
+               for(var i = 0; i < ct  && !(fx && fy); i++)
                {
                        //\89¼\82É\82¨\82¢\82Ä\82Ý\82é\8dÀ\95W
-                       var ex = sx + dx * i, ey = sy + dy * i;
+                       var ex = fx ? rx : sx + dx * i, ey = fy ? ry : sy + dy * i;
                        
-                       if(this.eachStageObject(function(f){
-                               if(!f.isPhantom && f != obj)
+                       this.eachStageObject(function(f){
+                               if(!f.isPhantom && f !== obj)
                                {
-                                       if(obj.isCollided(f, ex, ey))
+                                       if(!fx && obj.isCollided(f, ex + dx, ey))
                                        {
-                                               /*if(obj.isCollided(f, ex, ey - dy))
-                                               {
-                                                       obj.movingSpeedX = 0;
-                                               }
-                                               if(obj.isCollided(f, ex - dx, ey))
-                                               {
-                                                       obj.movingSpeedY = 0;
-                                               }*/
-                                               obj.origin.x = ex - dx;
-                                               obj.origin.y = ey - dy;
-                                               return false;
+                                               rx = ex;
+                                               fx = true;
+                                               collideDirection |= (dx > 0 ? 1 : 2);
+                                               console.log(0);
                                        }
+                               
+                                       if(!fy && obj.isCollided(f, ex, ey + dy))
+                                       {
+                                               ry = ey;
+                                               fy = true;
+                                               collideDirection |= (dy > 0 ? 4 : 8);
+                                       }
+                                       if(fx && fy) return false;
                                }
                                return true;
-                       }) == false) return;
+                       });
                }
                
-               obj.origin.x = x;
-               obj.origin.y = y;
+               obj.origin.x = rx;
+               obj.origin.y = ry;
        }
 };
 
index 80846ef..f9d2ec4 100644 (file)
@@ -27,14 +27,19 @@ var MovableStageObjectClass = function(stage)
                }
                
                //\8fd\97Í
-               this.movingSpeed.y += 160 / this.stage.manager.tickPerSecond;
+               this.movingSpeed.y += 300 / this.stage.manager.tickPerSecond;
 
                //\89^\93®\8f\88\97\9d
-               this.moveTo(
+               var col = this.moveTo(
                        this.origin.x + (this.movingSpeed.x / this.stage.manager.tickPerSecond),
                        this.origin.y + (this.movingSpeed.y / this.stage.manager.tickPerSecond)
                );
                
+               //\8fÕ\93Ë\8e\9e\82Ì\89^\93®\83G\83l\83\8b\83M\81[\8fÁ\96Å\90Ý\92è
+               if(col & 1 != 0 && this.movingSpeed.x > 0) this.movingSpeed.x = 0;
+               if(col & 2 != 0 && this.movingSpeed.x < 0) this.movingSpeed.x = 0;
+               if(col & 4 != 0 && this.movingSpeed.y > 0) this.movingSpeed.y = 0;
+               if(col & 8 != 0 && this.movingSpeed.y < 0) this.movingSpeed.y = 0;
        },
        moveTo : function(x, y) {
                //\93\96\82½\82è\94»\92è\82Ì\8eÀ\91\95
@@ -45,7 +50,8 @@ var MovableStageObjectClass = function(stage)
                //MovableStageObject\82ª(x, y)\82Ì\82Æ\82«\91\8a\8eè\82Ìobj\82Æ\8fÕ\93Ë\82·\82é\82©\94»\92è
                if(obj instanceof BlockClass)
                {
-                       return x < obj.origin.x + 32 && x + 32>= obj.origin.x && y < obj.origin.y + 32 && y + 32 >= obj.origin.y;
+                       var ox = obj.origin.x, oy = obj.origin.y;
+                       return x + 32 >= ox && x <= ox + 32 && y + 32 >= oy && y <= oy + 32;
                }
                return false;
        }
index 777f09c..2242d4e 100644 (file)
@@ -1,15 +1,18 @@
 var OperatedCharacterClass = function(stage, images){
        OperatedCharacterClass.base.apply(this, arguments);
-
+       
+       this.moveSpeed = 400;
+       this.jumpSpeed = 500;
+       
 }.extend(CharacterClass, {
        goLeft : function(){
-               this.movingSpeed.x -= 200;
+               this.movingSpeed.x = -this.moveSpeed;
        },
        goRight : function(){
-               this.movingSpeed.x += 200;
+               this.movingSpeed.x = this.moveSpeed;
        },
        jump : function(){
-               this.movingSpeed.y -= 400;
+               this.movingSpeed.y = -this.jumpSpeed;
        },
        tick : function(){
                OperatedCharacterClass.base.prototype.tick.apply(this);
index 2e5469f..97484ce 100755 (executable)
@@ -175,6 +175,14 @@ GameManager.prototype = {
                        this.runningStage.keyUp(event);
                }
        },
+       calculateFps: function(){
+               if(this.oldTickCount)
+               {
+                               drawText(this.debugContext, "FPS " + (this.tickCount - this.oldTickCount), 0, 120);
+               }
+               this.oldTickCount = this.tickCount;
+               setTimeout(this.calculateFps, 1000);
+       },
        timerTick: function(){
                //****timerTick****
                this.tickCount++;
@@ -248,6 +256,7 @@ GameManager.prototype = {
                stage.runStage();
                //runningStageに登録することで、イベントの通知が開始され、GameStageは実行状態に入る。
                this.runningStage = stage;
+               this.calculateFps();
        },
        stopStage: function(){
                //****現在実行中のステージを終了する****
@@ -321,7 +330,12 @@ GameManager.prototype = {
        },
 };
 
-
+var oldTickCount = 0;
+(calculateFps = function(){
+       
+       
+       setTimeout(calculateFps, 1000);
+})();
 
 
 //
index cd305bc..177487a 100644 (file)
@@ -62,9 +62,21 @@ var stgInfo = {
 
 with(stgObjects) {
     var tbl = [
-        [_,_,_,_],
-        [a,_,_,a],
-        [a,a,a,a]
+        [],
+        [],
+        [],
+        [],
+        [],
+        [],
+        [],
+        [],
+        [],
+        [],
+        [],
+        [],
+        [],
+        [],
+        [a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a],
     ];
 }
 
@@ -73,7 +85,7 @@ var stage = new PCDSLStageClass(stgInfo, tbl, null);
 var main = new MainCharacterClass(stage, ["kuma1.png","kuma2.png","kuma3.png"]);
 
 main.origin.x = 50;
-main.origin.y = 50;
+main.origin.y = 250;
 stage.operatingCharacter = main;
 stage.addStageObject(main);
 stage;