3 //
\83Q
\81[
\83\80\83X
\83e
\81[
\83W
7 //****
\83R
\83\93\83X
\83g
\83\89\83N
\83^****
8 //**
\83C
\83\93\83X
\83^
\83\93\83X
\95Ï
\90\94\90é
\8c¾
\81E
\8f\89\8aú
\89»**
9 //
\83^
\83C
\83}
\81[
\83J
\83E
\83\93\83g
\82ð
\8f\89\8aú
\89»
11 //GameManager
\82©
\82ç
\93n
\82³
\82ê
\82é
\83v
\83\8d\83p
\83e
\83B
13 this.mainCanvas = null;
14 this.debugCanvas = null;
15 this.mainContext = null;
16 this.debugContext = null;
17 //StageObject
\82Ì
\83\8a\83X
\83g
18 this.stageObjectList = new Array();
19 this.globalStageObjectList = new Array();
20 //
\8fÕ
\93Ë
\94»
\92è
\97pcanvas
21 this.collisionMapCanvas = null;
22 this.collisionMapContext = null;
23 this.debugMode = false;
24 //
\94w
\8ci
\82Ì
\89æ
\91\9c\82Ìimg
\83G
\83\8c\83\81\83\93\83g
\83I
\83u
\83W
\83F
\83N
\83g
\82ð
\8ew
\92è
25 this.background = null;
26 //
\83\86\81[
\83U
\81[
\82ª
\91\80\8dì
\82µ
\82Ä
\82¢
\82é
\83L
\83\83\83\89\83N
\83^
\81[
\83I
\83u
\83W
\83F
\83N
\83g
27 this.userControlledCharacter = null;
29 GameStage.prototype = {
30 //
\88È
\89º
\82Ì
\8aÖ
\90\94\82ð
\83I
\81[
\83o
\81[
\83\89\83C
\83h
\82µ
\82Ä
\83X
\83e
\81[
\83W
\82ð
\8dì
\90¬
\82·
\82é
\81B
31 keyDown: function(event){
34 keyUp: function(event){
37 timerTick: function(){
40 //
\91S
\82Ä
\82Ì
\83I
\83u
\83W
\83F
\83N
\83g
\82ð
\8cv
\8eZ
41 for(var sp in this.stageObjectList)
43 var tickAllObjects = true;
44 //
\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
47 tickAllObjects = sp.tick(this.stageObjectList[sp]);
49 //
\8e\9f\82É
\8ae
\8eíStageObject
\82Ìtick
\82ð
\8eÀ
\8ds
52 for(var i = 0; i < this.stageObjectList[sp].length; i++){
54 this.stageObjectList[sp][i].tick();
59 //
\91\80\8dì
\92\86\83L
\83\83\83\89\82Ì
\88Ú
\93®
\8f\88\97\9d
60 if(this.userControlledCharacter)
62 if(this.manager.UIManager.keyState.jump)
64 //
\83W
\83\83\83\93\83v
65 this.userControlledCharacter.jump();
67 this.userControlledCharacter.jumpEnd();
69 if(!(this.manager.UIManager.keyState.goLeft && this.manager.UIManager.keyState.goRight))
72 if(this.manager.UIManager.keyState.goLeft){
73 this.userControlledCharacter.goLeft();
75 if(this.manager.UIManager.keyState.goRight){
76 this.userControlledCharacter.goRight();
82 this.drawBackground();
84 this.drawAsPoint(0, 0);
86 drawAsPoint: function(x, y){
87 //
\82·
\82×
\82Ä
\82Ì
\83I
\83u
\83W
\83F
\83N
\83g
\82ð
\8dÄ
\95`
\89æ
88 //x, y
\82Í
\95`
\89æ
\88Ê
\92u
\82Ì
\83I
\83t
\83Z
\83b
\83g
89 for(var sp in this.stageObjectList)
91 //
\8ae
\8eíStageObject
\82Ìdraw
\82ð
\8eÀ
\8ds
92 for(var i = 0, li = this.stageObjectList[sp].length; i < li; i++){
93 var stgobj = this.stageObjectList[sp][i];
94 var px = stgobj.origin.x - x, py = stgobj.origin.y - y;
96 if(px > -stgobj.size.x && py > -stgobj.size.y && px < 640 && py < 480)
100 stgobj.debugDraw(px, py);
106 drawBackground: function(){
109 this.mainContext.drawImage(this.background, 0, 0, 640, 480);
112 //
\83L
\83\83\83\93\83o
\83X
\82ð
\91S
\8fÁ
\8b\8e
113 this.mainContext.clearRect(0, 0, this.mainCanvas.width, this.mainCanvas.height);
115 this.collisionMapContext.clearRect(0, 0, this.collisionMapCanvas.width, this.collisionMapCanvas.height);
117 runStage: function(){
118 //
\83X
\83e
\81[
\83W
\8f\89\8aú
\89»
\8f\88\97\9d
120 //
\8fÕ
\93Ë
\83}
\83b
\83v
\8f\89\8aú
\89»
121 this.collisionMapCanvas = createCanvas("collisionMapCanvas", this.mainCanvas.width, this.mainCanvas.height, this.mainCanvas.width, 0, 1, this.manager.mainArea);
122 this.collisionMapContext = this.collisionMapCanvas.getContext('2d');
123 this.collisionMapContext.fillStyle = "rgba(0,0,0, 0.2)";
124 this.collisionMapContext.strokeStyle = "rgba(0,0,0, 0.2)";
125 this.collisionMapContext.scale(1, 1);
127 stopStage: function(){
128 //
\83X
\83e
\81[
\83W
\8fI
\97¹
\8f\88\97\9d
129 destroyDOMObjectByID(this.collisionMapCanvas.id);
130 this.collisionMapCanvas = null;
131 this.collisionMapContext = null;
132 this.stageObjectList = null;
134 addStageObject: function(aStageObject, isGlobalObject){
135 //stageObject
\82ð
\83\8a\83X
\83g
\82É
\92Ç
\89Á
\82·
\82é
136 //isGlobalObject:
\83l
\83b
\83g
\83\8f\81[
\83N
\8dX
\90V
\82ª
\95K
\97v
\82È
\8fê
\8d\87true
\82ð
\93n
\82·
\81B
\95s
\97v
\82È
\8fê
\8d\87\82Í
\8fÈ
\97ª
\82Å
\82«
\82é
\81B
137 //stageObjectList
\82Í
\83I
\83u
\83W
\83F
\83N
\83g
\82Ì
\83N
\83\89\83X
\82²
\82Æ
\82Ì
\98A
\91z
\94z
\97ñ
\82É
\82È
\82Á
\82Ä
\82¢
\82é
\81B
138 var sp = aStageObject.constructor;
139 if(this.stageObjectList[sp] == undefined)
141 this.stageObjectList[sp] = [];
143 this.stageObjectList[sp].push(aStageObject);
145 this.globalStageObjectList.push(aStageObject);
148 removeStageObject: function(aStageObject){
149 //stageObject
\82ð
\83\8a\83X
\83g
\82©
\82ç
\8dí
\8f\9c\82·
\82é
150 var sp = aStageObject.constructor;
151 if(sp in this.stageObjectList)
153 removeObjectFromArray(this.stageObjectList[sp], aStageObject);
154 if(this.stageObjectList[sp].length == 0)
156 //
\8bó
\82É
\82È
\82Á
\82½
\83N
\83\89\83X
\82Ì
\94z
\97ñ
\82Í
\8dí
\8f\9c\82·
\82é
157 removeObjectFromArray(this.stageObjectList, sp);
160 //globalStageObjectList
\82©
\82ç
\8dí
\8f\9c\81B
\91¶
\8dÝ
\82µ
\82È
\82¢
\8fê
\8d\87\82Í
\89½
\82à
\8bN
\82«
\82È
\82¢
\82Ì
\82Å
\82±
\82ê
\82Å
\91å
\8fä
\95v
161 removeObjectFromArray(this.globalStageObjectList, aStageObject);
163 eachStageObject: function(f){
164 //
\83\8a\83X
\83g
\8fã
\82Ì
\82·
\82×
\82Ä
\82Ì
\83I
\83u
\83W
\83F
\83N
\83g
\88ê
\82Â
\82¸
\82Â
\82ð
\88ø
\90\94\82Æ
\82µ
\82Ä
\8aÖ
\90\94f
\82ð
\82»
\82ê
\82¼
\82ê
\8eÀ
\8ds
\82·
\82é
\81B
165 //
\8aÖ
\90\94f
\82ªfalse
\82ð
\95Ô
\82µ
\82½
\8fê
\8d\87\81A
\82»
\82±
\82Å
\8eÀ
\8ds
\82ð
\92\86\92f
\82µ
\82Äfalse
\82ð
\95Ô
\82·
\81B
166 for(var sp in this.stageObjectList)
168 for(var i = 0; i < this.stageObjectList[sp].length; i++){
170 var stgobj = this.stageObjectList[sp][i];
171 if(!f(stgobj)) return false;
176 eachStageObjectById: function(id, f){
177 for(var sp in this.stageObjectList)
179 for(i = 0; i < this.stageObjectList[sp].length; i++){
181 var stgobj = this.stageObjectList[sp][i];
184 if(!f(stgobj)) return false;
190 collideJudge: function(obj, x, y, items){
191 var gainItem = items instanceof Array;
193 this.eachStageObject(function(f){
196 if(obj.isCollided(f, x, y))
202 for(var titem in items)
205 if(titem == f) return true;
222 moveTo : function(obj, x, y){
223 //
\93\96\82½
\82è
\94»
\92è
\8f\88\97\9d
224 var sx = obj.origin.x, sy = obj.origin.y;
225 var lx = x - sx, ly = y - sy;
226 if(lx == 0 && ly == 0) return;
228 var collideDirection = 0; //
\89º
\88Ê4bit :
\8fã
\89º
\8d¶
\89E
229 ct = Math.max(Math.abs(lx), Math.abs(ly));
230 dx = lx / ct; dy = ly / ct;
231 var fx = dx == 0, fy = dy == 0;
232 var ex = sx, ey = sy;
234 for(var i = 0; i < ct && !(fx && fy); i++)
236 //
\89¼
\82É
\82¨
\82¢
\82Ä
\82Ý
\82é
\8dÀ
\95W
237 //var ex = fx ? rx : sx + dx * i, ey = fy ? ry : sy + dy * i;
239 if(!fx && this.collideJudge(obj, ex + dx, ey, gotItems))
241 if(this.collideJudge(obj, ex + dx, ey - 2, gotItems))
244 collideDirection |= (dx > 0 ? 1 : 2);
251 if(!fy && this.collideJudge(obj, ex, ey + dy, gotItems))
254 collideDirection |= (dy > 0 ? 4 : 8);
264 for(var i in gotItems)
266 var item = gotItems[i];
267 if(item.itemAttacked)
269 //
\83A
\83C
\83e
\83\80\82ð
\8eæ
\93¾
\82µ
\82½
\82Æ
\82«
\82Ì
\8f\88\97\9d\82ð
\8cÄ
\82Ô(
\92N
\82ª
\8eæ
\93¾
\82µ
\82½
\82©
\81A
\8eæ
\93¾
\82µ
\82½
\93z
\82Ì
\8c»
\8dÝ
\88Ê
\92u
\82ð
\93n
\82·
\81j
270 item.itemAttacked(obj, ex, ey);
274 return collideDirection;
276 eachOwnStageObject: function(f){
277 //
\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é
278 for(var sp in this.stageObjectList)
280 for(var i = 0; i < this.stageObjectList[sp].length; i++){
281 var stgobj = this.stageObjectList[sp][i];
282 if(stgobj.ownerUID == this.manager.userID){
288 getGlobalStageObject: function(objid){
289 for(var i = 0; i < this.globalStageObjectList.length; i++){
290 if(objid == this.globalStageObjectList[i].objectID){
291 return this.globalStageObjectList[i];
296 appendSyncDataTo: function(data){
297 for(var i = 0; i < this.globalStageObjectList.length; i++){
298 var anObj = this.globalStageObjectList[i];
299 if(anObj.ownerUID == this.manager.userID){
300 data.append(i, anObj.objectID + "|" + anObj.origin.x + "|" + anObj.origin.y + "|" + anObj.movingSpeed.x + "|" + anObj.movingSpeed.y+ "|" + anObj.attribute);
304 appendInitialSyncDataTo: function(data){
305 for(var i = 0; i < this.globalStageObjectList.length; i++){
306 anObj = this.globalStageObjectList[i];
307 data.append(i, anObj.origin.x.toString() + "|" + anObj.origin.y.toString() + "|" + anObj.movingSpeed.x.toString() + "|" + anObj.movingSpeed.y.toString() + "|" + anObj.className + "|" + parseArrayToStringSource(anObj.attribute) + "|" + parseArrayToStringSource(anObj.constructorArgs));