Skip to content

Commit

Permalink
Merge branch 'main' into csq
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdavidmills authored Feb 14, 2024
2 parents 88bd5c2 + 0a48206 commit 1a076c4
Show file tree
Hide file tree
Showing 110 changed files with 2,993 additions and 321 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/pr-check_url-issues.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Check URL issues

on:
pull_request:
branches:
- main
paths:
- "files/**/*.md"

jobs:
check_url_issues:
#if: github.repository == 'mdn/content'
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Node.js environment
uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
cache: yarn

- name: Check URL deletions and broken fragments
run: |
echo "::add-matcher::.github/workflows/url-issues-problem-matcher.json"
git fetch origin main
node scripts/log-url-issues.js --workflow
18 changes: 18 additions & 0 deletions .github/workflows/url-issues-problem-matcher.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"problemMatcher": [
{
"owner": "log-url-issues",
"severity": "error",
"pattern": [
{
"regexp": "^(ERROR|WARN|INFO):(.+):(\\d+):(\\d+):(.+)$",
"severity": 1,
"file": 2,
"line": 3,
"column": 4,
"message": 5
}
]
}
]
}
14 changes: 14 additions & 0 deletions .husky/post-merge
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
BRANCH="$(git rev-parse --abbrev-ref HEAD)"
if [[ "$BRANCH" != "main" ]]; then
exit 0
fi

if [ -f ".husky/_/history" ]; then
lastHash=$(cat ./.husky/_/history)
isUpdated=$(git diff $lastHash HEAD -- ./package.json)
if [ "$isUpdated" != "" ]; then
echo -e "\n⚠🔥 'package.json' has changed. Please run 'yarn install'! 🔥"
fi
else
yarn install
fi
7 changes: 7 additions & 0 deletions .husky/update-history
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This script stores the 'main' branch's HEAD commit hash in .husky/_/history
# The stored commit hash is used by the post-merge script .husky/post-merge

BRANCH="$(git rev-parse --abbrev-ref HEAD)"
if [[ "$BRANCH" == "main" ]]; then
echo $(git rev-parse HEAD) > ./.husky/_/history
fi
3 changes: 2 additions & 1 deletion .lintstagedrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
"prettier --write"
],
"tests/**/*.*": "yarn test:front-matter-linter",
"*.{svg,png,jpeg,jpg,gif}": "yarn filecheck"
"*.{svg,png,jpeg,jpg,gif}": "yarn filecheck",
"*": "node scripts/log-url-issues.js"
}
3 changes: 2 additions & 1 deletion .vscode/cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,6 @@
"path": "./project-words.txt",
"addWords": true
}
]
],
"enableFiletypes": ["xml"]
}
1 change: 0 additions & 1 deletion files/en-us/_redirects.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11555,7 +11555,6 @@
/en-US/docs/Web/CSS/calc() /en-US/docs/Web/CSS/calc
/en-US/docs/Web/CSS/clamp() /en-US/docs/Web/CSS/clamp
/en-US/docs/Web/CSS/color-adjust /en-US/docs/Web/CSS/print-color-adjust
/en-US/docs/Web/CSS/color-interpolation /en-US/docs/Web/SVG/Attribute/color-interpolation
/en-US/docs/Web/CSS/color-interpolation-filters /en-US/docs/Web/SVG/Attribute/color-interpolation-filters
/en-US/docs/Web/CSS/color_value/color() /en-US/docs/Web/CSS/color_value/color
/en-US/docs/Web/CSS/color_value/color-contrast() /en-US/docs/Web/CSS/color_value/color-contrast
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ page-type: guide

This is the **3rd step** out of 10 of the [Gamedev Canvas tutorial](/en-US/docs/Games/Tutorials/2D_Breakout_game_pure_JavaScript). You can find the source code as it should look after completing this lesson at [Gamedev-Canvas-workshop/lesson3.html](https://github.com/end3r/Gamedev-Canvas-workshop/blob/gh-pages/lesson03.html).

It is nice to see our ball moving, but it quickly disappears from the screen, limiting the fun we can have with it! To overcome that we will implement some very simple collision detection (which will be explained [later](/en-US/docs/Games/Tutorials/2D_Breakout_game_pure_JavaScript/Collision_detection) in more detail) to make the ball bounce off the four edges of the Canvas.
It is nice to see our ball moving, but it quickly disappears from the screen, limiting the fun we can have with it! To overcome that we will implement some collision detection (which will be explained [later](/en-US/docs/Games/Tutorials/2D_Breakout_game_pure_JavaScript/Collision_detection) in more detail) to make the ball bounce off the four edges of the Canvas.

## Simple collision detection

Expand Down Expand Up @@ -99,7 +99,63 @@ When the distance between the center of the ball and the edge of the wall is exa

Let's again check the finished code for this part against what you've got, and have a play:

{{JSFiddleEmbed("https://jsfiddle.net/end3r/redj37dc/","","395")}}
```html hidden
<canvas id="myCanvas" width="480" height="320"></canvas>
<button id="runButton">Start game</button>
```

```css hidden
canvas {
background: #eee;
}
button {
display: block;
}
```

```js
const canvas = document.getElementById("myCanvas");
const ctx = canvas.getContext("2d");
const ballRadius = 10;
let x = canvas.width / 2;
let y = canvas.height - 30;
let dx = 2;
let dy = -2;

function drawBall() {
ctx.beginPath();
ctx.arc(x, y, ballRadius, 0, Math.PI * 2);
ctx.fillStyle = "#0095DD";
ctx.fill();
ctx.closePath();
}

function draw() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
drawBall();

if (x + dx > canvas.width - ballRadius || x + dx < ballRadius) {
dx = -dx;
}
if (y + dy > canvas.height - ballRadius || y + dy < ballRadius) {
dy = -dy;
}

x += dx;
y += dy;
}

function startGame() {
const interval = setInterval(draw, 10);
}

document.getElementById("runButton").addEventListener("click", function () {
startGame();
this.disabled = true;
});
```

{{embedlivesample("compare_your_code", 600, 360)}}

> **Note:** Try changing the color of the ball to a random color every time it hits the wall.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,147 @@ drawBricks();

At this point, the game has got a little more interesting again:

{{JSFiddleEmbed("https://jsfiddle.net/raymondjplante/Lu3vtejz/","","395")}}
```html hidden
<canvas id="myCanvas" width="480" height="320"></canvas>
<button id="runButton">Start game</button>
```

```css hidden
canvas {
background: #eee;
}
button {
display: block;
}
```

```js hidden
const canvas = document.getElementById("myCanvas");
const ctx = canvas.getContext("2d");
const ballRadius = 10;

let x = canvas.width / 2;
let y = canvas.height - 30;

let dx = 2;
let dy = -2;

const paddleHeight = 10;
const paddleWidth = 75;

let paddleX = (canvas.width - paddleWidth) / 2;
let rightPressed = false;
let leftPressed = false;

const brickRowCount = 3;
const brickColumnCount = 5;
const brickWidth = 75;
const brickHeight = 20;
const brickPadding = 10;
const brickOffsetTop = 30;
const brickOffsetLeft = 30;

let bricks = [];
for (let c = 0; c < brickColumnCount; c++) {
bricks[c] = [];
for (let r = 0; r < brickRowCount; r++) {
bricks[c][r] = { x: 0, y: 0 };
}
}

document.addEventListener("keydown", keyDownHandler, false);
document.addEventListener("keyup", keyUpHandler, false);

function keyDownHandler(e) {
if (e.key == "Right" || e.key == "ArrowRight") {
rightPressed = true;
} else if (e.key == "Left" || e.key == "ArrowLeft") {
leftPressed = true;
}
}

function keyUpHandler(e) {
if (e.key == "Right" || e.key == "ArrowRight") {
rightPressed = false;
} else if (e.key == "Left" || e.key == "ArrowLeft") {
leftPressed = false;
}
}

function drawBall() {
ctx.beginPath();
ctx.arc(x, y, ballRadius, 0, Math.PI * 2);
ctx.fillStyle = "#0095DD";
ctx.fill();
ctx.closePath();
}
function drawPaddle() {
ctx.beginPath();
ctx.rect(paddleX, canvas.height - paddleHeight, paddleWidth, paddleHeight);
ctx.fillStyle = "#0095DD";
ctx.fill();
ctx.closePath();
}
function drawBricks() {
for (let c = 0; c < brickColumnCount; c++) {
for (let r = 0; r < brickRowCount; r++) {
let brickX = c * (brickWidth + brickPadding) + brickOffsetLeft;
let brickY = r * (brickHeight + brickPadding) + brickOffsetTop;
bricks[c][r].x = brickX;
bricks[c][r].y = brickY;
ctx.beginPath();
ctx.rect(brickX, brickY, brickWidth, brickHeight);
ctx.fillStyle = "#0095DD";
ctx.fill();
ctx.closePath();
}
}
}

function draw() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
drawBricks();
drawBall();
drawPaddle();

if (x + dx > canvas.width - ballRadius || x + dx < ballRadius) {
dx = -dx;
}
if (y + dy < ballRadius) {
dy = -dy;
} else if (y + dy > canvas.height - ballRadius) {
if (x > paddleX && x < paddleX + paddleWidth) {
if ((y = y - paddleHeight)) {
dy = -dy;
}
} else {
alert("GAME OVER");
document.location.reload();
clearInterval(interval); // Needed for Chrome to end game
}
}

if (rightPressed && paddleX < canvas.width - paddleWidth) {
paddleX += 7;
} else if (leftPressed && paddleX > 0) {
paddleX -= 7;
}

x += dx;
y += dy;
}

function startGame() {
const interval = setInterval(draw, 10);
}

document.getElementById("runButton").addEventListener("click", function () {
startGame();
this.disabled = true;
});
```

{{embedlivesample("compare_your_code", 600, 360)}}

> **Note:** Try changing the number of bricks in a row or a column, or their positions.
Expand Down
Loading

0 comments on commit 1a076c4

Please sign in to comment.