|
| 1 | +function initPhaserGame() { |
| 2 | + const config = { |
| 3 | + type: Phaser.AUTO, |
| 4 | + width: window.innerWidth, |
| 5 | + height: window.innerHeight, |
| 6 | + parent: "phaser-container", // Make sure this div exists in your HTML |
| 7 | + transparent: true, |
| 8 | + physics: { |
| 9 | + default: "arcade", |
| 10 | + arcade: { gravity: { y: 300 } }, |
| 11 | + }, |
| 12 | + scene: { |
| 13 | + preload: preload, |
| 14 | + create: create, |
| 15 | + }, |
| 16 | + }; |
| 17 | + |
| 18 | + const game = new Phaser.Game(config); |
| 19 | +} |
| 20 | + |
| 21 | +function preload() { |
| 22 | + // No need to preload images if we are only using text/emojis! |
| 23 | +} |
| 24 | + |
| 25 | +function create() { |
| 26 | + const emojis = [ |
| 27 | + // Gaming & Tech |
| 28 | + "🎮", |
| 29 | + "🕹️", |
| 30 | + "👾", |
| 31 | + "🚀", |
| 32 | + "💻", |
| 33 | + "📱", |
| 34 | + "⌨️", |
| 35 | + "🖱️", |
| 36 | + "🔋", |
| 37 | + "🔌", |
| 38 | + // Magic & Space |
| 39 | + "✨", |
| 40 | + "⭐", |
| 41 | + "🌟", |
| 42 | + "🔮", |
| 43 | + "🌌", |
| 44 | + "🌠", |
| 45 | + "🌙", |
| 46 | + "☄️", |
| 47 | + "🛸", |
| 48 | + "👽", |
| 49 | + // Action & Fun |
| 50 | + "🔥", |
| 51 | + "💥", |
| 52 | + "🧨", |
| 53 | + "⚡", |
| 54 | + "🌈", |
| 55 | + "🎉", |
| 56 | + "🎊", |
| 57 | + "🎈", |
| 58 | + "🎁", |
| 59 | + "💎", |
| 60 | + // Hearts & Expressions |
| 61 | + "💖", |
| 62 | + "🎯", |
| 63 | + "🏆", |
| 64 | + "🥇", |
| 65 | + "🧿", |
| 66 | + "🍀", |
| 67 | + "🍕", |
| 68 | + "🍭", |
| 69 | + "🍦", |
| 70 | + "🍩", |
| 71 | + // Creatures & Icons |
| 72 | + "🤖", |
| 73 | + "👻", |
| 74 | + "🐲", |
| 75 | + "🦄", |
| 76 | + "🦊", |
| 77 | + "🐱", |
| 78 | + "🐧", |
| 79 | + "🦖", |
| 80 | + "🍄", |
| 81 | + "🌍", |
| 82 | + ]; |
| 83 | + const heartRect = document |
| 84 | + .getElementById("footer-heart") |
| 85 | + .getBoundingClientRect(); |
| 86 | + |
| 87 | + for (let i = 0; i < 75; i++) { |
| 88 | + // 1. Pick a random emoji |
| 89 | + const randomEmoji = emojis[Math.floor(Math.random() * emojis.length)]; |
| 90 | + |
| 91 | + // 2. Create the emoji at the heart's location |
| 92 | + // We use this.add.text instead of this.physics.add.image |
| 93 | + const particle = this.add.text(heartRect.left, heartRect.top, randomEmoji, { |
| 94 | + fontSize: "32px", |
| 95 | + }); |
| 96 | + |
| 97 | + // 3. Manually add physics to the text object |
| 98 | + this.physics.add.existing(particle); |
| 99 | + |
| 100 | + // 4. Apply the "Explosion" physics |
| 101 | + // Shoots them out in a cone shape upward |
| 102 | + particle.body.setVelocity( |
| 103 | + Phaser.Math.Between(-300, 300), |
| 104 | + Phaser.Math.Between(-500, -1000), |
| 105 | + ); |
| 106 | + |
| 107 | + particle.body.setCollideWorldBounds(true); |
| 108 | + particle.body.setBounce(0.7); |
| 109 | + |
| 110 | + // Optional: Add a little random rotation for flair |
| 111 | + particle.setAngle(Phaser.Math.Between(0, 360)); |
| 112 | + } |
| 113 | +} |
0 commit comments