Sunday Game
Sunday Game
P
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Racing Game</title>
</head>
<body>
<div id="game-container">
<canvas id="gameCanvas"></canvas>
<div id="controls">
<button id="left-btn">Left</button>
<button id="right-btn">Right</button>
</div>
</div>
<script src="js/game.js"></script>
</body>
</html>
game.css
body {
margin: 0;
overflow: hidden;
background: #000;
#game-container {
position: relative;
width: 100vw;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
canvas {
#controls {
position: absolute;
bottom: 20px;
width: 100%;
text-align: center;
button {
padding: 10px;
font-size: 20px;
game.js
JavaScript
canvas.width = 800;
canvas.height = 600;
const player = {
x: canvas.width / 2 - 25,
y: canvas.height - 100,
width: 50,
height: 100,
speed: 5,
};
player.image.src = "../assets/motorbike.png";
function drawPlayer() {
if (e.key === "ArrowRight" && player.x < canvas.width - player.width) player.x += player.speed;
});
function gameLoop() {
drawPlayer();
requestAnimationFrame(gameLoop);
gameLoop();
const obstacle = {
y: -100,
width: 50,
height: 100,
speed: 3
};
obstacles.push(obstacle);
function drawObstacles() {
ctx.fillStyle = "red";
obs.y += obs.speed;
// Collision detection
if (
){
alert("Game Over!");
location.reload();
});
}
setInterval(createObstacle, 2000);
function gameLoop() {
drawPlayer();
drawObstacles();
requestAnimationFrame(gameLoop);
gameLoop();
function gameLoop() {
drawPlayer();
drawObstacles();
moveOpponents();
drawOpponents();
adjustAISpeed(score);
requestAnimationFrame(gameLoop);
}
server.js
players[socket.id].x += data.dx;
players[socket.id].y += data.dy;
io.emit("updatePlayers", players);
});
socket.on("disconnect", () => {
delete players[socket.id];
io.emit("updatePlayers", players);
});
});
});
Frontend deployment
git init
git add .
Backend deployment
game.js
const aiOpponents = [];
aiImage.src = "../assets/ai_motorbike.png";
function createOpponents() {
aiOpponents.push({
width: 50,
height: 100,
});
function drawOpponents() {
aiOpponents.forEach((ai) => {
});
}
function moveOpponents() {
aiOpponents.forEach((ai) => {
ai.y = -100;
// AI Avoiding obstacles
obstacles.forEach((obs) => {
if (
){
// Change direction when close to an obstacle
});
});
function adjustAISpeed(playerScore) {
aiOpponents.forEach((ai) => {
});
game.js
function createOpponents() {
aiOpponents.push({
width: 50,
height: 100,
speed: Math.random() * 2 + 2, // Different speeds for AI difficulty
});
function moveOpponents() {
aiOpponents.forEach((ai) => {
ai.targetPlayer = true;
} else {
ai.targetPlayer = false;
if (ai.targetPlayer) {
} else {
ai.x -= 2;
ai.x += 2;
ai.y = -100;
obstacles.forEach((obs) => {
if (
});
});
function reactToPlayerOvertake() {
aiOpponents.forEach((ai) => {
ai.targetPlayer = true;
ai.x -= ai.aggression / 8;
} else {
ai.x += ai.aggression / 8;
});
}
function gameLoop() {
drawPlayer();
drawObstacles();
moveOpponents();
drawOpponents();
reactToPlayerOvertake();
requestAnimationFrame(gameLoop);
function gameLoop() {
drawPlayer();
drawObstacles();
moveOpponents();
drawOpponents();
reactToPlayerOvertake();
requestAnimationFrame(gameLoop);
}
function gameLoop() {
drawPlayer();
drawObstacles();
moveOpponents();
drawOpponents();
reactToPlayerOvertake();
aiMistakes();
requestAnimationFrame(gameLoop);
function aiMistakes() {
aiOpponents.forEach((ai) => {
});
}
function adjustAIDifficulty(playerScore) {
aiOpponents.forEach((ai) => {
});
game.js
const aiNames = ["Razor", "Storm", "Shadow", "Blaze", "Viper", "Bolt"]; // Unique AI names
function createOpponents() {
aiOpponents.push({
width: 50,
height: 100,
speed: Math.random() * 2 + 2,
personality: chosenPersonality,
});
function moveOpponents() {
aiOpponents.forEach((ai) => {
ai.targetPlayer = true;
} else {
ai.targetPlayer = false;
if (ai.targetPlayer) {
ai.y = -100;
});
function drawOpponents() {
aiOpponents.forEach((ai) => {
ctx.fillStyle = "white";
});
function updateAIScores() {
aiOpponents.forEach((ai) => {
function gameLoop() {
drawPlayer();
drawObstacles();
moveOpponents();
drawOpponents();
updateAIScores();
requestAnimationFrame(gameLoop);
Modify ai speed
function reactToPowerUps(powerUpType) {
aiOpponents.forEach((ai) => {
if (ai.personality === "aggressive") ai.speed -= 0.5; // Aggressive AI slows when shield is active
});
}
function activatePowerUp(type) {
player.speed += 2;
Game.js
const difficultyLevels = {
};
function createOpponents() {
aiOpponents.push({
height: 100,
difficulty: chosenDifficulty,
speed: difficultyLevels[chosenDifficulty].speed,
aggression: difficultyLevels[chosenDifficulty].aggression,
reactionTime: difficultyLevels[chosenDifficulty].reactionTime,
score: 0,
});
function updateBestTimes() {
aiOpponents.forEach((ai) => {
});
function drawBestTimes() {
ctx.fillStyle = "yellow";
});
function gameLoop() {
drawPlayer();
drawObstacles();
moveOpponents();
drawOpponents();
updateAIScores();
drawBestTimes();
requestAnimationFrame(gameLoop);
function updateRivalry() {
aiOpponents.forEach((ai) => {
});
}
Websites creation for education
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Learning Website</title>
</head>
<body>
<header>
<h1>Learn Anywhere</h1>
<nav>
<ul>
<li><a href="#home">Home</a></li>
<li><a href="#subjects">Subjects</a></li>
<li><a href="#profile">Profile</a></li>
<li><a href="#" onclick="logout()">Logout</a></li>
</ul>
</nav>
</header>
<main>
<section id="home">
<button onclick="login()">Login/Register</button>
</section>
<section id="subjects">
<h2>Subjects</h2>
<div class="subject-list">
<button onclick="loadSubject('math')">Mathematics</button>
<button onclick="loadSubject('science')">Science</button>
<button onclick="loadSubject('history')">History</button>
<button onclick="loadSubject('programming')">Programming</button>
<button onclick="loadSubject('art')">Art</button>
</div>
</section>
<section id="subject-content">
<div id="weekly-lessons"></div>
<div id="quiz-section"></div>
<div id="assignment-section"></div>
<div id="project-section"></div>
</section>
<section id="profile">
<h2>Profile</h2>
<div id="progress"></div>
</section>
</main>
<footer>
</footer>
<script src="https://www.gstatic.com/firebasejs/9.22.0/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/9.22.0/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/9.22.0/firebase-firestore.js"></script>
<script src="script.js"></script>
</body>
</html>
/* styles.css */
body {
margin: 0;
padding: 0;
background-color: #f4f4f9;
header {
background-color: #4CAF50;
color: white;
padding: 1rem;
text-align: center;
nav ul {
list-style: none;
padding: 0;
display: flex;
justify-content: center;
nav ul li {
margin: 0 1rem;
nav ul li a {
color: white;
text-decoration: none;
main {
padding: 1rem;
}
button {
background-color: #4CAF50;
color: white;
border: none;
cursor: pointer;
margin: 0.5rem;
button:hover {
background-color: #45a049;
.subject-list {
display: flex;
justify-content: center;
flex-wrap: wrap;
#subject-content {
margin-top: 2rem;
footer {
text-align: center;
padding: 1rem;
background-color: #4CAF50;
color: white;
}
@media (max-width: 600px) {
nav ul {
flex-direction: column;
button {
width: 100%;
margin: 0.5rem 0;
// script.js
// Firebase configuration
const firebaseConfig = {
apiKey: "YOUR_API_KEY",
authDomain: "YOUR_AUTH_DOMAIN",
projectId: "YOUR_PROJECT_ID",
storageBucket: "YOUR_STORAGE_BUCKET",
messagingSenderId: "YOUR_MESSAGING_SENDER_ID",
appId: "YOUR_APP_ID"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
const subjects = {
math: {
title: "Mathematics",
weeks: [
{ week: 1, lesson: "Algebra Basics", quiz: ["What is 2 + 2?", "What is x in 2x = 4?"], answers: ["4", "2"], assignment:
"Solve 10 algebra problems.", project: "Create a math game." },
{ week: 2, lesson: "Geometry", quiz: ["What is the area of a circle?", "What is the Pythagorean theorem?"],
answers: ["πr²", "a² + b² = c²"], assignment: "Draw geometric shapes.", project: "Build a geometry calculator." }
},
science: {
title: "Science",
weeks: [
{ week: 1, lesson: "Physics", quiz: ["What is Newton's first law?", "What is gravity?"], answers: ["An object
remains at rest or moves uniformly unless acted upon by a force.", "A force pulling objects towards the Earth."],
assignment: "Experiment with forces.", project: "Build a simple machine." },
{ week: 2, lesson: "Chemistry", quiz: ["What is H2O?", "What is an atom?"], answers: ["Water", "The smallest unit
of matter."], assignment: "Identify elements.", project: "Create a periodic table." }
},
history: {
title: "History",
weeks: [
{ week: 1, lesson: "Ancient Civilizations", quiz: ["Who built the pyramids?", "What was the Roman Empire?"],
answers: ["Egyptians", "A powerful ancient civilization."], assignment: "Research ancient cultures.", project: "Write
an essay on ancient history." },
{ week: 2, lesson: "World Wars", quiz: ["What started World War I?", "Who was involved in World War II?"],
answers: ["Assassination of Archduke Franz Ferdinand", "Allies vs Axis powers."], assignment: "Analyze historical
events.", project: "Create a timeline." }
},
programming: {
title: "Programming",
weeks: [
{ week: 1, lesson: "JavaScript Basics", quiz: ["What is a variable?", "What is a function?"], answers: ["A container
for storing data.", "A block of code that performs a task."], assignment: "Write a basic program.", project: "Build a
calculator app." },
{ week: 2, lesson: "Data Structures", quiz: ["What is an array?", "What is an object?"], answers: ["A collection of
values.", "A key-value pair structure."], assignment: "Implement data structures.", project: "Create a todo app." }
},
art: {
title: "Art",
weeks: [
{ week: 1, lesson: "Drawing Techniques", quiz: ["What is perspective?", "What is shading?"], answers: ["A
technique for creating depth.", "Adding shadows to objects."], assignment: "Practice drawing techniques.", project:
"Create a landscape painting." },
{ week: 2, lesson: "Color Theory", quiz: ["What are primary colors?", "What is contrast?"], answers: ["Red, blue,
yellow.", "Difference between two colors."], assignment: "Experiment with colors.", project: "Design a color palette."
}
};
function loadSubject(subjectKey) {
document.getElementById("subject-title").textContent = subject.title;
weeklyLessons.innerHTML = "";
subject.weeks.forEach(week => {
<p><strong>Assignment:</strong> ${week.assignment}</p>
<p><strong>Project:</strong> ${week.project}</p>
`;
weeklyLessons.appendChild(weekDiv);
});
// Take quiz
quizSection.innerHTML = `
<form id="quiz-form">
<p>${question}</p>
`).join("")}
</form>
`;
document.getElementById("quiz-form").addEventListener("submit", function(event) {
event.preventDefault();
const answers = [];
answers.push(document.getElementById(`answer-${index}`).value);
});
});
// Save progress
if (user) {
await db.collection("users").doc(user.uid).set(
{ [`${subjectKey}_week_${week}`]: { score } },
{ merge: true }
);
showProgress();
} else {
// Show progress
progress.innerHTML = "";
// Login
function login() {
// Logout
function logout() {
auth.signOut().then(() => {
document.getElementById("progress").innerHTML = "";
});
auth.onAuthStateChanged(showProgress);
Site with improved user friendly
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Learning Website</title>
</head>
<body>
<header>
<nav>
<ul>
<li><a href="#home">Home</a></li>
<li><a href="#subjects">Subjects</a></li>
<li><a href="#profile">Profile</a></li>
</ul>
</nav>
</header>
<main>
</section>
<section id="subjects">
<h2 data-aos="fade-up">Subjects</h2>
<div class="subject-list">
</div>
</section>
<section id="subject-content">
<div id="weekly-lessons"></div>
<div id="quiz-section"></div>
<div id="assignment-section"></div>
<div id="project-section"></div>
</section>
<section id="profile">
<h2 data-aos="fade-left">Profile</h2>
<div id="progress"></div>
</section>
</main>
<footer>
</footer>
<script src="https://www.gstatic.com/firebasejs/9.22.0/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/9.22.0/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/9.22.0/firebase-firestore.js"></script>
<script src="script.js"></script>
</body>
</html>
/* styles.css */
body {
margin: 0;
padding: 0;
background-color: #f4f4f9;
header {
background-color: #4CAF50;
color: white;
padding: 1rem;
text-align: center;
@keyframes fadeIn {
from { opacity: 0; }
to { opacity: 1; }
nav ul {
list-style: none;
padding: 0;
display: flex;
justify-content: center;
nav ul li {
margin: 0 1rem;
nav ul li a {
color: white;
text-decoration: none;
nav ul li a:hover {
color: #ffffffbf;
main {
padding: 1rem;
}
button {
background-color: #4CAF50;
color: white;
border: none;
cursor: pointer;
margin: 0.5rem;
border-radius: 5px;
button:hover {
background-color: #45a049;
transform: scale(1.05);
.subject-card {
width: 100%;
max-width: 200px;
margin: 1rem;
padding: 1rem;
border-radius: 10px;
text-align: center;
font-weight: bold;
background-color: #ffffff;
color: #4CAF50;
border: 2px solid #4CAF50;
transition: background-color 0.3s ease, color 0.3s ease, transform 0.3s ease;
.subject-card:hover {
background-color: #4CAF50;
color: white;
transform: translateY(-5px);
#subject-content {
margin-top: 2rem;
footer {
text-align: center;
padding: 1rem;
background-color: #4CAF50;
color: white;
@keyframes slideIn {
.animated-button {
position: relative;
overflow: hidden;
}
.animated-button::before {
content: '';
position: absolute;
top: 0;
left: -100%;
width: 100%;
height: 100%;
.animated-button:hover::before {
left: 100%;
nav ul {
flex-direction: column;
button {
width: 100%;
margin: 0.5rem 0;
.subject-card {
max-width: 100%;
}
}
// script.js
// Firebase configuration
const firebaseConfig = {
apiKey: "YOUR_API_KEY",
authDomain: "YOUR_AUTH_DOMAIN",
projectId: "YOUR_PROJECT_ID",
storageBucket: "YOUR_STORAGE_BUCKET",
messagingSenderId: "YOUR_MESSAGING_SENDER_ID",
appId: "YOUR_APP_ID"
};
firebase.initializeApp(firebaseConfig);
const db = firebase.firestore();
AOS.init();
snapshot.forEach(doc => {
subjects[doc.id] = doc.data();
});
loadSubjects();
function loadSubjects() {
subjectList.innerHTML = "";
button.textContent = value.title;
button.classList.add("subject-card");
subjectList.appendChild(button);
function loadSubject(subjectKey) {
document.getElementById("subject-title").textContent = subject.title;
weeklyLessons.innerHTML = "";
subject.weeks.forEach(week => {
weekDiv.innerHTML = `
<p><strong>Assignment:</strong> ${week.assignment}</p>
<p><strong>Project:</strong> ${week.project}</p>
`;
weeklyLessons.appendChild(weekDiv);
});
// Take quiz
quizSection.innerHTML = `
<form id="quiz-form">
<p>${question}</p>
`).join("")}
</form>
`;
document.getElementById("quiz-form").addEventListener("submit", function(event) {
event.preventDefault();
answers.push(document.getElementById(`answer-${index}`).value.trim().toLowerCase());
});
});
// Save progress
if (user) {
await db.collection("users").doc(user.uid).set(
{ [`${subjectKey}_week_${week}`]: { score } },
{ merge: true }
);
showProgress();
} else {
// Show progress
if (user) {
progress.innerHTML = "";
// Login
function login() {
// Logout
function logout() {
auth.signOut().then(() => {
document.getElementById("progress").innerHTML = "";
});
auth.onAuthStateChanged(showProgress);
// Admin Panel
const isAdmin = confirm("Enter admin mode? (Only authorized users can manage content.)");
if (isAdmin) {
const adminContent = `
<h2>Admin Panel</h2>
`;
document.getElementById("subjects").innerHTML = adminContent;
// Add Subject
function addSubject() {
db.collection("subjects").add(subject).then(() => {
fetchSubjects();
});
}
// Edit Subject
if (!doc.exists) {
return;
const newQuiz = prompt(`Enter new quiz questions for Week ${week.week} (comma-separated):`,
week.quiz.join(",")).split(",");
const newAnswers = prompt(`Enter new quiz answers for Week ${week.week} (comma-separated):`,
week.answers.join(",")).split(",");
return { week: week.week, lesson: newLesson, quiz: newQuiz, answers: newAnswers, assignment: newAssignment,
project: newProject };
});
fetchSubjects();
// Delete Subject
fetchSubjects();
fetchSubjects();
firebase login
firebase init