diff --git a/.github/workflows/pr_check.yml b/.github/workflows/pr_check.yml index 132ef73383..739416cd9e 100644 --- a/.github/workflows/pr_check.yml +++ b/.github/workflows/pr_check.yml @@ -1,216 +1,216 @@ -name: Pull Request Validation - -on: - pull_request_target: - types: - - opened - - synchronize - -jobs: - pr-validation: - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v2 - - - name: Set up Node.js - uses: actions/setup-node@v2 - with: - node-version: '14' - - - name: Install dependencies - run: npm install --prefix .github octokit - - - name: Validate pull request - id: validate_pr - uses: actions/github-script@v4 - with: - github-token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} - script: | - const prNumber = context.payload.pull_request.number; - const repoOwner = context.payload.repository.owner.login; - const repoName = context.payload.repository.name; - - const { data: pr } = await github.pulls.get({ - owner: repoOwner, - repo: repoName, - pull_number: prNumber - }); - - // Check if the PR content contains an issue reference - const hasIssueReference = /#[0-9]+/.test(pr.body); - if (!hasIssueReference) { - // Close the PR - await github.pulls.update({ - owner: repoOwner, - repo: repoName, - pull_number: prNumber, - state: 'closed' - }); - - // Comment on the closed PR - await github.issues.createComment({ - owner: repoOwner, - repo: repoName, - issue_number: prNumber, - body: `Hey @${pr.user.login},\nPlease make sure to link the relevant issue using the appropriate syntax, such as "#issueNumber" 👀. \n Follow the proper guideline and make a new PR again 😀. \n Happy Hacking 💗` - }); - - console.log(`Closed and commented on pull request #${prNumber} due to missing issue reference.`); - return; // Stop further processing - } - - // Get the issue number from the PR content - const issueNumber = pr.body.match(/#([0-9]+)/)[1]; - - // Get the issue details - const { data: issue } = await github.issues.get({ - owner: repoOwner, - repo: repoName, - issue_number: issueNumber - }); - - // Check if the issue is open - if (issue.state !== 'open') { - // Close the PR - await github.pulls.update({ - owner: repoOwner, - repo: repoName, - pull_number: prNumber, - state: 'closed' - }); - - // Comment on the closed PR - await github.issues.createComment({ - owner: repoOwner, - repo: repoName, - issue_number: prNumber, - body: `Hey @${pr.user.login},\n You can't work on a closed issue 👀! \n Follow the proper guideline and make a new PR again 😀. \n Happy Hacking 💗` - }); - - console.log(`Closed and commented on pull request #${prNumber} due to closed issue reference.`); - return; // Stop further processing - } - - // Check if the issue has the "level3" label - const hasLevel3Label = issue.labels.some(label => label.name.toLowerCase() === 'level3'); - if (hasLevel3Label) { - // Get the PR files - const { data: files } = await github.pulls.listFiles({ - owner: repoOwner, - repo: repoName, - pull_number: prNumber - }); - - // Check for required changes in the PR - const changes = []; - - // Check if a new folder is created inside the "Games" folder and contains a new file - const gamesFolderPath = 'Games/'; - const newFolderRegex = new RegExp(`${gamesFolderPath}([^/]+)/.*$`); - const newFolderCreated = files.some(file => newFolderRegex.test(file.filename)); - - // Check if a README.md file is added in the newly created folder - const readmeRegex = new RegExp(`${gamesFolderPath}([^/]+)/README.md$`); - const readmeAdded = files.some(file => readmeRegex.test(file.filename)); - - // Comment with the required changes, if any - if (!newFolderCreated) { - changes.push('- Please create a new folder inside the "Games" folder.'); - } - if (!readmeAdded) { - changes.push('- Please add a README.md file inside the newly created folder.'); - } - - // Check if the main README.md file is modified - const mainReadmeModified = files.some(file => file.filename === 'README.md'); - - if (!mainReadmeModified) { - changes.push('- Please modify the main README.md file.'); - } - - // Check if an image is added to the assets/images directory - const imageAdded = files.some(file => file.filename.startsWith('assets/images/')); - - if (!imageAdded) { - changes.push('- Please add an image to the assets/images directory.'); - } - - if (changes.length > 0) { - const comment = [ - `Hello @${pr.user.login},`, - `You need to make the following changes:`, - ...changes.map(change => ` ${change}`), - '', - 'Hoping that you will make those changes soon 🚀' - ].join('\n'); - - // Comment on the pull request - await github.pulls.createReview({ - owner: repoOwner, - repo: repoName, - pull_number: prNumber, - event: 'REQUEST_CHANGES', - body: comment - }); - - // Add labels to the pull request - await github.issues.addLabels({ - owner: repoOwner, - repo: repoName, - issue_number: prNumber, - labels: ['Changes Requested ⚒ī¸', 'Pending ⏱ī¸'] - }); - - console.log(`Commented on pull request #${prNumber} with required changes.`); - } else { - const existingLabels = pr.labels.map(label => label.name.toLowerCase()); - - if (existingLabels.includes('changes requested') || existingLabels.includes('pending')) { - // Remove the "changes requested" and "pending" labels - await github.issues.removeLabel({ - owner: repoOwner, - repo: repoName, - issue_number: prNumber, - name: 'Changes Requested ⚒ī¸' - }); - await github.issues.removeLabel({ - owner: repoOwner, - repo: repoName, - issue_number: prNumber, - name: 'Pending ⏱ī¸' - }); - - // Approve the changes - await github.pulls.createReview({ - owner: repoOwner, - repo: repoName, - pull_number: prNumber, - event: 'APPROVE' - }); - - // Add the "under review" label - await github.issues.addLabels({ - owner: repoOwner, - repo: repoName, - issue_number: prNumber, - labels: ['Pending ⏱ī¸'] - }); - - console.log(`Updated pull request #${prNumber} with approved changes.`); - } else { - // Add label to the pull request - await github.issues.addLabels({ - owner: repoOwner, - repo: repoName, - issue_number: prNumber, - labels: ['Pending ⏱ī¸'] - }); - - console.log(`Pull request #${prNumber} is valid and meets the requirements.`); - } - } - } else { - console.log(`Pull request #${prNumber} does not have the "level3" label. No further validation is performed.`); - } +# name: Pull Request Validation + +# on: +# pull_request_target: +# types: +# - opened +# - synchronize + +# jobs: +# pr-validation: +# runs-on: ubuntu-latest + +# steps: +# - name: Checkout repository +# uses: actions/checkout@v2 + +# - name: Set up Node.js +# uses: actions/setup-node@v2 +# with: +# node-version: '14' + +# - name: Install dependencies +# run: npm install --prefix .github octokit + +# - name: Validate pull request +# id: validate_pr +# uses: actions/github-script@v4 +# with: +# github-token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} +# script: | +# const prNumber = context.payload.pull_request.number; +# const repoOwner = context.payload.repository.owner.login; +# const repoName = context.payload.repository.name; + +# const { data: pr } = await github.pulls.get({ +# owner: repoOwner, +# repo: repoName, +# pull_number: prNumber +# }); + +# // Check if the PR content contains an issue reference +# const hasIssueReference = /#[0-9]+/.test(pr.body); +# if (!hasIssueReference) { +# // Close the PR +# await github.pulls.update({ +# owner: repoOwner, +# repo: repoName, +# pull_number: prNumber, +# state: 'closed' +# }); + +# // Comment on the closed PR +# await github.issues.createComment({ +# owner: repoOwner, +# repo: repoName, +# issue_number: prNumber, +# body: `Hey @${pr.user.login},\nPlease make sure to link the relevant issue using the appropriate syntax, such as "#issueNumber" 👀. \n Follow the proper guideline and make a new PR again 😀. \n Happy Hacking 💗` +# }); + +# console.log(`Closed and commented on pull request #${prNumber} due to missing issue reference.`); +# return; // Stop further processing +# } + +# // Get the issue number from the PR content +# const issueNumber = pr.body.match(/#([0-9]+)/)[1]; + +# // Get the issue details +# const { data: issue } = await github.issues.get({ +# owner: repoOwner, +# repo: repoName, +# issue_number: issueNumber +# }); + +# // Check if the issue is open +# if (issue.state !== 'open') { +# // Close the PR +# await github.pulls.update({ +# owner: repoOwner, +# repo: repoName, +# pull_number: prNumber, +# state: 'closed' +# }); + +# // Comment on the closed PR +# await github.issues.createComment({ +# owner: repoOwner, +# repo: repoName, +# issue_number: prNumber, +# body: `Hey @${pr.user.login},\n You can't work on a closed issue 👀! \n Follow the proper guideline and make a new PR again 😀. \n Happy Hacking 💗` +# }); + +# console.log(`Closed and commented on pull request #${prNumber} due to closed issue reference.`); +# return; // Stop further processing +# } + +# // Check if the issue has the "level3" label +# const hasLevel3Label = issue.labels.some(label => label.name.toLowerCase() === 'level3'); +# if (hasLevel3Label) { +# // Get the PR files +# const { data: files } = await github.pulls.listFiles({ +# owner: repoOwner, +# repo: repoName, +# pull_number: prNumber +# }); + +# // Check for required changes in the PR +# const changes = []; + +# // Check if a new folder is created inside the "Games" folder and contains a new file +# const gamesFolderPath = 'Games/'; +# const newFolderRegex = new RegExp(`${gamesFolderPath}([^/]+)/.*$`); +# const newFolderCreated = files.some(file => newFolderRegex.test(file.filename)); + +# // Check if a README.md file is added in the newly created folder +# const readmeRegex = new RegExp(`${gamesFolderPath}([^/]+)/README.md$`); +# const readmeAdded = files.some(file => readmeRegex.test(file.filename)); + +# // Comment with the required changes, if any +# if (!newFolderCreated) { +# changes.push('- Please create a new folder inside the "Games" folder.'); +# } +# if (!readmeAdded) { +# changes.push('- Please add a README.md file inside the newly created folder.'); +# } + +# // Check if the main README.md file is modified +# const mainReadmeModified = files.some(file => file.filename === 'README.md'); + +# if (!mainReadmeModified) { +# changes.push('- Please modify the main README.md file.'); +# } + +# // Check if an image is added to the assets/images directory +# const imageAdded = files.some(file => file.filename.startsWith('assets/images/')); + +# if (!imageAdded) { +# changes.push('- Please add an image to the assets/images directory.'); +# } + +# if (changes.length > 0) { +# const comment = [ +# `Hello @${pr.user.login},`, +# `You need to make the following changes:`, +# ...changes.map(change => ` ${change}`), +# '', +# 'Hoping that you will make those changes soon 🚀' +# ].join('\n'); + +# // Comment on the pull request +# await github.pulls.createReview({ +# owner: repoOwner, +# repo: repoName, +# pull_number: prNumber, +# event: 'REQUEST_CHANGES', +# body: comment +# }); + +# // Add labels to the pull request +# await github.issues.addLabels({ +# owner: repoOwner, +# repo: repoName, +# issue_number: prNumber, +# labels: ['Changes Requested ⚒ī¸', 'Pending ⏱ī¸'] +# }); + +# console.log(`Commented on pull request #${prNumber} with required changes.`); +# } else { +# const existingLabels = pr.labels.map(label => label.name.toLowerCase()); + +# if (existingLabels.includes('changes requested') || existingLabels.includes('pending')) { +# // Remove the "changes requested" and "pending" labels +# await github.issues.removeLabel({ +# owner: repoOwner, +# repo: repoName, +# issue_number: prNumber, +# name: 'Changes Requested ⚒ī¸' +# }); +# await github.issues.removeLabel({ +# owner: repoOwner, +# repo: repoName, +# issue_number: prNumber, +# name: 'Pending ⏱ī¸' +# }); + +# // Approve the changes +# await github.pulls.createReview({ +# owner: repoOwner, +# repo: repoName, +# pull_number: prNumber, +# event: 'APPROVE' +# }); + +# // Add the "under review" label +# await github.issues.addLabels({ +# owner: repoOwner, +# repo: repoName, +# issue_number: prNumber, +# labels: ['Pending ⏱ī¸'] +# }); + +# console.log(`Updated pull request #${prNumber} with approved changes.`); +# } else { +# // Add label to the pull request +# await github.issues.addLabels({ +# owner: repoOwner, +# repo: repoName, +# issue_number: prNumber, +# labels: ['Pending ⏱ī¸'] +# }); + +# console.log(`Pull request #${prNumber} is valid and meets the requirements.`); +# } +# } +# } else { +# console.log(`Pull request #${prNumber} does not have the "level3" label. No further validation is performed.`); +# } diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000..5c297ee2ea --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ + +assets/images/Pixel_Painter.png diff --git a/Games/Chess_Game_computer/README.md b/Games/Chess_Game_computer/README.md new file mode 100644 index 0000000000..4c20db70e1 --- /dev/null +++ b/Games/Chess_Game_computer/README.md @@ -0,0 +1,22 @@ +# 🎮 AI Chess Game Request + +## **Description 📃** +We propose the development of an AI-powered chess game that offers an engaging and challenging experience to players of all levels. The game will leverage advanced algorithms to provide intelligent gameplay while also offering a user-friendly interface for an immersive gaming experience. + +## **functionalities 🎮** +- **Intelligent AI Opponent**: The game will feature an AI opponent with varying levels of difficulty, from beginner to grandmaster, to provide a challenging experience for players of all skill levels. + +## **How to play? 🕹ī¸** +- Players can make moves by dragging and dropping chess pieces to desired locations on the board. +- The game will follow standard chess rules, including move validation and checkmate detection. +- Players can select the difficulty level of the AI opponent to match their skill level. + +
+ +## **Screenshots 📸** + +
+![image](../../assets/images/chessComputer.png) + +
+ diff --git a/Games/Chess_Game_computer/index.html b/Games/Chess_Game_computer/index.html new file mode 100644 index 0000000000..92258599ad --- /dev/null +++ b/Games/Chess_Game_computer/index.html @@ -0,0 +1,14 @@ + + + + Chess Engine + + + + + +
+ + + + \ No newline at end of file diff --git a/Games/Chess_Game_computer/script.js b/Games/Chess_Game_computer/script.js new file mode 100644 index 0000000000..296d7bf0aa --- /dev/null +++ b/Games/Chess_Game_computer/script.js @@ -0,0 +1,1224 @@ +window.onload = function(){ + var w = window.innerWidth || 360; + var h = window.innerHeight || 500; + + var tsw = (w > h) ? h : w; + + var sw = (tsw - 16)/8; + + var container = document.getElementById("container"); + for(var n = 0; n < 64; n++){ + var square = document.createElement("div"); + square.classList.add("square"); + square.classList.add("s"+n); + square.style.height = sw + 'px'; + square.style.width = sw + 'px'; + square.style.top = 7+(h-tsw)/4+sw*(Math.floor(n/8)) + 'px'; + square.style.left = 7+(w-tsw)/2+sw*(Math.floor(n%8)) + 'px'; + square.style.fontSize = sw*3/4 + 'px'; + container.appendChild(square); + } + + var fonts = { + 'k' : '♚', + 'q' : '♛', + 'r' : '♜', + 'b' : '♝', + 'n' : '♞', + 'p' : '♟', + 'l' : '♔', + 'w' : '♕', + 't' : '♖', + 'v' : '♗', + 'm' : '♘', + 'o' : '♙', + + } + + var values = ['r','n','b','q','k','b','n','r','p','p','p','p','p','p','p','p',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'o','o','o','o','o','o','o','o','t','m','v','w','l','v','m','t']; + var ck = false; + var cr1 = false; + var cr2 = false; + var cl; + + var sqs = document.getElementsByClassName("square"); + + for(var n = 0; n < 64; n++){ + if(values[n] !== 0){ + sqs[n].innerHTML = fonts[values[n]]; + } + sqs[n].addEventListener("click",check); + } + + function updateSquarecolor(){ + for(var n = 0; n < 64; n++){ + if(Math.floor(n/8)%2 === 0){ + if(n%2 === 0){ + sqs[n].style.background = '#9ff'; + } + else { + sqs[n].style.background = '#5fa'; + } + } + else { + if(n%2 === 1){ + sqs[n].style.background = '#9ff'; + } + else { + sqs[n].style.background = '#5fa'; + } + } + } + } + + updateSquarecolor(); + + var moveable = false; + var moveTarget = ""; + var moveScopes = []; + + + function checkBlack(n,values){ + var target = values[n]; + var scopes = []; + var x = n; + + if(target === "o"){ + x -= 8; + if("prnbkq".indexOf(values[x-1]) >= 0 && x%8 != 0){ + scopes.push(x-1); + } + if("prnbkq".indexOf(values[x+1]) >= 0 && x%8 != 7){ + scopes.push(x+1); + } + if(x >= 0 && values[x] === 0){ + scopes.push(x); + if(x >= 40){ + if(x-8 >= 0 && values[x-8] === 0){ + scopes.push(x-8); + } + } + } + } + + else if(target === "t"){ + x = n; + x -= 8; + while(x >= 0){ + if(values[x] === 0){ + scopes.push(x); + } + else if("prnbqk".indexOf(values[x]) >= 0){ + scopes.push(x); + break; + } + else { + break; + } + x -= 8; + } + x = n; + x += 8; + while(x < 64){ + if(values[x] === 0){ + scopes.push(x); + } + else if("prnbqk".indexOf(values[x]) >= 0){ + scopes.push(x); + break; + } + else { + break; + } + x += 8; + } + x = n; + x++; + while(x%8 != 0){ + if(values[x] === 0){ + scopes.push(x); + } + else if("prnbqk".indexOf(values[x]) >= 0){ + scopes.push(x); + break; + } + else { + break; + } + x++; + } + x = n; + x--; + while(x%8 != 7){ + if(values[x] === 0){ + scopes.push(x); + } + else if("prnbqk".indexOf(values[x]) >= 0){ + scopes.push(x); + break; + } + else { + break; + } + x--; + } + } + + else if(target === "m"){ + x = n; + if(x%8 > 1 && x%8 < 6){ + x -= 17; + if(("prnbqk".indexOf(values[x]) >= 0 || values[x] === 0) && x < 64 && x >= 0){ + scopes.push(x); + } + x = n; + x -= 15; + if(("prnbqk".indexOf(values[x]) >= 0 || values[x] === 0) && x < 64 && x >= 0){ + scopes.push(x); + } + + x = n; + x -= 10; + if(("prnbqk".indexOf(values[x]) >= 0 || values[x] === 0) && x < 64 && x >= 0){ + scopes.push(x); + } + x = n; + x -= 6; + if(("prnbqk".indexOf(values[x]) >= 0 || values[x] === 0) && x < 64 && x >= 0){ + scopes.push(x); + } + x = n; + x += 6; + if(("prnbqk".indexOf(values[x]) >= 0 || values[x] === 0) && x < 64 && x >= 0){ + scopes.push(x); + } + x = n; + x += 10; + if(("prnbqk".indexOf(values[x]) >= 0 || values[x] === 0) && x < 64 && x >= 0){ + scopes.push(x); + } + x = n; + x += 15; + if(("prnbqk".indexOf(values[x]) >= 0 || values[x] === 0) && x < 64 && x >= 0){ + scopes.push(x); + } + x = n; + x += 17; + if(("prnbqk".indexOf(values[x]) >= 0 || values[x] === 0) && x < 64 && x >= 0){ + scopes.push(x); + } + } + else { + x = n; + if(x%8 <= 1){ + x = n; + x -= 15; + if(("prnbqk".indexOf(values[x]) >= 0 || values[x] === 0) && x < 64 && x >= 0){ + scopes.push(x); + } + x = n; + x -= 6; + if(("prnbqk".indexOf(values[x]) >= 0 || values[x] === 0) && x < 64 && x >= 0){ + scopes.push(x); + } + x = n; + x += 10; + if(("prnbqk".indexOf(values[x]) >= 0 || values[x] === 0) && x < 64 && x >= 0){ + scopes.push(x); + } + x = n; + x += 17; + if(("prnbqk".indexOf(values[x]) >= 0 || values[x] === 0) && x < 64 && x >= 0){ + scopes.push(x); + } + } + x = n; + if(x%8 === 1){ + x -= 17; + if(("prnbqk".indexOf(values[x]) >= 0 || values[x] === 0) && x < 64 && x >= 0){ + scopes.push(x); + } + x = n; + x += 15; + if(("prnbqk".indexOf(values[x]) >= 0 || values[x] === 0) && x < 64 && x >= 0){ + scopes.push(x); + } + } + if(x%8 >= 6){ + x = n; + x -= 17; + if(("prnbqk".indexOf(values[x]) >= 0 || values[x] === 0) && x < 64 && x >= 0){ + scopes.push(x); + } + x = n; + x -= 10; + if(("prnbqk".indexOf(values[x]) >= 0 || values[x] === 0) && x < 64 && x >= 0){ + scopes.push(x); + } + x = n; + x += 6; + if(("prnbqk".indexOf(values[x]) >= 0 || values[x] === 0) && x < 64 && x >= 0){ + scopes.push(x); + } + x = n; + x += 15; + if(("prnbqk".indexOf(values[x]) >= 0 || values[x] === 0) && x < 64 && x >= 0){ + scopes.push(x); + } + } + x = n; + if(x%8 === 6){ + x = n; + x -= 15; + if(("prnbqk".indexOf(values[x]) >= 0 || values[x] === 0) && x < 64 && x >= 0){ + scopes.push(x); + } + x = n; + x += 17; + if(("prnbqk".indexOf(values[x]) >= 0 || values[x] === 0) && x < 64 && x >= 0){ + scopes.push(x); + } + } + } + } + + else if(target === "v"){ + x = n; + x -= 9; + while(x >= 0 && x%8 !== 7){ + if(values[x] === 0){ + scopes.push(x); + } + else if("prnbqk".indexOf(values[x]) >= 0){ + scopes.push(x); + break; + } + else { + break; + } + x -= 9; + } + x = n; + x += 7; + while(x < 64 && x%8 !== 7){ + if(values[x] === 0){ + scopes.push(x); + } + else if("prnbqk".indexOf(values[x]) >= 0){ + scopes.push(x); + break; + } + else { + break; + } + x += 7; + } + x = n; + x += 9; + while(x%8 != 0 && x%8 !== 0){ + if(values[x] === 0){ + scopes.push(x); + } + else if("prnbqk".indexOf(values[x]) >= 0){ + scopes.push(x); + break; + } + else { + break; + } + x += 9; + } + x = n; + x -= 7; + while(x%8 != 0){ + if(values[x] === 0){ + scopes.push(x); + } + else if("prnbqk".indexOf(values[x]) >= 0){ + scopes.push(x); + break; + } + else { + break; + } + x -= 7; + } + } + + else if(target === "w"){ + x = n; + x -= 8; + while(x >= 0){ + if(values[x] === 0){ + scopes.push(x); + } + else if("prnbqk".indexOf(values[x]) >= 0){ + scopes.push(x); + break; + } + else { + break; + } + x -= 8; + } + x = n; + x += 8; + while(x < 64){ + if(values[x] === 0){ + scopes.push(x); + } + else if("prnbqk".indexOf(values[x]) >= 0){ + scopes.push(x); + break; + } + else { + break; + } + x += 8; + } + x = n; + x++; + while(x%8 != 0){ + if(values[x] === 0){ + scopes.push(x); + } + else if("prnbqk".indexOf(values[x]) >= 0){ + scopes.push(x); + break; + } + else { + break; + } + x++; + } + x = n; + x--; + while(x%8 != 7){ + if(values[x] === 0){ + scopes.push(x); + } + else if("prnbqk".indexOf(values[x]) >= 0){ + scopes.push(x); + break; + } + else { + break; + } + x--; + } + x = n; + x -= 9; + while(x >= 0 && x%8 !== 7){ + if(values[x] === 0){ + scopes.push(x); + } + else if("prnbqk".indexOf(values[x]) >= 0){ + scopes.push(x); + break; + } + else { + break; + } + x -= 9; + } + x = n; + x += 7; + while(x < 64 && x%8 !== 7){ + if(values[x] === 0){ + scopes.push(x); + } + else if("prnbqk".indexOf(values[x]) >= 0){ + scopes.push(x); + break; + } + else { + break; + } + x += 7; + } + x = n; + x += 9; + while(x%8 != 0 && x%8 !== 0){ + if(values[x] === 0){ + scopes.push(x); + } + else if("prnbqk".indexOf(values[x]) >= 0){ + scopes.push(x); + break; + } + else { + break; + } + x += 9; + } + x = n; + x -= 7; + while(x%8 != 0){ + if(values[x] === 0){ + scopes.push(x); + } + else if("prnbqk".indexOf(values[x]) >= 0){ + scopes.push(x); + break; + } + else { + break; + } + x -= 7; + } + } + + else if(target === "l"){ + x = n; + x += 8; + if(("prnbqk".indexOf(values[x]) >= 0 || values[x] === 0) && x < 64 && x >= 0){ + scopes.push(x); + } + x = n; + x -= 8; + if(("prnbqk".indexOf(values[x]) >= 0 || values[x] === 0) && x < 64 && x >= 0){ + scopes.push(x); + } + x = n; + if(x%8 > 0){ + x = n; + x -= 1; + if(("prnbqk".indexOf(values[x]) >= 0 || values[x] === 0) && x < 64 && x >= 0){ + scopes.push(x); + } + x = n; + x -= 9; + if(("prnbqk".indexOf(values[x]) >= 0 || values[x] === 0) && x < 64 && x >= 0){ + scopes.push(x); + } + + x = n; + x += 7; + if(("prnbqk".indexOf(values[x]) >= 0 || values[x] === 0) && x < 64 && x >= 0){ + scopes.push(x); + } + } + x = n; + if(x%8 < 7){ + x = n; + x += 1; + if(("prnbqk".indexOf(values[x]) >= 0 || values[x] === 0) && x < 64 && x >= 0){ + scopes.push(x); + } + x = n; + x += 9; + if(("prnbqk".indexOf(values[x]) >= 0 || values[x] === 0) && x < 64 && x >= 0){ + scopes.push(x); + } + x = n; + x -= 7; + if(("prnbqk".indexOf(values[x]) >= 0 || values[x] === 0) && x < 64 && x >= 0){ + scopes.push(x); + } + } + x = n; + if(!ck){ + cl = false; + if(!cr2){ + // cl = false; + if(values[n+1] === 0 && values[n+2] === 0 && values[n+3] === "t"){ + scopes.push(x+2); + cl = true; + } + } + if(!cr1){ + // cl = false; + if(values[n-1] === 0 && values[n-2] === 0 && values[n-3] === 0 && values[n-4] === "t"){ + scopes.push(x-2); + cl = true; + } + } + } + } + if(scopes.length) return scopes; + } + + function checkWhite(n,values){ + var target = values[n]; + var scopes = []; + var x = n; + if(target === "p"){ + x += 8; + if("otmvlw".indexOf(values[x-1]) >= 0 && x%8 != 0){ + scopes.push(x-1); + } + if("otmvlw".indexOf(values[x+1]) >= 0 && x%8 != 7){ + scopes.push(x+1); + } + if(x < 64 && values[x] === 0){ + scopes.push(x); + if(x <= 23){ + if(x+8 >= 0 && values[x+8] === 0){ + scopes.push(x+8); + } + } + } + } + + else if(target === "r"){ + x = n; + x -= 8; + while(x >= 0){ + if(values[x] === 0){ + scopes.push(x); + } + else if("otmvlw".indexOf(values[x]) >= 0){ + scopes.push(x); + break; + } + else { + break; + } + x -= 8; + } + x = n; + x += 8; + while(x < 64){ + if(values[x] === 0){ + scopes.push(x); + } + else if("otmvlw".indexOf(values[x]) >= 0){ + scopes.push(x); + break; + } + else { + break; + } + x += 8; + } + x = n; + x++; + while(x%8 != 0){ + if(values[x] === 0){ + scopes.push(x); + } + else if("otmvlw".indexOf(values[x]) >= 0){ + scopes.push(x); + break; + } + else { + break; + } + x++; + } + x = n; + x--; + while(x%8 != 7){ + if(values[x] === 0){ + scopes.push(x); + } + else if("otmvlw".indexOf(values[x]) >= 0){ + scopes.push(x); + break; + } + else { + break; + } + x--; + } + } + + else if(target === "n"){ + x = n; + if(x%8 > 1 && x%8 < 6){ + x -= 17; + if(("otmvlw".indexOf(values[x]) >= 0 || values[x] === 0) && x < 64 && x >= 0){ + scopes.push(x); + } + x = n; + x -= 15; + if(("otmvlw".indexOf(values[x]) >= 0 || values[x] === 0) && x < 64 && x >= 0){ + scopes.push(x); + } + + x = n; + x -= 10; + if(("otmvlw".indexOf(values[x]) >= 0 || values[x] === 0) && x < 64 && x >= 0){ + scopes.push(x); + } + x = n; + x -= 6; + if(("otmvlw".indexOf(values[x]) >= 0 || values[x] === 0) && x < 64 && x >= 0){ + scopes.push(x); + } + x = n; + x += 6; + if(("otmvlw".indexOf(values[x]) >= 0 || values[x] === 0) && x < 64 && x >= 0){ + scopes.push(x); + } + x = n; + x += 10; + if(("otmvlw".indexOf(values[x]) >= 0 || values[x] === 0) && x < 64 && x >= 0){ + scopes.push(x); + } + x = n; + x += 15; + if(("otmvlw".indexOf(values[x]) >= 0 || values[x] === 0) && x < 64 && x >= 0){ + scopes.push(x); + } + x = n; + x += 17; + if(("otmvlw".indexOf(values[x]) >= 0 || values[x] === 0) && x < 64 && x >= 0){ + scopes.push(x); + } + } + else { + x = n; + if(x%8 <= 1){ + x = n; + x -= 15; + if(("otmvlw".indexOf(values[x]) >= 0 || values[x] === 0) && x < 64 && x >= 0){ + scopes.push(x); + } + x = n; + x -= 6; + if(("otmvlw".indexOf(values[x]) >= 0 || values[x] === 0) && x < 64 && x >= 0){ + scopes.push(x); + } + x = n; + x += 10; + if(("otmvlw".indexOf(values[x]) >= 0 || values[x] === 0) && x < 64 && x >= 0){ + scopes.push(x); + } + x = n; + x += 17; + if(("otmvlw".indexOf(values[x]) >= 0 || values[x] === 0) && x < 64 && x >= 0){ + scopes.push(x); + } + } + x = n; + if(x%8 === 1){ + x -= 17; + if(("otmvlw".indexOf(values[x]) >= 0 || values[x] === 0) && x < 64 && x >= 0){ + scopes.push(x); + } + x = n; + x += 15; + if(("otmvlw".indexOf(values[x]) >= 0 || values[x] === 0) && x < 64 && x >= 0){ + scopes.push(x); + } + } + if(x%8 >= 6){ + x = n; + x -= 17; + if(("otmvlw".indexOf(values[x]) >= 0 || values[x] === 0) && x < 64 && x >= 0){ + scopes.push(x); + } + x = n; + x -= 10; + if(("otmvlw".indexOf(values[x]) >= 0 || values[x] === 0) && x < 64 && x >= 0){ + scopes.push(x); + } + x = n; + x += 6; + if(("otmvlw".indexOf(values[x]) >= 0 || values[x] === 0) && x < 64 && x >= 0){ + scopes.push(x); + } + x = n; + x += 15; + if(("otmvlw".indexOf(values[x]) >= 0 || values[x] === 0) && x < 64 && x >= 0){ + scopes.push(x); + } + } + x = n; + if(x%8 === 6){ + x = n; + x -= 15; + if(("otmvlw".indexOf(values[x]) >= 0 || values[x] === 0) && x < 64 && x >= 0){ + scopes.push(x); + } + x = n; + x += 17; + if(("otmvlw".indexOf(values[x]) >= 0 || values[x] === 0) && x < 64 && x >= 0){ + scopes.push(x); + } + } + } + } + + else if(target === "b"){ + x = n; + x -= 9; + while(x >= 0 && x%8 !== 7){ + if(values[x] === 0){ + scopes.push(x); + } + else if("otmvlw".indexOf(values[x]) >= 0){ + scopes.push(x); + break; + } + else { + break; + } + x -= 9; + } + x = n; + x += 7; + while(x < 64 && x%8 !== 7){ + if(values[x] === 0){ + scopes.push(x); + } + else if("otmvlw".indexOf(values[x]) >= 0){ + scopes.push(x); + break; + } + else { + break; + } + x += 7; + } + x = n; + x += 9; + while(x%8 != 0 && x%8 !== 0){ + if(values[x] === 0){ + scopes.push(x); + } + else if("otmvlw".indexOf(values[x]) >= 0){ + scopes.push(x); + break; + } + else { + break; + } + x += 9; + } + x = n; + x -= 7; + while(x%8 != 0){ + if(values[x] === 0){ + scopes.push(x); + } + else if("otmvlw".indexOf(values[x]) >= 0){ + scopes.push(x); + break; + } + else { + break; + } + x -= 7; + } + } + + else if(target === "q"){ + x = n; + x -= 8; + while(x >= 0){ + if(values[x] === 0){ + scopes.push(x); + } + else if("otmvlw".indexOf(values[x]) >= 0){ + scopes.push(x); + break; + } + else { + break; + } + x -= 8; + } + x = n; + x += 8; + while(x < 64){ + if(values[x] === 0){ + scopes.push(x); + } + else if("otmvlw".indexOf(values[x]) >= 0){ + scopes.push(x); + break; + } + else { + break; + } + x += 8; + } + x = n; + x++; + while(x%8 != 0){ + if(values[x] === 0){ + scopes.push(x); + } + else if("otmvlw".indexOf(values[x]) >= 0){ + scopes.push(x); + break; + } + else { + break; + } + x++; + } + x = n; + x--; + while(x%8 != 7){ + if(values[x] === 0){ + scopes.push(x); + } + else if("otmvlw".indexOf(values[x]) >= 0){ + scopes.push(x); + break; + } + else { + break; + } + x--; + } + x = n; + x -= 9; + while(x >= 0 && x%8 !== 7){ + if(values[x] === 0){ + scopes.push(x); + } + else if("otmvlw".indexOf(values[x]) >= 0){ + scopes.push(x); + break; + } + else { + break; + } + x -= 9; + } + x = n; + x += 7; + while(x < 64 && x%8 !== 7){ + if(values[x] === 0){ + scopes.push(x); + } + else if("otmvlw".indexOf(values[x]) >= 0){ + scopes.push(x); + break; + } + else { + break; + } + x += 7; + } + x = n; + x += 9; + while(x%8 != 0 && x%8 !== 0){ + if(values[x] === 0){ + scopes.push(x); + } + else if("otmvlw".indexOf(values[x]) >= 0){ + scopes.push(x); + break; + } + else { + break; + } + x += 9; + } + x = n; + x -= 7; + while(x%8 != 0){ + if(values[x] === 0){ + scopes.push(x); + } + else if("otmvlw".indexOf(values[x]) >= 0){ + scopes.push(x); + break; + } + else { + break; + } + x -= 7; + } + } + + else if(target === "k"){ + x = n; + x += 8; + if(("otmvlw".indexOf(values[x]) >= 0 || values[x] === 0) && x < 64 && x >= 0){ + scopes.push(x); + } + x = n; + x -= 8; + if(("otmvlw".indexOf(values[x]) >= 0 || values[x] === 0) && x < 64 && x >= 0){ + scopes.push(x); + } + x = n; + if(x%8 > 0){ + x = n; + x -= 1; + if(("otmvlw".indexOf(values[x]) >= 0 || values[x] === 0) && x < 64 && x >= 0){ + scopes.push(x); + } + x = n; + x -= 9; + if(("otmvlw".indexOf(values[x]) >= 0 || values[x] === 0) && x < 64 && x >= 0){ + scopes.push(x); + } + + x = n; + x += 7; + if(("otmvlw".indexOf(values[x]) >= 0 || values[x] === 0) && x < 64 && x >= 0){ + scopes.push(x); + } + } + x = n; + if(x%8 < 7){ + x = n; + x += 1; + if(("otmvlw".indexOf(values[x]) >= 0 || values[x] === 0) && x < 64 && x >= 0){ + scopes.push(x); + } + x = n; + x += 9; + if(("otmvlw".indexOf(values[x]) >= 0 || values[x] === 0) && x < 64 && x >= 0){ + scopes.push(x); + } + x = n; + x -= 7; + if(("otmvlw".indexOf(values[x]) >= 0 || values[x] === 0) && x < 64 && x >= 0){ + scopes.push(x); + } + } + } + if(scopes.length) return scopes; + } + + var myTurn = true; + + function check(){ + if(myTurn){ + var n = Number(this.classList[1].slice(1)); + var target = values[n]; + + var scopes = checkBlack(n,values) || []; + + var x = n; + + if(!moveable){ + if(scopes.length > 0){ + moveable = true; + moveTarget = n; + moveScopes = scopes.join(",").split(","); + } + else { + + } + } + else { + if(moveScopes.indexOf(String(n)) >= 0){ + var checkArr = []; + var saveKing = false; + for(var z = 0; z < 64; z++){ + checkArr[z] = values[z]; + } + + checkArr[n] = checkArr[moveTarget]; + checkArr[moveTarget] = 0; + + for(var y = 0; y < 64; y++){ + if("prnbkq".indexOf(checkArr[y]) >= 0){ + var checkScp = checkWhite(y,checkArr) || []; + for(var z = 0; z < checkScp.length; z++){ + if(checkArr[checkScp[z]] === 'l'){ + if(!saveKing){ + alert('Save Your King'); + saveKing = true; + } + } + } + } + } + + if(!saveKing){ + values[n] = values[moveTarget]; + values[moveTarget] = 0; + if(cl){ + if(n === 62 && moveTarget === 60){ + values[63] = 0; + values[61] = "t"; + } + else if(n === 58 && moveTarget === 60){ + values[59] = "t"; + values[56] = 0; + } + } + if(moveTarget === 60){ + ck = true; + } + else if(moveTarget === 63){ + cr2 = true; + } + else if(moveTarget === 56){ + cr1 = true; + } + if(values[n] === "o" && n < 8){ + values[n] = "w"; + } + moveable = false; + scopes = []; + myTurn = false; + setTimeout(chooseTurn,1000); + } + } + else { + moveScopes = []; + moveable = false; + } + } + + updateSquarecolor(); + + for(var x = 0; x < 64; x++){ + sqs[x].innerHTML = fonts[values[x]]; + if(values[x] === 0){ + sqs[x].innerHTML = ""; + } + } + + for(var x = 0; x < scopes.length; x++){ + sqs[scopes[x]].style.background = "#f45";//.classList.add("scope"); + // alert(scopes) + } + } + } + + + var arr = []; + + function chooseTurn(){ + var approved = []; + var actions = []; + var effects = []; + + + for(var n = 0; n < 64; n++){ + if("prnbqk".indexOf(values[n]) >= 0){ + var scopes = checkWhite(n,values) || []; + for(var x = 0; x < scopes.length; x++){ + var tmp = []//values.join(',').split(','); + for(var xx = 0; xx < 64; xx++){ + tmp[xx] = values[xx] + } + var effect = 0; + var action = Math.random()*3; + //Action value + var actionValue = tmp[scopes[x]]; + if(actionValue === "l"){ + action = 100 + Math.random()*3; + } + else if(actionValue === "w"){ + action = 50 + Math.random()*3; + } + else if(actionValue === "v"){ + action = 30 + Math.random()*3; + } + else if(actionValue === "m"){ + action = 30 + Math.random()*3; + } + else if(actionValue === "t"){ + action = 30 + Math.random()*3; + } + else if(actionValue === "o"){ + action = 15 + Math.random()*3; + } + //Effect value + tmp[scopes[x]] = tmp[n]; + tmp[n] = 0; + for(var y = 0; y < 64; y++){ + if("otmvlw".indexOf(values[y]) >= 0){ + var tmpScp = checkBlack(y,tmp) || []; + for(var z = 0; z < tmpScp.length; z++){ + var effectValue = tmp[tmpScp[z]]; + if(effectValue == "k"){ + if(effect < 100){ + effect = 100; + } + } + else if(effectValue == "q"){ + if(effect < 50){ + effect = 50; + } + } + else if(effectValue == "b"){ + if(effect < 30){ + effect = 30; + } + } + else if(effectValue == "n"){ + if(effect < 30){ + effect = 30; + } + } + else if(effectValue == "r"){ + if(effect < 30){ + effect = 30; + } + } + else if(effectValue == "p"){ + if(effect < 15){ + effect = 15; + } + } + } + } + } + + + + + actions.push(action); + effects.push(effect); + approved.push(n+"-"+scopes[x]); + } + } + } + + //alert(actions); + + var bestEffect = Math.min.apply(null,effects); + //alert(bestEffect); + if(bestEffect >= 100){ + alert("You Win"); + setTimeout(function(){ + values = ['r','n','b','q','k','b','n','r','p','p','p','p','p','p','p','p',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'o','o','o','o','o','o','o','o','t','m','v','w','l','v','m','t']; + },100); + } + + var tmpA = []; + var tmpB = []; + var tmpC = []; + var bestMove = ""; + + for(var n = 0; n < effects.length; n++){ + if(effects[n] === bestEffect){ + tmpA.push(actions[n]); + tmpB.push(approved[n]); + tmpC.push(effects[n]); + } + } + bestMove = tmpB[tmpA.indexOf(Math.max.apply(null,tmpA))]; + // alert(effects) + //alert(bestMove); + + + if(bestMove){ + values[Number(bestMove.split("-")[1])] = values[Number(bestMove.split("-")[0])]; + values[Number(bestMove.split("-")[0])] = 0; + if(values[Number(bestMove.split("-")[1])] === "p" && Number(bestMove.split("-")[1]) >= 56){ + values[Number(bestMove.split("-")[1])] = "q"; + } + + sqs[bestMove.split("-")[1]].style.background = '#aaf'; + sqs[bestMove.split("-")[0]].style.background = '#aaf'; + + for(var x = 0; x < 64; x++){ + //sqs[x].style.background = "#afa"//classList.add("scope"); + sqs[x].innerHTML = fonts[values[x]]; + if(values[x] === 0){ + sqs[x].innerHTML = ""; + } + } + myTurn = true; + } + else { + //alert('You Win'); + } + } +} +//chooseTurn(); \ No newline at end of file diff --git a/Games/Chess_Game_computer/style.css b/Games/Chess_Game_computer/style.css new file mode 100644 index 0000000000..20a54210b9 --- /dev/null +++ b/Games/Chess_Game_computer/style.css @@ -0,0 +1,28 @@ +body { + font-family:chess; + margin: 0; + background-color:#000; +} + +.square { + background:#afa; + display:inline-block; + border:1px solid #fff; + text-align:center; + position: absolute; + cursor: pointer; +} + +#buymeacoffee { + z-index: 10000; + position: absolute; + bottom: 20px; + width: 100%; + display: block; + text-align: center; +} + +#buymeacoffee img { + box-shadow: 0px 2px 6px rgba(255, 255, 255, 0.3); + border-radius: 10px; +} \ No newline at end of file diff --git a/Games/Grab_The_Carrot/README.md b/Games/Grab_The_Carrot/README.md new file mode 100644 index 0000000000..da04757813 --- /dev/null +++ b/Games/Grab_The_Carrot/README.md @@ -0,0 +1,24 @@ +# Grab The Carrot + +## Description +The Grab The Carrot is a simple web-based game designed to test and have fun . The game presents a sequence of obstacle which the players need to overcomes . The Players need to Grab The Carrot to survive the game + +# Functionality +- Displays a sequence of obstacles +- Increases the Highscore once the players Grab The Carrot. +- Simple and intuitive user interface. +- You can track your current score. + +## Usage +- Open the game by opening index.html in a web browser. +- Click the `Start Game` button to begin. +- A sequence of numbers will be displayed for a short period. +- Memorize the sequence and enter it into the input field once it disappears. +- Click the "Submit" button to check your input. +- If you recall the sequence correctly, a new number will be added to the sequence, and the game continues. +- If you input the sequence incorrectly, the game will end and display the correct sequence. + +## Files +- `index.html`: The main HTML file that sets up the structure of the game. +- `styles.css`: The CSS file that styles the game. +- `script.js`: The JavaScript file that contains the game logic. diff --git a/Games/Grab_The_Carrot/index.html b/Games/Grab_The_Carrot/index.html new file mode 100644 index 0000000000..5459dc7b8f --- /dev/null +++ b/Games/Grab_The_Carrot/index.html @@ -0,0 +1,32 @@ + + + + + + Grab the Carrot Game + + + +
+
+
+
+
+
Game Over
+
+
distance
+
000
+
+
+ Click to jump + — Grab the carrots / avoid the hedgehogs +
+ + + + + + + + diff --git a/Games/Grab_The_Carrot/script.js b/Games/Grab_The_Carrot/script.js new file mode 100644 index 0000000000..77072d3fa7 --- /dev/null +++ b/Games/Grab_The_Carrot/script.js @@ -0,0 +1,1520 @@ +//THREEJS RELATED VARIABLES + +var scene, + camera, + fieldOfView, + aspectRatio, + nearPlane, + farPlane, + gobalLight, + shadowLight, + backLight, + renderer, + container, + controls, + clock; +var delta = 0; +var floorRadius = 200; +var speed = 6; +var distance = 0; +var level = 1; +var levelInterval; +var levelUpdateFreq = 3000; +var initSpeed = 5; +var maxSpeed = 48; +var monsterPos = 0.65; +var monsterPosTarget = 0.65; +var floorRotation = 0; +var collisionObstacle = 10; +var collisionBonus = 20; +var gameStatus = "play"; +var cameraPosGame = 160; +var cameraPosGameOver = 260; +var monsterAcceleration = 0.004; +var malusClearColor = 0xb44b39; +var malusClearAlpha = 0; +var audio = new Audio( + "https://s3-us-west-2.amazonaws.com/s.cdpn.io/264161/Antonio-Vivaldi-Summer_01.mp3", +); + +var fieldGameOver, fieldDistance; + +//SCREEN & MOUSE VARIABLES + +var HEIGHT, + WIDTH, + windowHalfX, + windowHalfY, + mousePos = { + x: 0, + y: 0, + }; + +//3D OBJECTS VARIABLES + +var hero; + +// Materials +var blackMat = new THREE.MeshPhongMaterial({ + color: 0x100707, + flatShading: true, // Replace shading with flatShading +}); +var brownMat = new THREE.MeshPhongMaterial({ + color: 0xb44b39, + flatShading: true, +}); + +var greenMat = new THREE.MeshPhongMaterial({ + color: 0x7abf8e, + flatShading: true, +}); + +var pinkMat = new THREE.MeshPhongMaterial({ + color: 0xdc5f45, //0xb43b29,//0xff5b49, + flatShading: true, +}); + +var lightBrownMat = new THREE.MeshPhongMaterial({ + color: 0xe07a57, + flatShading: true, +}); + +var whiteMat = new THREE.MeshPhongMaterial({ + color: 0xa49789, + shading: THREE.FlatShading, +}); +var skinMat = new THREE.MeshPhongMaterial({ + color: 0xff9ea5, + shading: THREE.FlatShading, +}); + +// OTHER VARIABLES + +var PI = Math.PI; + +//INIT THREE JS, SCREEN AND MOUSE EVENTS + +function initScreenAnd3D() { + HEIGHT = window.innerHeight; + WIDTH = window.innerWidth; + windowHalfX = WIDTH / 2; + windowHalfY = HEIGHT / 2; + + scene = new THREE.Scene(); + + scene.fog = new THREE.Fog(0xd6eae6, 160, 350); + + aspectRatio = WIDTH / HEIGHT; + fieldOfView = 50; + nearPlane = 1; + farPlane = 2000; + camera = new THREE.PerspectiveCamera( + fieldOfView, + aspectRatio, + nearPlane, + farPlane, + ); + camera.position.x = 0; + camera.position.z = cameraPosGame; + camera.position.y = 30; + camera.lookAt(new THREE.Vector3(0, 30, 0)); + + renderer = new THREE.WebGLRenderer({ + alpha: true, + antialias: true, + }); + renderer.setPixelRatio(window.devicePixelRatio); + renderer.setClearColor(malusClearColor, malusClearAlpha); + + renderer.setSize(WIDTH, HEIGHT); + renderer.shadowMap.enabled = true; + + container = document.getElementById("world"); + container.appendChild(renderer.domElement); + + window.addEventListener("resize", handleWindowResize, false); + document.addEventListener("mousedown", handleMouseDown, false); + document.addEventListener("touchend", handleMouseDown, false); + + /* + controls = new THREE.OrbitControls(camera, renderer.domElement); + //controls.minPolarAngle = -Math.PI / 2; + //controls.maxPolarAngle = Math.PI / 2; + //controls.noZoom = true; + controls.noPan = true; + //*/ + + clock = new THREE.Clock(); +} + +function handleWindowResize() { + HEIGHT = window.innerHeight; + WIDTH = window.innerWidth; + windowHalfX = WIDTH / 2; + windowHalfY = HEIGHT / 2; + renderer.setSize(WIDTH, HEIGHT); + camera.aspect = WIDTH / HEIGHT; + camera.updateProjectionMatrix(); +} + +function handleMouseDown(event) { + if (gameStatus == "play") hero.jump(); + else if (gameStatus == "readyToReplay") { + replay(); + } +} + +function createLights() { + globalLight = new THREE.AmbientLight(0xffffff, 0.9); + + shadowLight = new THREE.DirectionalLight(0xffffff, 1); + shadowLight.position.set(-30, 40, 20); + shadowLight.castShadow = true; + shadowLight.shadow.camera.left = -400; + shadowLight.shadow.camera.right = 400; + shadowLight.shadow.camera.top = 400; + shadowLight.shadow.camera.bottom = -400; + shadowLight.shadow.camera.near = 1; + shadowLight.shadow.camera.far = 2000; + shadowLight.shadow.mapSize.width = shadowLight.shadow.mapSize.height = 2048; + + scene.add(globalLight); + scene.add(shadowLight); +} + +function createFloor() { + floorShadow = new THREE.Mesh( + new THREE.SphereGeometry(floorRadius, 50, 50), + new THREE.MeshPhongMaterial({ + color: 0x7abf8e, + specular: 0x000000, + shininess: 1, + transparent: true, + opacity: 0.5, + }), + ); + //floorShadow.rotation.x = -Math.PI / 2; + floorShadow.receiveShadow = true; + + floorGrass = new THREE.Mesh( + new THREE.SphereGeometry(floorRadius - 0.5, 50, 50), + new THREE.MeshBasicMaterial({ + color: 0x7abf8e, + }), + ); + //floor.rotation.x = -Math.PI / 2; + floorGrass.receiveShadow = false; + + floor = new THREE.Group(); + floor.position.y = -floorRadius; + + floor.add(floorShadow); + floor.add(floorGrass); + scene.add(floor); +} + +Hero = function () { + this.status = "running"; + this.runningCycle = 0; + this.mesh = new THREE.Group(); + this.body = new THREE.Group(); + this.mesh.add(this.body); + + var torsoGeom = new THREE.CubeGeometry(7, 7, 10, 1); + + this.torso = new THREE.Mesh(torsoGeom, brownMat); + this.torso.position.z = 0; + this.torso.position.y = 7; + this.torso.castShadow = true; + this.body.add(this.torso); + + var pantsGeom = new THREE.CubeGeometry(9, 9, 5, 1); + this.pants = new THREE.Mesh(pantsGeom, whiteMat); + this.pants.position.z = -3; + this.pants.position.y = 0; + this.pants.castShadow = true; + this.torso.add(this.pants); + + var tailGeom = new THREE.CubeGeometry(3, 3, 3, 1); + tailGeom.applyMatrix(new THREE.Matrix4().makeTranslation(0, 0, -2)); + this.tail = new THREE.Mesh(tailGeom, lightBrownMat); + this.tail.position.z = -4; + this.tail.position.y = 5; + this.tail.castShadow = true; + this.torso.add(this.tail); + + this.torso.rotation.x = -Math.PI / 8; + + var headGeom = new THREE.CubeGeometry(10, 10, 13, 1); + + headGeom.applyMatrix(new THREE.Matrix4().makeTranslation(0, 0, 7.5)); + this.head = new THREE.Mesh(headGeom, brownMat); + this.head.position.z = 2; + this.head.position.y = 11; + this.head.castShadow = true; + this.body.add(this.head); + + var cheekGeom = new THREE.CubeGeometry(1, 4, 4, 1); + this.cheekR = new THREE.Mesh(cheekGeom, pinkMat); + this.cheekR.position.x = -5; + this.cheekR.position.z = 7; + this.cheekR.position.y = -2.5; + this.cheekR.castShadow = true; + this.head.add(this.cheekR); + + this.cheekL = this.cheekR.clone(); + this.cheekL.position.x = -this.cheekR.position.x; + this.head.add(this.cheekL); + + var noseGeom = new THREE.CubeGeometry(6, 6, 3, 1); + this.nose = new THREE.Mesh(noseGeom, lightBrownMat); + this.nose.position.z = 13.5; + this.nose.position.y = 2.6; + this.nose.castShadow = true; + this.head.add(this.nose); + + var mouthGeom = new THREE.CubeGeometry(4, 2, 4, 1); + mouthGeom.applyMatrix(new THREE.Matrix4().makeTranslation(0, 0, 3)); + mouthGeom.applyMatrix(new THREE.Matrix4().makeRotationX(Math.PI / 12)); + this.mouth = new THREE.Mesh(mouthGeom, brownMat); + this.mouth.position.z = 8; + this.mouth.position.y = -4; + this.mouth.castShadow = true; + this.head.add(this.mouth); + + var pawFGeom = new THREE.CubeGeometry(3, 3, 3, 1); + this.pawFR = new THREE.Mesh(pawFGeom, lightBrownMat); + this.pawFR.position.x = -2; + this.pawFR.position.z = 6; + this.pawFR.position.y = 1.5; + this.pawFR.castShadow = true; + this.body.add(this.pawFR); + + this.pawFL = this.pawFR.clone(); + this.pawFL.position.x = -this.pawFR.position.x; + this.pawFL.castShadow = true; + this.body.add(this.pawFL); + + var pawBGeom = new THREE.CubeGeometry(3, 3, 6, 1); + this.pawBL = new THREE.Mesh(pawBGeom, lightBrownMat); + this.pawBL.position.y = 1.5; + this.pawBL.position.z = 0; + this.pawBL.position.x = 5; + this.pawBL.castShadow = true; + this.body.add(this.pawBL); + + this.pawBR = this.pawBL.clone(); + this.pawBR.position.x = -this.pawBL.position.x; + this.pawBR.castShadow = true; + this.body.add(this.pawBR); + + var earGeom = new THREE.CubeGeometry(7, 18, 2, 1); + earGeom.vertices[6].x += 2; + earGeom.vertices[6].z += 0.5; + + earGeom.vertices[7].x += 2; + earGeom.vertices[7].z -= 0.5; + + earGeom.vertices[2].x -= 2; + earGeom.vertices[2].z -= 0.5; + + earGeom.vertices[3].x -= 2; + earGeom.vertices[3].z += 0.5; + earGeom.applyMatrix(new THREE.Matrix4().makeTranslation(0, 9, 0)); + + this.earL = new THREE.Mesh(earGeom, brownMat); + this.earL.position.x = 2; + this.earL.position.z = 2.5; + this.earL.position.y = 5; + this.earL.rotation.z = -Math.PI / 12; + this.earL.castShadow = true; + this.head.add(this.earL); + + this.earR = this.earL.clone(); + this.earR.position.x = -this.earL.position.x; + this.earR.rotation.z = -this.earL.rotation.z; + this.earR.castShadow = true; + this.head.add(this.earR); + + var eyeGeom = new THREE.CubeGeometry(2, 4, 4); + + this.eyeL = new THREE.Mesh(eyeGeom, whiteMat); + this.eyeL.position.x = 5; + this.eyeL.position.z = 5.5; + this.eyeL.position.y = 2.9; + this.eyeL.castShadow = true; + this.head.add(this.eyeL); + + var irisGeom = new THREE.CubeGeometry(0.6, 2, 2); + + this.iris = new THREE.Mesh(irisGeom, blackMat); + this.iris.position.x = 1.2; + this.iris.position.y = 1; + this.iris.position.z = 1; + this.eyeL.add(this.iris); + + this.eyeR = this.eyeL.clone(); + this.eyeR.children[0].position.x = -this.iris.position.x; + + this.eyeR.position.x = -this.eyeL.position.x; + this.head.add(this.eyeR); + + this.body.traverse(function (object) { + if (object instanceof THREE.Mesh) { + object.castShadow = true; + object.receiveShadow = true; + } + }); +}; + +BonusParticles = function () { + this.mesh = new THREE.Group(); + var bigParticleGeom = new THREE.CubeGeometry(10, 10, 10, 1); + var smallParticleGeom = new THREE.CubeGeometry(5, 5, 5, 1); + this.parts = []; + for (var i = 0; i < 10; i++) { + var partPink = new THREE.Mesh(bigParticleGeom, pinkMat); + var partGreen = new THREE.Mesh(smallParticleGeom, greenMat); + partGreen.scale.set(0.5, 0.5, 0.5); + this.parts.push(partPink); + this.parts.push(partGreen); + this.mesh.add(partPink); + this.mesh.add(partGreen); + } +}; + +BonusParticles.prototype.explose = function () { + var _this = this; + var explosionSpeed = 0.5; + for (var i = 0; i < this.parts.length; i++) { + var tx = -50 + Math.random() * 100; + var ty = -50 + Math.random() * 100; + var tz = -50 + Math.random() * 100; + var p = this.parts[i]; + p.position.set(0, 0, 0); + p.scale.set(1, 1, 1); + p.visible = true; + var s = explosionSpeed + Math.random() * 0.5; + TweenMax.to(p.position, s, { x: tx, y: ty, z: tz, ease: Power4.easeOut }); + TweenMax.to(p.scale, s, { + x: 0.01, + y: 0.01, + z: 0.01, + ease: Power4.easeOut, + onComplete: removeParticle, + onCompleteParams: [p], + }); + } +}; + +function removeParticle(p) { + p.visible = false; +} + +Hero.prototype.run = function () { + this.status = "running"; + + var s = Math.min(speed, maxSpeed); + + this.runningCycle += delta * s * 0.7; + this.runningCycle = this.runningCycle % (Math.PI * 2); + var t = this.runningCycle; + + var amp = 4; + var disp = 0.2; + + // BODY + + this.body.position.y = 6 + Math.sin(t - Math.PI / 2) * amp; + this.body.rotation.x = 0.2 + Math.sin(t - Math.PI / 2) * amp * 0.1; + + this.torso.rotation.x = Math.sin(t - Math.PI / 2) * amp * 0.1; + this.torso.position.y = 7 + Math.sin(t - Math.PI / 2) * amp * 0.5; + + // MOUTH + this.mouth.rotation.x = Math.PI / 16 + Math.cos(t) * amp * 0.05; + + // HEAD + this.head.position.z = 2 + Math.sin(t - Math.PI / 2) * amp * 0.5; + this.head.position.y = 8 + Math.cos(t - Math.PI / 2) * amp * 0.7; + this.head.rotation.x = -0.2 + Math.sin(t + Math.PI) * amp * 0.1; + + // EARS + this.earL.rotation.x = Math.cos(-Math.PI / 2 + t) * (amp * 0.2); + this.earR.rotation.x = Math.cos(-Math.PI / 2 + 0.2 + t) * (amp * 0.3); + + // EYES + this.eyeR.scale.y = this.eyeL.scale.y = + 0.7 + Math.abs(Math.cos(-Math.PI / 4 + t * 0.5)) * 0.6; + + // TAIL + this.tail.rotation.x = Math.cos(Math.PI / 2 + t) * amp * 0.3; + + // FRONT RIGHT PAW + this.pawFR.position.y = 1.5 + Math.sin(t) * amp; + this.pawFR.rotation.x = (Math.cos(t) * Math.PI) / 4; + + this.pawFR.position.z = 6 - Math.cos(t) * amp * 2; + + // FRONT LEFT PAW + + this.pawFL.position.y = 1.5 + Math.sin(disp + t) * amp; + this.pawFL.rotation.x = (Math.cos(t) * Math.PI) / 4; + + this.pawFL.position.z = 6 - Math.cos(disp + t) * amp * 2; + + // BACK RIGHT PAW + this.pawBR.position.y = 1.5 + Math.sin(Math.PI + t) * amp; + this.pawBR.rotation.x = (Math.cos(t + Math.PI * 1.5) * Math.PI) / 3; + + this.pawBR.position.z = -Math.cos(Math.PI + t) * amp; + + // BACK LEFT PAW + this.pawBL.position.y = 1.5 + Math.sin(Math.PI + t) * amp; + this.pawBL.rotation.x = (Math.cos(t + Math.PI * 1.5) * Math.PI) / 3; + + this.pawBL.position.z = -Math.cos(Math.PI + t) * amp; +}; + +Hero.prototype.jump = function () { + if (this.status == "jumping") return; + this.status = "jumping"; + var _this = this; + var totalSpeed = 10 / speed; + var jumpHeight = 45; + + TweenMax.to(this.earL.rotation, totalSpeed, { + x: "+=.3", + ease: Back.easeOut, + }); + TweenMax.to(this.earR.rotation, totalSpeed, { + x: "-=.3", + ease: Back.easeOut, + }); + + TweenMax.to(this.pawFL.rotation, totalSpeed, { + x: "+=.7", + ease: Back.easeOut, + }); + TweenMax.to(this.pawFR.rotation, totalSpeed, { + x: "-=.7", + ease: Back.easeOut, + }); + TweenMax.to(this.pawBL.rotation, totalSpeed, { + x: "+=.7", + ease: Back.easeOut, + }); + TweenMax.to(this.pawBR.rotation, totalSpeed, { + x: "-=.7", + ease: Back.easeOut, + }); + + TweenMax.to(this.tail.rotation, totalSpeed, { x: "+=1", ease: Back.easeOut }); + + TweenMax.to(this.mouth.rotation, totalSpeed, { x: 0.5, ease: Back.easeOut }); + + TweenMax.to(this.mesh.position, totalSpeed / 2, { + y: jumpHeight, + ease: Power2.easeOut, + }); + TweenMax.to(this.mesh.position, totalSpeed / 2, { + y: 0, + ease: Power4.easeIn, + delay: totalSpeed / 2, + onComplete: function () { + //t = 0; + _this.status = "running"; + }, + }); +}; + +Monster = function () { + this.runningCycle = 0; + + this.mesh = new THREE.Group(); + this.body = new THREE.Group(); + + var torsoGeom = new THREE.CubeGeometry(15, 15, 20, 1); + this.torso = new THREE.Mesh(torsoGeom, blackMat); + + var headGeom = new THREE.CubeGeometry(20, 20, 40, 1); + headGeom.applyMatrix(new THREE.Matrix4().makeTranslation(0, 0, 20)); + this.head = new THREE.Mesh(headGeom, blackMat); + this.head.position.z = 12; + this.head.position.y = 2; + + var mouthGeom = new THREE.CubeGeometry(10, 4, 20, 1); + mouthGeom.applyMatrix(new THREE.Matrix4().makeTranslation(0, -2, 10)); + this.mouth = new THREE.Mesh(mouthGeom, blackMat); + this.mouth.position.y = -8; + this.mouth.rotation.x = 0.4; + this.mouth.position.z = 4; + + this.heroHolder = new THREE.Group(); + this.heroHolder.position.z = 20; + this.mouth.add(this.heroHolder); + + var toothGeom = new THREE.CubeGeometry(2, 2, 1, 1); + + toothGeom.vertices[1].x -= 1; + toothGeom.vertices[4].x += 1; + toothGeom.vertices[5].x += 1; + toothGeom.vertices[0].x -= 1; + + for (var i = 0; i < 3; i++) { + var toothf = new THREE.Mesh(toothGeom, whiteMat); + toothf.position.x = -2.8 + i * 2.5; + toothf.position.y = 1; + toothf.position.z = 19; + + var toothl = new THREE.Mesh(toothGeom, whiteMat); + toothl.rotation.y = Math.PI / 2; + toothl.position.z = 12 + i * 2.5; + toothl.position.y = 1; + toothl.position.x = 4; + + var toothr = toothl.clone(); + toothl.position.x = -4; + + this.mouth.add(toothf); + this.mouth.add(toothl); + this.mouth.add(toothr); + } + + var tongueGeometry = new THREE.CubeGeometry(6, 1, 14); + tongueGeometry.applyMatrix(new THREE.Matrix4().makeTranslation(0, 0, 7)); + + this.tongue = new THREE.Mesh(tongueGeometry, pinkMat); + this.tongue.position.z = 2; + this.tongue.rotation.x = -0.2; + this.mouth.add(this.tongue); + + var noseGeom = new THREE.CubeGeometry(4, 4, 4, 1); + this.nose = new THREE.Mesh(noseGeom, pinkMat); + this.nose.position.z = 39.5; + this.nose.position.y = 9; + this.head.add(this.nose); + + this.head.add(this.mouth); + + var eyeGeom = new THREE.CubeGeometry(2, 3, 3); + + this.eyeL = new THREE.Mesh(eyeGeom, whiteMat); + this.eyeL.position.x = 10; + this.eyeL.position.z = 5; + this.eyeL.position.y = 5; + this.eyeL.castShadow = true; + this.head.add(this.eyeL); + + var irisGeom = new THREE.CubeGeometry(0.6, 1, 1); + + this.iris = new THREE.Mesh(irisGeom, blackMat); + this.iris.position.x = 1.2; + this.iris.position.y = -1; + this.iris.position.z = 1; + this.eyeL.add(this.iris); + + this.eyeR = this.eyeL.clone(); + this.eyeR.children[0].position.x = -this.iris.position.x; + this.eyeR.position.x = -this.eyeL.position.x; + this.head.add(this.eyeR); + + var earGeom = new THREE.CubeGeometry(8, 6, 2, 1); + earGeom.vertices[1].x -= 4; + earGeom.vertices[4].x += 4; + earGeom.vertices[5].x += 4; + earGeom.vertices[5].z -= 2; + earGeom.vertices[0].x -= 4; + earGeom.vertices[0].z -= 2; + + earGeom.applyMatrix(new THREE.Matrix4().makeTranslation(0, 3, 0)); + + this.earL = new THREE.Mesh(earGeom, blackMat); + this.earL.position.x = 6; + this.earL.position.z = 1; + this.earL.position.y = 10; + this.earL.castShadow = true; + this.head.add(this.earL); + + this.earR = this.earL.clone(); + this.earR.position.x = -this.earL.position.x; + this.earR.rotation.z = -this.earL.rotation.z; + this.head.add(this.earR); + + var eyeGeom = new THREE.CubeGeometry(2, 4, 4); + + var tailGeom = new THREE.CylinderGeometry(5, 2, 20, 4, 1); + tailGeom.applyMatrix(new THREE.Matrix4().makeTranslation(0, 10, 0)); + tailGeom.applyMatrix(new THREE.Matrix4().makeRotationX(-Math.PI / 2)); + tailGeom.applyMatrix(new THREE.Matrix4().makeRotationZ(Math.PI / 4)); + + this.tail = new THREE.Mesh(tailGeom, blackMat); + this.tail.position.z = -10; + this.tail.position.y = 4; + this.torso.add(this.tail); + + var pawGeom = new THREE.CylinderGeometry(1.5, 0, 10); + pawGeom.applyMatrix(new THREE.Matrix4().makeTranslation(0, -5, 0)); + this.pawFL = new THREE.Mesh(pawGeom, blackMat); + this.pawFL.position.y = -7.5; + this.pawFL.position.z = 8.5; + this.pawFL.position.x = 5.5; + this.torso.add(this.pawFL); + + this.pawFR = this.pawFL.clone(); + this.pawFR.position.x = -this.pawFL.position.x; + this.torso.add(this.pawFR); + + this.pawBR = this.pawFR.clone(); + this.pawBR.position.z = -this.pawFL.position.z; + this.torso.add(this.pawBR); + + this.pawBL = this.pawBR.clone(); + this.pawBL.position.x = this.pawFL.position.x; + this.torso.add(this.pawBL); + + this.mesh.add(this.body); + this.torso.add(this.head); + this.body.add(this.torso); + + this.torso.castShadow = true; + this.head.castShadow = true; + this.pawFL.castShadow = true; + this.pawFR.castShadow = true; + this.pawBL.castShadow = true; + this.pawBR.castShadow = true; + + this.body.rotation.y = Math.PI / 2; +}; + +Monster.prototype.run = function () { + var s = Math.min(speed, maxSpeed); + this.runningCycle += delta * s * 0.7; + this.runningCycle = this.runningCycle % (Math.PI * 2); + var t = this.runningCycle; + + this.pawFR.rotation.x = (Math.sin(t) * Math.PI) / 4; + this.pawFR.position.y = -5.5 - Math.sin(t); + this.pawFR.position.z = 7.5 + Math.cos(t); + + this.pawFL.rotation.x = (Math.sin(t + 0.4) * Math.PI) / 4; + this.pawFL.position.y = -5.5 - Math.sin(t + 0.4); + this.pawFL.position.z = 7.5 + Math.cos(t + 0.4); + + this.pawBL.rotation.x = (Math.sin(t + 2) * Math.PI) / 4; + this.pawBL.position.y = -5.5 - Math.sin(t + 3.8); + this.pawBL.position.z = -7.5 + Math.cos(t + 3.8); + + this.pawBR.rotation.x = (Math.sin(t + 2.4) * Math.PI) / 4; + this.pawBR.position.y = -5.5 - Math.sin(t + 3.4); + this.pawBR.position.z = -7.5 + Math.cos(t + 3.4); + + this.torso.rotation.x = (Math.sin(t) * Math.PI) / 8; + this.torso.position.y = 3 - Math.sin(t + Math.PI / 2) * 3; + + //this.head.position.y = 5-Math.sin(t+Math.PI/2)*2; + this.head.rotation.x = -0.1 + Math.sin(-t - 1) * 0.4; + this.mouth.rotation.x = 0.2 + Math.sin(t + Math.PI + 0.3) * 0.4; + + this.tail.rotation.x = 0.2 + Math.sin(t - Math.PI / 2); + + this.eyeR.scale.y = 0.5 + Math.sin(t + Math.PI) * 0.5; +}; + +Hero.prototype.nod = function () { + var _this = this; + var sp = 0.5 + Math.random(); + + // HEAD + var tHeadRotY = -Math.PI / 6 + (Math.random() * Math.PI) / 3; + TweenMax.to(this.head.rotation, sp, { + y: tHeadRotY, + ease: Power4.easeInOut, + onComplete: function () { + _this.nod(); + }, + }); + + // EARS + var tEarLRotX = Math.PI / 4 + (Math.random() * Math.PI) / 6; + var tEarRRotX = Math.PI / 4 + (Math.random() * Math.PI) / 6; + + TweenMax.to(this.earL.rotation, sp, { x: tEarLRotX, ease: Power4.easeInOut }); + TweenMax.to(this.earR.rotation, sp, { x: tEarRRotX, ease: Power4.easeInOut }); + + // PAWS BACK LEFT + + var tPawBLRot = (Math.random() * Math.PI) / 2; + var tPawBLY = -4 + Math.random() * 8; + + TweenMax.to(this.pawBL.rotation, sp / 2, { + x: tPawBLRot, + ease: Power1.easeInOut, + yoyo: true, + repeat: 2, + }); + TweenMax.to(this.pawBL.position, sp / 2, { + y: tPawBLY, + ease: Power1.easeInOut, + yoyo: true, + repeat: 2, + }); + + // PAWS BACK RIGHT + + var tPawBRRot = (Math.random() * Math.PI) / 2; + var tPawBRY = -4 + Math.random() * 8; + TweenMax.to(this.pawBR.rotation, sp / 2, { + x: tPawBRRot, + ease: Power1.easeInOut, + yoyo: true, + repeat: 2, + }); + TweenMax.to(this.pawBR.position, sp / 2, { + y: tPawBRY, + ease: Power1.easeInOut, + yoyo: true, + repeat: 2, + }); + + // PAWS FRONT LEFT + + var tPawFLRot = (Math.random() * Math.PI) / 2; + var tPawFLY = -4 + Math.random() * 8; + + TweenMax.to(this.pawFL.rotation, sp / 2, { + x: tPawFLRot, + ease: Power1.easeInOut, + yoyo: true, + repeat: 2, + }); + + TweenMax.to(this.pawFL.position, sp / 2, { + y: tPawFLY, + ease: Power1.easeInOut, + yoyo: true, + repeat: 2, + }); + + // PAWS FRONT RIGHT + + var tPawFRRot = (Math.random() * Math.PI) / 2; + var tPawFRY = -4 + Math.random() * 8; + + TweenMax.to(this.pawFR.rotation, sp / 2, { + x: tPawFRRot, + ease: Power1.easeInOut, + yoyo: true, + repeat: 2, + }); + + TweenMax.to(this.pawFR.position, sp / 2, { + y: tPawFRY, + ease: Power1.easeInOut, + yoyo: true, + repeat: 2, + }); + + // MOUTH + var tMouthRot = (Math.random() * Math.PI) / 8; + TweenMax.to(this.mouth.rotation, sp, { + x: tMouthRot, + ease: Power1.easeInOut, + }); + // IRIS + var tIrisY = -1 + Math.random() * 2; + var tIrisZ = -1 + Math.random() * 2; + var iris1 = this.iris; + var iris2 = this.eyeR.children[0]; + TweenMax.to([iris1.position, iris2.position], sp, { + y: tIrisY, + z: tIrisZ, + ease: Power1.easeInOut, + }); + + //EYES + if (Math.random() > 0.2) + TweenMax.to([this.eyeR.scale, this.eyeL.scale], sp / 8, { + y: 0, + ease: Power1.easeInOut, + yoyo: true, + repeat: 1, + }); +}; + +Hero.prototype.hang = function () { + var _this = this; + var sp = 1; + var ease = Power4.easeOut; + + TweenMax.killTweensOf(this.eyeL.scale); + TweenMax.killTweensOf(this.eyeR.scale); + + this.body.rotation.x = 0; + this.torso.rotation.x = 0; + this.body.position.y = 0; + this.torso.position.y = 7; + + TweenMax.to(this.mesh.rotation, sp, { y: 0, ease: ease }); + TweenMax.to(this.mesh.position, sp, { y: -7, z: 6, ease: ease }); + TweenMax.to(this.head.rotation, sp, { + x: Math.PI / 6, + ease: ease, + onComplete: function () { + _this.nod(); + }, + }); + + TweenMax.to(this.earL.rotation, sp, { x: Math.PI / 3, ease: ease }); + TweenMax.to(this.earR.rotation, sp, { x: Math.PI / 3, ease: ease }); + + TweenMax.to(this.pawFL.position, sp, { y: -1, z: 3, ease: ease }); + TweenMax.to(this.pawFR.position, sp, { y: -1, z: 3, ease: ease }); + TweenMax.to(this.pawBL.position, sp, { y: -2, z: -3, ease: ease }); + TweenMax.to(this.pawBR.position, sp, { y: -2, z: -3, ease: ease }); + + TweenMax.to(this.eyeL.scale, sp, { y: 1, ease: ease }); + TweenMax.to(this.eyeR.scale, sp, { y: 1, ease: ease }); +}; + +Monster.prototype.nod = function () { + var _this = this; + var sp = 1 + Math.random() * 2; + + // HEAD + var tHeadRotY = -Math.PI / 3 + Math.random() * 0.5; + var tHeadRotX = Math.PI / 3 - 0.2 + Math.random() * 0.4; + TweenMax.to(this.head.rotation, sp, { + x: tHeadRotX, + y: tHeadRotY, + ease: Power4.easeInOut, + onComplete: function () { + _this.nod(); + }, + }); + + // TAIL + + var tTailRotY = -Math.PI / 4; + TweenMax.to(this.tail.rotation, sp / 8, { + y: tTailRotY, + ease: Power1.easeInOut, + yoyo: true, + repeat: 8, + }); + + // EYES + + TweenMax.to([this.eyeR.scale, this.eyeL.scale], sp / 20, { + y: 0, + ease: Power1.easeInOut, + yoyo: true, + repeat: 1, + }); +}; + +Monster.prototype.sit = function () { + var sp = 1.2; + var ease = Power4.easeOut; + var _this = this; + TweenMax.to(this.torso.rotation, sp, { x: -1.3, ease: ease }); + TweenMax.to(this.torso.position, sp, { + y: -5, + ease: ease, + onComplete: function () { + _this.nod(); + gameStatus = "readyToReplay"; + }, + }); + + TweenMax.to(this.head.rotation, sp, { + x: Math.PI / 3, + y: -Math.PI / 3, + ease: ease, + }); + TweenMax.to(this.tail.rotation, sp, { x: 2, y: Math.PI / 4, ease: ease }); + TweenMax.to(this.pawBL.rotation, sp, { x: -0.1, ease: ease }); + TweenMax.to(this.pawBR.rotation, sp, { x: -0.1, ease: ease }); + TweenMax.to(this.pawFL.rotation, sp, { x: 1, ease: ease }); + TweenMax.to(this.pawFR.rotation, sp, { x: 1, ease: ease }); + TweenMax.to(this.mouth.rotation, sp, { x: 0.3, ease: ease }); + TweenMax.to(this.eyeL.scale, sp, { y: 1, ease: ease }); + TweenMax.to(this.eyeR.scale, sp, { y: 1, ease: ease }); + + //TweenMax.to(this.body.rotation, sp, {y:Math.PI/4}); +}; + +Carrot = function () { + this.angle = 0; + this.mesh = new THREE.Group(); + + var bodyGeom = new THREE.CylinderGeometry(5, 3, 10, 4, 1); + bodyGeom.vertices[8].y += 2; + bodyGeom.vertices[9].y -= 3; + + this.body = new THREE.Mesh(bodyGeom, pinkMat); + + var leafGeom = new THREE.CubeGeometry(5, 10, 1, 1); + leafGeom.applyMatrix(new THREE.Matrix4().makeTranslation(0, 5, 0)); + leafGeom.vertices[2].x -= 1; + leafGeom.vertices[3].x -= 1; + leafGeom.vertices[6].x += 1; + leafGeom.vertices[7].x += 1; + + this.leaf1 = new THREE.Mesh(leafGeom, greenMat); + this.leaf1.position.y = 7; + this.leaf1.rotation.z = 0.3; + this.leaf1.rotation.x = 0.2; + + this.leaf2 = this.leaf1.clone(); + this.leaf2.scale.set(1, 1.3, 1); + this.leaf2.position.y = 7; + this.leaf2.rotation.z = -0.3; + this.leaf2.rotation.x = -0.2; + + this.mesh.add(this.body); + this.mesh.add(this.leaf1); + this.mesh.add(this.leaf2); + + this.body.traverse(function (object) { + if (object instanceof THREE.Mesh) { + object.castShadow = true; + object.receiveShadow = true; + } + }); +}; + +Hedgehog = function () { + this.angle = 0; + this.status = "ready"; + this.mesh = new THREE.Group(); + var bodyGeom = new THREE.CubeGeometry(6, 6, 6, 1); + this.body = new THREE.Mesh(bodyGeom, blackMat); + + var headGeom = new THREE.CubeGeometry(5, 5, 7, 1); + this.head = new THREE.Mesh(headGeom, lightBrownMat); + this.head.position.z = 6; + this.head.position.y = -0.5; + + var noseGeom = new THREE.CubeGeometry(1.5, 1.5, 1.5, 1); + this.nose = new THREE.Mesh(noseGeom, blackMat); + this.nose.position.z = 4; + this.nose.position.y = 2; + + var eyeGeom = new THREE.CubeGeometry(1, 3, 3); + + this.eyeL = new THREE.Mesh(eyeGeom, whiteMat); + this.eyeL.position.x = 2.2; + this.eyeL.position.z = -0.5; + this.eyeL.position.y = 0.8; + this.eyeL.castShadow = true; + this.head.add(this.eyeL); + + var irisGeom = new THREE.CubeGeometry(0.5, 1, 1); + + this.iris = new THREE.Mesh(irisGeom, blackMat); + this.iris.position.x = 0.5; + this.iris.position.y = 0.8; + this.iris.position.z = 0.8; + this.eyeL.add(this.iris); + + this.eyeR = this.eyeL.clone(); + this.eyeR.children[0].position.x = -this.iris.position.x; + this.eyeR.position.x = -this.eyeL.position.x; + + var spikeGeom = new THREE.CubeGeometry(0.5, 2, 0.5, 1); + spikeGeom.applyMatrix(new THREE.Matrix4().makeTranslation(0, 1, 0)); + + for (var i = 0; i < 9; i++) { + var row = i % 3; + var col = Math.floor(i / 3); + var sb = new THREE.Mesh(spikeGeom, blackMat); + sb.rotation.x = -Math.PI / 2 + (Math.PI / 12) * row - 0.5 + Math.random(); + sb.position.z = -3; + sb.position.y = -2 + row * 2; + sb.position.x = -2 + col * 2; + this.body.add(sb); + var st = new THREE.Mesh(spikeGeom, blackMat); + st.position.y = 3; + st.position.x = -2 + row * 2; + st.position.z = -2 + col * 2; + st.rotation.z = Math.PI / 6 - (Math.PI / 6) * row - 0.5 + Math.random(); + this.body.add(st); + + var sr = new THREE.Mesh(spikeGeom, blackMat); + sr.position.x = 3; + sr.position.y = -2 + row * 2; + sr.position.z = -2 + col * 2; + sr.rotation.z = -Math.PI / 2 + (Math.PI / 12) * row - 0.5 + Math.random(); + this.body.add(sr); + + var sl = new THREE.Mesh(spikeGeom, blackMat); + sl.position.x = -3; + sl.position.y = -2 + row * 2; + sl.position.z = -2 + col * 2; + sl.rotation.z = Math.PI / 2 - (Math.PI / 12) * row - 0.5 + Math.random(); + this.body.add(sl); + } + + this.head.add(this.eyeR); + var earGeom = new THREE.CubeGeometry(2, 2, 0.5, 1); + this.earL = new THREE.Mesh(earGeom, lightBrownMat); + this.earL.position.x = 2.5; + this.earL.position.z = -2.5; + this.earL.position.y = 2.5; + this.earL.rotation.z = -Math.PI / 12; + this.earL.castShadow = true; + this.head.add(this.earL); + + this.earR = this.earL.clone(); + this.earR.position.x = -this.earL.position.x; + this.earR.rotation.z = -this.earL.rotation.z; + this.earR.castShadow = true; + this.head.add(this.earR); + + var mouthGeom = new THREE.CubeGeometry(1, 1, 0.5, 1); + this.mouth = new THREE.Mesh(mouthGeom, blackMat); + this.mouth.position.z = 3.5; + this.mouth.position.y = -1.5; + this.head.add(this.mouth); + + this.mesh.add(this.body); + this.body.add(this.head); + this.head.add(this.nose); + + this.mesh.traverse(function (object) { + if (object instanceof THREE.Mesh) { + object.castShadow = true; + object.receiveShadow = true; + } + }); +}; + +Hedgehog.prototype.nod = function () { + var _this = this; + var speed = 0.1 + Math.random() * 0.5; + var angle = -Math.PI / 4 + (Math.random() * Math.PI) / 2; + TweenMax.to(this.head.rotation, speed, { + y: angle, + onComplete: function () { + _this.nod(); + }, + }); +}; + +function createHero() { + hero = new Hero(); + hero.mesh.rotation.y = Math.PI / 2; + scene.add(hero.mesh); + hero.nod(); +} + +function createMonster() { + monster = new Monster(); + monster.mesh.position.z = 20; + //monster.mesh.scale.set(1.2,1.2,1.2); + scene.add(monster.mesh); + updateMonsterPosition(); +} + +function updateMonsterPosition() { + monster.run(); + monsterPosTarget -= delta * monsterAcceleration; + monsterPos += (monsterPosTarget - monsterPos) * delta; + if (monsterPos < 0.56) { + gameOver(); + } + + var angle = Math.PI * monsterPos; + monster.mesh.position.y = -floorRadius + Math.sin(angle) * (floorRadius + 12); + monster.mesh.position.x = Math.cos(angle) * (floorRadius + 15); + monster.mesh.rotation.z = -Math.PI / 2 + angle; +} + +function gameOver() { + fieldGameOver.className = "show"; + gameStatus = "gameOver"; + monster.sit(); + hero.hang(); + monster.heroHolder.add(hero.mesh); + TweenMax.to(this, 1, { speed: 0 }); + TweenMax.to(camera.position, 3, { z: cameraPosGameOver, y: 60, x: -30 }); + carrot.mesh.visible = false; + obstacle.mesh.visible = false; + clearInterval(levelInterval); +} + +function replay() { + gameStatus = "preparingToReplay"; + + fieldGameOver.className = ""; + + TweenMax.killTweensOf(monster.pawFL.position); + TweenMax.killTweensOf(monster.pawFR.position); + TweenMax.killTweensOf(monster.pawBL.position); + TweenMax.killTweensOf(monster.pawBR.position); + + TweenMax.killTweensOf(monster.pawFL.rotation); + TweenMax.killTweensOf(monster.pawFR.rotation); + TweenMax.killTweensOf(monster.pawBL.rotation); + TweenMax.killTweensOf(monster.pawBR.rotation); + + TweenMax.killTweensOf(monster.tail.rotation); + TweenMax.killTweensOf(monster.head.rotation); + TweenMax.killTweensOf(monster.eyeL.scale); + TweenMax.killTweensOf(monster.eyeR.scale); + + //TweenMax.killTweensOf(hero.head.rotation); + + monster.tail.rotation.y = 0; + + TweenMax.to(camera.position, 3, { + z: cameraPosGame, + x: 0, + y: 30, + ease: Power4.easeInOut, + }); + TweenMax.to(monster.torso.rotation, 2, { x: 0, ease: Power4.easeInOut }); + TweenMax.to(monster.torso.position, 2, { y: 0, ease: Power4.easeInOut }); + TweenMax.to(monster.pawFL.rotation, 2, { x: 0, ease: Power4.easeInOut }); + TweenMax.to(monster.pawFR.rotation, 2, { x: 0, ease: Power4.easeInOut }); + TweenMax.to(monster.mouth.rotation, 2, { x: 0.5, ease: Power4.easeInOut }); + + TweenMax.to(monster.head.rotation, 2, { + y: 0, + x: -0.3, + ease: Power4.easeInOut, + }); + + TweenMax.to(hero.mesh.position, 2, { x: 20, ease: Power4.easeInOut }); + TweenMax.to(hero.head.rotation, 2, { x: 0, y: 0, ease: Power4.easeInOut }); + TweenMax.to(monster.mouth.rotation, 2, { x: 0.2, ease: Power4.easeInOut }); + TweenMax.to(monster.mouth.rotation, 1, { + x: 0.4, + ease: Power4.easeIn, + delay: 1, + onComplete: function () { + resetGame(); + }, + }); +} + +Fir = function () { + var height = 200; + var truncGeom = new THREE.CylinderGeometry(2, 2, height, 6, 1); + truncGeom.applyMatrix(new THREE.Matrix4().makeTranslation(0, height / 2, 0)); + this.mesh = new THREE.Mesh(truncGeom, greenMat); + this.mesh.castShadow = true; +}; + +var firs = new THREE.Group(); + +function createFirs() { + var nTrees = 100; + for (var i = 0; i < nTrees; i++) { + var phi = (i * (Math.PI * 2)) / nTrees; + var theta = Math.PI / 2; + //theta += .25 + Math.random()*.3; + theta += + Math.random() > 0.05 + ? 0.25 + Math.random() * 0.3 + : -0.35 - Math.random() * 0.1; + + var fir = new Tree(); + fir.mesh.position.x = Math.sin(theta) * Math.cos(phi) * floorRadius; + fir.mesh.position.y = Math.sin(theta) * Math.sin(phi) * (floorRadius - 10); + fir.mesh.position.z = Math.cos(theta) * floorRadius; + + var vec = fir.mesh.position.clone(); + var axis = new THREE.Vector3(0, 1, 0); + fir.mesh.quaternion.setFromUnitVectors(axis, vec.clone().normalize()); + floor.add(fir.mesh); + } +} + +function createCarrot() { + carrot = new Carrot(); + scene.add(carrot.mesh); +} + +function updateCarrotPosition() { + carrot.mesh.rotation.y += delta * 6; + carrot.mesh.rotation.z = Math.PI / 2 - (floorRotation + carrot.angle); + carrot.mesh.position.y = + -floorRadius + Math.sin(floorRotation + carrot.angle) * (floorRadius + 50); + carrot.mesh.position.x = + Math.cos(floorRotation + carrot.angle) * (floorRadius + 50); +} + +function updateObstaclePosition() { + if (obstacle.status == "flying") return; + + // TODO fix this, + if (floorRotation + obstacle.angle > 2.5) { + obstacle.angle = -floorRotation + Math.random() * 0.3; + obstacle.body.rotation.y = Math.random() * Math.PI * 2; + } + + obstacle.mesh.rotation.z = floorRotation + obstacle.angle - Math.PI / 2; + obstacle.mesh.position.y = + -floorRadius + Math.sin(floorRotation + obstacle.angle) * (floorRadius + 3); + obstacle.mesh.position.x = + Math.cos(floorRotation + obstacle.angle) * (floorRadius + 3); +} + +function updateFloorRotation() { + floorRotation += delta * 0.03 * speed; + floorRotation = floorRotation % (Math.PI * 2); + floor.rotation.z = floorRotation; +} + +function createObstacle() { + obstacle = new Hedgehog(); + obstacle.body.rotation.y = -Math.PI / 2; + obstacle.mesh.scale.set(1.1, 1.1, 1.1); + obstacle.mesh.position.y = floorRadius + 4; + obstacle.nod(); + scene.add(obstacle.mesh); +} + +function createBonusParticles() { + bonusParticles = new BonusParticles(); + bonusParticles.mesh.visible = false; + scene.add(bonusParticles.mesh); +} + +function checkCollision() { + var db = hero.mesh.position.clone().sub(carrot.mesh.position.clone()); + var dm = hero.mesh.position.clone().sub(obstacle.mesh.position.clone()); + + if (db.length() < collisionBonus) { + getBonus(); + } + + if (dm.length() < collisionObstacle && obstacle.status != "flying") { + getMalus(); + } +} + +function getBonus() { + bonusParticles.mesh.position.copy(carrot.mesh.position); + bonusParticles.mesh.visible = true; + bonusParticles.explose(); + carrot.angle += Math.PI / 2; + //speed*=.95; + monsterPosTarget += 0.025; +} + +function getMalus() { + obstacle.status = "flying"; + var tx = + Math.random() > 0.5 ? -20 - Math.random() * 10 : 20 + Math.random() * 5; + TweenMax.to(obstacle.mesh.position, 4, { + x: tx, + y: Math.random() * 50, + z: 350, + ease: Power4.easeOut, + }); + TweenMax.to(obstacle.mesh.rotation, 4, { + x: Math.PI * 3, + z: Math.PI * 3, + y: Math.PI * 6, + ease: Power4.easeOut, + onComplete: function () { + obstacle.status = "ready"; + obstacle.body.rotation.y = Math.random() * Math.PI * 2; + obstacle.angle = -floorRotation - Math.random() * 0.4; + + obstacle.angle = obstacle.angle % (Math.PI * 2); + obstacle.mesh.rotation.x = 0; + obstacle.mesh.rotation.y = 0; + obstacle.mesh.rotation.z = 0; + obstacle.mesh.position.z = 0; + }, + }); + // + monsterPosTarget -= 0.04; + TweenMax.from(this, 0.5, { + malusClearAlpha: 0.5, + onUpdate: function () { + renderer.setClearColor(malusClearColor, malusClearAlpha); + }, + }); +} + +function updateDistance() { + distance += delta * speed; + var d = distance / 2; + fieldDistance.innerHTML = Math.floor(d); +} + +function updateLevel() { + if (speed >= maxSpeed) return; + level++; + speed += 2; +} + +function loop() { + delta = clock.getDelta(); + updateFloorRotation(); + + if (gameStatus == "play") { + if (hero.status == "running") { + hero.run(); + } + updateDistance(); + updateMonsterPosition(); + updateCarrotPosition(); + updateObstaclePosition(); + checkCollision(); + } + + render(); + requestAnimationFrame(loop); +} + +function render() { + renderer.render(scene, camera); +} + +window.addEventListener("load", init, false); + +function init(event) { + initScreenAnd3D(); + createLights(); + createFloor(); + createHero(); + createMonster(); + createFirs(); + createCarrot(); + createBonusParticles(); + createObstacle(); + initUI(); + resetGame(); + loop(); + + //setInterval(hero.blink.bind(hero), 3000); +} + +function resetGame() { + scene.add(hero.mesh); + hero.mesh.rotation.y = Math.PI / 2; + hero.mesh.position.y = 0; + hero.mesh.position.z = 0; + hero.mesh.position.x = 0; + + monsterPos = 0.56; + monsterPosTarget = 0.65; + speed = initSpeed; + level = 0; + distance = 0; + carrot.mesh.visible = true; + obstacle.mesh.visible = true; + gameStatus = "play"; + hero.status = "running"; + hero.nod(); + audio.play(); + updateLevel(); + levelInterval = setInterval(updateLevel, levelUpdateFreq); +} + +function initUI() { + fieldDistance = document.getElementById("distValue"); + fieldGameOver = document.getElementById("gameoverInstructions"); +} + +//////////////////////////////////////////////// +// MODELS +//////////////////////////////////////////////// + +// TREE + +Tree = function () { + this.mesh = new THREE.Object3D(); + this.trunc = new Trunc(); + this.mesh.add(this.trunc.mesh); +}; + +Trunc = function () { + var truncHeight = 50 + Math.random() * 150; + var topRadius = 1 + Math.random() * 5; + var bottomRadius = 5 + Math.random() * 5; + var mats = [ + blackMat, + brownMat, + pinkMat, + whiteMat, + greenMat, + lightBrownMat, + pinkMat, + ]; + var matTrunc = blackMat; //mats[Math.floor(Math.random()*mats.length)]; + var nhSegments = 3; //Math.ceil(2 + Math.random()*6); + var nvSegments = 3; //Math.ceil(2 + Math.random()*6); + var geom = new THREE.CylinderGeometry( + topRadius, + bottomRadius, + truncHeight, + nhSegments, + nvSegments, + ); + geom.applyMatrix(new THREE.Matrix4().makeTranslation(0, truncHeight / 2, 0)); + + this.mesh = new THREE.Mesh(geom, matTrunc); + + for (var i = 0; i < geom.vertices.length; i++) { + var noise = Math.random(); + var v = geom.vertices[i]; + v.x += -noise + Math.random() * noise * 2; + v.y += -noise + Math.random() * noise * 2; + v.z += -noise + Math.random() * noise * 2; + + geom.computeVertexNormals(); + + // FRUITS + + if (Math.random() > 0.7) { + var size = Math.random() * 3; + var fruitGeometry = new THREE.CubeGeometry(size, size, size, 1); + var matFruit = mats[Math.floor(Math.random() * mats.length)]; + var fruit = new THREE.Mesh(fruitGeometry, matFruit); + fruit.position.x = v.x; + fruit.position.y = v.y + 3; + fruit.position.z = v.z; + fruit.rotation.x = Math.random() * Math.PI; + fruit.rotation.y = Math.random() * Math.PI; + + this.mesh.add(fruit); + } + + // BRANCHES + + if (Math.random() > 0.5 && v.y > 10 && v.y < truncHeight - 10) { + var h = 3 + Math.random() * 5; + var thickness = 0.2 + Math.random(); + + var branchGeometry = new THREE.CylinderGeometry( + thickness / 2, + thickness, + h, + 3, + 1, + ); + branchGeometry.applyMatrix( + new THREE.Matrix4().makeTranslation(0, h / 2, 0), + ); + var branch = new THREE.Mesh(branchGeometry, matTrunc); + branch.position.x = v.x; + branch.position.y = v.y; + branch.position.z = v.z; + + var vec = new THREE.Vector3(v.x, 2, v.z); + var axis = new THREE.Vector3(0, 1, 0); + branch.quaternion.setFromUnitVectors(axis, vec.clone().normalize()); + + this.mesh.add(branch); + } + } + + this.mesh.castShadow = true; +}; diff --git a/Games/Grab_The_Carrot/styles.css b/Games/Grab_The_Carrot/styles.css new file mode 100644 index 0000000000..56829774ea --- /dev/null +++ b/Games/Grab_The_Carrot/styles.css @@ -0,0 +1,100 @@ +@import url("https://fonts.googleapis.com/css?family=Voltaire"); + +#world { + position: absolute; + width: 100%; + height: 100%; + background-color: #dbe6e6; + overflow: hidden; +} + +#gameoverInstructions { + position: absolute; + font-family: "Voltaire", sans-serif; + font-weight: bold; + text-transform: uppercase; + font-size: 120px; + text-align: center; + color: #ffc5a2; + opacity: 0; + left: 50%; + top: 50%; + width: 100%; + transform: translate(-50%, -100%); + user-select: none; + transition: all 500ms ease-in-out; + + &.show { + opacity: 1; + transform: translate(-50%, -50%); + transition: all 500ms ease-in-out; + } +} + +#dist { + position: absolute; + left: 50%; + top: 50px; + transform: translate(-50%, 0%); + user-select: none; +} + +.label { + position: relative; + font-family: "Voltaire", sans-serif; + text-transform: uppercase; + color: #ffa873; + font-size: 12px; + letter-spacing: 2px; + text-align: center; + margin-bottom: 5px; +} + +#distValue { + position: relative; + text-transform: uppercase; + color: #dc5f45; + font-size: 40px; + font-family: "Voltaire"; + text-align: center; +} + +#credits { + position: absolute; + width: 100%; + margin: auto; + bottom: 0; + margin-bottom: 20px; + font-family: "Voltaire", sans-serif; + color: #544027; + font-size: 12px; + letter-spacing: 0.5px; + text-transform: uppercase; + text-align: center; + user-select: none; +} +#credits a { + color: #544027; +} + +#credits a:hover { + color: #dc5f45; +} + +#instructions { + position: absolute; + width: 100%; + bottom: 0; + margin: auto; + margin-bottom: 50px; + font-family: "Voltaire", sans-serif; + color: #dc5f45; + font-size: 16px; + letter-spacing: 1px; + text-transform: uppercase; + text-align: center; + user-select: none; +} +.lightInstructions { + color: #5f9042; +} diff --git a/Games/Intellect_Quest/README.md b/Games/Intellect_Quest/README.md new file mode 100644 index 0000000000..14d5b93b8a --- /dev/null +++ b/Games/Intellect_Quest/README.md @@ -0,0 +1,27 @@ +### 🎮 Game Request + +

Game logic and basic description:

+ +
  • This game is created with the help of html, css and javascript.
  • +
  • You can play whenever and wherever you want
  • +
  • You will get to know the correct answer of every question once you answer it
  • + + +### Point down the features + +

    Game points

    + +
      +
    1. Answer the questions
    2. +
    3. Show correct answer with green, and wrong answers with red
    4. +
    5. Option to go to next question
    6. +
    + + +### Select The Game Type + +Single Player + +### Pictures + +![Game screen](https://github.com/kunjgit/GameZone/assets/138088550/79592ab5-f2dd-412f-8f74-286dbb147108) \ No newline at end of file diff --git a/Games/Intellect_Quest/index.html b/Games/Intellect_Quest/index.html new file mode 100644 index 0000000000..64c13f82c9 --- /dev/null +++ b/Games/Intellect_Quest/index.html @@ -0,0 +1,29 @@ + + + + + + + Intellect Quest + + + + +
    +

    Intellect Quest

    +
    +
    +
    +
    + +
    +

    Your Score:

    + +
    +
    Loading...
    +
    + + + + + \ No newline at end of file diff --git a/Games/Intellect_Quest/script.js b/Games/Intellect_Quest/script.js new file mode 100644 index 0000000000..f2a7f0ae84 --- /dev/null +++ b/Games/Intellect_Quest/script.js @@ -0,0 +1,112 @@ +const questionContainer = document.getElementById('question-container'); +const questionElement = document.getElementById('question'); +const answerButtonsElement = document.getElementById('answer-buttons'); +const nextButton = document.getElementById('next-button'); +const resultContainer = document.getElementById('result-container'); +const scoreElement = document.getElementById('score'); +const restartButton = document.getElementById('restart-button'); +const loader = document.getElementById('loader'); + +let questions = []; +let currentQuestionIndex, score; + +async function fetchQuestions() { + loader.classList.remove('hide'); + try { + const response = await fetch('https://opentdb.com/api.php?amount=10&type=multiple'); + const data = await response.json(); + questions = data.results.map((question) => { + const formattedQuestion = { + question: question.question, + answers: [...question.incorrect_answers.map(answer => ({ text: answer, correct: false }))] + }; + formattedQuestion.answers.push({ text: question.correct_answer, correct: true }); + return formattedQuestion; + }); + startQuiz(); + } catch (error) { + console.error('Error fetching questions:', error); + } finally { + loader.classList.add('hide'); + } +} + +function startQuiz() { + currentQuestionIndex = 0; + score = 0; + resultContainer.classList.add('hide'); + nextButton.classList.remove('hide'); + questionContainer.classList.remove('hide'); + setNextQuestion(); +} + +function setNextQuestion() { + resetState(); + showQuestion(questions[currentQuestionIndex]); +} + +function showQuestion(question) { + questionElement.innerHTML = question.question; + question.answers.forEach(answer => { + const button = document.createElement('button'); + button.innerText = answer.text; + button.classList.add('btn'); + if (answer.correct) { + button.dataset.correct = answer.correct; + } + button.addEventListener('click', selectAnswer); + answerButtonsElement.appendChild(button); + }); +} + +function resetState() { + nextButton.classList.add('hide'); + while (answerButtonsElement.firstChild) { + answerButtonsElement.removeChild(answerButtonsElement.firstChild); + } +} + +function selectAnswer(e) { + const selectedButton = e.target; + const correct = selectedButton.dataset.correct === 'true'; + if (correct) { + score++; + } + Array.from(answerButtonsElement.children).forEach(button => { + setStatusClass(button, button.dataset.correct === 'true'); + }); + nextButton.classList.remove('hide'); +} + +function setStatusClass(element, correct) { + clearStatusClass(element); + if (correct) { + element.classList.add('correct'); + } else { + element.classList.add('wrong'); + } +} + +function clearStatusClass(element) { + element.classList.remove('correct'); + element.classList.remove('wrong'); +} + +function showResult() { + questionContainer.classList.add('hide'); + resultContainer.classList.remove('hide'); + scoreElement.innerText = score; +} + +nextButton.addEventListener('click', () => { + if (questions.length > currentQuestionIndex + 1) { + currentQuestionIndex++; + setNextQuestion(); + } else { + showResult(); + } +}); + +restartButton.addEventListener('click', fetchQuestions); + +fetchQuestions(); \ No newline at end of file diff --git a/Games/Intellect_Quest/style.css b/Games/Intellect_Quest/style.css new file mode 100644 index 0000000000..b26c1cbc86 --- /dev/null +++ b/Games/Intellect_Quest/style.css @@ -0,0 +1,57 @@ +body { + font-family: Arial, sans-serif; + background: #f4f4f4; + display: flex; + justify-content: center; + align-items: center; + height: 100vh; + margin: 0; +} + +#quiz-container { + background: #fff; + border-radius: 5px; + box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); + width: 300px; + padding: 20px; + text-align: center; +} + +.btn { + background-color: #007BFF; + color: white; + border: none; + padding: 10px; + border-radius: 5px; + cursor: pointer; + margin-top: 10px; +} + +.btn:hover { + background-color: #0056b3; +} + +.btn-container { + display: flex; + flex-direction: column; +} + +.btn-container .btn { + margin: 5px 0; +} + +.hide { + display: none; +} + +.correct { + background-color: #28a745 !important; +} + +.wrong { + background-color: #dc3545 !important; +} + +#loader { + font-size: 18px; +} \ No newline at end of file diff --git a/Games/Morse_Code_Generator/README.md b/Games/Morse_Code_Generator/README.md new file mode 100644 index 0000000000..7774aff9af --- /dev/null +++ b/Games/Morse_Code_Generator/README.md @@ -0,0 +1,33 @@ +# Game_Name + +## Description 📃 + +[Game_Name] is a simple yet engaging Morse Code generator. It allows users to convert regular text input into Morse Code, a method of encoding text characters using sequences of dots and dashes. + +## Functionalities 🎮 + +- Translate regular text input into Morse Code representations. +- Display the translated Morse Code output alongside the input text. +- Handle whitespace characters (spaces) between words in the input text. +- Provide real-time conversion, updating the Morse Code output as the user types or modifies the input text. +- Ensure case insensitivity, allowing both uppercase and lowercase characters in the input text. +- Handle errors gracefully, such as invalid characters that cannot be translated into Morse Code. + +## How to play? 🕹ī¸ + +1. Input the desired text into the provided text field. +2. The Morse Code equivalent of the input text will be displayed in real-time. +3. Copy the Morse Code output if needed for further use or communication. + +## Screenshots 📸 +![image](https://github.com/Saipradyumnagoud/GameZone/assets/143107589/d1418c4e-6db9-4cb8-86e0-e8ab971de658) + + + +## Working video 📹 + + + +https://github.com/Saipradyumnagoud/GameZone/assets/143107589/799ff7d0-18ac-4068-9026-8b0980b706b7 + + diff --git a/Games/Morse_Code_Generator/index.html b/Games/Morse_Code_Generator/index.html new file mode 100644 index 0000000000..2ca67a6063 --- /dev/null +++ b/Games/Morse_Code_Generator/index.html @@ -0,0 +1,21 @@ + + + + + + + Morse Code Generator + + + +
    +

    Morse Code Generator

    + +
    + + + +
    + + + diff --git a/Games/Morse_Code_Generator/script.js b/Games/Morse_Code_Generator/script.js new file mode 100644 index 0000000000..a193264d59 --- /dev/null +++ b/Games/Morse_Code_Generator/script.js @@ -0,0 +1,26 @@ +document.getElementById('convert-btn').addEventListener('click', function() { + const inputText = document.getElementById('input-text').value.trim().toLowerCase(); + const morseCode = convertToMorse(inputText); + document.getElementById('output-morse').value = morseCode; +}); + +function convertToMorse(text) { + const morseCodeMap = { + 'a': '.-', 'b': '-...', 'c': '-.-.', 'd': '-..', 'e': '.', 'f': '..-.', 'g': '--.', 'h': '....', + 'i': '..', 'j': '.---', 'k': '-.-', 'l': '.-..', 'm': '--', 'n': '-.', 'o': '---', 'p': '.--.', + 'q': '--.-', 'r': '.-.', 's': '...', 't': '-', 'u': '..-', 'v': '...-', 'w': '.--', 'x': '-..-', + 'y': '-.--', 'z': '--..', + '0': '-----', '1': '.----', '2': '..---', '3': '...--', '4': '....-', '5': '.....', '6': '-....', + '7': '--...', '8': '---..', '9': '----.' + }; + + return text.split('').map(char => { + if (char === ' ') { + return '/'; + } else if (morseCodeMap[char]) { + return morseCodeMap[char]; + } else { + return ''; + } + }).join(' '); +} diff --git a/Games/Morse_Code_Generator/style.css b/Games/Morse_Code_Generator/style.css new file mode 100644 index 0000000000..b0073d83f1 --- /dev/null +++ b/Games/Morse_Code_Generator/style.css @@ -0,0 +1,31 @@ +body { + font-family: Arial, sans-serif; + } + + .container { + max-width: 600px; + margin: 0 auto; + text-align: center; + padding: 20px; + } + + textarea { + width: 100%; + margin-bottom: 10px; + padding: 10px; + resize: none; + } + + button { + padding: 10px 20px; + background-color: #007bff; + color: #fff; + border: none; + cursor: pointer; + transition: background-color 0.3s; + } + + button:hover { + background-color: #0056b3; + } + \ No newline at end of file diff --git a/Games/Number_Guessing_Game/README.md b/Games/Number_Guessing_Game/README.md new file mode 100644 index 0000000000..486067be86 --- /dev/null +++ b/Games/Number_Guessing_Game/README.md @@ -0,0 +1,32 @@ +

    NUMBERGUESSINGGAME

    + + +

    Description

    +Game Overview: +The Number Guessing Game is a fun and engaging activity where players attempt to guess a secret number within a specified range. This game tests players' ability to use logic and intuition to narrow down their guesses and find the correct number in the fewest attempts possible. It's suitable for all ages and can be played solo or with friends. + +Objective: +The objective of the game is to guess the secret number chosen by the computer (or another player) in as few guesses as possible. + +How to Play: +Start the Game: The game begins with the computer selecting a random number within a predefined range, for example, 1 to 100. +Make a Guess: The player makes their first guess by entering a number within the range. +Receive Feedback: The computer provides feedback on whether the guessed number is too high, too low, or correct. +Adjust Guess: Based on the feedback, the player adjusts their next guess accordingly. +Repeat: Steps 2 to 4 are repeated until the player correctly guesses the secret number. +Win: Once the player guesses the correct number, the game congratulates the player and displays the number of attempts taken. +Features: +Difficulty Levels: Players can choose different difficulty levels, which change the range of numbers (e.g., 1-50 for easy, 1-100 for medium, and 1-1000 for hard). +Hint System: Optional hints can be provided to help players, such as indicating if they are within 10 numbers of the correct answer. +Score Tracking: The game can track the number of attempts and time taken to guess the correct number, allowing players to challenge themselves to improve. +Multiplayer Mode: Players can take turns guessing the number, and the one who guesses correctly in the fewest attempts wins. +Benefits: +Educational: Helps improve number sense and logical thinking. +Entertaining: Provides a fun challenge and a sense of achievement when the correct number is guessed. +Versatile: Suitable for players of all ages and can be played in various settings, from casual gatherings to classroom activities. +Conclusion: +The Number Guessing Game is a simple yet captivating game that can provide hours of entertainment and mental stimulation. Whether played alone or with friends, it offers a perfect blend of fun and learning, making it a great choice for anyone looking to pass the time with a challenge. + + + + diff --git a/Games/Number_Guessing_Game/favicon/android-chrome-192x192.png b/Games/Number_Guessing_Game/favicon/android-chrome-192x192.png new file mode 100644 index 0000000000..0de9ddd06a Binary files /dev/null and b/Games/Number_Guessing_Game/favicon/android-chrome-192x192.png differ diff --git a/Games/Number_Guessing_Game/favicon/android-chrome-512x512.png b/Games/Number_Guessing_Game/favicon/android-chrome-512x512.png new file mode 100644 index 0000000000..74ca078605 Binary files /dev/null and b/Games/Number_Guessing_Game/favicon/android-chrome-512x512.png differ diff --git a/Games/Number_Guessing_Game/favicon/apple-touch-icon.png b/Games/Number_Guessing_Game/favicon/apple-touch-icon.png new file mode 100644 index 0000000000..470ea4d1cb Binary files /dev/null and b/Games/Number_Guessing_Game/favicon/apple-touch-icon.png differ diff --git a/Games/Number_Guessing_Game/favicon/favicon-16x16.png b/Games/Number_Guessing_Game/favicon/favicon-16x16.png new file mode 100644 index 0000000000..b4e4c4deee Binary files /dev/null and b/Games/Number_Guessing_Game/favicon/favicon-16x16.png differ diff --git a/Games/Number_Guessing_Game/favicon/favicon-32x32.png b/Games/Number_Guessing_Game/favicon/favicon-32x32.png new file mode 100644 index 0000000000..de11ac4442 Binary files /dev/null and b/Games/Number_Guessing_Game/favicon/favicon-32x32.png differ diff --git a/Games/Number_Guessing_Game/favicon/favicon.ico b/Games/Number_Guessing_Game/favicon/favicon.ico new file mode 100644 index 0000000000..fb125fe304 Binary files /dev/null and b/Games/Number_Guessing_Game/favicon/favicon.ico differ diff --git a/Games/Number_Guessing_Game/favicon/site.webmanifest b/Games/Number_Guessing_Game/favicon/site.webmanifest new file mode 100644 index 0000000000..b2853f64f8 --- /dev/null +++ b/Games/Number_Guessing_Game/favicon/site.webmanifest @@ -0,0 +1,19 @@ +{ + "name": "Number Guessing Game", + "short_name": "Number Guessing Game", + "icons": [ + { + "src": "/android-chrome-192x192.png", + "sizes": "192x192", + "type": "image/png" + }, + { + "src": "/android-chrome-512x512.png", + "sizes": "512x512", + "type": "image/png" + } + ], + "theme_color": "#ffffff", + "background_color": "#000300", + "display": "standalone" +} diff --git a/Games/Number_Guessing_Game/index.html b/Games/Number_Guessing_Game/index.html new file mode 100644 index 0000000000..400e0c4374 --- /dev/null +++ b/Games/Number_Guessing_Game/index.html @@ -0,0 +1,98 @@ + + + + + + + + + + + + + + + Number Guessing Game + + + + + + + +
    +
    +
    +

    Guess The Number

    +

    + We have randomly selected numbers between 1 - 33. Can you guess it? +

    +
    + + +
    + + + + + +
    + +

    + + + +
    +
    + + + \ No newline at end of file diff --git a/Games/Quick_Click/README.md b/Games/Quick_Click/README.md new file mode 100644 index 0000000000..a8e368f522 --- /dev/null +++ b/Games/Quick_Click/README.md @@ -0,0 +1,39 @@ +Quick Click Game using HTML, CSS, and JavaScript. The game features a grid of square , with one square becoming active randomly to show a Different Colour. The player must click the active square to score points. The game will end if the player clicks a non-active Square or when the timer reaches zero. + +Features + + Play memory game with short musical notes. + Difficulty levels to adjust the number of musical pairs. + Track your score and high score. + Clean and responsive design for any device. +How to Play + + Clicking the start button initializes the game with a score of 0 and a timer set to 60 seconds. + A Yellow Square appears randomly in one of the squares every second. + + Scoring: + + Clicking the active square (with the Yellow Square) increments the score by 1. + The Yellow Square disappears and reappears in another random square. + + Game End Conditions: + + Clicking a non-active square ends the game with a "You Lose!" message. + The timer reaching zero ends the game with a "Time's Up! Game Over!" message displaying the final score. + + Resetting: + + At the end of the game, the active Yellow Square disappears, event listeners are removed, and the start button is re-enabled. + +Technologies Used + + HTML: Creates the structure of the game board and interface. + CSS: Styles the game elements for a visually appealing experience. + JavaScript: Manages the game logic, including card flipping, matching sounds, and scorekeeping. +Running the Game + + Ensure you have a web browser installed on your computer (e.g., Chrome, Firefox, Safari). + Clone or download the project files. + Open the index.html file in your web browser. + The game should launch and be ready to play! + diff --git a/Games/Quick_Click/assets/Images/image.png b/Games/Quick_Click/assets/Images/image.png new file mode 100644 index 0000000000..41d0f7dc35 Binary files /dev/null and b/Games/Quick_Click/assets/Images/image.png differ diff --git a/Games/Quick_Click/index.html b/Games/Quick_Click/index.html new file mode 100644 index 0000000000..9c345b7c68 --- /dev/null +++ b/Games/Quick_Click/index.html @@ -0,0 +1,33 @@ + + + + + + + Quick Click + + + + +

    Quick Click

    +
    + Score: 0 + Time: 60s +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + + + + + + \ No newline at end of file diff --git a/Games/Quick_Click/script.js b/Games/Quick_Click/script.js new file mode 100644 index 0000000000..03e9b10968 --- /dev/null +++ b/Games/Quick_Click/script.js @@ -0,0 +1,61 @@ +const circles = document.querySelectorAll('.circle'); +const scoreDisplay = document.getElementById('score'); +const timeDisplay = document.getElementById('time'); +const startButton = document.getElementById('start'); +let score = 0; +let activeCircle = null; +let gameTimer = null; +let countdownTimer = null; +let timeLeft = 60; + +function randomCircle() { + circles.forEach(circle => circle.classList.remove('active')); + const randomIndex = Math.floor(Math.random() * circles.length); + activeCircle = circles[randomIndex]; + activeCircle.classList.add('active'); + console.log("Random Circle Selected:", activeCircle); +} + +function startGame() { + score = 0; + timeLeft = 60; + scoreDisplay.textContent = score; + timeDisplay.textContent = timeLeft; + startButton.disabled = true; + randomCircle(); + gameTimer = setInterval(randomCircle, 1000); + countdownTimer = setInterval(countDown, 1000); + circles.forEach(circle => circle.addEventListener('click', whack)); + console.log("Game Started"); +} + +function whack(event) { + if (event.target === activeCircle) { + score++; + scoreDisplay.textContent = score; + activeCircle.classList.remove('active'); + randomCircle(); + } else { + endGame('You Lose!'); + } +} + +function countDown() { + timeLeft--; + timeDisplay.textContent = timeLeft; + if (timeLeft <= 0) { + endGame('Time\'s Up! Game Over!'); + } +} + +function endGame(message) { + console.log("Game Ended:", message); + clearInterval(gameTimer); + clearInterval(countdownTimer); + circles.forEach(circle => circle.classList.remove('active')); + circles.forEach(circle => circle.removeEventListener('click', whack)); + startButton.disabled = false; + alert(`${message} Your final score is ${score}`); +} + +startButton.addEventListener('click', startGame); \ No newline at end of file diff --git a/Games/Quick_Click/style.css b/Games/Quick_Click/style.css new file mode 100644 index 0000000000..5bd09e6d77 --- /dev/null +++ b/Games/Quick_Click/style.css @@ -0,0 +1,48 @@ +body { + font-family: Arial, sans-serif; + text-align: center; + background-color: #f0f0f0; + margin: 0; + padding: 0; +} + +h1 { + margin-top: 20px; +} + +.scoreboard { + margin: 20px 0; + font-size: 1.5em; +} + +.grid { + display: grid; + grid-template-columns: repeat(3, 100px); + grid-gap: 10px; + justify-content: center; + margin: 20px auto; +} + +.circle { + width: 100px; + height: 100px; + background-color: #ccc; + border-radius: 50%; + position: relative; + cursor: pointer; +} + +.circle.active { + background-image: url('GameZone\Games\Reflex_text\Mole2.jpg'); + background-size: cover; + background-position: center; + background-color: #ffd700; + /* Fallback background color */ +} + +button { + margin-top: 20px; + padding: 10px 20px; + font-size: 1em; + cursor: pointer; +} \ No newline at end of file diff --git a/Games/Soccer/README.md b/Games/Soccer/README.md new file mode 100644 index 0000000000..7cf796cc35 --- /dev/null +++ b/Games/Soccer/README.md @@ -0,0 +1,38 @@ +# **Soccer** + + +## **Description 📃** +It is a two player soccer game where the player with maximum number of goals is declared the winner. + + +
    + +## **Functionalities 🎮** + +Player must use the arrow keys and the a/s/d/w keys to move your player and aim a goal. The player with higher number of goals in the set time limit is declared as the winner. Enjoy a strategic and fun-filled challenge with dynamic movement of the players! + +
    + +## **How to play? 🕹ī¸** + +1. Start the game on your preferred platform. +2. Click on the start button to start the game. +3. Each player's goal is to aim a goal. Player with maximum goal is the winner. +4. Click on play again to play again. + +
    + +## **Installation** +1. Clone or download the repository. +2. Navigate to the downloaded repository. +3. Open index.html with live server. + + + + +
    + +## **Screenshots 📸** + +
    +Game Screenshot diff --git a/Games/Soccer/index.html b/Games/Soccer/index.html new file mode 100644 index 0000000000..76c7716c77 --- /dev/null +++ b/Games/Soccer/index.html @@ -0,0 +1,24 @@ + + + + + + Soccer Penalty Shootout + + + +
    +
    +

    Instructions

    +

    Player 1 uses keys W/A/S/D to move

    +

    Player 2 uses Arrow keys to move

    +

    The player with the most goals in 3 minutes wins!

    + +
    + + + +
    + + + diff --git a/Games/Soccer/script.js b/Games/Soccer/script.js new file mode 100644 index 0000000000..ad91e61b63 --- /dev/null +++ b/Games/Soccer/script.js @@ -0,0 +1,464 @@ +var canvas = document.getElementById("canvas"); +var c = canvas.getContext("2d"); +var out = document.getElementById("out"); +var timerDisplay = document.getElementById("timer"); +var instructions = document.getElementById("instructions"); +var startButton = document.getElementById("startButton"); + +window.requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame; + +var player1 = new Player(100,250); +var player2 = new Player(600,250); +var ball = new Ball(350,250); +var wDown = false; +var sDown = false; +var aDown = false; +var dDown = false; +var upDown = false; +var downDown = false; +var leftDown = false; +var rightDown = false; +var timeLeft = 180; // 3 minutes in seconds +var gameInterval; + +function startGame(){ + instructions.style.display = 'none'; + canvas.style.display = 'block'; + out.style.display = 'block'; + timerDisplay.style.display = 'block'; + + gameInterval = setInterval(function(){ + timeLeft--; + updateTimer(); + if (timeLeft <= 0) { + clearInterval(gameInterval); + endGame(); + } + }, 1000); + requestAnimationFrame(start); +} + +startButton.addEventListener("click", startGame); + +function start(){ + clear(); + renderBackground(); + renderGates(); + checkKeyboardStatus(); + checkPlayersBounds(); + checkBallBounds(); + checkPlayers_BallCollision(); + movePlayers(); + moveBall(); + renderPlayers(); + renderBall(); + + out.innerHTML = "Player 1 Score: " + player1.score + "
    Player 2 Score: " + player2.score; + requestAnimationFrame(start); +} + +function updateTimer() { + var minutes = Math.floor(timeLeft / 60); + var seconds = timeLeft % 60; + timerDisplay.innerHTML = "Time Left: " + minutes + ":" + (seconds < 10 ? "0" : "") + seconds; +} + +function endGame() { + var winner; + if (player1.score > player2.score) { + winner = "Player 1 Wins!"; + } else if (player2.score > player1.score) { + winner = "Player 2 Wins!"; + } else { + winner = "It's a Draw!"; + } + alert(winner); + resetGame(); +} + +function resetGame() { + player1 = new Player(100,250); + player2 = new Player(600,250); + ball = new Ball(350,250); + timeLeft = 180; + updateTimer(); + clearInterval(gameInterval); + instructions.style.display = 'block'; + canvas.style.display = 'none'; + out.style.display = 'none'; + timerDisplay.style.display = 'none'; +} + +function Ball(x,y){ + this.x = x; + this.y = y; + this.xVel = 0; + this.yVel = 0; + this.decel = 0.1; + this.size = 5; +} + +function Player(x,y){ + this.x = x; + this.y = y; + this.size = 20; + this.xVel = 0; + this.yVel = 0; + this.score = 0; + this.accel = 0.55; + this.decel = 0.55; + this.maxSpeed = 3; +} + +function reset(){ + var score1 = player1.score; + var score2 = player2.score; + player1 = new Player(100,250); + player1.score = score1; + player2 = new Player(600,250); + player2.score = score2; + ball = new Ball(350,250); + wDown = false; + sDown = false; + aDown = false; + dDown = false; + upDown = false; + downDown = false; + leftDown = false; + rightDown = false; +} + +function movePlayers(){ + player1.x += player1.xVel; + player1.y += player1.yVel; + player2.x += player2.xVel; + player2.y += player2.yVel; +} + +function checkPlayers_BallCollision(){ + var p1_ball_distance = getDistance(player1.x,player1.y,ball.x,ball.y) - player1.size - ball.size; + if(p1_ball_distance < 0){ + collide(ball,player1); + } + var p2_ball_distance = getDistance(player2.x,player2.y,ball.x,ball.y) - player2.size - ball.size; + if(p2_ball_distance < 0){ + collide(ball,player2); + } +} + +function collide(cir1,cir2){ + var dx = (cir1.x - cir2.x) / (cir1.size); + var dy = (cir1.y - cir2.y) / (cir1.size); + cir2.xVel = -dx; + cir2.yVel = -dy; + cir1.xVel = dx; + cir1.yVel = dy; +} + +function getDistance(x1,y1,x2,y2){ + return Math.sqrt(Math.pow(x1-x2,2)+Math.pow(y1-y2,2)); +} + +function moveBall(){ + if(ball.xVel !== 0){ + if(ball.xVel > 0){ + ball.xVel -= ball.decel; + if(ball.xVel < 0) ball.xVel = 0; + } else { + ball.xVel += ball.decel; + if(ball.xVel > 0) ball.xVel = 0; + } + } + if(ball.yVel !== 0){ + if(ball.yVel > 0){ + ball.yVel -= ball.decel; + if(ball.yVel < 0) ball.yVel = 0; + } else { + ball.yVel += ball.decel; + if(ball.yVel > 0) ball.yVel = 0; + } + } + ball.x += ball.xVel; + ball.y += ball.yVel; +} + +function checkBallBounds(){ + if(ball.x + ball.size > canvas.width){ + if(ball.y > 150 && ball.y < 350){ + player1.score++; + reset(); + return; + } + ball.x = canvas.width - ball.size; + ball.xVel *= -1.5; + } + if(ball.x - ball.size < 0){ + if(ball.y > 150 && ball.y < 350){ + player2.score++; + reset(); + return; + } + ball.x = 0 + ball.size; + ball.xVel *= -1.5; + } + if(ball.y + ball.size > canvas.height){ + ball.y = canvas.height - ball.size; + ball.yVel *= -1.5; + } + if(ball.y - ball.size < 0){ + ball.y = 0 + ball.size; + ball.yVel *= -1.5; + } +} + +function checkPlayersBounds(){ + if(player1.x + player1.size > canvas.width){ + player1.x = canvas.width - player1.size; + player1.xVel *= -0.5; + } + if(player1.x - player1.size < 0){ + player1.x = 0 + player1.size; + player1.xVel *= -0.5; + } + if(player1.y + player1.size > canvas.height){ + player1.y = canvas.height - player1.size; + player1.yVel *= -0.5; + } + if(player1.y - player1.size < 0){ + player1.y = 0 + player1.size; + player1.yVel *= -0.5; + } + if(player2.x + player2.size > canvas.width){ + player2.x = canvas.width - player2.size; + player2.xVel *= -0.5; + } + if(player2.x - player2.size < 0){ + player2.x = 0 + player2.size; + player2.xVel *= -0.5; + } + if(player2.y + player2.size > canvas.height){ + player2.y = canvas.height - player2.size; + player2.yVel *= -0.5; + } + if(player2.y - player2.size < 0){ + player2.y = 0 + player2.size; + player2.yVel *= -0.5; + } +} + +function checkKeyboardStatus(){ + if(wDown){ + if(player1.yVel > -player1.maxSpeed){ + player1.yVel -= player1.accel; + } else { + player1.yVel = -player1.maxSpeed; + } + } else { + if(player1.yVel < 0){ + player1.yVel += player1.decel; + if(player1.yVel > 0) player1.yVel = 0; + } + } + if(sDown){ + if(player1.yVel < player1.maxSpeed){ + player1.yVel += player1.accel; + } else { + player1.yVel = player1.maxSpeed; + } + } else { + if(player1.yVel > 0){ + player1.yVel -= player1.decel; + if(player1.yVel < 0) player1.yVel = 0; + } + } + if(aDown){ + if(player1.xVel > -player1.maxSpeed){ + player1.xVel -= player1.accel; + } else { + player1.xVel = -player1.maxSpeed; + } + } else { + if(player1.xVel < 0){ + player1.xVel += player1.decel; + if(player1.xVel > 0) player1.xVel = 0; + } + } + if(dDown){ + if(player1.xVel < player1.maxSpeed){ + player1.xVel += player1.accel; + } else { + player1.xVel = player1.maxSpeed; + } + } else { + if(player1.xVel > 0){ + player1.xVel -= player1.decel; + if(player1.xVel < 0) player1.xVel = 0; + } + } + + //PLAYER 2 + + if(upDown){ + if(player2.yVel > -player2.maxSpeed){ + player2.yVel -= player2.accel; + } else { + player2.yVel = -player2.maxSpeed; + } + } else { + if(player2.yVel < 0){ + player2.yVel += player2.decel; + if(player2.yVel > 0) player2.yVel = 0; + } + } + if(downDown){ + if(player2.yVel < player2.maxSpeed){ + player2.yVel += player2.accel; + } else { + player2.yVel = player2.maxSpeed; + } + } else { + if(player2.yVel > 0){ + player2.yVel -= player2.decel; + if(player2.yVel < 0) player2.yVel = 0; + } + } + if(leftDown){ + if(player2.xVel > -player2.maxSpeed){ + player2.xVel -= player2.accel; + } else { + player2.xVel = -player2.maxSpeed; + } + } else { + if(player2.xVel < 0){ + player2.xVel += player2.decel; + if(player2.xVel > 0) player2.xVel = 0; + } + } + if(rightDown){ + if(player2.xVel < player2.maxSpeed){ + player2.xVel += player2.accel; + } else { + player2.xVel = player2.maxSpeed; + } + } else { + if(player2.xVel > 0){ + player2.xVel -= player2.decel; + if(player2.xVel < 0) player2.xVel = 0; + } + } +} + +document.onkeyup = function(e){ + if(e.keyCode === 87){ + wDown = false; + } + if(e.keyCode === 65){ + aDown = false; + } + if(e.keyCode === 68){ + dDown = false; + } + if(e.keyCode === 83){ + sDown = false; + } + if(e.keyCode === 38){ + upDown = false; + } + if(e.keyCode === 37){ + leftDown = false; + } + if(e.keyCode === 40){ + downDown = false; + } + if(e.keyCode === 39){ + rightDown = false; + } +} + +document.onkeydown = function(e){ + if(e.keyCode === 87){ + wDown = true; + } + if(e.keyCode === 65){ + aDown = true; + } + if(e.keyCode === 68){ + dDown = true; + } + if(e.keyCode === 83){ + sDown = true; + } + if(e.keyCode === 38){ + upDown = true; + } + if(e.keyCode === 37){ + leftDown = true; + } + if(e.keyCode === 40){ + downDown = true; + } + if(e.keyCode === 39){ + rightDown = true; + } +} + +function renderBall(){ + c.save(); + c.beginPath(); + c.fillStyle = "black"; + c.arc(ball.x,ball.y,ball.size,0,Math.PI*2); + c.fill(); + c.closePath(); + c.restore(); +} + +function renderPlayers(){ + c.save(); + c.fillStyle = "red"; + c.beginPath(); + c.arc(player1.x,player1.y,player1.size,0,Math.PI*2); + c.fill(); + c.closePath(); + c.beginPath(); + c.fillStyle = "blue"; + c.arc(player2.x,player2.y,player2.size,0,Math.PI*2); + c.fill(); + c.closePath(); + c.restore(); +} + +function renderGates(){ + c.save(); + c.beginPath(); + c.moveTo(0,150); + c.lineTo(0,350); + c.strokeStyle = "red"; + c.lineWidth = 10; + c.stroke(); + c.closePath(); + c.beginPath(); + c.moveTo(canvas.width,150); + c.lineTo(canvas.width,350); + c.strokeStyle = "blue"; + c.lineWidth = 10; + c.stroke(); + c.closePath(); + c.restore(); +} + +function renderBackground(){ + c.save(); + c.fillStyle = "#66aa66"; + c.fillRect(0,0,canvas.width,canvas.height); + c.strokeStyle = "rgba(255,255,255,0.6)"; + c.beginPath(); + c.arc(canvas.width/2,canvas.height/2,150,0,Math.PI*2); + c.closePath(); + c.lineWidth = 10; + c.stroke(); + c.restore(); +} + +function clear(){ + c.clearRect(0,0,canvas.width,canvas.height); +} diff --git a/Games/Soccer/style.css b/Games/Soccer/style.css new file mode 100644 index 0000000000..af2b68fc9f --- /dev/null +++ b/Games/Soccer/style.css @@ -0,0 +1,41 @@ +body{ + background-image: url('https://wallpapers.com/images/hd/plain-green-background-vjb4wrgir58bpssc.jpg'); + margin: 10px; + display: flex; + justify-content: center; + align-items: center; + height: 100vh; + font-family: Arial, sans-serif; +} + +.game-container { + text-align: center; + background-color: #ffffff; + padding: 20px; + border: 2px solid #000000; + border-radius: 10px; + box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1); +} + +#instructions { + margin-bottom: 20px; +} + +#out { + color: black; + font-size: 24px; + font-weight: bold; + margin-top: 20px; +} + +canvas { + background-color: white; + border: 2px solid black; + margin-top: 20px; +} + +#timer { + font-size: 24px; + font-weight: bold; + margin-top: 20px; +} diff --git a/README.md b/README.md index 716d8f3922..3e3d8415b0 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@

    -Video Game GameZone

    +Video GameGameZone @@ -226,9 +226,11 @@ This repository also provides one such platforms where contributers come over an | [Steampunk_FlappyBird](https://github.com/kunjgit/GameZone/tree/main/Games/Steampunk_FlappyBird) | | [Catch_The_Circle](https://github.com/kunjgit/GameZone/tree/main/Games/Catch_The_Circle) | | [Automated_rock_paper_scissor](https://github.com/kunjgit/GameZone/tree/main/Games/automated_rock_paper_scissor) | +| [Grab_The_Carrot](https://github.com/Aksshay88/GameZone/tree/main/Games/Grab_The_Carrot) | | [Maze_Game](https://github.com/kunjgit/GameZone/tree/main/Games/Maze_Game) | [Astronaut_runner](https://github.com/tanishkaa08/GameZone/tree/main/Games/Astronaunt_runner) | | [16_Puzzle](https://github.com/kunjgit/GameZone/tree/main/Games/16_Puzzle) | | [Musical_Memory](https://github.com/kunjgit/GameZone/tree/main/Games/Musical_Memory) | +|[Quick_Click](https://github.com/kunjgit/GameZone/tree/main/Games/Quick_Click) | | [Dragon_Tower](https://github.com/kunjgit/GameZone/tree/main/Games/Dragon_Tower) | | [Hover_Board_Effect](https://github.com/kunjgit/GameZone/tree/main/Games/Hover_Board_Effect) | [Mancala_Game](https://github.com/kunjgit/GameZone/tree/main/Games/Mancala_Game) | @@ -251,7 +253,7 @@ This repository also provides one such platforms where contributers come over an | [Puzzel_Winner](https://github.com/kunjgit/GameZone/tree/main/Games/Puzzel_Winner) | | [Emoji_Intruder](https://github.com/kunjgit/GameZone/tree/main/Games/Emoji_Intruder) | [Guess The Weapon](https://github.com/kunjgit/GameZone/tree/main/Games/Guess_The_Weapon) | | [Guess Who](https://github.com/kunjgit/GameZone/tree/main/Games/Guess_Who) | [Pop My Balloon](https://github.com/kunjgit/GameZone/tree/main/Games/Pop_My_Balloon) | -| [Tower Stack](https://github.com/kunjgit/GameZone/tree/main/Games/Tower_Stack) | +| [Tower Stack](https://github.com/kunjgit/GameZone/tree/main/Games/Tower_Stack) | [Soccer](https://github.com/kunjgit/GameZone/tree/main/Games/Soccer) | | [TriHand_Tactics](https://github.com/kunjgit/GameZone/tree/main/Games/TriHand_Tactics) | | [Earth_Guardian](https://github.com/kunjgit/GameZone/tree/main/Games/Earth_Guardian) | | [CatchTheBall](https://github.com/kunjgit/GameZone/tree/main/Games/CatchTheBall) | @@ -320,26 +322,31 @@ This repository also provides one such platforms where contributers come over an |[Cartoon character guessing game](https://github.com/kunjgit/GameZone/tree/main/Games/Cartoon_Character_Guessing_Game)| |[Carrom Board Game](https://github.com/kunjgit/GameZone/tree/main/Games/carrom)| | [Number_Recall_Game](https://github.com/kunjgit/GameZone/tree/main/Games/Number_Recall_Game) | -| [Hit_the_hamster] (https://github.com/kunjgit/GameZone/tree/main/Games/Hit_the_hamster) | +| [Hit_the_hamster](https://github.com/kunjgit/GameZone/tree/main/Games/Hit_the_hamster) | | [Forest_Guardian](https://github.com/kunjgit/GameZone/tree/main/Games/Forst_Guardian) | | [Sudoku_light_theme](https://github.com/kunjgit/GameZone/tree/main/Games/Sudoku_light_theme) | | [Find_the_ball](https://github.com/kunjgit/GameZone/tree/main/Games/Find_the_ball) | |[Color The Page](https://github.com/kunjgit/GameZone/tree/main/Games/Color_The_Page)| |[AquaSort_Game](https://github.com/kunjgit/GameZone/tree/main/Games/AquaSort_Game) | +|[Chess_Game_computer](https://github.com/kunjgit/GameZone/tree/main/Games/Chess_Game_computer) | |[Turn_on_the_light](https://github.com/kunjgit/GameZone/tree/main/Games/Turn_on_the_light) | | [Tic-Tac-Toe Game](https://github.com/kunjgit/GameZone/tree/main/Games/Tic-Tac-Toe) | -| [Rapid_click_frenzy](https://github.com/kunjgit/GameZone/tree/main/Games/Rapid_click_frenzy) | -|[Dsa_quiz_game](https://github.com/kunjgit/GameZone/tree/main/Games/Dsa_quiz_game) | -| [Rapid_click_frenzy](https://github.com/kunjgit/GameZone/tree/main/Games/Rapid_click_frenzy) | -| [Gravity_Simulation_Game](https://github.com/kunjgit/GameZone/tree/main/Games/Gravity_Simulation_Game) | +| [Rapid_click_frenzy](https://github.com/kunjgit/GameZone/tree/main/Games/Rapid_click_frenzy) | +| [Dsa_quiz_game](https://github.com/kunjgit/GameZone/tree/main/Games/Dsa_quiz_game) | +| [Gravity_Simulation_Game](https://github.com/kunjgit/GameZone/tree/main/Games/Gravity_Simulation_Game) | | [Anagarm-Word-Game](https://github.com/kunjgit/GameZone/tree/main/Games/Anagarm-Word-Game) | | [Brick Buster Game](https://github.com/kunjgit/GameZone/tree/main/Games/Brick Buster) | | [Rapid_click_frenzy](https://github.com/kunjgit/GameZone/tree/main/Games/Rapid_click_frenzy) |[Penguins Can't Fly](https://github.com/Will2Jacks/GameZoneForked/tree/Task/Games/Penguins_Can't_Fly)| | [Taash_Game](https://github.com/kunjgit/GameZone/tree/main/Games/Taash_Game)| +| [Brick Buster Game](https://github.com/kunjgit/GameZone/tree/main/Games/Brick%20Buster) | +| [Rapid_click_frenzy](https://github.com/kunjgit/GameZone/tree/main/Games/Rapid_click_frenzy) | +| [Penguins Can't Fly](https://github.com/Will2Jacks/GameZoneForked/tree/Task/Games/Penguins_Can't_Fly) | +| [Intellect Quest](https://github.com/Will2Jacks/GameZoneForked/tree/Task/Games/Intellect_Quest) | +| [Taash_Game](https://github.com/kunjgit/GameZone/tree/main/Games/Taash_Game) | +| [Number_Guessing_Game](https://github.com/kunjgit/GameZone/tree/main/Games/Number_Guessing_Game) | |[Tower Defence Game](https://github.com/Will2Jacks/GameZoneForked/tree/Task/Games/Tower_Defence_Game)| -
    @@ -392,7 +399,7 @@ Terms and conditions for use, reproduction and distribution are under the [Apach
    - This project thanking all the contributors for having your valuable contribution to our project -- Make sure you show some love by giving ⭐ to our repository +- Make sure you show some love by giving ⭐ to our repository
    @@ -402,4 +409,6 @@ Terms and conditions for use, reproduction and distribution are under the [Apach
    -

    Back to top

    \ No newline at end of file + +

    Back to top

    + diff --git a/assets/images/Intellect_Quest.png b/assets/images/Intellect_Quest.png new file mode 100644 index 0000000000..b7d7eed1aa Binary files /dev/null and b/assets/images/Intellect_Quest.png differ diff --git a/assets/images/Morse_Code_Generator.png b/assets/images/Morse_Code_Generator.png new file mode 100644 index 0000000000..055decf524 Binary files /dev/null and b/assets/images/Morse_Code_Generator.png differ diff --git a/assets/images/NumberGuessingGame.png b/assets/images/NumberGuessingGame.png new file mode 100644 index 0000000000..02fcaf5c7d Binary files /dev/null and b/assets/images/NumberGuessingGame.png differ diff --git a/assets/images/Quick Click.png b/assets/images/Quick Click.png new file mode 100644 index 0000000000..41d0f7dc35 Binary files /dev/null and b/assets/images/Quick Click.png differ diff --git a/assets/images/Soccer.png b/assets/images/Soccer.png new file mode 100644 index 0000000000..b9b19aa4a1 Binary files /dev/null and b/assets/images/Soccer.png differ diff --git a/assets/images/chessComputer.png b/assets/images/chessComputer.png new file mode 100644 index 0000000000..0f4d29f932 Binary files /dev/null and b/assets/images/chessComputer.png differ diff --git a/assets/images/demo_bug.jpeg b/assets/images/demo_bug.jpeg new file mode 100644 index 0000000000..109a770d9e Binary files /dev/null and b/assets/images/demo_bug.jpeg differ diff --git a/assets/images/grabthecarrot.png b/assets/images/grabthecarrot.png new file mode 100644 index 0000000000..69a5874ced Binary files /dev/null and b/assets/images/grabthecarrot.png differ diff --git a/assets/js/gamesData.json b/assets/js/gamesData.json index d5d2d47bf6..0b139faa80 100644 --- a/assets/js/gamesData.json +++ b/assets/js/gamesData.json @@ -2102,11 +2102,25 @@ "gameTitle": "Guess_The_Song", "gameUrl": "Guess_The_Song", "thumbnailUrl": "Guess_The_Song.png" -},"417":{ + } +},"408":{ "gameTitle": "Brick Buster", "gameUrl": "Brick Buster", "thumbnailUrl": "Brick.png" - } + }, + "417":{ + "gameTitle": "Soccer", + "gameUrl": "Soccer", + "thumbnailUrl": "Soccer" +}, +"409":{"gameTitle": "Pen_Pointer_Fight", +"gameUrl": "PenPointerFight", +"thumbnailUrl": "PenPointerFight.png" +}, +"418":{ +"gameTitle": "MathQuiz", +"gameUrl": "MathQuiz", +"thumbnailUrl": "MathQuiz.png" +} } - diff --git a/assets/js/index.js b/assets/js/index.js index 86f599b40f..6bf16f73ff 100644 --- a/assets/js/index.js +++ b/assets/js/index.js @@ -4,7 +4,7 @@ const generateLiTags = (gamesData, searchText = "") => { const liTags = []; searchText = searchText.trim().toLowerCase(); // Trim whitespace and convert to lowercase - for (let tagNumber = 1; tagNumber <= 417; tagNumber++) { + for (let tagNumber = 1; tagNumber <= 418; tagNumber++) { const gameData = gamesData[tagNumber.toString()]; if (gameData) { diff --git a/index.html b/index.html index f32891a0f5..62e69f176a 100644 --- a/index.html +++ b/index.html @@ -168,7 +168,7 @@ -
    +
    Welcome to our website! Your ultimate destination for a vast collection of free-to-play games. Dive into a world of endless entertainment and excitement as you explore our diverse selection of games, ranging from timeless classics to @@ -233,9 +233,9 @@
    -

    Our Valuable Contributors

    +

    Our Valuable Contributors

    -

    +