Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sand Tetris #4971

Merged
merged 9 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Games/sand_tetris/assets/1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 45 additions & 0 deletions Games/sand_tetris/handleinput.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Left Arrow Key: 37
// Up Arrow Key: 38
// Right Arrow Key: 39
// Down Arrow Key: 40

document.addEventListener('keydown', event => {
if ([32, 37, 38, 39, 40].includes(event.keyCode)) {
event.preventDefault();
}
switch (event.keyCode) {

// Down arrow
case 40:
fallingPiece.moveDown();
if (!playfield.isValid(fallingPiece))
fallingPiece.moveUp()
else
fallingPiece.resetBuffer()
break;
// Top arrow
case 38:
fallingPiece.rotateCW();

// if not valid, rotate back
if (!playfield.isValid(fallingPiece))
fallingPiece.rotateCCW();

break;

// Left arrow
case 37:
fallingPiece.moveLeft();
if (!playfield.isValid(fallingPiece))
fallingPiece.moveRight()
break;

// Right Arrow
case 39:
fallingPiece.moveRight();
if (!playfield.isValid(fallingPiece))
fallingPiece.moveLeft()
break;
}

});
129 changes: 129 additions & 0 deletions Games/sand_tetris/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sand Tetris Demo</title>
<link rel="icon" type="image/png" href="./logo.png">

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"
integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL"
crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.1/font/bootstrap-icons.css">

<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.7.0/p5.js"
integrity="sha512-M7uzkKVt12bO/ClDOwaTk0AUwDPmJzjxri/KQKft2cisI6q3zJ4KxX3IfSQXF9Z6WU6NNW67JAljgWrA4WiiOA=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<link rel="stylesheet" href="style.css">
</head>

<body>
<div class="container">





<div class="row">
<div class="col-md-3"></div>
<div class="col-md-6">




<nav class="navbar bg-body-tertiary mb-3">
<div class="container-fluid">
<a class="navbar-brand" href="#">
<img src="./logo.png" alt="Logo" width="30" height="30"
class="d-inline-block align-text-top">
Sand Tetris
</a>
</div>
</nav>



</div>
<div class="col-md-3"></div>

</div>



<div class="row">
<div class="col-md-4"></div>
<div class="col-md-3">


<div class="card">
<div class="card-body">
<div id="canvasBox"></div>

</div>
</div>
</div>
<div class="col-md-2">
<div class="card mb-2">
<div class="card-body">
<h5 class="card-title">Score: <span id="scoreui">0</span></h5>


</div>
</div>

<div class="card mb-2">
<div class="card-body">
<div class="d-grid gap-2">
<button id="pausebtn" class="btn btn-outline-primary btn-sm" type="button"><i
class="bi bi-pause"></i>
Pause</button>
<button id="resetbtn" class="btn btn-outline-primary btn-sm" type="button"><i
class="bi bi-x"></i>
Reset</button>

<button id="scrshotbtn" class="btn btn-outline-primary btn-sm mt-3" type="button"><i
class="bi bi-file-image"></i> Screenshot</button>

</div>
</div>
</div>


<div class="card mb-2">
<div class="card-body">

<div class="form-check">
<input checked class="form-check-input" type="radio" name="difficultyradio"
id="difficultyradio1">
<label class="form-check-label" for="difficultyradio1">
Intermediate
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="difficultyradio" id="difficultyradio2">
<label class="form-check-label" for="difficultyradio2">
Expert<br> <span class="small">(No diagonal check)</span>
</label>
</div>


</div>
</div>

</div>
<div class="col-md-3"></div>

</div>

</div>

<script defer src="./playfield.js"></script>
<script defer src="./piece.js"></script>
<script defer src="./handleinput.js"></script>
<script defer src="./script.js"></script>
</body>

</html>
Binary file added Games/sand_tetris/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading