OSDN Git Service

68dd8cfff645936b1e94477487a8e7462545840b
[h58pcdgame/GameScriptCoreLibrary.git] / www / corelib / classes / BakingOvenObjectClass.js
1 var BakingOvenObjectClass = function(ownerStage, args){
2         BakingOvenObjectClass.base.apply(this, arguments);
3         
4         this.imgs = new Array();
5         for(var i = 0; i < 3; i++){
6                 this.imgs[i] = document.createElement('img');
7         }
8         this.imgs[0].src = "images/furnace.png";
9         this.imgs[1].src = "images/furnaceof1.png";
10         this.imgs[2].src = "images/furnaceof2.png";
11         
12         this.img_puff = [];
13         this.img_puff[0] = document.createElement('img');
14         this.img_puff[0].src = "images/puff.png";
15         this.img_puff[1] = document.createElement('img');
16         this.img_puff[1].src = "images/puff2.png";
17         
18         this.cookSound = createAudio("baking.mp3");
19         this.image = this.imgs[0];
20         this.size.x = 64;
21         this.size.y = 96;
22         this.isPhantom = true;
23         this.isSelecting = false;
24         this.basePoint = 0;
25         this.bakingTickCount = 0;
26         this.bakingCount = 0;
27         this.bakingStartTime = -1;              //調理開始時に時刻を代入
28         this.isBaking = false;
29         
30         
31         
32 }.extend(BlockClass, {
33         tick : function()
34         {
35                 this.checkTouchingDirection();
36                 if((this.touchingDirection & CollideBody) == CollideBody){
37                         if(this.ownerStage.manager.UIManager.keyState.select && !this.isSelecting){
38                                 var that = this;
39                                 var thatManager = that.ownerStage.manager;
40                                 if(!this.isBaking){
41                                         //焼き始め
42                                         if(thatManager.userManager.ingredientList.length <= 0){
43                                                 thatManager.addWidget(new MessageWidgetClass(thatManager, ["手持ちの材料がありません!\n"]));
44                                                 that.isSelecting = false;
45                                         } else{
46                                                 this.isSelecting = true;
47                                                 thatManager.addWidget(
48                                                         new SelectWidgetClass(thatManager, [thatManager.userManager.ingredientList, function(retv){
49                                                                 if(retv != null){
50                                                                         if(retv.length > 0){
51                                                                                 that.basePoint = that.calculateBreadBasePoint(retv);
52                                                                                 if(that.basePoint < 0){
53                                                                                         thatManager.addWidget(new MessageWidgetClass(thatManager, ["見るからにまずそう…焼くのはやめておこう。\n"]));
54                                                                                 } else{
55                                                                                         var text = new TextWidgetClass(thatManager, ["焼き始めました!\nもう一度窯を選択すると取り出します。       ", true, true]);
56                                                                                         thatManager.addWidget(text);
57                                                                                         that.bakingTickCount = 0;
58                                                                                         that.bakingCount = 0;
59                                                                                         that.bakingStartTime = +new Date();     //時間のミリ秒を代入
60                                                                                         that.isBaking = true;
61                                                                                         for(var i = 0, m = retv.length; i < m; i++){
62                                                                                                 removeAnObjectFromArray(thatManager.userManager.ingredientList, retv[i]);
63                                                                                         }
64                                                                                         that.cookSound.load();
65                                                                                         that.cookSound.play();
66                                                                                 }
67                                                                         } else{
68                                                                                 thatManager.addWidget(new MessageWidgetClass(thatManager, ["一つも材料が選択されていないので、パンを焼くことができません!\n"]));
69                                                                         }
70                                                                 }
71                                                                 that.isSelecting = false;
72                                                         },true, 0, true])
73                                                 );
74                                         }
75                                 } else if(this.bakingCount > 10){
76                                         //焼き終わり
77                                         this.isSelecting = true;
78                                         var s = null;
79                                         var p = 1;
80                                         var t = ((+new Date()) - this.bakingStartTime) * (100/16000);   //16秒が基準(下の判定の100)
81                                         var c = this.bakingCount;
82                                         if(t < 30){
83                                                 s = "まだ生だった…。";
84                                                 p = 0.25;
85                                         } else if(t < 60){
86                                                 s = "生焼けだった…。";
87                                                 p = 0.50;
88                                         } else if(t < 80){
89                                                 s = "火通りが甘い…。";
90                                                 p = 0.75;
91                                         } else if(t < 95){
92                                                 s = "いい焼け具合だ!";
93                                                 p = 1.00;
94                                         } else if(t < 100){
95                                                 s = "最高の焼き具合だ!";
96                                                 p = 1.25;
97                                         } else if(t < 101){
98                                                 s = "完璧な焼き具合だ!";
99                                                 p = 1.50;
100                                         } else if(t < 110){
101                                                 s = "いい焦げ方だ!";
102                                                 p = 1.00;
103                                         } else if(t < 116){
104                                                 s = "焦げ過ぎだった…。";
105                                                 p = 0.50;
106                                         } else if(t < 121){
107                                                 s = "炭になってる…。";
108                                                 p = 0.25;
109                                         } else{
110                                                 s = "もはや灰しか残らなかった…。";
111                                                 p = 0.00;
112                                         }
113                                         that.basePoint = Math.floor(p * that.basePoint);
114                                         thatManager.userManager.breadList.push(that.basePoint);
115                                         thatManager.addWidget(new MessageWidgetClass(thatManager, [s + that.basePoint + "ポイントのパンをゲットした。\n"]));
116                                         that.isSelecting = false;
117                                         that.isBaking = false;
118                                         this.bakingCount = 0;
119                                         this.image = this.imgs[0];
120                                         that.cookSound.pause();
121                                 }
122                         }
123                 }
124                 if(this.isBaking){
125                         //焼き途中
126                         this.bakingTickCount++;
127                         if(this.bakingTickCount >= 6){
128                                 this.bakingTickCount = 0;
129                                 this.bakingCount++;
130                                 this.image = this.imgs[(this.bakingCount & 1) + 1];
131                         }
132                 }
133         },
134         calculateBreadBasePoint: function(ingr){
135                 var p = 0;
136                 for(var i = 0, m = ingr.length; i < m; i++){
137                         p += IngredientAttributeList[ingr[i].index][1];
138                 }
139                 return p;
140         },
141         draw : function(x, y)
142         {
143                 BakingOvenObjectClass.base.prototype.draw.apply(this, [x, y]);
144                 
145                 if(this.bakingCount > 80)
146                 {
147                         var puff = ((+new Date()) - this.bakingStartTime) * (100/16000) - 80;
148                         if(puff > 40)puff = 40;
149                         var opacity = 0.5 * (puff / 40) + (this.ownerStage.manager.tickCount % 10) / 20;
150                         this.ownerStage.mainContext.save();
151                         this.ownerStage.mainContext.globalAlpha = opacity;
152                         this.ownerStage.mainContext.drawImage(this.img_puff[this.ownerStage.manager.tickCount % 20 < 10 ? 0 : 1], x - 32 , y - 400, 320, 480);
153                         this.ownerStage.mainContext.restore();
154                 }
155         }
156 });