極めてスタイリッシュなテトリスをより面白く作成してください。
- User
極めてスタイリッシュなテトリスをより面白く作成してください。
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
極めてスタイリッシュなテトリスをより面白く作成してください。
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
以下のコードは、モダンで視覚的に美しいテトリスゲームです。通常のテトリスに比べて次の特徴があります:
<!DOCTYPE html>
<html>
<head>
<title>Neo Tetris</title>
<style>
body {
margin: 0;
background: #111;
color: #fff;
font-family: 'Arial', sans-serif;
overflow: hidden;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.game-container {
position: relative;
width: 300px;
height: 600px;
box-shadow: 0 0 20px rgba(0, 255, 255, 0.5);
border-radius: 4px;
overflow: hidden;
}
#game {
background: rgba(0, 0, 0, 0.8);
}
.info-panel {
margin-left: 20px;
width: 150px;
height: 600px;
padding: 20px;
background: rgba(0, 0, 0, 0.7);
border-radius: 4px;
box-shadow: 0 0 10px rgba(255, 0, 255, 0.5);
}
.score-container {
margin-bottom: 30px;
text-align: center;
}
.combo-meter {
height: 20px;
background: linear-gradient(to right, #ff00ff, #00ffff);
width: 0%;
margin-top: 10px;
border-radius: 10px;
transition: width 0.3s;
}
.background {
position: absolute;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
z-index: -1;
background: radial-gradient(circle, #222, #000);
}
@keyframes pulse {
0% { opacity: 0.5; }
50% { opacity: 0.7; }
100% { opacity: 0.5; }
}
.pulse {
animation: pulse 2s infinite;
}
.particle {
position: absolute;
background: white;
border-radius: 50%;
pointer-events: none;
}
</style>
</head>
<body>
<div class="background"></div>
<div class="game-container">
<canvas id="game" width="300" height="600"></canvas>
</div>
<div class="info-panel">
<div class="score-container">
<h2>SCORE</h2>
<div id="score">0</div>
<h3>COMBO</h3>
<div class="combo-meter" id="combo-meter"></div>
<div id="combo-multiplier">x1</div>
</div>
<div class="next-piece">
<h3>NEXT</h3>
<canvas id="next" width="100" height="100"></canvas>
</div>
<div class="controls">
<h3>CONTROLS</h3>
<p>← → : Move</p>
<p>↑ : Rotate</p>
<p>↓ : Soft Drop</p>
<p>Space : Hard Drop</p>
</div>
</div>
<script>
// Main game class
class NeoTetris {
constructor() {
this.canvas = document.getElementById('game');
this.ctx = this.canvas.getContext('2d');
this.nextCanvas = document.getElementById('next');
this.nextCtx = this.nextCanvas.getContext('2d');
this.blockSize = 30;
this.cols = 10;
this.rows = 20;
this.grid = this.createGrid();
this.colors = [
null,
'#ff00ff', // Pink
'#00ffff', // Cyan
'#ffff00', // Yellow
'#00ff00', // Green
'#ff0000', // Red
'#0000ff', // Blue
'#ff8800', // Orange
'#ffffff' // Special block
];
this.shapes = [
null,
[[1, 1, 1, 1]], // I
[[1, 1], [1, 1]], // O
[[0, 1, 0], [1, 1, 1]], // T
[[0, 1, 1], [1, 1, 0]], // S
[[1, 1, 0], [0, 1, 1]], // Z
[[1, 0, 0], [1, 1, 1]], // L
[[0, 0, 1], [1, 1, 1]] // J
];
this.currentPiece = this.createPiece();
this.nextPiece = this.createPiece();
this.dropCounter = 0;
this.dropInterval = 1000;
this.lastTime = 0;
this.gameOver = false;
this.score = 0;
this.combo = 0;
this.comboMultiplier = 1;
this.bindControls();
this.update();
// Background effect
this.background = document.querySelector('.background');
this.background.classList.add('pulse');
}
createGrid() {
let grid = [];
for (let y = 0; y < this.rows; y++) {
grid.push(new Array(this.cols).fill(0));
}
return grid;
}
createPiece() {
// 10% chance of special block
const isSpecial = Math.random() < 0.1;
const piece = {
pos: {x: Math.floor(this.cols / 2) - 1, y: 0},
shape: [...this.shapes[Math.floor(Math.random() * 7) + 1]],
type: Math.floor(Math.random() * 7) + 1,
isSpecial: isSpecial
};
if (isSpecial) {
// Mark the center block as special (type 8)
const centerY = Math.floor(piece.shape.length / 2);
const centerX = Math.floor(piece.shape[0].length / 2);
if (piece.shape[centerY] && piece.shape[centerY][centerX] === 1) {
piece.shape[centerY][centerX] = 8;
}
}
return piece;
}
draw() {
this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
// Draw grid
this.drawMatrix(this.grid, {x: 0, y: 0});
// Draw current piece
this.drawMatrix(this.currentPiece.shape, this.currentPiece.pos);
// Draw next piece preview
this.nextCtx.clearRect(0, 0, this.nextCanvas.width, this.nextCanvas.height);
this.drawNextPiece();
}
drawMatrix(matrix, offset) {
matrix.forEach((row, y) => {
row.forEach((value, x) => {
if (value !== 0) {
const blockType = value === 8 ? 8 : this.currentPiece.isSpecial && value === 1 ? 8 : value;
this.drawBlock(x + offset.x, y + offset.y, blockType);
}
});
});
}
drawBlock(x, y, type) {
const color = this.colors[type];
this.ctx.save();
// Draw glow effect
this.ctx.shadowBlur = 10;
this.ctx.shadowColor = color;
// Main block
this.ctx.fillStyle = color;
this.ctx.fillRect(x * this.blockSize, y * this.blockSize, this.blockSize, this.blockSize);
// Inner highlight
this.ctx.fillStyle = 'rgba(255, 255, 255, 0.3)';
this.ctx.fillRect(
x * this.blockSize + 3,
y * this.blockSize + 3,
this.blockSize - 6,
this.blockSize - 6
);
// Special block effects
if (type === 8) {
this.ctx.fillStyle = 'rgba(255, 255, 255, 0.7)';
this.ctx.beginPath();
this.ctx.arc(
x * this.blockSize + this.blockSize/2,
y * this.blockSize + this.blockSize/2,
this.blockSize/4,
0,
Math.PI * 2
);
this.ctx.fill();
}
this.ctx.restore();
}
drawNextPiece() {
const centerX = (this.nextCanvas.width - this.nextPiece.shape[0].length * 20) / 2;
const centerY = (this.nextCanvas.height - this.nextPiece.shape.length * 20) / 2;
this.nextPiece.shape.forEach((row, y) => {
row.forEach((value, x) => {
if (value !== 0) {
const blockType = value === 8 ? 8 : this.nextPiece.isSpecial && value === 1 ? 8 : this.nextPiece.type;
this.nextCtx.save();
// Draw glow effect
this.nextCtx.shadowBlur = 10;
this.nextCtx.shadowColor = this.colors[blockType];
// Main block
this.nextCtx.fillStyle = this.colors[blockType];
this.nextCtx.fillRect(
centerX + x * 20,
centerY + y * 20,
20,
20
);
// Inner highlight
this.nextCtx.fillStyle = 'rgba(255, 255, 255, 0.3)';
this.nextCtx.fillRect(
centerX + x * 20 + 3,
centerY + y * 20 + 3,
14,
14
);
// Special block effects
if (blockType === 8) {
this.nextCtx.fillStyle = 'rgba(255, 255, 255, 0.7)';
this.nextCtx.beginPath();
this.nextCtx.arc(
centerX + x * 20 + 10,
centerY + y * 20 + 10,
5,
0,
Math.PI * 2
);
this.nextCtx.fill();
}
this.nextCtx.restore();
}
});
});
}
collide() {
const [m, o] = [this.currentPiece.shape, this.currentPiece.pos];
for (let y = 0; y < m.length; ++y) {
for (let x = 0; x < m[y].length; ++x) {
if (m[y][x] !== 0 &&
(this.grid[y + o.y] &&
this.grid[y + o.y][x + o.x]) !== 0) {
return true;
}
}
}
return false;
}
merge() {
this.currentPiece.shape.forEach((row, y) => {
row.forEach((value, x) => {
if (value !== 0) {
const gridY = y + this.currentPiece.pos.y;
const gridX = x + this.currentPiece.pos.x;
if (gridY >= 0 && gridY < this.rows && gridX >= 0 && gridX < this.cols) {
if (value === 8) {
// Special block
this.grid[gridY][gridX] = 8;
} else if (this.currentPiece.isSpecial && value === 1) {
// Part of a special piece
this.grid[gridY][gridX] = 8;
} else {
this.grid[gridY][gridX] = this.currentPiece.type;
}
}
}
});
});
}
rotate() {
const original = this.currentPiece.shape.map(row => [...row]);
// Transpose matrix
for (let y = 0; y < this.currentPiece.shape.length; ++y) {
for (let x = 0; x < y; ++x) {
[
this.currentPiece.shape[x][y],
this.currentPiece.shape[y][x],
] = [
this.currentPiece.shape[y][x],
this.currentPiece.shape[x][y],
];
}
}
// Reverse each row
this.currentPiece.shape.forEach(row => row.reverse());
// Check if rotation causes collision
if (this.collide()) {
this.currentPiece.shape = original;
}
}
moveDown() {
this.currentPiece.pos.y++;
if (this.collide()) {
this.currentPiece.pos.y--;
this.merge();
this.checkLines();
this.currentPiece = this.nextPiece;
this.nextPiece = this.createPiece();
// Check for game over
if (this.collide()) {
this.gameOver = true;
alert('GAME OVER - Final Score: ' + this.score);
}
}
this.dropCounter = 0;
}
moveHorizontal(dir) {
this.currentPiece.pos.x += dir;
if (this.collide()) {
this.currentPiece.pos.x -= dir;
}
}
hardDrop() {
while (!this.collide()) {
this.currentPiece.pos.y++;
}
this.currentPiece.pos.y--;
this.moveDown();
}
checkLines() {
let linesCleared = 0;
let specialBlocksCleared = 0;
let linesToClear = [];
// Find lines to clear
outer: for (let y = this.rows - 1; y >= 0; y--) {
for (let x = 0; x < this.cols; x++) {
if (this.grid[y][x] === 0) {
continue outer;
}
if (this.grid[y][x] === 8) {
specialBlocksCleared++;
}
}
linesToClear.push(y);
linesCleared++;
}
if (specialBlocksCleared > 0) {
// Clear additional lines for special blocks
for (let y = this.rows - 1; y >= 0; y--) {
if (!linesToClear.includes(y) && specialBlocksCleared > 0) {
linesToClear.push(y);
linesCleared++;
specialBlocksCleared--;
}
}
// Sort lines to clear properly
linesToClear.sort((a, b) => a - b);
}
if (linesCleared > 0) {
// Create particle effect
this.createParticles(linesToClear);
// Update combo
this.combo++;
this.comboMultiplier = Math.min(4, 1 + (this.combo * 0.5));
document.getElementById('combo-multiplier').textContent = 'x' + this.comboMultiplier.toFixed(1);
document.getElementById('combo-meter').style.width = Math.min(100, this.combo * 10) + '%';
// Remove cleared lines
linesToClear.forEach(y => {
this.grid.splice(y, 1);
this.grid.unshift(new Array(this.cols).fill(0));
});
// Update score
const points = [0, 100, 300, 500, 800][linesCleared] || 1000;
this.score += points * this.comboMultiplier;
document.getElementById('score').textContent = this.score;
// Increase speed slightly
this.dropInterval = Math.max(100, this.dropInterval - 10);
} else {
// Reset combo
this.combo = 0;
this.comboMultiplier = 1;
document.getElementById('combo-multiplier').textContent = 'x1';
document.getElementById('combo-meter').style.width = '0%';
}
}
createParticles(lines) {
lines.forEach(y => {
for (let i = 0; i < 30; i++) {
const particle = document.createElement('div');
particle.classList.add('particle');
// Random position along the cleared line
const x = Math.random() * this.canvas.width;
const yPos = y * this.blockSize;
// Random size and color
const size = Math.random() * 5 + 2;
const colors = ['#ff00ff', '#00ffff', '#ffff00', '#ffffff'];
const color = colors[Math.floor(Math.random() * colors.length)];
particle.style.width = size + 'px';
particle.style.height = size + 'px';
particle.style.backgroundColor = color;
particle.style.left = x + 'px';
particle.style.top = yPos + 'px';
document.body.appendChild(particle);
// Animation
const angle = Math.random() * Math.PI * 2;
const speed = Math.random() * 3 + 1;
const vx = Math.cos(angle) * speed;
const vy = Math.sin(angle) * speed;
let posX = x;
let posY = yPos;
const animate = () => {
posX += vx;
posY += vy;
particle.style.left = posX + 'px';
particle.style.top = posY + 'px';
if (posX < -10 || posX > window.innerWidth + 10 ||
posY < -10 || posY > window.innerHeight + 10) {
particle.remove();
} else {
requestAnimationFrame(animate);
}
};
requestAnimationFrame(animate);
}
});
}
update(time = 0) {
const deltaTime = time - this.lastTime;
this.lastTime = time;
this.dropCounter += deltaTime;
if (this.dropCounter > this.dropInterval) {
this.moveDown();
}
this.draw();
if (!this.gameOver) {
requestAnimationFrame(this.update.bind(this));
}
}
bindControls() {
document.addEventListener('keydown', event => {
if (this.gameOver) return;
switch (event.keyCode) {
case 37: // Left arrow
this.moveHorizontal(-1);
break;
case 39: // Right arrow
this.moveHorizontal(1);
break;
case 40: // Down arrow
this.moveDown();
break;
case 38: // Up arrow
this.rotate();
break;
case 32: // Space
this.hardDrop();
break;
}
});
}
}
// Start the game
const game = new NeoTetris();
</script>
</body>
</html>
このコードを実行すると、ネオンカラーのエフェクトを持つスタイリッシュなテトリスが楽しめます。コードの説明や動作原理について詳しく知りたい場合はお知らせください。