Skip to content

Commit dbbdba4

Browse files
committed
more tetris
SQUASHED:
1 parent f065824 commit dbbdba4

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

src/components/demo/lively-tetris.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export default class LivelyTetris extends Morph {
8787
this.score = 0;
8888
this.level = 1;
8989
this.linesCleared = 0;
90+
this.isPaused = false;
9091
this.updateScore();
9192

9293
// Ersten Block erstellen
@@ -145,6 +146,7 @@ export default class LivelyTetris extends Morph {
145146
this.score = 0;
146147
this.level = 1;
147148
this.linesCleared = 0;
149+
this.isPaused = false;
148150
this.updateScore();
149151

150152
// Neuen Block spawnen
@@ -158,6 +160,11 @@ export default class LivelyTetris extends Morph {
158160
}
159161

160162
gameStep() {
163+
// Wenn pausiert, nichts tun
164+
if (this.isPaused) {
165+
return;
166+
}
167+
161168
// Versuche Block nach unten zu bewegen
162169
if (this.isValidPosition(this.currentBlock.x, this.currentBlock.y + 1)) {
163170
this.currentBlock.y++;
@@ -182,6 +189,18 @@ export default class LivelyTetris extends Morph {
182189
}
183190
}
184191

192+
togglePause() {
193+
this.isPaused = !this.isPaused;
194+
195+
if (this.isPaused) {
196+
lively.notify("Pause - Leertaste zum Fortsetzen");
197+
} else {
198+
lively.notify("Spiel läuft weiter");
199+
}
200+
201+
this.draw();
202+
}
203+
185204
spawnNewBlock() {
186205
// Zufälligen Tetromino auswählen
187206
let randomIndex = Math.floor(Math.random() * this.tetrominoes.length);
@@ -286,6 +305,28 @@ export default class LivelyTetris extends Morph {
286305

287306
// Aktuellen Block zeichnen
288307
this.drawBlock();
308+
309+
// Wenn pausiert, "PAUSE" anzeigen
310+
if (this.isPaused) {
311+
this.drawPauseText();
312+
}
313+
}
314+
315+
drawPauseText() {
316+
// Halbtransparenter Hintergrund
317+
this.ctx.fillStyle = "rgba(0, 0, 0, 0.5)";
318+
this.ctx.fillRect(0, 0, this.canvas.width, this.canvas.height);
319+
320+
// "PAUSE" Text
321+
this.ctx.fillStyle = "white";
322+
this.ctx.font = "bold 40px Arial";
323+
this.ctx.textAlign = "center";
324+
this.ctx.textBaseline = "middle";
325+
this.ctx.fillText("PAUSE", this.canvas.width / 2, this.canvas.height / 2);
326+
327+
// Kleiner Text darunter
328+
this.ctx.font = "20px Arial";
329+
this.ctx.fillText("Leertaste drücken", this.canvas.width / 2, this.canvas.height / 2 + 50);
289330
}
290331

291332
drawLockedBlocks() {
@@ -361,6 +402,18 @@ export default class LivelyTetris extends Morph {
361402
}
362403

363404
onKeyDown(evt) {
405+
// Leertaste für Pause
406+
if (evt.key === " ") {
407+
this.togglePause();
408+
evt.preventDefault();
409+
return;
410+
}
411+
412+
// Wenn pausiert, keine Steuerung
413+
if (this.isPaused) {
414+
return;
415+
}
416+
364417
// Pfeiltasten abfangen
365418
if (evt.key === "ArrowLeft") {
366419
this.moveBlock(-1, 0); // Nach links

0 commit comments

Comments
 (0)