Skip to content

Commit 407c2a5

Browse files
authored
Create main
1 parent 02ed270 commit 407c2a5

1 file changed

Lines changed: 130 additions & 0 deletions

File tree

main

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
<<<<<<< HEAD
2+
1|class Example extends Phaser.Scene {
3+
2| constructor() {
4+
3| super();
5+
4| }
6+
5|
7+
6| create() {
8+
7| // Set the background color to black
9+
8| this.cameras.main.setBackgroundColor('#000000');
10+
9| }
11+
10|}
12+
11|
13+
12|const config = {
14+
13| type: Phaser.AUTO,
15+
14| parent: 'renderDiv',
16+
15| scale: {
17+
16| mode: Phaser.Scale.FIT,
18+
17| autoCenter: Phaser.Scale.CENTER_BOTH,
19+
18| },
20+
19| width: 800,
21+
20| height: 600,
22+
21| scene: Example
23+
22|};
24+
23|
25+
24|window.phaserGame = new Phaser.Game(config);
26+
=======
27+
1|class Example extends Phaser.Scene {
28+
2| constructor() {
29+
3| super();
30+
4| this.backgroundMusic;
31+
5| }
32+
6|
33+
7| preload() {
34+
8| this.load.image('orchard', `https://play.rosebud.ai/assets/orchard.png?PYWE`);
35+
9| this.load.image('apple', `https://play.rosebud.ai/assets/apple.png?Hypw`);
36+
10| this.load.image('red', `https://play.rosebud.ai/assets/red.png?mn03`);
37+
11| this.load.audio('background_music', `https://play.rosebud.ai/assets/2D_playground_template_music.mp3?qH05`);
38+
12| }
39+
13|
40+
14| create() {
41+
15| const { width, height } = this.scale;
42+
16|
43+
17| // Add the new orchard background
44+
18| const background = this.add.image(width / 2, height / 2, 'orchard');
45+
19|
46+
20| // Scale the background to cover the entire game area while maintaining aspect ratio
47+
21| const scaleX = width / background.width;
48+
22| const scaleY = height / background.height;
49+
23| const scale = Math.max(scaleX, scaleY);
50+
24| background.setScale(scale);
51+
25|
52+
26| const particles = this.add.particles('red');
53+
27| const emitter = particles.createEmitter({
54+
28| speed: 100,
55+
29| scale: { start: 1, end: 0 },
56+
30| blendMode: 'ADD',
57+
31| tint: 0x42e0f5 // Set the tint to light blue color (#42e0f5)
58+
32| });
59+
33|
60+
34| const apple = this.physics.add.image(width / 2, height * 0.2, 'apple');
61+
35|
62+
36| // Make the apple 20% smaller than its previous size
63+
37| apple.setScale(0.2 * 0.8);
64+
38|
65+
39| apple.setVelocity(100, 200);
66+
40| apple.setBounce(0.8, 0.8);
67+
41| apple.setCollideWorldBounds(true);
68+
42|
69+
43| emitter.startFollow(apple);
70+
44|
71+
45| // Enable dragging of the apple
72+
46| apple.setInteractive();
73+
47| this.input.setDraggable(apple);
74+
48| this.input.on('dragstart', (pointer, gameObject) => {
75+
49| gameObject.body.setVelocity(0);
76+
50| gameObject.body.setAcceleration(0);
77+
51| gameObject.body.setAngularVelocity(0);
78+
52| });
79+
53| this.input.on('drag', (pointer, gameObject, dragX, dragY) => {
80+
54| gameObject.body.setVelocity(0);
81+
55| gameObject.body.setAcceleration(0);
82+
56| gameObject.body.setAngularVelocity(0);
83+
57| gameObject.x = dragX;
84+
58| gameObject.y = dragY;
85+
59| });
86+
60| this.input.on('pointerdown', (pointer, currentlyOver) => {
87+
61| if (currentlyOver.length === 0) {
88+
62| const newApple = this.physics.add.image(pointer.x, pointer.y, 'apple');
89+
63| newApple.setScale(0.2 * 0.8);
90+
64| newApple.setBounce(0.8, 0.8);
91+
65| newApple.setCollideWorldBounds(true);
92+
66| newApple.setInteractive();
93+
67| this.input.setDraggable(newApple);
94+
68| emitter.startFollow(newApple);
95+
69| } else {
96+
70| currentlyOver.forEach(gameObject => {
97+
71| gameObject.body.setVelocity(0);
98+
72| gameObject.body.setAcceleration(0);
99+
73| gameObject.body.setAngularVelocity(0);
100+
74| });
101+
75| }
102+
76| });
103+
77|
104+
78| // Background music
105+
79| this.backgroundMusic = this.sound.add('background_music', { loop: true, volume: 0.1 });
106+
80| this.backgroundMusic.play();
107+
81| }
108+
82|}
109+
83|
110+
84|const config = {
111+
85| type: Phaser.AUTO,
112+
86| parent: 'renderDiv',
113+
87| pixelArt: true,
114+
88| scale: {
115+
89| mode: Phaser.Scale.FIT,
116+
90| autoCenter: Phaser.Scale.CENTER_BOTH,
117+
91| width: 360,
118+
92| height: 640
119+
93| },
120+
94| physics: {
121+
95| default: 'arcade',
122+
96| arcade: {
123+
97| gravity: { y: 200 }
124+
98| }
125+
99| },
126+
100| scene: Example
127+
101|};
128+
102|
129+
103|window.phaserGame = new Phaser.Game(config);
130+
>>>>>>> updated

0 commit comments

Comments
 (0)