mirror of
https://github.com/tiennm99/ai-coding-workflow-labs.git
synced 2026-09-16 22:21:16 +00:00
feat: init
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Phaser Project</title>
|
||||
<script src="https://cdn.jsdelivr.net/npm/phaser@3.55.2/dist/phaser.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script src="src/main.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"name": "phaser-project",
|
||||
"version": "1.0.0",
|
||||
"description": "Phaser 3 TypeScript Project",
|
||||
"main": "src/main.js",
|
||||
"scripts": {
|
||||
"start": "webpack serve --open",
|
||||
"build": "webpack --mode production"
|
||||
},
|
||||
"devDependencies": {
|
||||
"webpack": "^5.76.3",
|
||||
"webpack-cli": "^5.1.4",
|
||||
"webpack-dev-server": "^4.13.3",
|
||||
"babel-loader": "^9.1.2",
|
||||
"@babel/core": "^7.22.11",
|
||||
"@babel/preset-env": "^7.22.10"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
const config = {
|
||||
type: Phaser.AUTO,
|
||||
width: 800,
|
||||
height: 600,
|
||||
physics: {
|
||||
default: 'arcade',
|
||||
arcade: {
|
||||
gravity: { y: 1000 },
|
||||
debug: false
|
||||
}
|
||||
},
|
||||
scene: {
|
||||
preload: preload,
|
||||
create: create,
|
||||
update: update
|
||||
}
|
||||
};
|
||||
|
||||
let bird;
|
||||
let pipes;
|
||||
let score = 0;
|
||||
let gameOver = false;
|
||||
let scoreText;
|
||||
|
||||
const game = new Phaser.Game(config);
|
||||
|
||||
function preload() {
|
||||
// Placeholder assets - using Phaser's graphics API instead of loading images
|
||||
}
|
||||
|
||||
function create() {
|
||||
// Create bird
|
||||
bird = this.add.circle(100, 250, 15, 0xffffff);
|
||||
this.physics.add.existing(bird);
|
||||
bird.body.velocity.y = -300;
|
||||
|
||||
// Create pipes
|
||||
pipes = this.physics.add.group();
|
||||
|
||||
// Create score text
|
||||
scoreText = this.add.text(16, 16, 'Score: 0', { fontSize: '32px', fill: '#fff' });
|
||||
|
||||
// Input
|
||||
this.input.keyboard.on('keydown-SPACE', () => {
|
||||
if (gameOver) {
|
||||
restartGame();
|
||||
} else {
|
||||
bird.body.velocity.y = -300;
|
||||
}
|
||||
});
|
||||
|
||||
// Timer for pipe generation
|
||||
this.time.addEvent({
|
||||
delay: 1500,
|
||||
callback: addPipe,
|
||||
callbackScope: this,
|
||||
loop: true
|
||||
});
|
||||
}
|
||||
|
||||
function update() {
|
||||
// Check for collisions
|
||||
this.physics.overlap(bird, pipes, () => {
|
||||
gameOver = true;
|
||||
scoreText.setText('Game Over! Score: ' + score);
|
||||
});
|
||||
|
||||
// Move pipes
|
||||
pipes.getChildren().forEach(pipe => {
|
||||
pipe.x -= 200 * this.game.loop.delta;
|
||||
|
||||
// Reset pipe position
|
||||
if (pipe.x < -50) {
|
||||
score++;
|
||||
scoreText.setText('Score: ' + score);
|
||||
pipe.x = 850;
|
||||
pipe.y = Phaser.Math.Between(50, 550);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function addPipe() {
|
||||
const pipe = this.physics.add.image(850, Phaser.Math.Between(50, 550), 'pipe');
|
||||
pipe.setImmovable(true);
|
||||
pipes.add(pipe);
|
||||
}
|
||||
|
||||
function restartGame() {
|
||||
score = 0;
|
||||
gameOver = false;
|
||||
scoreText.setText('Score: 0');
|
||||
bird.setPosition(100, 250);
|
||||
bird.body.velocity.y = -300;
|
||||
pipes.getChildren().forEach(pipe => {
|
||||
pipe.setPosition(850, Phaser.Math.Between(50, 550));
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user