├── .gitattributes
├── media
├── mixkit-game-ball-tap-2073.wav
├── mixkit-game-level-music-689.wav
├── mixkit-small-hit-in-a-game-2072.wav
├── mixkit-winning-notification-2018.wav
├── mixkit-winning-an-extra-bonus-2060.wav
├── mixkit-arcade-retro-changing-tab-206.wav
├── mixkit-neutral-bot-pinbal-tone-3137.wav
└── mixkit-thin-metal-card-deck-shuffle-3175.wav
├── Paddle.js
├── README.md
├── Ball.js
├── index.html
├── style.css
└── script.js
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
--------------------------------------------------------------------------------
/media/mixkit-game-ball-tap-2073.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BriteBloomSolutions/Bit-Pong/HEAD/media/mixkit-game-ball-tap-2073.wav
--------------------------------------------------------------------------------
/media/mixkit-game-level-music-689.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BriteBloomSolutions/Bit-Pong/HEAD/media/mixkit-game-level-music-689.wav
--------------------------------------------------------------------------------
/media/mixkit-small-hit-in-a-game-2072.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BriteBloomSolutions/Bit-Pong/HEAD/media/mixkit-small-hit-in-a-game-2072.wav
--------------------------------------------------------------------------------
/media/mixkit-winning-notification-2018.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BriteBloomSolutions/Bit-Pong/HEAD/media/mixkit-winning-notification-2018.wav
--------------------------------------------------------------------------------
/media/mixkit-winning-an-extra-bonus-2060.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BriteBloomSolutions/Bit-Pong/HEAD/media/mixkit-winning-an-extra-bonus-2060.wav
--------------------------------------------------------------------------------
/media/mixkit-arcade-retro-changing-tab-206.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BriteBloomSolutions/Bit-Pong/HEAD/media/mixkit-arcade-retro-changing-tab-206.wav
--------------------------------------------------------------------------------
/media/mixkit-neutral-bot-pinbal-tone-3137.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BriteBloomSolutions/Bit-Pong/HEAD/media/mixkit-neutral-bot-pinbal-tone-3137.wav
--------------------------------------------------------------------------------
/media/mixkit-thin-metal-card-deck-shuffle-3175.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BriteBloomSolutions/Bit-Pong/HEAD/media/mixkit-thin-metal-card-deck-shuffle-3175.wav
--------------------------------------------------------------------------------
/Paddle.js:
--------------------------------------------------------------------------------
1 | const SPEED = 0.02;
2 |
3 | export default class Paddle {
4 | constructor(paddleEl) {
5 | this.paddleEl = paddleEl;
6 | this.reset();
7 | }
8 |
9 | get position() {
10 | return parseFloat(
11 | getComputedStyle(this.paddleEl).getPropertyValue("--position")
12 | );
13 | }
14 |
15 | set position(value) {
16 | this.paddleEl.style.setProperty("--position", value);
17 | }
18 |
19 | rect() {
20 | return this.paddleEl.getBoundingClientRect();
21 | }
22 |
23 | reset() {
24 | this.position = 50;
25 | }
26 |
27 | update(delta, ballHeight) {
28 | this.position += SPEED * delta * (ballHeight - this.position);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Bit-Pong
2 |
3 | ## Recommended Specs
4 |
5 | * Operating Systems
6 | - Windows 10
7 | - Windows 8, 8.1
8 | - Windows 7
9 | - Windows vista
10 | - Mac
11 | * Hardware Environment
12 | - Processor: x86 or x64
13 | - RAM : 512 MB (minimum), 1 GB (recommended)
14 | - Hard disc: up to 1 GB of free space may be required
15 | * Web browsers
16 | - Internet Explorer 8+
17 | - Microsoft Edge Latest
18 | - Mozilla Firefox Latest
19 | - Chrome 20+
20 | - Opera 17+
21 | - Safari 12+
22 |
23 |
24 | ## The inspiration
25 |
26 | -
35 |
36 | ## Tech Stack
37 | * Javascript
38 | * HTML
39 | * CSS
40 |
41 | ## Upcoming Features
42 | -multi-ball play
43 | -additional difficulty levels
44 | -multi-player
45 |
46 | ## Sources
47 | -https://www.youtube.com/watch?v=LXTnfp7nU_0
48 | -https://www.youtube.com/watch?v=nl0KXCa5pJk
49 | -https://www.youtube.com/watch?v=PeY6lXPrPaA&t=1909s
50 |
51 |
52 |
--------------------------------------------------------------------------------
/Ball.js:
--------------------------------------------------------------------------------
1 | let INITIAL_VELOCITY = 0.015;
2 | let VELOCITY_INCREASE = 0.000001;
3 |
4 | export default class Ball {
5 | constructor(ballElem) {
6 | this.ballElem = ballElem;
7 | this.reset();
8 | }
9 |
10 | get x() {
11 | return parseFloat(getComputedStyle(this.ballElem).getPropertyValue("--x"));
12 | }
13 |
14 | set x(value) {
15 | this.ballElem.style.setProperty("--x", value);
16 | }
17 |
18 | get y() {
19 | return parseFloat(getComputedStyle(this.ballElem).getPropertyValue("--y"));
20 | }
21 |
22 | set y(value) {
23 | this.ballElem.style.setProperty("--y", value);
24 | }
25 |
26 | rect() {
27 | return this.ballElem.getBoundingClientRect();
28 | }
29 |
30 | reset() {
31 | this.x = 50;
32 | this.y = 50;
33 | this.direction = { x: 0 };
34 | while (
35 | Math.abs(this.direction.x) <= 0.25 ||
36 | Math.abs(this.direction.x) >= 0.85
37 | ) {
38 | const heading = randomNumberBetween(0, 1.75 * Math.PI);
39 | this.direction = { x: Math.cos(heading), y: Math.sin(heading) };
40 | }
41 | this.velocity = INITIAL_VELOCITY;
42 | }
43 |
44 | update(delta, paddleRects) {
45 | this.x += this.direction.x * this.velocity * delta;
46 | this.y += this.direction.y * this.velocity * delta;
47 | this.velocity += VELOCITY_INCREASE * delta;
48 | const rect = this.rect();
49 |
50 | //collision occurrances
51 | if (rect.bottom >= window.innerHeight || rect.top <= 0) {
52 | this.direction.y *= -1;
53 | }
54 |
55 | if (paddleRects.some((r) => isCollision(r, rect))) {
56 | this.direction.x *= -1;
57 | }
58 | }
59 | }
60 |
61 | function randomNumberBetween(min, max) {
62 | return Math.random() * (max - min) + min;
63 | }
64 |
65 | function isCollision(rect1, rect2) {
66 | return (
67 | rect1.left <= rect2.right &&
68 | rect1.right >= rect2.left &&
69 | rect1.top <= rect2.bottom &&
70 | rect1.bottom >= rect2.top
71 | );
72 | }
73 |
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |