PageSourceSearch

https://gravitygo.de/src/washingPartOne.js

js gravitygo.de collected 2026-10-06 17:33:03 UTC 26,421 bytes, 625 lines download raw bytes

1/*
2* Washing Sorting Game
3*/
4var WashingPartOne = new Phaser.Class({
5
6    Extends: Phaser.Scene,
7
8    initialize:
9
10    function StartScene (config)
11    {
12        Phaser.Scene.call(this, {key: 'washingPartOne'})
13    },
14    init: function (data) {
15        this.currentStage = 1;
16        var n = 0.1;
17
18        this.setup = {
19            stage1 : {
20                diff1 : {
21                    countdown : 60,
22                    speedShirts: n,
23                    speedShirtsModifier: 0.275,
24                    maxSpawnShirts: 14
25                },
26                diff2 : {
27                    countdown : 40,
28                    speedShirts: n,
29                    speedShirtsModifier: 0.9,
30                    maxSpawnShirts: 33
31                },
32                diff3 : {
33                    countdown : 30,
34                    speedShirts: n,
35                    speedShirtsModifier: 2,
36                    maxSpawnShirts: 56
37                },
38                shirts: {
39                    0 : {
40                        color: [0xffffff],
41                        key: "white",
42                        symbols: null,
43                        percentage: 0.4
44                    },
45                    1: {
46                        //red, blue, green, orange
47                        color: [0xea3636, 0x00b1ff, 0x3acc5f, 0xf29100],
48                        key: "color",
49                        symbols: null,
50                        percentage: 0.6
51                    }
52                },
53                baskets: [
54                    {
55                        key: "white",
56                        text: "White",
57                        size: 1,
58                        positionX: 220,
59                        positionY: 530
60                    }, 
61                    {
62                        key: "color",
63                        text: "Color",
64                        size: 1,
65                        positionX: 900,
66                        positionY: 530
67                    }
68                ],
69                instruction: "Sortiere die Wäsche in ihre Körbe. \nIn weiß kommt “helle, weiße, unempfindliche Wäsche”. \nIn bunt kommt “empfindliche Buntwäsche”.",
70                instruction2: "Ziehe die Wäschestücke direkt in die Körbe.\nLos geht's!"
71
72            },
73            stage2 : {
74                diff1 : {
75                    countdown : 90,
76                    speedShirts: n,
77                    speedShirtsModifier: 0.225,
78                    maxSpawnShirts: 17
79                },
80                diff2 : {
81                    countdown : 60,
82                    speedShirts: n,
83                    speedShirtsModifier: 0.75,
84                    maxSpawnShirts: 41
85                },
86                diff3 : {
87                    countdown : 30,
88                    speedShirts: n,
89                    speedShirtsModifier: 1.65,
90                    maxSpawnShirts: 46
91                },
92                shirts: {
93                    0 : {
94                        //red, blue, green, orange
95                        color: [0xea3636, 0x00b1ff, 0x3acc5f, 0xf29100],
96                        key: "30degrees",
97                        symbols: "color30",
98                        percentage: 0.33
99                    },
100                    1: {
101                        //red, blue, green, orange
102                        color: [0xea3636, 0x00b1ff, 0x3acc5f, 0xf29100],
103                        key: "40degrees",
104                        symbols: "color40",
105                        percentage: 0.33
106                    },
107                    2: {
108                        //darkred, darkblue, darkgreen, darkorange
109                        color: [0x890000, 0x3322cc, 0x096818, 0xa04100],
110                        key: "60degrees",
111                        symbols: "color60",
112                        percentage: 0.33
113                    }
114                },
115                baskets: [
116                    {
117                        key: "30degrees",
118                        text: "Color30",
119                        size: 0.8,
120                        positionX: 180,
121                        positionY: 550
122                    }, 
123                    {
124                        key: "40degrees",
125                        text: "Color40",
126                        size: 0.8,
127                        positionX: 570,
128                        positionY: 575
129                    }, 
130                    {
131                        key: "60degrees",
132                        text: "Color60",
133                        size: 0.8,
134                        positionX: 960,
135                        positionY: 550
136                    }
137                ],
138                instruction: "Sortiere die Wäsche nach \n“empfindlicher Bu
138ntwäsche” in bunt 30°, \n“empfindlicher Buntwäsche” in bunt 40° und \n“dunklere, unempfindliche Wäsche” in bunt 60°.",
139                instruction2: "Los geht's!"
140            },
141            stage3 : {
142                diff1 : {
143                    countdown : 90,
144                    speedShirts: n/1.75,
145                    speedShirtsModifier: 0.3,
146                    maxSpawnShirts: 12
147                },
148                diff2 : {
149                    countdown : 60,
150                    speedShirts: n/1.75,
151                    speedShirtsModifier: 0.85,
152                    maxSpawnShirts: 26
153                },
154                diff3 : {
155                    countdown : 30,
156                    speedShirts: n/1.75,
157                    speedShirtsModifier: 1.8,
158                    maxSpawnShirts: 27
159                },
160                shirts: {
161                    0 : {
162                        //red, blue, green, orange
163                        color: [0xea3636, 0x00b1ff, 0x3acc5f, 0xf29100],
164                        key: "noTumbledry",
165                        symbols: "tumbleNot",
166                        desc: "Nicht im Trommel-\ntrockner trocknen",
167                        percentage: 0.2
168                    },
169                    1: {
170                        //red, blue, green, orange
171                        color: [0xea3636, 0x00b1ff, 0x3acc5f, 0xf29100],
172                        key: "noWashing",
173                        symbols: "washNot",
174                        desc: "Nicht waschen",
175                        percentage: 0.2
176                    },
177                    2: {
178                        //red, blue, green, orange
179                        color: [0xea3636, 0x00b1ff, 0x3acc5f, 0xf29100],
180                        key: "wash40",
181                        symbols: "wash40",
182                        desc: "Waschen 40°C\nschonend.",
183                        percentage: 0.2
184                    },
185                    3: {
186                        //red, blue, green, orange
187                        color: [0xea3636, 0x00b1ff, 0x3acc5f, 0xf29100],
188                        key: "handwash",
189                        symbols: "washHand",
190                        desc: "Handwäsche",
191                        percentage: 0.2
192                    },
193                    4: {
194                        //red, blue, green, orange
195                        color: [0xea3636, 0x00b1ff, 0x3acc5f, 0xf29100],
196                        key: "wash30",
197                        symbols: "washCold",
198                        desc: "Waschen 30°C\nsehr schonend.",
199                        percentage: 0.2
200                    }
201                },
202                baskets: [
203                    {
204                        key: "noWashing",
205                        text: "WashNot",                        
206                        size: 0.6,
207                        positionX: 140,
208                        positionY: 440
209                    }, 
210                    {
211                        key: "handwash",
212                        text: "WashHand",
213                        size: 0.6,
214                        positionX: 270,
215                        positionY: 530
216                    }, 
217                    {
218                        key: "wash30",
219                        text: "WashCold",
220                        size: 0.6,
221                        positionX: 485,
222                        positionY: 580
223                    }, 
224                    {
225                        key: "wash40",
226                        text: "Wash40",
227                        size: 0.6,
228                        positionX: 740,
229                        positionY: 565
230                    }, 
231                    {
232                        key: "noTumbledry",
233                        text: "TumbleNot",                        
234                        size: 0.6,
235                        positionX: 990,
236                        positionY: 490
237                    }
238                ],
239                instruction: "Sortiere die Wäsche anhand ihrer Textilpflegesymbole \nin den passenden Wäschekorb. \nBewege ein Wäschestück unter die Lupe, \num das Wäschesymbol genau anzuschauen.",
240                instruction2: "Los geht's!"
241            },
242            speedMobile: 1.35,
243            highscore1a: "Mmh, die Wäsche reicht für heute.",
244            highscore1b: "Morgen muss ich dann nochmal ran!",
245
246            highscore2a: "Mmh, jetzt habe ich $VAR$ Wäschestücke\nrichtig sortiert. Das sind $PERC$%. Naja.",
247            highscore2b: "Die $VAR$ Wäschestücke auf dem Boden \nwasche ich nächstes Mal!",
248
249            highscore3a: "Super. Ich habe $VAR$ Wäschestücke,\nalso $PERC$% der Wäsche richtig sortiert!",
250            highscore3b: "Die $VAR$ Wäschestücke auf dem Boden \nwasche ich nächstes Mal!",
251        }
252
253        //todo highscore1b if != 0 : "Die $floorScoreSum Wäschestücke auf dem Boden \nwasche ich nächstes Mal!"
254
255        this.scores = {
256            stage1 : {
257                correct : 0,
258                wrong : 0,
259                floor: 0
260            },
261            stage2 : {
262                correct : 0,
263                wrong : 0,
264                floor: 0
265            },
266            stage3 : {
267                correct : 0,
268                wrong : 0,
269                floor: 0
270            }
271        }
272    },
273    preload: function () {},
274    create: function (data) {
275        masterScene = this.scene.get('masterScene');
276        //console.log("opened washing scene");
277        var that = this;
278
279        masterScene.atmoGames.play({loop:true});
280        masterScene.atmoMap.stop();
281
282        //initial dialogue
283        masterScene.dialogueBox.visible = true;
284        masterScene.updateDialogueText(this.setup["stage" + this.currentStage].instruction);
285
286        masterScene.character.x = 120 * r;
287        masterScene.character.y = 885 * r;
288        masterScene.character.play("Loop_Idle_A");
289
290        this.baskets = [];
291        this.shirts = [];
292
293        this.background = this.add.image(0,0,'laundryBackground_Sorting').setOrigin(0).setInteractive();
294        this.timerBG = this.add.image(550 * r,0 * r, 'timeBarBackground').setOrigin(0.5, 0);
295        this.timerBar = this.add.image(256 * r, 22 * r, 'timeBar').setOrigin(0).setTint(0x45f88a);
296        this.timer = this.add.image(550 * r,0 * r, 'time').setOrigin(0.5, 0); 
297        this.timerBar.depth = this.timer.depth = this.timerBG.depth = 50;  
298
299        this.input.once('pointerdown', () => {
300            masterScene.updateDialogueText(this.setup["stage" + this.currentStage].instruction2);
301            that.input.once('pointerdown', () => {
302                that.setupStage();
303            }, this);
304        }, this);
305
306        //add dirty laundry
307        this.laundryPile = this.add.image(550 * r,480 * r, 'laundryPile');
308        this.laundryPile.visible = false;
309
310        this.setupDragLogic();    
311
312        //buttons to skip to washing part or back to map
313        /*this.buttonBack = this.add.image(40 * r, 50 * r, 'buttonTriangle').setScale(-1,1).setTint(masterScene.uiColor).setInteractive().on('pointerdown', () => {
314            masterScene.playFeedback(this.buttonBack, 'map'); 
315            masterScene.gameData.gameState = 1;   
316        }, this);
317
318        this.buttonContinue = this.add.image(1080 * r, 50 * r, 'buttonTriangle').setTint(masterScene.uiColor).setInteractive().on('pointerdown', () => {
319            masterScene.playFeedback(this.buttonContinue, 'washingPartTwo'); 
320            masterScene.gameData.gameState = 1;   
321        }, this);*/
322    },
323    update: function (time, delta) {
324        if(this.timedEvent != undefined){
325            this.timerBar.setScale(1 - this.timedEvent.getProgress(),1);
326        }       
327        if(this.shirts.length > 0){
328            for(var i = 0; i < this.shirts.length; i++){
329                if(!this.shirts[i].dragging){
330                    this.shirts[i].y += (this.speedShirts * this.speedShirtsModifier * (window.USER_IS_TOUCHING ? this.setup.speedMobile : 1) * delta) * r;
331
332                    if(this.shirts[i].y > 410 * r){
333                        this.shirts[i].destroy();
334                        this.shirts.splice(i, 1);
335                        this.scores['stage' + this.currentStage].floor ++;
336
337                        if(this.scores['stage' + this.currentStage].floor == 2){
338                            this.laundryPile.visible = true;
339                        }
340                        masterScene.playFeedback(this.laundryPile,"", false, masterScene.cloth)
341                    }
342                }
343            }
344        }  
345    },
346    basketFeedbackSetup: function(gameObject, value){
347        gameObject.setInteractive(new Phaser.Geom.Rectangle(-gameObject.first.width/2, -gameObject.first.height/2, gameObject.first.width, gameObject.first.height * 2), Phaser.Geom.Rectangle.Contains, { dropZone: true });
348        gameObject.value = value;
349        gameObject.counter = 0;
350    },
351    setupStage: function(){
352        this.laundryPile.visible = false;
353        masterScene.dialogueBox.visible = false;
354        masterScene.character.visible = false;
355        masterScene.updateDialogueText('');
356
357        this.speedShirts = this.setup["stage" + this.currentStage]["diff" + masterScene.gameData.difficulty].speedShirts;
358        this.speedShirtsModifier = this.setup["stage" + this.currentStage]["diff" + masterScene.gameData.difficulty].speedShirtsModifier;
359        var that = this;
360        //create baskets
361        for(var i = 0; i < this.setup["stage" + this.currentStage].baskets.length; i++){
362            var size = this.setup["stage" + this.currentStage].baskets[i].size;
363            var posX = this.setup["stage" + this.currentStage].baskets[i].positionX * r;
364            var posY = this.setup["stage" + this.currentStage].baskets[i].positionY * r;
365
366            this.basketImage = this.add.image(0,0, 'basketScreen').setOrigin(0.5);
367            this.basketCounter = this.add.text(160 * r, -115 * r, '0', { fontFamily: 'Mina', fontSize: 24 * r, color: '#000000' });
368            this.basketText = this.add.image(0 * r, 45 * r, 'laundryBasket_text' + this.setup["stage" + this.currentStage].baskets[i].text);
369            this.basket = this.add.container(posX, posY, [this.basketImage, this.basketText, this.basketCounter]);
370            this.basket.setScale(size);
371            this.basket.counterText = this.basketCounter;
372            this.basket.baseImage = this.basketImage;
373
374            this.basketFeedbackSetup(this.basket, this.setup["stage" + this.currentStage].baskets[i].key);
375            this.baskets.push(this.basket);
376        }
377
378        //add magnifying glass and info panel for stage 3
379        if(this.currentStage == 3){
380            this.glasses = this.add.image(1000 * r, 200 * r, 'magnifyingGlass').setInteractive({ dropZone: true });
381            this.glasses.dropType = "glasses";
382
383            this.panelBg = this.add.image(0,0, 'infobox');
384            this.panelIcon = this.add.image(-140 * r,0, 'laundryIcon_color30').setTint(0x000000);
385            this.panelText = this.add.text(-90 * r, 0, "Vorsichtig Waschen", { fontFamily: 'Mina', fontSize: 24 * r, color: '#000000' }).setOrigin(0,0.5);
386
387            this.panel = this.add.container(1000 * r, 300 * r, [this.panelBg, this.panelText, this.panelIcon]);
388            this.panel.visible = false;
389        }
390
391        //setup timer
392        var secs = this.setup["stage" + this.currentStage]["diff" + masterScene.gameData.difficulty].countdown;
393        //secs = 20;
394        this.timedEvent = this.time.delayedCall(secs * 1000, function(){
395            masterScene.win.play();
396
397            masterScene.dialogueBox.visible = true;
398            masterScene.character.visible = true;
399
400            var percentage = Math.round(that.scores['stage' + that.currentStage].correct/Math.floor((that.setup["stage" + this.currentStage]["diff" + masterScene.gameData.difficulty].maxSpawnShirts * (window.USER_IS_TOUCHING ? this.setup.speedMobile : 1))) * 100);
401            var index = 1;
402            if(percentage > 10){
403                index = 2;
404            }
405            if(percentage > 40){
406                index = 3;
407            }
408
409            var highscoreText = this.setup["highscore" + index + "a"].replace("$VAR$", that.scores['stage' + that.currentStage].correct);
410            highscoreText = highscoreText.replace("$PERC$", percentage);
411            masterScene.updateDialogueText(highscoreText);
412
413            this.input.once('pointerdown', () => {
414                if(that.scores['stage' + that.currentStage].floor > 0){
415                    var highscoreText = this.setup["highscore" + index + "b"].replace("$VAR$", that.scores['stage' + that.currentStage].floor);
416                    masterScene.updateDialogueText(highscoreText);
417                    that.currentStage ++;
418                    this.input.once('pointerdown', () => {
419                        if(that.currentStage < 4){
420                            masterScene.updateDialogueText(this.setup["stage" + this.currentStage].instruction);
421                            this.input.once('pointerdown', () => {
422                                masterScene.updateDialogueText(this.setup["stage" + this.currentStage].instruction2);
423                                that.setupStage();
424                                    
425                                }, this);
426                            
427                        }else{
428                            masterScene.startNextScene('washingPartTwo'); 
429                        }
430                    }, this);
431                }
432                else{
433                    that.currentStage ++;
434                    if(that.currentStage < 4){
435                        masterScene.updateDialogueText(this.setup["stage" + this.currentStage].instruction);
436                        that.input.once('pointerdown', () => {
437                            masterScene.updateDialogueText(this.setup["stage" + this.currentStage].instruction2);
438                            that.input.once('pointerdown', () => {
439                                if(that.currentStage < 4){
440                                    that.setupStage();
441                                }else{
442                                    masterScene.startNextScene('washingPartTwo'); 
443                                }
444                            }, this);
445                        }, this);
446                    }else{
447                        masterScene.startNextScene('washingPartTwo'); 
448                    };
449                }
450                
451                for(var i = 0; i < this.shirts.length; i++){
452                    this.shirts[i].destroy();
453                };
454                this.shirts = [];
455                for(var i = 0; i < this.baskets.length; i++){
456                    this.baskets[i].destroy();
457                };
458                this.baskets = [];
459                    
460            }, this);
461            
462        }, [], this);
463
464        //spawn shirts
465        this.spawnShirts();
466    },
467    spawnShirts: function(){
468        var maxShirts = 10;
469        var maxShirts = this.setup["stage" + this.currentStage]["diff" + masterScene.gameData.difficulty].maxSpawnShirts * (window.USER_IS_TOUCHING ? this.setup.speedMobile : 1);
470
471        var clothingTypes = ["clothingShirt", "clothingUnderpants", "clothingTowel", "clothingTrousers"];
472
473        var color;
474        var icon;
475        var shirtContainer;
476
477        var shirtType;
478
479        for(var i = 1; i <= maxShirts; i++){
480            var d = Math.random();
481
482            switch(this.currentStage){
483                case 1:
484                    if (d < this.setup["stage1"].shirts[0].percentage){
485                        shirtType = 0;                    
486                    }   
487                    else{
488                        shirtType = 1;
489                    }
490                    break;
491                case 2:
492                    if (d < this.setup["stage2"].shirts[0].percentage){
493                        shirtType = 0;
494                    }   
495                    else if(d < this.setup["stage2"].shirts[0].percentage + this.setup["stage2"].shirts[1].percentage){
496                        shirtType = 1;
497                    }
498                    else{
499                        shirtType = 2;
500                    }
501                    break;
502                case 3:
503                    if (d < this.setup["stage3"].shirts[0].percentage){
504                        shirtType = 0;
505                    }   
506                    else if(d < this.setup["stage3"].shirts[0].percentage + this.setup["stage3"].shirts[1].percentage){
507                        shirtType = 1;
508                    }
509                    else if(d < this.setup["stage3"].shirts[0].percentage + this.setup["stage3"].shirts[1].percentage + this.setup["stage3"].shirts[2].percentage){
510                        shirtType = 2;
511                    }
512                    else if(d < this.setup["stage3"].shirts[0].percentage + this.setup["stage3"].shirts[1].percentage + this.setup["stage3"].shirts[2].percentage + this.setup["stage3"].shirts[3].percentage){
513                        shirtType = 3;
514                    }
515                    else{
516                        shirtType = 4;
517                    }
518                    break;
519            }
520
521            var col = Math.round(Math.random() * (this.setup["stage" + this.currentStage].shirts[shirtType].color.length - 1) + 0);
522            color = this.setup["stage" + this.currentStage].shirts[shirtType].color[col];
523
524            var rand = Math.round(Math.random() * (clothingTypes.length - 1) + 0);
525            clothingType = clothingTypes[rand];
526            
527            var shirt = this.add.image(0, 0, clothingType).setTint(color);
528
529            if(this.setup["stage" + this.currentStage].shirts[shirtType].symbols != null){
530                icon = this.add.image(0, 0, 'laundryIcon_' + this.setup["stage" + this.currentStage].shirts[shirtType].symbols);
531                shirtContainer = this.add.container(550 * r, (-100 * i) * r, [shirt, icon]).setInteractive(new Phaser.Geom.Circle(0, 0, 60 * r), Phaser.Geom.Circle.Contains);
532            }else{
533                shirtContainer = this.add.container(550 * r, (-100 * i)  * r, [shirt]).setInteractive(new Phaser.Geom.Circle(0, 0, 60 * r), Phaser.Geom.Circle.Contains);
534            }
535
536            shirtContainer.value = this.setup["stage" + this.currentStage].shirts[shirtType].key;
537            if(this.setup["stage" + this.currentStage].shirts[shirtType].desc != undefined){
538                shirtContainer.desc = this.setup["stage" + this.currentStage].shirts[shirtType].desc;
539                shirtContainer.icon = this.setup["stage" + this.currentStage].shirts[shirtType].symbols;
540            }
541
542            this.input.setDraggable(shirtContainer);
543            this.shirts.push(shirtContainer);
544        }
545    },
546    setupDragLogic: function(){
547        var that = this;
548        //drag & drop logic
549        this.dragging = false;
550        
551        this.input.on('dragstart', function (pointer, gameObject) {
552            that.dragging = true;
553            gameObject.dragging = true;
554            masterScene.drag.play();
555            //gameObject.tween.pause();
556
557        });
558
559        this.input.on('drag', function (pointer, gameObject, dragX, dragY) {
560            gameObject.x = dragX;
561            gameObject.y = dragY;     
562        });
563
564        this.input.on('dragend', function (pointer, gameObject) {
565            masterScene.drop.play();
566            if(that.panel != undefined){
567                that.panel.visible = false;
568            }
569            that.dragging = false;
570            gameObject.dragging = false;
571        });
572
573        this.input.on('dragenter', function (pointer, gameObject, target) {
574            if(target.dropType == "glasses"){
575                that.panel.visible = true;
576                that.panelText.setText(gameObject.desc);
577                that.panelIcon.setTexture('laundryIcon_' + gameObject.icon);
578                masterScene.cloth.play();
579            }
580            else {
581                if(target.tween == null || !target.tween.isPlaying()){
582                    startX = target.scaleX;
583                    startY = target.scaleY;
584
585                    target.tween = that.tweens.add({
586                        targets: target,
587                        scaleX: startX * 1.2,
588                        scaleY: startY * 1.2,
589                        ease: 'Sine.easeInOut',
590                        duration: 100,
591                        yoyo: true,
592                    });
593                }
594            } 
595        });
596
597        this.input.on('dragleave', function (pointer, gameObject, target) {
598            if(target.dropType == "glasses"){
599                that.panel.visible = false;
600            }
601        });
602
603        this.input.on('drop', function (pointer, gameObject, target) {
604            if(target.dropType == "glasses"){
605                return;
606            }
607            if(gameObject.value == target.value){
608                masterScene.correct.play();
609                that.scores['stage' + that.currentStage].correct ++;
610                target.counter ++;
611                target.counterText.setText(target.counter);
612                target.baseImage.setTint(0x59f881);
613                that.time.delayedCall(100, function(){target.baseImage.setTint(0xffffff);}, [], this);
614                gameObject.destroy();
615            }else{
616                masterScene.wrong.play();
617                that.scores['stage' + that.currentStage].wrong ++;
618                target.baseImage.setTint(0xf85959);
619                that.time.delayedCall(100, function(){target.baseImage.setTint(0xffffff);}, [], this);
620                masterScene.playFeedbackWrong(target);
621                gameObject.destroy();
622            }
623        });
624    }
625});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.