Skip to content

Commit 292afd3

Browse files
committed
Consistent naming for space game.
1 parent 6ffb345 commit 292afd3

3 files changed

Lines changed: 38 additions & 38 deletions

File tree

‎Projects/space-game/step01/js/game.js‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,34 @@ const GAME_STATE = {
66
playerY: 0,
77
};
88

9-
function setPosition(el, x, y) {
10-
el.style.transform = `translate(${x}px, ${y}px)`;
9+
function setPosition($el, x, y) {
10+
$el.style.transform = `translate(${x}px, ${y}px)`;
1111
}
1212

13-
function createPlayer(container) {
13+
function createPlayer($container) {
1414
GAME_STATE.playerX = GAME_WIDTH / 2;
1515
GAME_STATE.playerY = GAME_HEIGHT - 50;
16-
const player = document.createElement("img");
17-
player.src = "img/player-blue-1.png";
18-
player.className = "player";
19-
container.appendChild(player);
20-
setPosition(player, GAME_STATE.playerX, GAME_STATE.playerY);
16+
const $player = document.createElement("img");
17+
$player.src = "img/player-blue-1.png";
18+
$player.className = "player";
19+
$container.appendChild($player);
20+
setPosition($player, GAME_STATE.playerX, GAME_STATE.playerY);
2121
}
2222

2323
function init() {
24-
const container = document.querySelector(".game");
25-
createPlayer(container);
24+
const $container = document.querySelector(".game");
25+
createPlayer($container);
2626
}
2727

2828
function onKeyPress(e) {
2929
if (e.key === 'a') {
3030
GAME_STATE.playerX -= 5;
31-
const player = document.querySelector(".player");
32-
setPosition(player, GAME_STATE.playerX, GAME_STATE.playerY);
31+
const $player = document.querySelector(".player");
32+
setPosition($player, GAME_STATE.playerX, GAME_STATE.playerY);
3333
} else if (e.key === 'd') {
3434
GAME_STATE.playerX += 5;
35-
const player = document.querySelector(".player");
36-
setPosition(player, GAME_STATE.playerX, GAME_STATE.playerY);
35+
const $player = document.querySelector(".player");
36+
setPosition($player, GAME_STATE.playerX, GAME_STATE.playerY);
3737
}
3838
}
3939

‎Projects/space-game/step02/js/game.js‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ const GAME_STATE = {
1515
playerY: 0,
1616
};
1717

18-
function setPosition(el, x, y) {
19-
el.style.transform = `translate(${x}px, ${y}px)`;
18+
function setPosition($el, x, y) {
19+
$el.style.transform = `translate(${x}px, ${y}px)`;
2020
}
2121

2222
function clamp(v, min, max) {
@@ -29,14 +29,14 @@ function clamp(v, min, max) {
2929
}
3030
}
3131

32-
function createPlayer(container) {
32+
function createPlayer($container) {
3333
GAME_STATE.playerX = GAME_WIDTH / 2;
3434
GAME_STATE.playerY = GAME_HEIGHT - 50;
35-
const player = document.createElement("img");
36-
player.src = "img/player-blue-1.png";
37-
player.className = "player";
38-
container.appendChild(player);
39-
setPosition(player, GAME_STATE.playerX, GAME_STATE.playerY);
35+
const $player = document.createElement("img");
36+
$player.src = "img/player-blue-1.png";
37+
$player.className = "player";
38+
$container.appendChild($player);
39+
setPosition($player, GAME_STATE.playerX, GAME_STATE.playerY);
4040
}
4141

4242
function updatePlayer() {
@@ -53,13 +53,13 @@ function updatePlayer() {
5353
GAME_WIDTH - PLAYER_WIDTH
5454
);
5555

56-
const player = document.querySelector(".player");
57-
setPosition(player, GAME_STATE.playerX, GAME_STATE.playerY);
56+
const $player = document.querySelector(".player");
57+
setPosition($player, GAME_STATE.playerX, GAME_STATE.playerY);
5858
}
5959

6060
function init() {
61-
const container = document.querySelector(".game");
62-
createPlayer(container);
61+
const $container = document.querySelector(".game");
62+
createPlayer($container);
6363
}
6464

6565
function update(e) {

‎Projects/space-game/step03/js/game.js‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ const GAME_STATE = {
1717
playerY: 0,
1818
};
1919

20-
function setPosition(el, x, y) {
21-
el.style.transform = `translate(${x}px, ${y}px)`;
20+
function setPosition($el, x, y) {
21+
$el.style.transform = `translate(${x}px, ${y}px)`;
2222
}
2323

2424
function clamp(v, min, max) {
@@ -31,14 +31,14 @@ function clamp(v, min, max) {
3131
}
3232
}
3333

34-
function createPlayer(container, x, y) {
34+
function createPlayer($container, x, y) {
3535
GAME_STATE.playerX = GAME_WIDTH / 2;
3636
GAME_STATE.playerY = GAME_HEIGHT - 50;
37-
const player = document.createElement("img");
38-
player.src = "img/player-blue-1.png";
39-
player.className = "player";
40-
container.appendChild(player);
41-
setPosition(player, GAME_STATE.playerX, GAME_STATE.playerY);
37+
const $player = document.createElement("img");
38+
$player.src = "img/player-blue-1.png";
39+
$player.className = "player";
40+
$container.appendChild($player);
41+
setPosition($player, GAME_STATE.playerX, GAME_STATE.playerY);
4242
}
4343

4444
function updatePlayer(dt) {
@@ -55,13 +55,13 @@ function updatePlayer(dt) {
5555
GAME_WIDTH - PLAYER_WIDTH
5656
);
5757

58-
const player = document.querySelector(".player");
59-
setPosition(player, GAME_STATE.playerX, GAME_STATE.playerY);
58+
const $player = document.querySelector(".player");
59+
setPosition($player, GAME_STATE.playerX, GAME_STATE.playerY);
6060
}
6161

6262
function init() {
63-
const container = document.querySelector(".game");
64-
createPlayer(container);
63+
const $container = document.querySelector(".game");
64+
createPlayer($container);
6565
}
6666

6767
function update(e) {

0 commit comments

Comments
 (0)