Skip to content

Commit 5d9059a

Browse files
committed
- improve responsive design with fluid layout using aspect-ratio
- enhance multiball powerup to duplicate all active balls - fix mobile styling with better container sizing and padding - optimize controls display with flex-wrap for small screens - add additional media queries for large screens (1200px+)
1 parent 732e9e7 commit 5d9059a

File tree

1 file changed

+81
-24
lines changed

1 file changed

+81
-24
lines changed

games/breakout.html

Lines changed: 81 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,15 @@
3636
align-items: center;
3737
justify-content: center;
3838
min-height: 100vh;
39-
overflow: hidden;
40-
transition: background-color 0.3s ease;
39+
margin: 0;
40+
padding: 0;
4141
}
4242

4343
.game-container {
4444
position: relative;
4545
width: var(--game-width);
46-
margin: 20px auto;
46+
max-width: 100%;
47+
margin: 0 auto;
4748
}
4849

4950
.game-header {
@@ -104,8 +105,9 @@
104105
}
105106

106107
#game-board {
107-
width: var(--game-width);
108-
height: var(--game-height);
108+
width: 100%;
109+
aspect-ratio: 6/5;
110+
max-height: 80vh;
109111
background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
110112
border-radius: 10px;
111113
position: relative;
@@ -259,15 +261,16 @@
259261
display: flex;
260262
flex-direction: column;
261263
align-items: center;
262-
justify-content: center;
264+
justify-content: flex-start;
263265
background: rgba(18, 18, 18, 0.9);
264266
z-index: 50;
265267
opacity: 0;
266268
pointer-events: none;
267269
transition: opacity 0.5s ease;
268270
text-align: center;
269-
padding: 20px;
271+
padding: 5% 5% 0 5%;
270272
overflow-y: auto;
273+
box-sizing: border-box;
271274
}
272275

273276
.screen.active {
@@ -319,14 +322,15 @@
319322
background: rgba(25, 27, 58, 0.7);
320323
border-radius: 10px;
321324
padding: 15px;
322-
margin: 20px auto;
323-
width: 80%;
324-
max-width: 500px;
325+
margin: 10px 0 20px 0;
326+
width: 90%;
325327
gap: 20px;
328+
flex-wrap: wrap;
326329
}
327330

328331
.controls-column {
329332
flex: 1;
333+
min-width: 120px;
330334
padding: 10px;
331335
text-align: left;
332336
}
@@ -444,8 +448,7 @@
444448

445449
@media (max-width: 768px) {
446450
:root {
447-
--game-width: 100%;
448-
--game-height: 400px;
451+
--game-width: 95vw;
449452
}
450453

451454
.game-container {
@@ -464,8 +467,17 @@
464467
.controls-info {
465468
flex-direction: column;
466469
}
467-
}
468470

471+
.screen h2 {
472+
font-size: 1.8rem;
473+
margin-top: 10px;
474+
}
475+
476+
.screen p {
477+
font-size: 1rem;
478+
margin-bottom: 15px;
479+
}
480+
}
469481

470482
@media (min-width: 769px) {
471483
.game-container {
@@ -478,6 +490,12 @@
478490
height: min(var(--game-height), 70vh);
479491
}
480492
}
493+
494+
@media (min-width: 1200px) {
495+
:root {
496+
--game-width: 800px;
497+
}
498+
}
481499
</style>
482500
</head>
483501
<body>
@@ -1679,33 +1697,72 @@ <h2>You Win!</h2>
16791697
}
16801698

16811699
function applyMultiballPowerup() {
1682-
for (let i = 0; i < config.multiBallCount; i++) {
1683-
createNewBall();
1700+
// Store all active balls that need to be duplicated
1701+
const activeBalls = [];
1702+
1703+
// Add main ball if it's launched
1704+
if (ball.launched) {
1705+
activeBalls.push({
1706+
x: ball.x,
1707+
y: ball.y,
1708+
speed: ball.speed,
1709+
fireball: ball.fireball
1710+
});
1711+
}
1712+
1713+
// Add all other active balls
1714+
state.balls.forEach(ballObj => {
1715+
if (ballObj.launched) {
1716+
activeBalls.push({
1717+
x: ballObj.x,
1718+
y: ballObj.y,
1719+
speed: ballObj.speed,
1720+
fireball: ballObj.fireball
1721+
});
1722+
}
1723+
});
1724+
1725+
// If no active balls, create from main ball position even if not launched
1726+
if (activeBalls.length === 0) {
1727+
activeBalls.push({
1728+
x: ball.x,
1729+
y: ball.y,
1730+
speed: ball.speed,
1731+
fireball: ball.fireball
1732+
});
16841733
}
1734+
1735+
// Create new balls based on each active ball
1736+
activeBalls.forEach(activeBall => {
1737+
for (let i = 0; i < config.multiBallCount; i++) {
1738+
createNewBall(activeBall.x, activeBall.y, activeBall.speed, activeBall.fireball);
1739+
}
1740+
});
16851741
}
16861742

1687-
function createNewBall() {
1743+
function createNewBall(x, y, speed, isFireball) {
16881744
const newBallElement = document.createElement('div');
16891745
newBallElement.classList.add('ball');
16901746
newBallElement.style.width = config.ballSize + 'px';
16911747
newBallElement.style.height = config.ballSize + 'px';
16921748

1693-
if (ball.fireball) {
1749+
if (isFireball) {
16941750
newBallElement.style.background = 'radial-gradient(circle at 30% 30%, white, #FF9E00)';
16951751
newBallElement.style.boxShadow = '0 0 15px rgba(255, 158, 0, 0.7)';
16961752
}
16971753

16981754
elements.gameBoard.appendChild(newBallElement);
16991755

1756+
const angle = (Math.random() * 90 - 45) * Math.PI / 180;
17001757
const newBall = {
1701-
x: ball.x,
1702-
y: ball.y,
1703-
dx: (Math.random() * 2 - 1) * ball.speed,
1704-
dy: -ball.speed,
1705-
speed: ball.speed,
1758+
x: x,
1759+
y: y,
1760+
dx: speed * Math.sin(angle),
1761+
dy: -speed * Math.cos(angle),
1762+
speed: speed,
17061763
launched: true,
1707-
radius: ball.radius,
1708-
fireball: ball.fireball,
1764+
radius: config.ballSize / 2,
1765+
fireball: isFireball,
17091766
element: newBallElement
17101767
};
17111768

0 commit comments

Comments
 (0)