Created
March 22, 2024 01:30
-
-
Save CharlyJazz/0cad773d2c86012215cbfeb6566eceb7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const config = { | |
// Use the innerWidth and innerHeight for full screen game | |
width: window.innerWidth, // Changed from a fixed value to adapt to screen width | |
height: window.innerHeight, // Changed from window.height (which is undefined) to innerHeight | |
parent: "container", | |
type: Phaser.AUTO, // Let Phaser decide whether to use WebGL or Canvas | |
physics: { | |
default: "arcade", | |
arcade: { | |
gravity: { y: 300 }, // Adjust if necessary to fit game design | |
debug: false, | |
}, | |
}, | |
scale: { | |
mode: Phaser.Scale.RESIZE, // This will resize the canvas to fit the parent div | |
autoCenter: Phaser.Scale.CENTER_BOTH, // Center the game canvas in the middle of the screen | |
}, | |
scene: { | |
preload: precarga, | |
create: crear, | |
update: updatesss, | |
}, | |
}; | |
var juegoNelson = new Phaser.Game(config); | |
function precarga() { | |
console.log("soy preload"); | |
// Note: Adjust paths if necessary | |
this.load.image("background", "./assets/images/background/background.png"); | |
this.load.audio("cancionCarlosFondo", "assets/sounds/music.mp3"); | |
this.load.image("spines", "./assets/images/wall_enemies/1.png"); | |
} | |
function crear() { | |
console.log("soy create"); | |
// Background position adjusted to be responsive | |
this.imagenFondo = this.add | |
.image(this.cameras.main.centerX, this.cameras.main.centerY, "background") | |
.setDisplaySize(this.cameras.main.width, this.cameras.main.height); | |
// Adjusting Downspikes and Upperspikes positioning to be responsive | |
this.Downspikes = this.physics.add.staticGroup({ | |
key: "spines", | |
repeat: Math.floor(this.cameras.main.width / 35) - 1, // Adjust count based on screen width | |
setXY: { x: 19, y: this.cameras.main.height - 30, stepX: 35 }, | |
}); | |
this.UpperSpikes = this.physics.add.staticGroup({ | |
key: "spines", | |
repeat: Math.floor(this.cameras.main.width / 35) - 1, // Adjust count based on screen width | |
setXY: { x: 19, y: 30, stepX: 35 }, | |
}); | |
this.UpperSpikes.children.iterate(function (spines) { | |
spines.angle = 180; | |
spines.setScale(0.25, 0.25); | |
}); | |
this.Downspikes.children.iterate(function (spines) { | |
spines.setScale(0.25, 0.25); | |
}); | |
let sound = this.sound.add("cancionCarlosFondo"); | |
sound.play(); | |
} | |
function updatesss(time, delta) { | |
console.log("soy update"); | |
// Add game update logic here | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment