OSDN Git Service

stage.moveToでアイテムを取れるようにした
authorttwilb <ttwilb@users.sourceforge.jp>
Wed, 14 Aug 2013 05:01:58 +0000 (14:01 +0900)
committerttwilb <ttwilb@users.sourceforge.jp>
Wed, 14 Aug 2013 05:01:58 +0000 (14:01 +0900)
www/corelib/classes/GameStageClass.js
www/corelib/classes/StageObjectClass.js

index 67bbfa7..713ce21 100644 (file)
@@ -78,9 +78,12 @@ GameStage.prototype = {
                        //\8e\9f\82É\8ae\8eíStageObject\82Ìdraw\82ð\8eÀ\8ds
                        for(i = 0, li = this.stageObjectList[sp].length; i < li; i++){
                                var stgobj = this.stageObjectList[sp][i];
-                               //console.log(this.stageObjectList[sp]);
-                               stgobj.draw(stgobj.origin.x - x, stgobj.origin.y - y);
+                               var px = stgobj.origin.x - x, py = stgobj.origin.y - y;
                                
+                               if(px > -stgobj.size.x && py > -stgobj.size.y && px < 640 && py < 480)
+                               {
+                                       stgobj.draw(px, py);
+                               }
                        }
                }
        },
@@ -147,17 +150,34 @@ GameStage.prototype = {
                }
                return true;
        },
-       collideJudge: function(obj, x, y){
+       collideJudge: function(obj, x, y, items){
+               var gainItem = items instanceof Array;
                return !this.eachStageObject(function(f){
                        if(!f.isPhantom && f !== obj)
                        {
-                               if(obj.isCollided(f, x, y)) return false;
+                               if(obj.isCollided(f, x, y))
+                               {
+                                       if(f.isPhantom)
+                                       {
+                                               if(gainItem)
+                                               {
+                                                       for(var titem in items)
+                                                       {
+                                                               if(titem == f) return true;
+                                                       }
+                                                       items.push(f);
+                                               }
+                                       }else
+                                       {
+                                               return false;
+                                       }
+                               }
                        }
                        return true;
                });
        },
-       moveTo : function(obj, x, y){
-               //\96{\97\88\82Í\82±\82±\82É\93\96\82½\82è\94»\92è\8f\88\97\9d\82ð\93ü\82ê\82é
+       moveTo : function(obj, x, y, gotItems){
+               //\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) return;
@@ -172,13 +192,13 @@ GameStage.prototype = {
                        //\89¼\82É\82¨\82¢\82Ä\82Ý\82é\8dÀ\95W
                        //var ex = fx ? rx : sx + dx * i, ey = fy ? ry : sy + dy * i;
                        
-                       if(!fx && this.collideJudge(obj, ex + dx, ey))
+                       if(!fx && this.collideJudge(obj, ex + dx, ey, gotItems))
                        {
                                fx = true;
                                collideDirection |= (dx > 0 ? 1 : 2);
                        }
                        
-                       if(!fy && this.collideJudge(obj, ex, ey + dy))
+                       if(!fy && this.collideJudge(obj, ex, ey + dy, gotItems))
                        {
                                fy = true;
                                collideDirection |= (dy > 0 ? 4 : 8);
index 5f93e35..59cbac4 100644 (file)
@@ -30,6 +30,10 @@ StageObject.prototype = {
        },
        draw: function(){
                //\8eÀ\8dÛ\82Ì\95`\89æ\82Ì\82Ý\82ð\8ds\82¤\81B\8cv\8eZ\82Ítick\82Å\8ds\82¤\81B
+       },
+       isCollided: function()
+       {
+               return false;
        }
 };