-
Notifications
You must be signed in to change notification settings - Fork 839
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/newgamealien_trans
- Loading branch information
Showing
203 changed files
with
11,914 additions
and
3,325 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# **Game_Name** | ||
|
||
Airhockey_game | ||
|
||
<br> | ||
|
||
## **Description 📃** | ||
- game involves simulating the movement and interactions of the puck and mallets on a table. | ||
|
||
## **functionalities 🎮** | ||
- this game is played by just moving your cursor or mouse around and score a goal. providing a challenging experience for the player against the computer-controlled opponent. | ||
<br> | ||
|
||
## **How to play? 🕹️** | ||
-Start the Game | ||
Score Goals | ||
Defend Your Goal | ||
<br> | ||
|
||
## **Screenshots 📸** | ||
|
||
<br> | ||
[image](GameZone\Games\Airhocky_game\airhockey_game.png) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
const canvas = document.getElementById('gameCanvas'); | ||
const ctx = canvas.getContext('2d'); | ||
|
||
const WIDTH = canvas.width; | ||
const HEIGHT = canvas.height; | ||
const PUCK_RADIUS = 15; | ||
const MALLET_RADIUS = 30; | ||
const FRICTION = 0.99; | ||
const GOAL_WIDTH = 200; | ||
const GOAL_HEIGHT = 40; | ||
const MAX_SPEED = 10; | ||
|
||
let puck = { x: WIDTH / 2, y: HEIGHT / 2, vx: 0, vy: 0 }; | ||
let mallet1 = { x: WIDTH / 4, y: HEIGHT / 2 }; | ||
let mallet2 = { x: 3 * WIDTH / 4, y: HEIGHT / 2 }; | ||
let playerScore = 0; | ||
let computerScore = 0; | ||
|
||
canvas.addEventListener('mousemove', (event) => { | ||
mallet1.x = event.offsetX; | ||
mallet1.y = event.offsetY; | ||
mallet1.x = Math.min(Math.max(mallet1.x, MALLET_RADIUS), WIDTH - MALLET_RADIUS); | ||
mallet1.y = Math.min(Math.max(mallet1.y, MALLET_RADIUS), HEIGHT - MALLET_RADIUS); | ||
}); | ||
|
||
function drawCircle(x, y, radius, color) { | ||
ctx.beginPath(); | ||
ctx.arc(x, y, radius, 0, Math.PI * 2); | ||
ctx.fillStyle = color; | ||
ctx.fill(); | ||
ctx.closePath(); | ||
} | ||
|
||
function drawRectangle(x, y, width, height, color) { | ||
ctx.beginPath(); | ||
ctx.rect(x, y, width, height); | ||
ctx.fillStyle = color; | ||
ctx.fill(); | ||
ctx.closePath(); | ||
} | ||
|
||
function drawLine(x1, y1, x2, y2, color) { | ||
ctx.beginPath(); | ||
ctx.moveTo(x1, y1); | ||
ctx.lineTo(x2, y2); | ||
ctx.strokeStyle = color; | ||
ctx.lineWidth = 5; | ||
ctx.stroke(); | ||
ctx.closePath(); | ||
} | ||
|
||
function updatePuck() { | ||
puck.x += puck.vx; | ||
puck.y += puck.vy; | ||
puck.vx *= FRICTION; | ||
puck.vy *= FRICTION; | ||
|
||
// Ensure speed does not exceed maximum | ||
let speed = Math.sqrt(puck.vx * puck.vx + puck.vy * puck.vy); | ||
if (speed > MAX_SPEED) { | ||
puck.vx *= MAX_SPEED / speed; | ||
puck.vy *= MAX_SPEED / speed; | ||
} | ||
|
||
// Ensure puck does not move out of the borders | ||
if (puck.x < PUCK_RADIUS) { | ||
puck.x = PUCK_RADIUS; | ||
puck.vx = -puck.vx; | ||
} | ||
if (puck.x > WIDTH - PUCK_RADIUS) { | ||
puck.x = WIDTH - PUCK_RADIUS; | ||
puck.vx = -puck.vx; | ||
} | ||
if (puck.y < PUCK_RADIUS) { | ||
puck.y = PUCK_RADIUS; | ||
puck.vy = -puck.vy; | ||
} | ||
if (puck.y > HEIGHT - PUCK_RADIUS) { | ||
puck.y = HEIGHT - PUCK_RADIUS; | ||
puck.vy = -puck.vy; | ||
} | ||
|
||
if (puck.x <= PUCK_RADIUS && (puck.y > HEIGHT / 2 - GOAL_WIDTH / 2 && puck.y < HEIGHT / 2 + GOAL_WIDTH / 2)) { | ||
computerScore++; | ||
resetPuck(); | ||
} | ||
|
||
if (puck.x >= WIDTH - PUCK_RADIUS && (puck.y > HEIGHT / 2 - GOAL_WIDTH / 2 && puck.y < HEIGHT / 2 + GOAL_WIDTH / 2)) { | ||
playerScore++; | ||
resetPuck(); | ||
} | ||
} | ||
|
||
function resetPuck() { | ||
puck.x = WIDTH / 2; | ||
puck.y = HEIGHT / 2; | ||
puck.vx = 0; | ||
puck.vy = 0; | ||
} | ||
|
||
function checkCollisionWithMallet(mallet) { | ||
let dx = puck.x - mallet.x; | ||
let dy = puck.y - mallet.y; | ||
let distance = Math.sqrt(dx * dx + dy * dy); | ||
|
||
if (distance < PUCK_RADIUS + MALLET_RADIUS) { | ||
let angle = Math.atan2(dy, dx); | ||
puck.vx = Math.cos(angle) * 5; | ||
puck.vy = Math.sin(angle) * 5; | ||
|
||
// Move puck out of collision | ||
let overlap = PUCK_RADIUS + MALLET_RADIUS - distance; | ||
puck.x += Math.cos(angle) * overlap; | ||
puck.y += Math.sin(angle) * overlap; | ||
} | ||
} | ||
|
||
function updateComputerMallet() { | ||
let dx = puck.x - mallet2.x; | ||
let dy = puck.y - mallet2.y; | ||
|
||
// Simplified AI: Move towards the puck | ||
mallet2.x += dx * 0.05; | ||
mallet2.y += dy * 0.05; | ||
|
||
// Restrict to the table | ||
mallet2.x = Math.min(Math.max(mallet2.x, MALLET_RADIUS), WIDTH - MALLET_RADIUS); | ||
mallet2.y = Math.min(Math.max(mallet2.y, MALLET_RADIUS), HEIGHT - MALLET_RADIUS); | ||
} | ||
|
||
function draw() { | ||
ctx.clearRect(0, 0, WIDTH, HEIGHT); | ||
|
||
drawRectangle(0, HEIGHT / 2 - GOAL_WIDTH / 2, GOAL_HEIGHT, GOAL_WIDTH, '#00ff00'); | ||
drawRectangle(WIDTH - GOAL_HEIGHT, HEIGHT / 2 - GOAL_WIDTH / 2, GOAL_HEIGHT, GOAL_WIDTH, '#00ff00'); | ||
drawLine(WIDTH / 2, 0, WIDTH / 2, HEIGHT, '#ffffff'); | ||
|
||
drawCircle(puck.x, puck.y, PUCK_RADIUS, '#ff0000'); | ||
drawCircle(mallet1.x, mallet1.y, MALLET_RADIUS, '#00ff00'); | ||
drawCircle(mallet2.x, mallet2.y, MALLET_RADIUS, '#0000ff'); | ||
|
||
updatePuck(); | ||
checkCollisionWithMallet(mallet1); | ||
checkCollisionWithMallet(mallet2); | ||
updateComputerMallet(); | ||
|
||
ctx.font = "20px Arial"; | ||
ctx.fillStyle = "#ffffff"; | ||
ctx.fillText(`Player: ${playerScore}`, 20, 30); | ||
ctx.fillText(`Computer: ${computerScore}`, WIDTH - 150, 30); | ||
|
||
requestAnimationFrame(draw); | ||
} | ||
|
||
draw(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Air Hockey Game</title> | ||
<style> | ||
body { | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
height: 100vh; | ||
background-color: #1e1e1e; | ||
color: #ffffff; | ||
margin: 0; | ||
font-family: Arial, sans-serif; | ||
} | ||
canvas { | ||
background-color: #2c2c2c; | ||
border: 5px solid #ffffff; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<canvas id="gameCanvas" width="800" height="400"></canvas> | ||
<script src="game.js"></script> | ||
</body> | ||
</html> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>About Anagram Checker Game</title> | ||
<link rel="stylesheet" href="styles.css"> | ||
</head> | ||
<body> | ||
<h1 align="center">About Anagram Checker Game</h1> | ||
<div class="container"> | ||
<p>This Anagram Checker Game allows you to check if two words are anagrams of each other. An anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.</p> | ||
|
||
<h2>Features:</h2> | ||
<ul> | ||
<li>Simple and intuitive interface</li> | ||
<li>Quickly check if two words are anagrams</li> | ||
<li>Learn about anagrams and how they work</li> | ||
</ul> | ||
|
||
<h2>About Us:</h2> | ||
<p>We are dedicated to creating fun and educational games that challenge your mind and expand your knowledge of language and literature.</p> | ||
|
||
<h2>Contact Us:</h2> | ||
<p>If you have any questions or feedback about the Anagram Checker Game, feel free to reach out to us at <a href="mailto:[email protected]">[email protected]</a>.</p> | ||
|
||
<p>Follow us on social media for updates and more games!</p> | ||
<ul> | ||
<li><a href="#">Facebook</a></li> | ||
<li><a href="#">Twitter</a></li> | ||
<li><a href="#">Instagram</a></li> | ||
</ul> | ||
|
||
<p>Thank you for playing!</p> | ||
</div> | ||
</body> | ||
</html> |
Oops, something went wrong.