Skip to content

Commit c012748

Browse files
committed
Deploy compiled game files to root for GitHub Pages
- Copied all compiled JavaScript files from dist/ to root - Added all game assets (images, sprites) to root - Game now accessible via GitHub Pages at 2toml.github.io/Game-Arkanoid
1 parent 12b0b0b commit c012748

21 files changed

Lines changed: 390 additions & 0 deletions

Collision.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
export class Collision {
2+
isCollidingBrick(ball, brick) {
3+
// Add some tolerance for collision detection
4+
const tolerance = 2;
5+
if (ball.pos.x + ball.width > brick.pos.x - tolerance &&
6+
ball.pos.x < brick.pos.x + brick.width + tolerance &&
7+
ball.pos.y + ball.height > brick.pos.y - tolerance &&
8+
ball.pos.y < brick.pos.y + brick.height + tolerance) {
9+
return true;
10+
}
11+
return false;
12+
}
13+
// Check ball collision with bricks
14+
isCollidingBricks(ball, bricks) {
15+
let colliding = false;
16+
// Loop backwards to safely remove items from array
17+
for (let i = bricks.length - 1; i >= 0; i--) {
18+
const brick = bricks[i];
19+
if (this.isCollidingBrick(ball, brick)) {
20+
console.log(`Collision detected with brick ${i}, energy before: ${brick.energy}`);
21+
ball.changeYDirection();
22+
// Reduce brick energy
23+
brick.energy -= 1;
24+
console.log(`Brick ${i} energy after hit: ${brick.energy}`);
25+
// Remove brick if energy is 0 or less
26+
if (brick.energy <= 0) {
27+
console.log(`Removing brick ${i} - energy depleted`);
28+
bricks.splice(i, 1);
29+
}
30+
colliding = true;
31+
break; // Only handle one collision per frame
32+
}
33+
}
34+
return colliding;
35+
}
36+
checkBallCollision(ball, paddle, view) {
37+
// 1. Check ball collision with paddle
38+
if (ball.pos.x + ball.width > paddle.pos.x &&
39+
ball.pos.x < paddle.pos.x + paddle.width &&
40+
ball.pos.y + ball.height === paddle.pos.y) {
41+
ball.changeYDirection();
42+
}
43+
// 2. Check ball collision with walls
44+
// Ball movement X constraints
45+
if (ball.pos.x > view.canvas.width - ball.width || ball.pos.x < 0) {
46+
ball.changeXDirection();
47+
}
48+
// Ball movement Y constraints
49+
if (ball.pos.y < 0) {
50+
ball.changeYDirection();
51+
}
52+
}
53+
}

Collison.js

Lines changed: 46 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

helpers.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { Brick } from './sprites/Brick.js';
2+
import { BRICK_IMAGES, LEVEL, STAGE_COLS, STAGE_PADDING, BRICK_WIDTH, BRICK_HEIGHT, BRICK_PADDING, BRICK_ENERGY } from "./setup.js";
3+
export function createBricks() {
4+
return LEVEL.reduce((ack, element, i) => {
5+
const row = Math.floor((i + 1) / STAGE_COLS);
6+
const col = i % STAGE_COLS;
7+
const x = STAGE_PADDING + col * (BRICK_WIDTH + BRICK_PADDING);
8+
const y = STAGE_PADDING + row * (BRICK_HEIGHT + BRICK_PADDING);
9+
if (element === 0)
10+
return ack;
11+
return [
12+
...ack,
13+
new Brick(BRICK_WIDTH, BRICK_HEIGHT, { x, y }, BRICK_ENERGY[element], BRICK_IMAGES[element])
14+
];
15+
}, []);
16+
}

images/background.png

714 KB
Loading

images/background1.png

1.07 MB
Loading

images/background2.png

1.42 MB
Loading

images/ball.png

583 Bytes
Loading

images/brick-blue.png

114 KB
Loading

images/brick-green.png

113 KB
Loading

images/brick-purple.png

106 KB
Loading

0 commit comments

Comments
 (0)