OSDN Git Service

当たり判定の修正と敵キャラクターを踏んでダメージを与える動作の実装
author西田 耀 <hikarupsp@users.sourceforge.jp>
Fri, 23 Aug 2013 17:55:34 +0000 (02:55 +0900)
committer西田 耀 <hikarupsp@users.sourceforge.jp>
Fri, 23 Aug 2013 17:55:34 +0000 (02:55 +0900)
ジャンプの高さおよび隠しブロックの動作に修正が入ったので挙動が多少変わる。

14 files changed:
www/corelib/classes/BlockClass.js
www/corelib/classes/CharacterClass.js
www/corelib/classes/EnemyCharacterClass.js
www/corelib/classes/FreeItemClass.js
www/corelib/classes/GameStageClass.js
www/corelib/classes/HiddenBlockClass.js
www/corelib/classes/HorizonalScrollStageClass.js
www/corelib/classes/ItemClass.js
www/corelib/classes/MovableStageObjectClass.js
www/corelib/classes/OperatedCharacterClass.js
www/corelib/classes/StageObjectClass.js
www/corelib/core.js
www/corelib/coresubc.js
www/corelib/coresubf.js

index ee7ed0d..7d43a01 100644 (file)
@@ -5,7 +5,6 @@ var BlockClass = function(ownerStage, args)
        var img = document.createElement('img');
        img.src = "images/" + args[0];
        this.image = img;
-       
 }.extend(StageObject, {
        draw: function(x, y){
                if(this.image){
index 76f4109..e0e960e 100644 (file)
@@ -14,19 +14,16 @@ var CharacterClass = function(ownerStage, args)
        //\83L\83\83\83\89\82ª\8cü\82¢\82Ä\82¢\82é\8cü\82«(0:Left,1:Right,[2:Up,3:Down])
        this.direction = 0;
        
-       for(var k in args)
-       {
+       for(var k in args){
                var a = [];
-               for(var f in args[k])
-               {
+               for(var f in args[k]){
                        var img = document.createElement('img');
                        img.src = "images/" + args[k][f];
                        a.push(img);
                }
                this.imageList.push(a);
        }
-       if(this.imageList.length > 0)
-       {
+       if(this.imageList.length > 0){
                this.imageState = 0;
        }
        
@@ -38,13 +35,11 @@ var CharacterClass = function(ownerStage, args)
        className: "CharacterClass",
        draw: function(x, y){
                MovableStageObjectClass.prototype.draw.apply(this, arguments);
-               if(this.lastImage)
-               {
+               if(this.lastImage){
                        //\83R\83\93\83e\83L\83X\83g\95Ï\8a·\8ds\97ñ\82ð\95Û\91
                        this.ownerStage.mainContext.save();
                        //\83R\83\93\83e\83L\83X\83g\95Ï\8a·\8ds\97ñ\82ð\90Ý\92è
                        switch(this.direction){
-                               
                                case 1:
                                        //Right
                                        this.ownerStage.mainContext.transform(-1, 0, 0, 1, x + this.size.x, y);
@@ -65,34 +60,26 @@ var CharacterClass = function(ownerStage, args)
        tick: function(){
                MovableStageObjectClass.prototype.tick.apply(this, []);
                
-               if(this.ownerStage.manager.tickCount % this.interval == 0)
-               {
+               if(this.ownerStage.manager.tickCount % this.interval == 0){
                        //\83C\83\93\83^\81[\83o\83\8b\8e\9e\8d\8f\82É\82È\82Á\82½
-                       if(this.imageState != -1)
-                       {
-                               if(this.imageList[this.imageState])
-                               {
-                                       if(this.imageList[this.imageState].length > 0)
-                                       {
+                       if(this.imageState != -1){
+                               if(this.imageList[this.imageState]){
+                                       if(this.imageList[this.imageState].length > 0){
                                                if(this.imageIndex >= this.imageList[this.imageState].length){
                                                        this.imageIndex = 0;
                                                }
                                                this.lastImage = this.imageList[this.imageState][this.imageIndex];
-                                               if(this.imageState > 0 || Math.abs(this.movingSpeed.x) > this.hysteresis)
-                                               {
+                                               if(this.imageState > 0 || Math.abs(this.movingSpeed.x) > this.hysteresis){
                                                        //imageState:0\82Ì\8e\9e\82Éspeed == 0\82Ì\82Æ\82«\82Í\89æ\91\9c\82ð\83A\83j\83\81\82µ\82È\82¢\81B\82»\82ê\88È\8aO\82Ì\8e\9e\82Í\83C\83\93\83f\83b\83N\83X\82ð\90i\82ß\82é\81B
                                                        this.imageIndex ++;
                                                }
-                                       }else
-                                       {
+                                       } else{
                                                this.lastImage = null;
                                        }
-                               }else
-                               {
+                               } else{
                                        this.lastImage = null;
                                }
-                       }else
-                       {
+                       } else{
                                this.lastImage = null;
                        }
                }
index 74a2658..990639f 100644 (file)
@@ -7,11 +7,21 @@ var EnemyCharacterClass = function(stage, args){
        this.chasing = true;
        //メインキャラクターを感知する範囲(原点距離がこれ以内の場合に追跡をする。)
        this.chasingRange = 200;
-       
+       //メインキャラクターに与えるダメージの設定
        this.touchDamage = 10;
        this.damagePerTickBase = 60;
        this.damagePerTickCount = this.damagePerTickBase;
+       this.damageLastTick = 0;
        this.damaging = false;
+       //メインキャラクターから受けるダメージの設定
+       this.hurt = 10;
+       this.hurtPerTickBase = 60;
+       this.hurtPerTickCount = this.hurtPerTickBase;
+       this.hurtLastTick = 0;
+       this.hurting = false;
+       //
+       this.max_HP = 20;
+       this.HP = this.max_HP;
 }.extend(OperatedCharacterClass, {
        className: "EnemyCharacterClass",
        tick : function()
@@ -26,9 +36,9 @@ var EnemyCharacterClass = function(stage, args){
                        }
                }
                if(this.damaging){
-                       console.log("s");
                        if(this.damagePerTickCount == this.damagePerTickBase){
                                this.ownerStage.manager.userManager.damage(this.touchDamage);
+                               this.damagePerTickCount--;
                        } else{
                                this.damagePerTickCount--;
                                if(this.damagePerTickCount <= 0){
@@ -36,18 +46,84 @@ var EnemyCharacterClass = function(stage, args){
                                }
                        }
                }
+               if(this.hurting){
+                       if(this.hurtPerTickCount == this.hurtPerTickBase){
+                               this.HP -= this.hurt;
+                               this.hurtPerTickCount--;
+                               if(this.HP <= 0){
+                                       this.ownerStage.removeStageObject(this);
+                               }
+                       } else{
+                               this.hurtPerTickCount--;
+                               if(this.hurtPerTickCount <= 0){
+                                       this.hurtPerTickCount = this.hurtPerTickBase;
+                               }
+                       }
+               }
+               
                EnemyCharacterClass.base.prototype.tick.apply(this);
        },
+       draw: function(x, y){
+               EnemyCharacterClass.base.prototype.draw.apply(this, arguments);
+               this.ownerStage.mainContext.save();
+               this.ownerStage.mainContext.fillStyle = "rgba(255,255,255,0.5)";
+               this.ownerStage.mainContext.strokeStyle = "rgba(0, 0, 0, 1)";
+               this.ownerStage.mainContext.font = "normal 12px sans-serif";
+               drawText(this.ownerStage.mainContext, this.HP, x, y - 20);
+               this.ownerStage.mainContext.restore();
+       },
+       judgeCollideRange: function(x1, y1, x2, y2, obj){
+               //objは範囲の対象となるオブジェクトのインスタンス。省略可能
+               // 1 - - +
+               // |     |
+               // |     |
+               // + - - 2
+               var retv = OperatedCharacterClass.prototype.judgeCollideRange.apply(this, arguments);
+               if(obj == this.ownerStage.userControlledCharacter){
+                       if(retv){
+                               var cd = this.judgeCollideRange_getDirection(x1, y1, x2, y2);
+                               if(cd & CollideTop){
+                                       this.hurting = true;
+                                       var tickCount = this.ownerStage.manager.tickCount;
+                                       this.hurtLastTick = tickCount;
+                               } else{
+                                       this.hurting = false;
+                                       this.hurtPerTickCount = this.hurtPerTickBase;
+                               }
+                       } else{
+                               if(this.hurting){
+                                       this.hurting = false;
+                                       this.hurtPerTickCount = this.hurtPerTickBase;
+                               }
+                       }
+               }
+               return retv;
+       },
        isCollided : function(obj, x, y)
        {
                //MovableStageObjectが(x, y)のとき相手のobjと衝突するか判定
                var retv = OperatedCharacterClass.prototype.isCollided.apply(this, arguments);
                if(obj == this.ownerStage.userControlledCharacter){
+                       var tickCount = this.ownerStage.manager.tickCount;
                        if(retv){
-                               this.damaging = true;
+                               if((this.collideFlag & 8) != 0){
+                                       //上から衝突された場合は自分がダメージを受ける
+                                       //this.hurting = true;
+                                       //this.hurtLastTick = tickCount;
+                               } else{
+                                       //それ以外の場合はメインキャラにダメージを与える
+                                       this.damaging = true;
+                                       this.damageLastTick = tickCount;
+                               }
                        } else{
-                               this.damaging = false;
-                               this.damagePerTickCount = this.damagePerTickBase;
+                               if(this.damaging && tickCount > (this.damageLastTick + 5)){
+                                       this.damaging = false;
+                                       this.damagePerTickCount = this.damagePerTickBase;
+                               }
+                               //if(this.hurting && tickCount > (this.hurtLastTick + 5)){
+                               //      this.hurting = false;
+                               //      this.hurtPerTickCount = this.hurtPerTickBase;
+                               //}
                        }
                }
                return retv
index a864f30..fb1a51c 100644 (file)
@@ -68,7 +68,7 @@ var FreeItemClass = function(stage, args){
        },
        itemAttacked : function(obj, obj_x, obj_y)
        {
-               var tickCount = this.ownerStage.manager.tickCount
+               var tickCount = this.ownerStage.manager.tickCount;
                if(!this.isCollided)
                {
                        this.isCollided = true;
index 74b5f97..d06b003 100644 (file)
@@ -42,10 +42,9 @@ GameStage.prototype = {
                {
                        var tickAllObjects = true;
                        //\82Ü\82¸\81A\83N\83\89\83X\92è\8b`.tick() (\97á\82¦\82ÎBlockStageObjectClass.tick = function(){};) \82ª\92è\8b`\82³\82ê\82Ä\82½\82ç\8eÀ\8ds
-                       if(sp.tick)
-                       {
-                               tickAllObjects = sp.tick(this.stageObjectList[sp]);
-                       }
+                       //if(sp.tick){
+                       //      tickAllObjects = sp.tick(this.stageObjectList[sp]);
+                       //}
                        //\8e\9f\82É\8ae\8eíStageObject\82Ìtick\82ð\8eÀ\8ds
                        if(tickAllObjects)
                        {
@@ -63,7 +62,8 @@ GameStage.prototype = {
                        {
                                //\83W\83\83\83\93\83v
                                this.userControlledCharacter.jump();
-                       } else{
+                       } else if(this.userControlledCharacter.jumpEnd){
+                               //\83W\83\83\83\93\83v\8cã\82Ì\8f\88\97\9d
                                this.userControlledCharacter.jumpEnd();
                        }
                        if(!(this.manager.UIManager.keyState.goLeft && this.manager.UIManager.keyState.goRight))
@@ -190,26 +190,23 @@ GameStage.prototype = {
                return true;
        },
        collideJudge: function(obj, x, y, items){
-               //obj\82Ì\8fÕ\93Ë\8fó\91Ô\82ð\92²\82×\82é\81B
+               //\82·\82×\82Ä\82Ì\83I\83u\83W\83F\83N\83g\82É\91Î\82µ\82Äobj\82Ì\8fÕ\93Ë\8fó\91Ô\82ð\92²\82×\82é\81B
                //\83A\83C\83e\83\80\82ð\8eæ\93¾\82·\82é\82©\94Û\82©
                var gainItem = items instanceof Array;
                var retv = false;
                this.eachStageObject(function(f){
-                       if(f !== obj)
-                       {
-                               if(obj.isCollided(f, x, y))
-                               {
+                       if(f !== obj){
+                               if(obj.isCollided(f, x, y)){
                                        //\8fÕ\93Ë\90æf\82Ì\8fÕ\93Ë\94Í\88Í\93à\82É\82¢\82é
-                                       if(f.isPhantom)
-                                       {
+                                       if(f.isPhantom){
                                                //\8fÕ\93Ë\90æf\82ª\8fÕ\93Ë\94»\92è\96³\8e\8b\82¾\82Á\82½\82ç\81A\8fÕ\93Ë\82Í\82µ\82È\82¢
-                                               if(gainItem)
-                                               {
+                                               if(gainItem){
                                                        //\8fÕ\93Ë\90æf\82ð\8eæ\93¾\82µ\82½\83A\83C\83e\83\80\82É\89Á\82¦\82é\81B
-                                                       for(var titem in items)
-                                                       {
+                                                       for(var titem in items){
                                                                //\95¡\90\94\92Ç\89Á\82Ì\96h\8e~
-                                                               if(titem == f) return true;
+                                                               if(titem == f){
+                                                                       return true;
+                                                               }
                                                        }
                                                        items.push(f);
                                                }
@@ -230,52 +227,81 @@ GameStage.prototype = {
                //\93\96\82½\82è\94»\92è\8f\88\97\9d
                var sx = obj.origin.x, sy = obj.origin.y;
                var lx = x - sx, ly = y - sy;
-               if(lx == 0 && ly == 0){
-                       //\88Ú\93®\8b\97\97£\82ª0\82Å\82 \82ê\82Î\82Ç\82±\82É\82à\8fÕ\93Ë\82µ\82È\82¢\82Ì\82Å\81A\88Ú\93®\82¹\82¸\82É\95Ô\82é
-                       return 0;
-               }
+               //if(lx == 0 && ly == 0){
+               //      //\88Ú\93®\8b\97\97£\82ª0\82Å\82 \82ê\82Î\82Ç\82±\82É\82à\8fÕ\93Ë\82µ\82È\82¢\82Ì\82Å\81A\88Ú\93®\82¹\82¸\82É\95Ô\82é
+               //      return 0;
+               //}
                var collideDirection = 0;//\89º\88Ê4bit : \8fã \89º \8d¶ \89E
+               //\88Ú\93®\8b\97\97£\82ð\82Ç\82¿\82ç\82©\88ê\8e²\82Å\82Í\82©\82é
                var ct = Math.max(Math.abs(lx), Math.abs(ly));
+               //\82»\82ê\82ð\8aî\8f\80\82É\82µ\82½\88ê\92P\88Ê\93\96\82½\82è\82Ì\88Ú\93®\97Ê
                var dx = lx / ct;
                var dy = ly / ct;
+               //\88Ú\93®\82µ\82È\82¢\8e²\82ª\82 \82é\82©\82Ç\82¤\82©\81i\8d\82\91¬\89»\81H\81j
                var fx = (dx == 0);
                var fy = (dy == 0);
+               //\8eÀ\8dÛ\82É\88Ú\93®\82·\82é\90æ\82Ì\8dÀ\95W
                var ex = sx;
                var ey = sy;
+               //\8eæ\93¾\82µ\82½\83A\83C\83e\83\80\82Ì\83\8a\83X\83g
                var gotItems = [];
                var caterpillar = Math.abs(obj.caterpillar * dx);
-               for(var i = 0; i < ct; i++){
-                       if(!fx && this.collideJudge(obj, ex + dx, ey, gotItems)){
-                               if(this.collideJudge(obj, ex + dx, ey - caterpillar, gotItems)){
-                                       fx = true;
-                                       collideDirection |= (dx > 0 ? 1 : 2);
-                               } else{
-                                       ey -= caterpillar;
+               if(!(fx && fy)){
+                       for(var i = 0; i < ct; i++){
+                               if(!fx && this.collideJudge(obj, ex + dx, ey, gotItems)){
+                                       //caterpillar\82Ì\8d\82\82³\82ð\91«\82µ\82Ä\88Ú\93®\82Å\82«\82é\82©\8e\8e\82µ\82Ä\82Ý\82é
+                                       if(this.collideJudge(obj, ex + dx, ey - caterpillar, gotItems)){
+                                               //\82»\82ê\82Å\82àx\8e²\82ª\8fÕ\93Ë\82µ\82½\82Ì\82Å\88Ú\93®\82ð\92â\8e~\82µ\83t\83\89\83O\82ð\83Z\83b\83g\82·\82é
+                                               fx = true;
+                                               collideDirection |= (dx > 0 ? 1 : 2);
+                                       } else{
+                                               //\8d\82\82³\82ð\95Ï\82¦\82ê\82Î\88Ú\93®\82Å\82«\82é\82Ì\82Å\8d\82\82³\82ð\95Ï\82¦\82Ä\8cp\91±\82·\82é
+                                               ey -= caterpillar;
+                                       }
+                               }
+                               if(!fy && this.collideJudge(obj, ex, ey + dy, gotItems)){
+                                       //y\8e²\82ª\8fÕ\93Ë\82µ\82½\82Ì\82Å\88Ú\93®\82ð\92â\8e~\82µ\83t\83\89\83O\82ð\83Z\83b\83g\82·\82é
+                                       fy = true;
+                                       collideDirection |= (dy > 0 ? 4 : 8);
+                               }
+                               if(!fx){
+                                       ex += dx;
+                               }
+                               if(!fy){
+                                       ey += dy;
                                }
-                       }
-                       if(!fy && this.collideJudge(obj, ex, ey + dy, gotItems)){
-                               fy = true;
-                               collideDirection |= (dy > 0 ? 4 : 8);
-                       }
-                       if(!fx){
-                               ex += dx;
-                       }
-                       if(!fy){
-                               ey += dy;
-                       }
-                       if(fx && fy){
-                               break;
                        }
                }
                //\88Ú\93®
                obj.origin.x = ex;
                obj.origin.y = ey;
                
-               for(var i in gotItems)
-               {
+               //\88Ú\93®\82µ\82½\95û\8cü\82Æ\82Í\8bt\95û\8cü\82É\90Ú\90G\82µ\82Ä\82¢\82é\82©\92²\82×\82é
+               dx = (dx > 0 ? -1 : 1);
+               if(!fx && this.collideJudge(obj, ex + dx, ey, gotItems)){
+                       collideDirection |= (dx > 0 ? 1 : 2);
+               }
+               if(fx){
+                       dx = -1;
+                       if(!fx && this.collideJudge(obj, ex + dx, ey, gotItems)){
+                               collideDirection |= (dx > 0 ? 1 : 2);
+                       }
+               }
+               
+               dy = (dy > 0 ? -1 : 1);
+               if(!fy && this.collideJudge(obj, ex, ey + dy, gotItems)){
+                       collideDirection |= (dy > 0 ? 4 : 8);
+               }
+               if(fy){
+                       dy = -1;
+                       if(!fy && this.collideJudge(obj, ex, ey + dy, gotItems)){
+                               collideDirection |= (dy > 0 ? 4 : 8);
+                       }
+               }
+               
+               for(var i in gotItems){
                        var item = gotItems[i];
-                       if(item.itemAttacked)
-                       {
+                       if(item.itemAttacked){
                                //\83A\83C\83e\83\80\82É\91Î\82µ\82Ä\8eæ\93¾\82³\82ê\82½\82±\82Æ\82ð\92Ê\92m\82·\82é\81B(\8eæ\93¾\82µ\82½\83I\83u\83W\83F\83N\83g\82Ì\83C\83\93\83X\83^\83\93\83X\82¨\82æ\82Ñ\8dÀ\95W\81j
                                item.itemAttacked(obj, ex, ey);
                        }
@@ -285,8 +311,7 @@ GameStage.prototype = {
        },
        eachOwnStageObject: function(f){
                //\8e©\95ª\8e©\90g\82ª\8f\8a\97L\82·\82é\83I\83u\83W\83F\83N\83g\82·\82×\82Ä\82É\91Î\82µ\82Ä\8aÖ\90\94f\82ð\93K\97p\82·\82é
-               for(var sp in this.stageObjectList)
-               {
+               for(var sp in this.stageObjectList){
                        for(var i = 0; i < this.stageObjectList[sp].length; i++){
                                var stgobj = this.stageObjectList[sp][i];
                                if(stgobj.ownerUID == this.manager.userID){
index 86703a5..f404685 100644 (file)
@@ -7,24 +7,37 @@ var HiddenBlockClass = function(ownerStage, args)
        this.image0 = img;
        //画像はなし
        this.image = null;
-       this.phantomFlag = false;
+       this.phantomFlag = 0;
        
+       this.debugMode = true;
 }.extend(BlockClass, {
-       judgeCollideRange: function(x1, y1, x2, y2){
+       judgeCollideRange: function(x1, y1, x2, y2, obj){
+               //objは範囲の対象となるオブジェクトのインスタンス。省略可能
+               // 1 - - +
+               // |     |
+               // |     |
+               // + - - 2
                var retv = BlockClass.prototype.judgeCollideRange.apply(this, arguments);
                if(retv){
-                       if(this.phantomFlag || (y1 < this.origin.y)){
+                       var cd = this.judgeCollideRange_getDirection(x1, y1, x2, y2);
+                       if(this.phantomFlag || (cd & CollideTop)){
                                //上から当たった場合はなかったことにする
                                retv = false;
-                               this.phantomFlag = true;
-                       } else{
+                               this.phantomFlag = 2;
+                       } else if(obj == this.ownerStage.userControlledCharacter && (obj.origin.y >= this.origin.y + this.size.y - 1)){
                                //下から当たっていたら画像を表示させて、さらにこの関数をベースクラスのものに戻す。
                                this.image = this.image0;
                                this.judgeCollideRange = BlockClass.prototype.judgeCollideRange;
                                this.debugDraw = BlockClass.prototype.debugDraw;
+                       } else{
+                               retv = false;
                        }
                } else{
-                       this.phantomFlag = false;
+                       if(obj == this.ownerStage.userControlledCharacter){
+                               if(this.phantomFlag > 0){
+                                       this.phantomFlag--;
+                               }
+                       }
                }
                return retv;
        },
index da610ea..1f137d2 100644 (file)
@@ -11,33 +11,31 @@ var HorizonalScrollStageClass = function()
        timerTick: function(){
 
                HorizonalScrollStageClass.base.prototype.timerTick.call(this);
-               if(this.userControlledCharacter)        this.scrollTo(this.getScrollLocation());
-               this.eachStageObject(function(f){
-                       f.movingSpeedY -= 1;
-                       return true;
-               });
+               if(this.userControlledCharacter){
+                       //\83L\83\83\83\89\83N\83^\81[\82ð\92Ç\94ö\82·\82é
+                       this.scrollTo(this.getScrollLocation());
+               }
+               //this.eachStageObject(function(f){
+               //      f.movingSpeedY -= 1;
+               //      return true;
+               //});
        },
        
        // \8eq\83X\83e\81[\83W\82Å\81A\91\80\8dì\92\86\83L\83\83\83\89\88È\8aO\82ð\92\86\90S\82É\8e\9d\82Á\82Ä\82«\82½\82¢\82Æ\82«\82Í\82±\82Ì\8aÖ\90\94\82ð\83I\81[\83o\81[\83\89\83C\83h\82·\82é
-       getScrollLocation: function()
-       {
+       getScrollLocation: function(){
                var pos = 0;
-               if(this.userControlledCharacter)
-               {
+               if(this.userControlledCharacter){
                        return this.userControlledCharacter.origin.x - 320;
                }
                
                return 0;
        },
-       draw: function()
-       {
+       draw: function(){
                this.drawBackground();
-               
                this.drawAsPoint(this.scrollX, 0);
        },
        drawBackground: function(){
-               if(this.background)
-               {
+               if(this.background){
                        //\89æ\96Ê\88Ê\92u\82É\8d\87\82í\82¹\82Ä\89æ\91\9c\82ð\83X\83N\83\8d\81[\83\8b\95\\8e¦\82·\82é
                        var width = this.background.width;
                        var pos = -((this.scrollX / 2) % width);
@@ -49,8 +47,7 @@ var HorizonalScrollStageClass = function()
                        //\83L\83\83\83\93\83o\83X\82ð\91S\8fÁ\8b\8e
                        this.mainContext.clearRect(0, 0, this.mainCanvas.width, this.mainCanvas.height);
                }
-               if(this.collisionMapContext)
-               {
+               if(this.collisionMapContext){
                        this.collisionMapContext.clearRect(0, 0, this.collisionMapCanvas.width, this.collisionMapCanvas.height);
                }
        },
@@ -58,8 +55,12 @@ var HorizonalScrollStageClass = function()
        //\83X\83N\83\8d\81[\83\8b\82µ\82½\82¢\82Æ\82«\82É\81Atick\96\88\82É\8cÄ\82Ô\81B
        scrollTo: function(x){
                this.scrollX += (x - this.scrollX) / 7;
-               if(this.scrollX > this.scrollMaxX) this.scrollX = this.scrollMaxX;
-               if(this.scrollX < 0) this.scrollX = 0;
+               if(this.scrollX > this.scrollMaxX){
+                       this.scrollX = this.scrollMaxX;
+               }
+               if(this.scrollX < 0){
+                       this.scrollX = 0;
+               }
        }
 });
 
index 9f3f16f..64bcff5 100644 (file)
@@ -22,8 +22,7 @@ var ItemClass = function(ownerStage, args)
                return x2 >= this.origin.x && x1 < this.origin.x + this.size.x && y2 >= this.origin.y && y1 < this.origin.y + this.size.y;
        },
        
-       itemAttacked : function(obj, obj_x, obj_y)
-       {
+       itemAttacked : function(obj, obj_x, obj_y){
                //\82±\82Ì\8f\88\97\9d\82ð\8eq\83N\83\89\83X\82Å\8fã\8f\91\82«\82µ\82Ä\83A\83C\83e\83\80\82Ì\93®\8dì\82ð\92è\8b`\82·\82é
                //obj : \82±\82Ì\83A\83C\83e\83\80\82É\90G\82Á\82½\90l(MainCharacter\82È\82Ç)
                //obj_x : obj\82Ì\90G\82ê\82½\92¼\8cã\82Ìx\8dÀ\95W
index 45d524b..19cdd49 100644 (file)
@@ -57,7 +57,7 @@ var MovableStageObjectClass = function(stage, args)
        {
                //MovableStageObject\82ª(x, y)\82Ì\82Æ\82«\91\8a\8eè\82Ìobj\82Æ\8fÕ\93Ë\82·\82é\82©\94»\92è
                if(obj.judgeCollideRange){
-                       return obj.judgeCollideRange(x + this.collisionMarginLeft, y + this.collisionMarginTop, x + this.size.x - this.collisionMarginRight, y + this.size.y - this.collisionMarginBottom);
+                       return obj.judgeCollideRange(x + this.collisionMarginLeft, y + this.collisionMarginTop, x + this.size.x - this.collisionMarginRight, y + this.size.y - this.collisionMarginBottom, this);
                }
                return false;
        }
index 66325de..b8c3e27 100644 (file)
@@ -36,8 +36,9 @@ var OperatedCharacterClass = function(ownerStage, args){
        //\92Ê\8fí\83W\83\83\83\93\83v\82·\82é\82Æ\82«\82É\8cÄ\82Î\82ê\82é\81B\83W\83\83\83\93\83v\83L\81[\82ð\89\9f\82µ\82Ä\82¢\82é\8aÔ\82Í\82¸\82Á\82Æ\8cÄ\82Î\82ê\82é
        //\83W\83\83\83\93\83v\83L\81[\82ð\89\9f\82µ\82Ä\82¢\82é\8e\9e\8aÔ\82Ì\92·\82³\82É\89\9e\82\82Ä\83W\83\83\83\93\83v\82Ì\8d\82\82³\82ª\95Ï\89»\82·\82é\81B
        jump : function(){
-               if((this.collideFlag & 4) != 0)
-               {
+               if(this.collideFlag & CollideBottom){
+                       //\83W\83\83\83\93\83v\82Ì\8f\89\8aú\89»
+                       this.jumpEnd = OperatedCharacterClass.prototype.jumpEnd;
                        this.jumpPower_tickCount = this.jumpPower_tickCountBase;
                }
                if(this.jumpPower_tickCount > 0){
@@ -51,10 +52,11 @@ var OperatedCharacterClass = function(ownerStage, args){
                }
        },
        jumpEnd: function(){
-               //\83W\83\83\83\93\83v\83L\81[\82ª\89\9f\82³\82ê\82Ä\82¢\82È\82¢\8aÔ\82Í\82±\82¿\82ç\82ª\8cÄ\82Ñ\8fo\82³\82ê\82é\81B
+               //\83W\83\83\83\93\83v\83L\81[\82ª\89\9f\82³\82ê\82Ä\82¢\82È\82¢\8aÔ\82Í\82±\82¿\82ç\82ª\8cÄ\82Ñ\8fo\82³\82ê\82é\81B\83W\83\83\83\93\83v\8f\88\97\9d\82ª\82·\82×\82Ä\8fI\97¹\82µ\82½\8cã\82Ínull\82É\82È\82é\81B
                //\83W\83\83\83\93\83v\83L\81[\82ð\82²\82­\92Z\8e\9e\8aÔ\89\9f\82µ\82½\8fê\8d\87\82Å\82à\81A\82 \82é\88ê\92è\82Ì\8d\82\82³\82Ü\82Å\82Í\83W\83\83\83\93\83v\82·\82é\82æ\82¤\82É\82·\82é\82½\82ß\81B
                if(this.jumpPower_tickCount < this.jumpPower_tickCountBase - this.jumpPower_tickCountAtLeast){
                        this.jumpPower_tickCount = 0;
+                       this.jumpEnd = null;
                } else{
                        this.jump();
                }
index ef50f6b..605778f 100644 (file)
@@ -64,7 +64,7 @@ StageObject.prototype = {
                        return obj.judgeCollideRange(x + this.collisionMarginLeft,
                                                                                 y + this.collisionMarginTop,
                                                                                 x + this.size.x - 1 - this.collisionMarginRight,
-                                                                                y + this.size.y - 1 - this.collisionMarginBottom);
+                                                                                y + this.size.y - 1 - this.collisionMarginBottom, this);
                }
                return false;
        },
@@ -75,12 +75,29 @@ StageObject.prototype = {
        // |     |
        // |     |
        // + - - 2
-       judgeCollideRange: function(x1, y1, x2, y2){
-               //isPhantom\82É\8aÖ\8cW\82È\82­\81A\8fÕ\93Ë\94Í\88Í\82ª\8fd\82È\82é\82©\82Ç\82¤\82©\82ð\92²\82×\82é\81B
-               return x2 >= this.origin.x + this.collisionMarginLeft &&
-                       x1 <= this.origin.x + this.size.x - 1 - this.collisionMarginRight &&
-                       y2 >= this.origin.y + this.collisionMarginTop &&
-                       y1 <= this.origin.y + this.size.y - 1 - this.collisionMarginBottom;
+       judgeCollideRange: function(x1, y1, x2, y2, obj){
+               //isPhantom\82É\8aÖ\8cW\82È\82­\81A\8fÕ\93Ë\94Í\88Í\82ª\8fd\82È\82é\82©\82Ç\82¤\82©\82ð\92²\82×\82é\81B\97×\90Ú\82µ\82Ä\82¢\82é\8fê\8d\87\82à\90Ú\90G\82µ\82Ä\82¢\82é\82Æ\94»\92è\82·\82é\81B
+               return x2 + 1 >= this.origin.x + this.collisionMarginLeft &&
+                       x1 - 1 <= this.origin.x + this.size.x - this.collisionMarginRight &&
+                       y2 + 1 >= this.origin.y + this.collisionMarginTop &&
+                       y1 - 1 <= this.origin.y + this.size.y - this.collisionMarginBottom;
+       },
+       judgeCollideRange_getDirection: function(x1, y1, x2, y2){
+               //\8fÕ\93Ë\82·\82é\82±\82Æ\82ª\94»\96¾\82µ\82Ä\82¢\82é\8fó\8bµ\89º\82Å\82Ì\8fÕ\93Ë\83t\83\89\83O\82ð\8eæ\93¾\82·\82é
+               var retv = 0;
+               if(x1 <= this.origin.x){
+                       retv |= CollideLeft;
+               }
+               if(y2 >= this.origin.y + this.size.y - 1){
+                       retv |= CollideBottom;
+               }
+               if(y1 <= this.origin.y){
+                       retv |= CollideTop;
+               }
+               if(x2 >= this.origin.x + this.size.x - 1){
+                       retv |= CollideRight;
+               }
+               return retv;
        },
        bindAttribute: function(attr)
        {
index 7eb2fb4..6a7df5b 100644 (file)
@@ -43,6 +43,12 @@ var URL_PCD_Stage = URL_PCD_Root + "stage/";
 // audio, corelib, images, stageの各フォルダをコピーしたdirにhtmlを置き、<div>.InitGameManager() と実行するスクリプトを書く
 // stageName == nullだとステージを開始しない。指定する時は.jsおよびパスを省く
 
+//
+var CollideTop = 8;
+var CollideBottom = 4;
+var CollideLeft = 2;
+var CollideRight = 1;
+
 HTMLDivElement.prototype.InitGameManager = function(stageName)
 {
        if(this instanceof HTMLDivElement)
index 37d8264..9833722 100644 (file)
@@ -345,6 +345,16 @@ Rectangle.prototype = {
        
 }
 
+function OffsetBox(top, down, left, right){
+       this.top = top;
+       this.down = down;
+       this.left = left;
+       this.right = right;
+}
+OffsetBox.prototype = {
+       
+}
+
 function RequestData(){
        //FormDataがIEで動かないので代替
        this.data = "";
index d5ad413..0fade87 100644 (file)
@@ -146,9 +146,6 @@ function parseArrayToStringSource(anArray){
 }
 
 function parseArrayToStringSource_Sub(anArray){
-       //戻り値を直接evalすると等価なオブジェクトを得ることができる。
-       //parseArrayToStringSource({1,"321a","abc",test:["cder","",554]});
-       //parseArrayToStringSource([1,"321a","abc",{a:"cder",0:"",1:554}]);
        if(!anArray){
                return "null";
        }