Compare commits

...

2 Commits

Author SHA1 Message Date
Flatlogic Bot
26f79dd724 menu 2025-09-01 15:02:18 +00:00
Flatlogic Bot
4ca6854316 game 2025-09-01 14:43:00 +00:00
2 changed files with 373 additions and 98 deletions

368
game.js Normal file
View File

@ -0,0 +1,368 @@
const config = {
type: Phaser.AUTO,
width: 800,
height: 600,
physics: {
default: 'arcade',
arcade: {
gravity: { y: 800 },
debug: false
}
},
scene: [] // Scenes will be added dynamically
};
const game = new Phaser.Game(config);
// --- Base Scene for common functionality ---
class BaseScene extends Phaser.Scene {
constructor(key) {
super(key);
}
createBackButton() {
const backButton = this.add.text(this.cameras.main.width - 20, 20, 'Back to Menu', {
fontSize: '24px',
fill: '#fff',
backgroundColor: '#333',
padding: { x: 10, y: 5 }
}).setOrigin(1, 0);
backButton.setInteractive();
backButton.on('pointerdown', () => {
this.scene.start('MainMenuScene');
});
backButton.on('pointerover', () => backButton.setStyle({ fill: '#ff0' }));
backButton.on('pointerout', () => backButton.setStyle({ fill: '#fff' }));
}
}
// --- Main Menu Scene ---
class MainMenuScene extends Phaser.Scene {
constructor() {
super('MainMenuScene');
}
create() {
this.add.text(400, 100, 'Cosmic Runner', { fontSize: '64px', fill: '#fff' }).setOrigin(0.5);
const startButton = this.add.text(400, 250, 'Start Game', { fontSize: '32px', fill: '#0f0', backgroundColor: '#333', padding: { x: 10, y: 5 } }).setOrigin(0.5);
const rulesButton = this.add.text(400, 320, 'Rules & Bonuses', { fontSize: '32px', fill: '#ff0', backgroundColor: '#333', padding: { x: 10, y: 5 } }).setOrigin(0.5);
const scoresButton = this.add.text(400, 390, 'High Scores', { fontSize: '32px', fill: '#f0f', backgroundColor: '#333', padding: { x: 10, y: 5 } }).setOrigin(0.5);
// Interactivity
[startButton, rulesButton, scoresButton].forEach(button => {
button.setInteractive();
button.on('pointerover', () => button.setAlpha(0.8));
button.on('pointerout', () => button.setAlpha(1));
});
startButton.on('pointerdown', () => this.scene.start('GameScene'));
rulesButton.on('pointerdown', () => this.scene.start('RulesScene'));
scoresButton.on('pointerdown', () => this.scene.start('HighScoresScene'));
}
}
// --- Rules Scene ---
class RulesScene extends BaseScene {
constructor() {
super('RulesScene');
}
create() {
this.add.text(400, 50, 'Rules & Bonuses', { fontSize: '48px', fill: '#fff' }).setOrigin(0.5);
const rulesText = [
'1. Click or press SPACE to jump.',
'2. Avoid the green and blue obstacles.',
'3. Collect yellow coins for extra points (+100).',
'',
'Bonuses:',
'- Blue Shield: Grants 10 seconds of invincibility.',
' (You will destroy obstacles on contact!)'
];
this.add.text(400, 300, rulesText, { fontSize: '24px', fill: '#fff', align: 'center' }).setOrigin(0.5);
this.createBackButton();
}
}
// --- High Scores Scene ---
class HighScoresScene extends BaseScene {
constructor() {
super('HighScoresScene');
}
create() {
this.add.text(400, 50, 'High Scores', { fontSize: '48px', fill: '#fff' }).setOrigin(0.5);
const highScore = localStorage.getItem('highScore') || 0;
this.add.text(400, 200, `Best Score: ${highScore}`, { fontSize: '38px', fill: '#fff' }).setOrigin(0.5);
const clearButton = this.add.text(400, 400, 'Clear Scores', { fontSize: '24px', fill: '#f00', backgroundColor: '#333', padding: { x: 10, y: 5 } }).setOrigin(0.5);
clearButton.setInteractive();
clearButton.on('pointerdown', () => {
localStorage.setItem('highScore', '0');
this.scene.restart();
});
clearButton.on('pointerover', () => clearButton.setAlpha(0.8));
clearButton.on('pointerout', () => clearButton.setAlpha(1));
this.createBackButton();
}
}
// --- Game Scene ---
class GameScene extends Phaser.Scene {
constructor() {
super('GameScene');
this.player = null;
this.ground = null;
this.obstacles = null;
this.coins = null;
this.shields = null;
this.score = 0;
this.scoreText = null;
this.highScore = 0;
this.highScoreText = null;
this.bg1 = null;
this.bg2 = null;
this.bg3 = null;
this.jumpParticles = null;
this.landParticles = null;
this.wasOnGround = false;
this.gameState = 'playing';
this.gameOverText = null;
this.restartText = null;
this.obstacleTimer = null;
this.scoreTimer = null;
this.coinTimer = null;
this.shieldTimer = null;
}
preload() {
// Preload assets if any - currently all generated dynamically
}
create() {
this.gameState = 'playing';
this.score = 0;
this.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();
this.bg1 = this.add.tileSprite(400, 300, 800, 600, 'starfield').setAlpha(0.3);
this.bg2 = this.add.tileSprite(400, 300, 800, 600, 'starfield').setAlpha(0.6);
this.bg3 = this.add.tileSprite(400, 300, 800, 600, 'starfield');
this.ground = this.add.rectangle(400, 580, 800, 40, 0x333333).setOrigin(0.5);
this.physics.add.existing(this.ground, true);
this.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);
this.player.add([body, cockpit, wing]);
this.physics.add.existing(this.player);
this.player.body.setBounce(0);
this.player.body.setCollideWorldBounds(true);
this.player.body.setSize(40, 40);
this.player.isInvincible = false;
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();
this.jumpParticles = this.add.particles('jump_particle');
this.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
});
this.landParticles = this.add.particles('land_particle');
this.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(this.player, this.ground);
const handleAction = () => {
if (this.gameState === 'playing' && this.player.body.touching.down) {
this.player.body.setVelocityY(-500);
this.jumpParticles.emitParticleAt(this.player.x, this.player.y + 25);
} else if (this.gameState === 'gameOver') {
this.scene.start('MainMenuScene'); // Go back to menu
}
};
this.input.on('pointerdown', handleAction);
this.input.keyboard.on('keydown-SPACE', handleAction);
this.obstacles = this.physics.add.group();
this.physics.add.collider(this.player, this.obstacles, this.hitObstacle, null, this);
this.coins = this.physics.add.group({ allowGravity: false });
this.physics.add.overlap(this.player, this.coins, this.collectCoin, null, this);
this.shields = this.physics.add.group({ allowGravity: false });
this.physics.add.overlap(this.player, this.shields, this.collectShield, null, this);
this.obstacleTimer = this.time.addEvent({ delay: 1500, callback: this.addObstacle, callbackScope: this, loop: true });
this.coinTimer = this.time.addEvent({ delay: 2000, callback: this.addCoin, callbackScope: this, loop: true });
this.shieldTimer = this.time.addEvent({ delay: 10000, callback: this.addShield, callbackScope: this, loop: true });
this.scoreText = this.add.text(16, 16, 'Score: 0', { fontSize: '32px', fill: '#fff' });
this.highScoreText = this.add.text(16, 50, `Best: ${this.highScore}`, { fontSize: '24px', fill: '#fff', alpha: 0.7 });
this.scoreTimer = this.time.addEvent({
delay: 100,
callback: () => {
if (this.gameState === 'playing') {
this.score++;
this.scoreText.setText('Score: ' + this.score);
}
},
callbackScope: this,
loop: true
});
this.gameOverText = this.add.text(400, 250, 'Game Over', { fontSize: '64px', fill: '#ff0000', align: 'center' }).setOrigin(0.5).setVisible(false);
this.restartText = this.add.text(400, 380, 'Click or Press Space for Menu', { fontSize: '32px', fill: '#fff' }).setOrigin(0.5).setVisible(false);
}
update() {
this.bg1.tilePositionX += 0.2;
this.bg2.tilePositionX += 0.4;
this.bg3.tilePositionX += 0.8;
if (this.gameState !== 'playing') {
return;
}
const onGround = this.player.body.touching.down;
if (onGround && !this.wasOnGround) {
this.landParticles.emitParticleAt(this.player.x, this.player.y + 20);
}
this.wasOnGround = onGround;
['obstacles', 'coins', 'shields'].forEach(groupName => {
this[groupName].getChildren().forEach(child => {
if (child.x < -50) {
child.destroy();
}
});
});
}
addObstacle() {
if (this.gameState !== 'playing') return;
const isFlying = Phaser.Math.Between(0, 2) === 0;
const obstacleHeight = Phaser.Math.Between(50, 120);
let obstacleY = isFlying ? Phaser.Math.Between(400, 480) : 600 - obstacleHeight;
const obstacle = this.add.rectangle(850, obstacleY, 50, obstacleHeight, isFlying ? 0x00aaff : 0x00ff00).setOrigin(0.5, 0);
this.physics.add.existing(obstacle);
this.obstacles.add(obstacle);
obstacle.body.setVelocityX(-200).setImmovable(true).setAllowGravity(false);
}
addCoin() {
if (this.gameState !== 'playing') return;
const coin = this.add.circle(850, Phaser.Math.Between(300, 500), 15, 0xffff00);
this.physics.add.existing(coin);
this.coins.add(coin);
coin.body.setVelocityX(-200).setAllowGravity(false);
}
addShield() {
if (this.gameState !== 'playing') return;
const shield = this.add.rectangle(850, Phaser.Math.Between(300, 500), 30, 30, 0x0000ff).setOrigin(0.5);
this.physics.add.existing(shield);
this.shields.add(shield);
shield.body.setVelocityX(-200).setAllowGravity(false);
}
collectCoin(player, coin) {
coin.destroy();
this.score += 100;
this.scoreText.setText('Score: ' + this.score);
}
collectShield(player, shield) {
shield.destroy();
player.isInvincible = true;
player.setAlpha(0.5);
this.time.delayedCall(10000, () => {
player.isInvincible = false;
player.setAlpha(1);
}, [], this);
}
hitObstacle(player, obstacle) {
if (player.isInvincible) {
obstacle.destroy();
return;
}
if (this.gameState === 'gameOver') return;
this.gameState = 'gameOver';
this.physics.pause();
[this.obstacleTimer, this.scoreTimer, this.coinTimer, this.shieldTimer].forEach(timer => timer.remove());
player.list.forEach(child => child.setTint && child.setTint(0xff0000));
if (this.score > this.highScore) {
this.highScore = this.score;
localStorage.setItem('highScore', this.highScore);
}
this.gameOverText.setText(`Game Over\nScore: ${this.score}\nBest: ${this.highScore}`).setVisible(true);
this.restartText.setVisible(true);
this.highScoreText.setVisible(false);
}
}
// Add all scenes to the game
game.scene.add('MainMenuScene', MainMenuScene);
game.scene.add('GameScene', GameScene);
game.scene.add('RulesScene', RulesScene);
game.scene.add('HighScoresScene', HighScoresScene);
// Start with the Main Menu
game.scene.start('MainMenuScene');

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>