This commit is contained in:
Flatlogic Bot 2025-09-01 14:43:00 +00:00
parent ff0457c4aa
commit 4ca6854316
2 changed files with 262 additions and 98 deletions

257
game.js Normal file
View File

@ -0,0 +1,257 @@
const config = {
type: Phaser.AUTO,
width: 800,
height: 600,
physics: {
default: 'arcade',
arcade: {
gravity: { y: 800 },
debug: false
}
},
scene: {
preload: preload,
create: create,
update: update
}
};
const game = new Phaser.Game(config);
let player;
let ground;
let obstacles;
let score = 0;
let scoreText;
let highScore = 0;
let highScoreText;
let bg1;
let bg2;
let bg3;
let jumpParticles;
let landParticles;
let wasOnGround = false;
let gameState = 'playing'; // Can be 'playing' or 'gameOver'
let gameOverText;
let restartText;
let obstacleTimer;
let scoreTimer;
function preload () {
}
function create () {
gameState = 'playing';
// --- Get High Score ---
highScore = localStorage.getItem('highScore') || 0;
// --- Create Starfield ---
const starfieldGraphics = this.add.graphics();
starfieldGraphics.fillStyle(0xffffff);
for (let i = 0; i < 100; i++) {
starfieldGraphics.fillPoint(
Phaser.Math.Between(0, 800),
Phaser.Math.Between(0, 600),
Phaser.Math.Between(1, 2)
);
}
starfieldGraphics.generateTexture('starfield', 800, 600);
starfieldGraphics.destroy();
bg1 = this.add.tileSprite(400, 300, 800, 600, 'starfield').setAlpha(0.3);
bg2 = this.add.tileSprite(400, 300, 800, 600, 'starfield').setAlpha(0.6);
bg3 = this.add.tileSprite(400, 300, 800, 600, 'starfield');
// Create the ground
ground = this.add.rectangle(400, 580, 800, 40, 0x333333).setOrigin(0.5);
this.physics.add.existing(ground, true);
// Create the player
player = this.add.container(100, 450);
const body = this.add.rectangle(0, 0, 40, 40, 0xff8800);
const cockpit = this.add.rectangle(10, -5, 20, 20, 0x88ccff);
const wing = this.add.triangle(0, 0, -20, -15, -20, 15, 0, 0, 0xffffff);
player.add([body, cockpit, wing]);
this.physics.add.existing(player);
player.body.setBounce(0);
player.body.setCollideWorldBounds(true);
player.body.setSize(40, 40);
// --- Particle Effects ---
const jumpParticleGraphics = this.add.graphics();
jumpParticleGraphics.fillStyle(0xffffff, 1);
jumpParticleGraphics.fillGradientStyle(0xffff00, 0xffff00, 0xffffff, 0xffffff, 1);
jumpParticleGraphics.fillRect(0, 0, 16, 16);
jumpParticleGraphics.generateTexture('jump_particle', 16, 16);
jumpParticleGraphics.destroy();
const landParticleGraphics = this.add.graphics();
landParticleGraphics.fillStyle(0xffffff, 0.5);
landParticleGraphics.fillCircle(8, 8, 8);
landParticleGraphics.generateTexture('land_particle', 16, 16);
landParticleGraphics.destroy();
jumpParticles = this.add.particles('jump_particle');
jumpParticles.createEmitter({
speed: { min: -100, max: 100 },
angle: { min: 250, max: 290 },
scale: { start: 0.8, end: 0 },
blendMode: 'ADD',
lifespan: 400,
tint: { start: 0xffff00, end: 0xffffff },
quantity: 15,
on: false
});
landParticles = this.add.particles('land_particle');
landParticles.createEmitter({
speed: { min: 50, max: 100 },
angle: { min: 260, max: 280 },
scale: { start: 1, end: 0 },
alpha: { start: 0.6, end: 0 },
lifespan: 500,
quantity: 20,
on: false
});
this.physics.add.collider(player, ground);
// --- ACTION HANDLER ---
const handleAction = () => {
if (gameState === 'playing' && player.body.touching.down) {
player.body.setVelocityY(-500);
jumpParticles.emitParticleAt(player.x, player.y + 25);
} else if (gameState === 'gameOver') {
this.scene.restart();
}
};
// Input for jumping and restarting
this.input.on('pointerdown', handleAction);
this.input.keyboard.on('keydown-SPACE', handleAction);
obstacles = this.physics.add.group();
this.physics.add.collider(player, obstacles, hitObstacle, null, this);
// Timer to add new obstacles
obstacleTimer = this.time.addEvent({
delay: 1500,
callback: addObstacle,
callbackScope: this,
loop: true
});
score = 0;
scoreText = this.add.text(16, 16, 'Score: 0', { fontSize: '32px', fill: '#fff' });
highScoreText = this.add.text(16, 50, `Best: ${highScore}`, { fontSize: '24px', fill: '#fff', alpha: 0.7 });
// Timer to increment score
scoreTimer = this.time.addEvent({
delay: 100,
callback: () => {
if (gameState === 'playing') {
score++;
scoreText.setText('Score: ' + score);
}
},
callbackScope: this,
loop: true
});
// Game Over text (initially invisible)
gameOverText = this.add.text(400, 250, 'Game Over', { fontSize: '64px', fill: '#ff0000', align: 'center' }).setOrigin(0.5);
restartText = this.add.text(400, 380, 'Click or Press Space to Restart', { fontSize: '32px', fill: '#fff' }).setOrigin(0.5);
gameOverText.setVisible(false);
restartText.setVisible(false);
}
function update () {
// Always scroll the starfield, even on game over screen
bg1.tilePositionX += 0.2;
bg2.tilePositionX += 0.4;
bg3.tilePositionX += 0.8;
// Stop all game logic updates if the game is over
if (gameState !== 'playing') {
return;
}
const onGround = player.body.touching.down;
if (onGround && !wasOnGround) {
landParticles.emitParticleAt(player.x, player.y + 20);
}
wasOnGround = onGround;
// Automatically destroy obstacles that go off-screen
obstacles.getChildren().forEach(obstacle => {
if (obstacle.x < -50) {
obstacle.destroy();
}
});
}
function addObstacle() {
if (gameState !== 'playing') return;
const isFlying = Phaser.Math.Between(0, 2) === 0; // 1 in 3 chance
const obstacleHeight = Phaser.Math.Between(50, 120);
let obstacleY;
let obstacleColor = 0x00ff00; // Default green
if (isFlying) {
// Flying obstacle
obstacleY = Phaser.Math.Between(400, 480); // Adjusted Y to avoid being too high
obstacleColor = 0x00aaff; // Light blue for flying
} else {
// Ground obstacle
obstacleY = 600 - obstacleHeight;
}
const obstacle = this.add.rectangle(850, obstacleY, 50, obstacleHeight, obstacleColor).setOrigin(0.5, 0);
this.physics.add.existing(obstacle);
obstacles.add(obstacle);
obstacle.body.setVelocityX(-200);
obstacle.body.setImmovable(true);
obstacle.body.setAllowGravity(false);
}
function hitObstacle(player, obstacle) {
if (gameState === 'gameOver') return; // Don't run this logic twice
gameState = 'gameOver';
this.physics.pause(); // Stop all physics
// Stop timers
obstacleTimer.remove();
scoreTimer.remove();
// Make player red to show they've been hit
player.list.forEach(child => {
if (child.setTint) {
child.setTint(0xff0000);
}
});
// Check for and set high score
if (score > highScore) {
highScore = score;
localStorage.setItem('highScore', highScore);
}
// Show "Game Over" text
gameOverText.setText(`Game Over\nScore: ${score}\nBest: ${highScore}`);
gameOverText.setVisible(true);
restartText.setVisible(true);
highScoreText.setVisible(false); // Hide score during game over
}

103
index.php
View File

@ -1,115 +1,22 @@
<?php
declare(strict_types=1);
@ini_set('display_errors', '1');
@error_reporting(E_ALL);
@date_default_timezone_set('UTC');
$phpVersion = PHP_VERSION;
$now = date('Y-m-d H:i:s');
?>
<!doctype html>
<html lang="en">
<html lang="ru">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>New Style</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap" rel="stylesheet">
<title>Geometry Dash Clone</title>
<script src="https://cdn.jsdelivr.net/npm/phaser@3.55.2/dist/phaser.min.js"></script>
<style>
:root {
--bg-color-start: #ffecd2;
--bg-color-end: #fcb69f;
--text-color: #333333;
--card-bg-color: rgba(255, 255, 255, 0.5);
--card-border-color: rgba(0, 0, 0, 0.1);
}
body {
margin: 0;
font-family: 'Inter', sans-serif;
background: linear-gradient(45deg, var(--bg-color-start), var(--bg-color-end));
color: var(--text-color);
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
text-align: center;
overflow: hidden;
position: relative;
}
body::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><path d="M-10 10L110 10M10 -10L10 110" stroke-width="1" stroke="rgba(0,0,0,0.05)"/></svg>');
animation: bg-pan 20s linear infinite;
z-index: -1;
}
@keyframes bg-pan {
0% { background-position: 0% 0%; }
100% { background-position: 100% 100%; }
}
main {
padding: 2rem;
}
.card {
background: var(--card-bg-color);
border: 1px solid var(--card-border-color);
border-radius: 16px;
padding: 2rem;
backdrop-filter: blur(20px);
-webkit-backdrop-filter: blur(20px);
box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.1);
animation: float 6s ease-in-out infinite, fadeIn 1s ease-out forwards;
}
h1 {
font-size: 3rem;
font-weight: 700;
margin: 0 0 1rem;
letter-spacing: -1px;
animation: fadeIn 1.5s ease-out forwards;
}
p {
margin: 0.5rem 0;
font-size: 1.1rem;
animation: fadeIn 2s ease-out forwards;
}
@keyframes float {
0% { transform: translateY(0px); }
50% { transform: translateY(-10px); }
100% { transform: translateY(0px); }
}
@keyframes fadeIn {
from { opacity: 0; transform: translateY(10px); }
to { opacity: 1; transform: translateY(0); }
}
code {
background: rgba(0,0,0,0.2);
padding: 2px 6px;
border-radius: 4px;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
footer {
position: absolute;
bottom: 1rem;
font-size: 0.8rem;
opacity: 0.7;
background-color: #000;
}
</style>
</head>
<body>
<main>
<div class="card">
<h1>Welcome!</h1>
<p>Your project is ready to conquer the peaks.</p>
<p>PHP version: <code><?= htmlspecialchars($phpVersion) ?></code></p>
</div>
</main>
<footer>
Page updated: <?= htmlspecialchars($now) ?> (UTC)
</footer>
<script src="game.js?v=<?php echo time(); ?>"></script>
</body>
</html>