Yeah thanks for pointing out the double head tag. I was doing that for a specific reason and forgot to take it off 😂
I finally figured it out! I’ll post about it later because I’ve been working on something that I think is pretty cool
Yeah thanks for pointing out the double head tag. I was doing that for a specific reason and forgot to take it off 😂
I finally figured it out! I’ll post about it later because I’ve been working on something that I think is pretty cool
🤗
There's unused variable declarations, so I assume it's unfinished.
You forgot 'new' the line should be -->
var game = new Phaser.Game(config);
There's a few other things... And I'm pretty sure there's an extra } for no reason... Unless I counted wrong.
Yeah there are definitely unused variables. I coded this on my phone, so I don’t really have the best tools. And wtf, I left a variable named fart 😂🤭 I was supposed to remove that before sharing this publicly.
Otherwise it should be good. I have the new, but it’s kind of hard to see on here. Not sure about the extra } because my code doesn’t throw any errors and works as expected. I’ll DM you what I was working on so you can check it out
#gameDiv {
margin-top: 200px;
}
let spriteExample = new Phaser.Scene('spriteExample');
function launchBitcoinWallet() {
var fallbackLink = 'https://getalby.com/p/btcapsule';
var fallbackTimeout = setTimeout(function () {
window.location.href = fallbackLink;
}, 1000);
window.location.href = 'walletofsatoshi://bronzeping54@walletofsatoshi.com';
window.onblur = function () {
clearTimeout(fallbackTimeout);
};
}
var config = {
type: Phaser.AUTO,
width: 950,
height: 1800,
parent: 'gameDiv',
backgroundColor: '#ffffff',
audio: { disableWebAudio: true },
plugins: {
scene: [{
plugin: PhaserMatterCollisionPlugin.default,
key: "matterCollision",
mapping: "matterCollision"
}]
},
scene: {
create: create
},
physics: {
default: 'matter',
matter: {
gravity: {
x: 0,
y: 3
},
//debug: true
}
}
};
var fart;
var jump;
var score = 0;
var maxScore = 0;
var scoreText;
var game = new Phaser.Game(config);
function create() {
this.load.spritesheet('player', '
', {
frameWidth: 466.64,
frameHeight: 400
});
this.load.image('block', '
')
this.load.image('coin', '
')
this.load.image('shitcoin', '
')
this.load.image('dogeShit', '
')
this.load.image('retry', '
')
this.load.image('menu', '
')
this.load.image('zap', '
')
this.load.audio('zap_sound', ['https://nostr.build/p/nb9083.mp3']);
this.load.audio('theBeginning', ['https://nostr.build/p/nb9074.mp3']);
this.load.audio('fail', ['https://nostr.build/p/nb9076.mp3']);
this.sound.unlock();
var poly = '69.090 0.500, 139.603 114.347, 71.013 211.838, 0.500 115.309';
var scene = this;
this.scene = {
preload: function () {
scene.load.spritesheet('player', '
', {
frameWidth: 466.64,
frameHeight: 400
});
scene.load.image('block', '
');
scene.load.image('coin', '
');
scene.load.image('shitcoin', '
');
scene.load.image('dogeShit', '
');
scene.load.image('retry', '
');
scene.load.image('menu', '
');
scene.load.image('zap', '
');
scene.load.audio('zap_sound', ['https://nostr.build/p/nb9083.mp3']);
scene.load.audio('theBeginning', ['https://nostr.build/p/nb9074.mp3']);
scene.load.audio('fail', ['https://nostr.build/p/nb9076.mp3']);
},
create: function () {
var poly = '69.090 0.500, 139.603 114.347, 71.013 211.838, 0.500 115.309';
fart = scene.sound.add('zap_sound');
fart.allowMultiple = true;
jump = scene.sound.add('theBeginning');
jump.allowMultiple = true;
fail = scene.sound.add('fail');
fail.allowMultiple = true;
scoreText = scene.add.text(16, 16, 'Score: 0', {
fontSize: '32px',
fill: '#000'
});
player = scene.matter.add.sprite(200, 200, 'player');
player.setScale(0.4);
player.setOrigin(0, 0);
scene.anims.create({
key: 'run',
frames: scene.anims.generateFrameNumbers('player', {
start: 0,
end: 14
}),
frameRate: 20,
repeat: -1
});
player.anims.play('run');
var platformGroup = scene.matter.world.nextGroup(true);
var platform = scene.matter.add.image(475, 2000, 'block', null, {
shape: poly
});
platform.setStatic(true);
platform.setCollisionGroup(platformGroup);
player.setCollisionGroup(platformGroup);
scene.matterCollision.addOnCollideStart({
objectA: platform,
callback: function (eventData) {
var platform = eventData.gameObjectA;
var player = eventData.gameObjectB;
if (player.y <= platform.y - 150) {
score++;
scoreText.setText('Score: ' + score);
fart.play();
if (score > maxScore) {
maxScore = score;
}
} else {
scene.scene.start('EndScene');
fail.play();
score = 0;
}
}
});
var coinGroup = scene.matter.world.nextGroup(true);
var coin = scene.matter.add.image(200, 500, 'coin', null, {
shape: poly
});
coin.setStatic(true);
coin.setCollisionGroup(coinGroup);
player.setCollisionGroup(coinGroup);
scene.matterCollision.addOnCollideStart({
objectA: coin,
callback: function (eventData) {
var coin = eventData.gameObjectA;
var player = eventData.gameObjectB;
coin.destroy();
score += 10;
scoreText.setText('Score: ' + score);
fart.play();
if (score > maxScore) {
maxScore = score;
}
}
});
var shitcoinGroup = scene.matter.world.nextGroup(true);
var shitcoin = scene.matter.add.image(700, 500, 'shitcoin', null, {
shape: poly
});
shitcoin.setStatic(true);
shitcoin.setCollisionGroup(shitcoinGroup);
player.setCollisionGroup(shitcoinGroup);
scene.matterCollision.addOnCollideStart({
objectA: shitcoin,
callback: function (eventData) {
var shitcoin = eventData.gameObjectA;
var player = eventData.gameObjectB;
shitcoin.destroy();
score -= 5;
scoreText.setText('Score: ' + score);
fart.play();
if (score > maxScore) {
maxScore = score;
}
}
});
var dogeShitGroup = scene.matter.world.nextGroup(true);
var dogeShit = scene.matter.add.image(400, 800, 'dogeShit', null, {
shape: poly
});
dogeShit.setStatic(true);
dogeShit.setCollisionGroup(dogeShitGroup);
player.setCollisionGroup(dogeShitGroup);
scene.matterCollision.addOnCollideStart({
objectA: dogeShit,
callback: function (eventData) {
var dogeShit = eventData.gameObjectA;
var player = eventData.gameObjectB;
dogeShit.destroy();
score -= 10;
scoreText.setText('Score: ' + score);
fart.play();
if (score > maxScore) {
maxScore = score;
}
}
});
scene.input.on('pointerdown', function () {
player.applyForce({
x: 0,
y: -0.1
});
jump.play();
});
scene.matter.world.on('collisionstart', function (event, bodyA, bodyB) {
if (bodyA.gameObject === null || bodyB.gameObject === null) {
return;
}
var gameObjectA = bodyA.gameObject;
var gameObjectB = bodyB.gameObject;
if (gameObjectA.texture.key === 'player' && gameObjectB.texture.key === 'retry') {
scene.scene.restart();
fart.play();
}
if (gameObjectA.texture.key === 'player' && gameObjectB.texture.key === 'menu') {
launchBitcoinWallet();
fart.play();
}
});
scene.events.on('shutdown', function () {
scene.matter.world.off('collisionstart');
});
}
};
game.scene.add('spriteExample', scene);
game.scene.start('spriteExample');
}
//** Here I think this code includes all the necessary fixes to make it work properly. However, I haven't tested the functionality of the game, per se. **//
I'm missing a closed parentheses. And probably something else.
Missing ) in this section:
scene.anims.create({
key: 'run',
frames:
Should be:
scene.anims.create(){
key: 'run',
frames:
>> I think
That part looks okay. I think you may be mixing Phaser Arcade physics with Matter physics. This game would probably run better if I used arcade, but I’ve spent so much time working with Matter that I don’t really know all the functions of arcade.
Phaser is awesome if you ever want to get into 2D game development. It’s the new Adobe Flash, but written in JavaScript so it will always be compatible.
Maybe. I haven't played with phaser yet.
No leave the fart! Lol
😂😂😂 I kinda have to now, because it’s pulling the code from the note.
Hey I appreciate you trying to fix it, but it all works. I tried to run your code, but I’m getting a script error. It doesn’t tell me anything beyond that. I just use Textastic on my phone, so it doesn’t give me a lot of information.
Do you make games with Phaser too?