<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Phaser Game</title>
<script src="https://cdn.jsdelivr.net/npm/phaser@3.55.2/dist/phaser.js"></script>
</head>
<body>
<script>
const config = {
type: Phaser.AUTO,
width: 800,
height: 600,
physics: {
default: 'arcade',
arcade: {
gravity: { y: 0 },
debug: false
}
},
scene: {
preload: preload,
create: create,
update: update
}
};
const game = new Phaser.Game(config);
let player;
function preload() {
this.load.image('spaceship', 'path/to/spaceship.png');
}
function create() {
player = this.physics.add.image(400, 500, 'spaceship');
player.setCollideWorldBounds(true);
}
function update() {
const cursors = this.input.keyboard.createCursorKeys();
if (cursors.left.isDown) {
player.setVelocityX(-160);
} else if (cursors.right.isDown) {
player.setVelocityX(160);
} else {
player.setVelocityX(0);
}
if (cursors.up.isDown) {
player.setVelocityY(-160);
} else if (cursors.down.isDown) {
player.setVelocityY(160);
} else {
player.setVelocityY(0);
}
}
</script>
</body>
</html>
No comments:
Post a Comment