-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
38,501 additions
and
255 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
var test = ''; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<!DOCTYPE html> | ||
<html lang="en" > | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Baseball - Home Run </title> | ||
<link rel="stylesheet" href="./style.css"> | ||
<link href="https://straight-code.github.io/assets/straight-code.png" rel="shortcut icon" /> | ||
</head> | ||
<body> | ||
<!-- partial:index.partial.html --> | ||
<!-- I apologize for the janky gameplay on mobile Safari--> | ||
<div id='game_console'> | ||
<div id='ballpark'> | ||
<div id='scoreboard'></div> | ||
<div id='pitcher'></div> | ||
<div id='batter' class=''></div> | ||
<div id='ball' style='left: 43%; top: 58.5%;'></div> | ||
</div> | ||
<div id='homeruns'>0</div> | ||
<div id='outs'>0</div> | ||
<div id='start_screen'><span>T</span><span>A</span><span>P</span> <span>T</span><span>O</span> <span>P</span><span>L</span><span>A</span><span>Y</span> | ||
<p>Tap to throw pitch<br>Tap again to swing</p> | ||
</div> | ||
</div> | ||
|
||
<link href="https://fonts.googleapis.com/css2?family=Press+Start+2P&family=VT323&display=swap" rel="stylesheet"> | ||
|
||
<audio src="http://contentservice.mc.reyrey.net/audio_v1.0.0/?id=d1f9b7da-033e-5f86-94e6-4500351eb570" id='back_sound' preload loop></audio> | ||
<audio src="http://contentservice.mc.reyrey.net/audio_v1.0.0/?id=4b11ab1d-fdba-569d-b932-1974bde0671a" id='bat_hit' preload></audio> | ||
<audio src="http://contentservice.mc.reyrey.net/audio_v1.0.0/?id=b916d76b-e068-55e0-bfae-5833b9c3004f" id='clapping' preload></audio> | ||
<!-- partial --> | ||
<script src="./script.js"></script> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
const gc = document.querySelector('#game_console') | ||
const ss = document.querySelector('#start_screen') | ||
const ball = document.querySelector('#ball') | ||
const batter = document.querySelector('#batter') | ||
const pitcher = document.querySelector('#pitcher') | ||
const bp = document.querySelector('#ballpark') | ||
const homers = document.querySelector('#homeruns') | ||
const outss = document.querySelector('#outs') | ||
const sb = document.querySelector('#scoreboard') | ||
const backingTrack = document.querySelector('#back_sound') | ||
const hitBall = document.querySelector('#bat_hit') | ||
const clapping = document.querySelector('#clapping') | ||
|
||
var thrown = false; | ||
const hr = [6,7,8,14,15,16,22,23,24] | ||
var homeruns = 0 | ||
var outs = 0 | ||
|
||
var b_loc = ball.getBoundingClientRect() | ||
var x = b_loc.x | ||
const start_x = b_loc.x | ||
var y = b_loc.y | ||
const start_y = b_loc.y | ||
|
||
|
||
function throwPitch() { | ||
if(thrown){ | ||
bp.removeEventListener('click', throwPitch) | ||
batter.classList.add('swing') | ||
var bp_loc = bp.getBoundingClientRect() | ||
var b_loc = ball.getBoundingClientRect() | ||
var dist = Math.round(Math.hypot(0, (bp_loc.y + bp_loc.height) - (b_loc.y + (b_loc.height*.5)))) | ||
// console.log(dist) | ||
|
||
if(dist <= 30) { | ||
hitBall.play() | ||
ball.style.transition = '2s' | ||
ball.classList.add('hit_ball') | ||
bp.classList.add('alt_bp') | ||
|
||
if(hr.includes(dist)) { | ||
clapping.play() | ||
homeruns++ | ||
homers.innerHTML = homeruns | ||
sb.innerHTML = 'HOME<br>RUN' | ||
gc.classList.add('hr_sparkle') | ||
if([22,23,24].includes(dist)) { | ||
ball.style.left = (30 - dist) / 4 * 100 + '%' | ||
ball.style.top = '-600px' | ||
} | ||
if([14,15,16].includes(dist)) { | ||
ball.style.left = '800px' | ||
ball.style.top = '-400px' | ||
} | ||
if([6,7,8].includes(dist)) { | ||
ball.style.left = '1000px' | ||
ball.style.top = 100 - (dist / 4 * 100) + '%' | ||
} | ||
} else { | ||
if(dist >= 17) { | ||
ball.style.left = ((30 - dist) * 11.11) + 1 + '%' | ||
ball.style.top = Math.random() < .5 ? -Math.random()*100 + '%' : -Math.random()*100 + '%'; | ||
} | ||
if(dist <= 13) { | ||
ball.style.left = Math.random()*150 + 50 + '%' | ||
ball.style.top = 99 - (dist * 11.11) + '%' | ||
} | ||
} | ||
if(!hr.includes(dist)) { | ||
outs++ | ||
outss.innerHTML = outs | ||
sb.innerHTML = 'OUT' | ||
} | ||
} | ||
|
||
setTimeout(function(){ | ||
if(outs == 3) { | ||
ss.style.display = 'block' | ||
bp.classList.remove('alt_bp') | ||
ball.classList.remove('hit_ball') | ||
ball.style.transition = '' | ||
ball.style.left = '43%' | ||
ball.style.top = '58.5%' | ||
batter.classList.remove('swing') | ||
gc.classList.remove('hr_sparkle') | ||
} else { | ||
thrown = false | ||
bp.addEventListener('click', throwPitch) | ||
bp.classList.remove('alt_bp') | ||
ball.classList.remove('hit_ball') | ||
ball.style.transition = '' | ||
ball.style.left = '43%' | ||
ball.style.top = '58.5%' | ||
batter.classList.remove('swing') | ||
gc.classList.remove('hr_sparkle') | ||
} | ||
}, 2500) | ||
} | ||
|
||
if(!thrown) { | ||
thrown = true | ||
var speed = Math.random() + 1.25 | ||
ball.style.transition = speed + 's' | ||
ball.style.left = '-58px' | ||
ball.style.top = 'calc(100% + 50px)' | ||
clapping.pause() | ||
clapping.currentTime = 0 | ||
} | ||
// console.log(speed) | ||
} | ||
|
||
ss.addEventListener('click', function(){ | ||
ss.style.display = 'none' | ||
bp.addEventListener('click', throwPitch) | ||
homeruns = 0 | ||
outs = 0 | ||
outss.innerHTML = outs | ||
homers.innerHTML = homeruns | ||
thrown = false | ||
back_sound.volume = .025 | ||
back_sound.play() | ||
}) | ||
|
||
function updateBall() { | ||
if(thrown) { | ||
x-- | ||
y++ | ||
ball.style.left = x + 'px' | ||
ball.style.top = y + 'px' | ||
} | ||
|
||
setTimeout(updateBall,1000/10) | ||
} |
Oops, something went wrong.