From: ttwilb Date: Wed, 14 Aug 2013 05:01:58 +0000 (+0900) Subject: stage.moveToでアイテムを取れるようにした X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=41b31c4dfe4e166465715a16b4db31eb487d6d1a;p=h58pcdgame%2FGameScriptCoreLibrary.git stage.moveToでアイテムを取れるようにした --- diff --git a/www/corelib/classes/GameStageClass.js b/www/corelib/classes/GameStageClass.js index 67bbfa7..713ce21 100644 --- a/www/corelib/classes/GameStageClass.js +++ b/www/corelib/classes/GameStageClass.js @@ -78,9 +78,12 @@ GameStage.prototype = { //ŽŸ‚ÉŠeŽíStageObject‚Ìdraw‚ðŽÀs 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){ - //–{—ˆ‚Í‚±‚±‚É“–‚½‚è”»’菈—‚ð“ü‚ê‚é + moveTo : function(obj, x, y, gotItems){ + //“–‚½‚è”»’菈— 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 = { //‰¼‚É‚¨‚¢‚Ä‚Ý‚éÀ•W //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); diff --git a/www/corelib/classes/StageObjectClass.js b/www/corelib/classes/StageObjectClass.js index 5f93e35..59cbac4 100644 --- a/www/corelib/classes/StageObjectClass.js +++ b/www/corelib/classes/StageObjectClass.js @@ -30,6 +30,10 @@ StageObject.prototype = { }, draw: function(){ //ŽÀÛ‚Ì•`‰æ‚Ì‚Ý‚ðs‚¤BŒvŽZ‚Ítick‚ōs‚¤B + }, + isCollided: function() + { + return false; } };