Merge pull request #2 from chancewalter0907/main

project 2 pull request
This commit is contained in:
TriantaTV 2023-02-14 14:18:13 -06:00 committed by GitHub
commit 62cd1a60b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 126 additions and 87 deletions

View File

@ -2,9 +2,11 @@
<html> <html>
<head> <head>
<title>Gregory Crawford</title> <title>Gregory Crawford</title>
<meta charset="UTF-8">
<link rel="stylesheet" href="style.css">
</head> </head>
<body> <body>
<a href="pong.html">Play pong here!</a> <button class="button" type="button" onclick="window.location.href='pong.html'">Start Game</button>
<script src = "scripts.js"></script>
</body> </body>
</html> </html>

View File

@ -2,13 +2,19 @@
<html> <html>
<head> <head>
<title>Basic Pong HTML Game</title> <title>Pong Game</title>
<meta charset="UTF-8"> <meta charset="UTF-8">
<link rel="stylesheet" href="style.css"> <link rel="stylesheet" href="style.css">
</head> </head>
<body> <body>
<canvas width="750" height="585" id="game"></canvas> <canvas width="750" height="585" id="game"></canvas>
<script src="scripts.js"></script> <script src="scripts.js"></script>
<div id="gameover" hidden="true">
<h1>Game Over</h1>
</div>
<div id="restart" hidden="true">
<button class="button" type="button" onclick = "restartGame()">Restart Game</a>
</div>
</body> </body>
</html> </html>

View File

@ -54,9 +54,29 @@ function collides(obj1, obj2) {
obj1.y + obj1.height > obj2.y; obj1.y + obj1.height > obj2.y;
} }
function gameOver() {
context.clearRect(0, 0, canvas.width, canvas.height);
let restartGame = document.getElementById("restart");
let gameOverText = document.getElementById("gameover");
restartGame.hidden = false;
gameOverText.hidden = false;
}
function restartGame() {
leftScore = 0;
rightScore = 0;
let restartGame = document.getElementById("restart");
restartGame.hidden = true;
requestAnimationFrame(loop);
}
// game loop // game loop
function loop() { function loop() {
if (leftScore < 7 && rightScore < 7) {
requestAnimationFrame(loop); requestAnimationFrame(loop);
} else if (leftScore >= 7 || rightScore >= 7) {
gameOver();
}
context.clearRect(0,0,canvas.width,canvas.height); context.clearRect(0,0,canvas.width,canvas.height);
// move paddles by their velocity // move paddles by their velocity

View File

@ -9,3 +9,14 @@ body {
align-items: center; align-items: center;
justify-content: center; justify-content: center;
} }
.button {
background: blue;
color: white;
padding: 15px 20px;
font-size: 32px;
font-family: Arial, Helvetica, sans-serif;
text-transform: uppercase;
cursor: pointer;
position: relative;
}