pacman-contribution-graph 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.prettierrc +8 -0
- package/.vscode/extensions.json +5 -0
- package/.vscode/settings.json +6 -0
- package/README.md +20 -0
- package/dist/pacman-contribution-graph.js +1106 -0
- package/dist/pacman-contribution-graph.js.map +1 -0
- package/dist/pacman-contribution-graph.min.js +1 -0
- package/index.html +405 -0
- package/package.json +26 -0
- package/src/assets/sounds/pacman_beginning.wav +0 -0
- package/src/assets/sounds/pacman_chomp.wav +0 -0
- package/src/assets/sounds/pacman_death.wav +0 -0
- package/src/assets/sounds/pacman_eatghost.wav +0 -0
- package/src/canvas.ts +200 -0
- package/src/constants.ts +40 -0
- package/src/game.ts +344 -0
- package/src/index.ts +31 -0
- package/src/music-player.ts +113 -0
- package/src/store.ts +22 -0
- package/src/svg.ts +172 -0
- package/src/types.ts +60 -0
- package/src/utils.ts +47 -0
- package/tsconfig.json +11 -0
- package/webpack.common.js +19 -0
- package/webpack.dev.js +23 -0
- package/webpack.prod.js +18 -0
|
@@ -0,0 +1,1106 @@
|
|
|
1
|
+
/******/ var __webpack_modules__ = ({
|
|
2
|
+
|
|
3
|
+
/***/ "./src/canvas.ts":
|
|
4
|
+
/*!***********************!*\
|
|
5
|
+
!*** ./src/canvas.ts ***!
|
|
6
|
+
\***********************/
|
|
7
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
8
|
+
|
|
9
|
+
__webpack_require__.r(__webpack_exports__);
|
|
10
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
11
|
+
/* harmony export */ Canvas: () => (/* binding */ Canvas)
|
|
12
|
+
/* harmony export */ });
|
|
13
|
+
/* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./constants */ "./src/constants.ts");
|
|
14
|
+
/* harmony import */ var _music_player__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./music-player */ "./src/music-player.ts");
|
|
15
|
+
/* harmony import */ var _store__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./store */ "./src/store.ts");
|
|
16
|
+
/* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./utils */ "./src/utils.ts");
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
const resizeCanvas = () => {
|
|
22
|
+
const canvasWidth = _constants__WEBPACK_IMPORTED_MODULE_0__.GRID_WIDTH * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE);
|
|
23
|
+
const canvasHeight = _constants__WEBPACK_IMPORTED_MODULE_0__.GRID_HEIGHT * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE) + 20; // Adding some space for months on top
|
|
24
|
+
_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.width = canvasWidth;
|
|
25
|
+
_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.height = canvasHeight;
|
|
26
|
+
};
|
|
27
|
+
const drawGrid = () => {
|
|
28
|
+
_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').fillStyle = _utils__WEBPACK_IMPORTED_MODULE_3__.Utils.getCurrentTheme().gridBackground;
|
|
29
|
+
_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').fillRect(0, 0, _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.width, _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.height);
|
|
30
|
+
for (let x = 0; x < _constants__WEBPACK_IMPORTED_MODULE_0__.GRID_HEIGHT; x++) {
|
|
31
|
+
for (let y = 0; y < _constants__WEBPACK_IMPORTED_MODULE_0__.GRID_WIDTH; y++) {
|
|
32
|
+
const intensity = _store__WEBPACK_IMPORTED_MODULE_2__.Store.grid[x][y];
|
|
33
|
+
if (intensity > 0) {
|
|
34
|
+
const adjustedIntensity = intensity < 0.2 ? 0.3 : intensity;
|
|
35
|
+
const color = _utils__WEBPACK_IMPORTED_MODULE_3__.Utils.hexToRGBA(_utils__WEBPACK_IMPORTED_MODULE_3__.Utils.getCurrentTheme().contributionBoxColor, adjustedIntensity);
|
|
36
|
+
_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').fillStyle = color;
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').fillStyle = _utils__WEBPACK_IMPORTED_MODULE_3__.Utils.getCurrentTheme().emptyContributionBoxColor;
|
|
40
|
+
}
|
|
41
|
+
_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').beginPath();
|
|
42
|
+
_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas
|
|
43
|
+
.getContext('2d')
|
|
44
|
+
.roundRect(y * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE), x * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE) + 15, _constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE, _constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE, 5);
|
|
45
|
+
_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').fill();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').fillStyle = _utils__WEBPACK_IMPORTED_MODULE_3__.Utils.getCurrentTheme().textColor;
|
|
49
|
+
_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').font = '10px Arial';
|
|
50
|
+
_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').textAlign = 'center';
|
|
51
|
+
let lastMonth = '';
|
|
52
|
+
for (let y = 0; y < _constants__WEBPACK_IMPORTED_MODULE_0__.GRID_WIDTH; y++) {
|
|
53
|
+
if (_store__WEBPACK_IMPORTED_MODULE_2__.Store.monthLabels[y] !== lastMonth) {
|
|
54
|
+
const xPos = y * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE) + _constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE / 2;
|
|
55
|
+
_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').fillText(_store__WEBPACK_IMPORTED_MODULE_2__.Store.monthLabels[y], xPos, 10);
|
|
56
|
+
lastMonth = _store__WEBPACK_IMPORTED_MODULE_2__.Store.monthLabels[y];
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
const drawPacman = () => {
|
|
61
|
+
const x = _store__WEBPACK_IMPORTED_MODULE_2__.Store.pacman.y * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE) + _constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE / 2;
|
|
62
|
+
const y = _store__WEBPACK_IMPORTED_MODULE_2__.Store.pacman.x * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE) + _constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE / 2 + 15;
|
|
63
|
+
const radius = _constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE / 2;
|
|
64
|
+
// Change Pac-Man's color to red if he's on power-up, dead, else yellow
|
|
65
|
+
if (_store__WEBPACK_IMPORTED_MODULE_2__.Store.pacman.deadReaminingDuration) {
|
|
66
|
+
_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').fillStyle = _constants__WEBPACK_IMPORTED_MODULE_0__.PACMAN_COLOR_DEAD;
|
|
67
|
+
}
|
|
68
|
+
else if (_store__WEBPACK_IMPORTED_MODULE_2__.Store.pacman.powerupReaminingDuration) {
|
|
69
|
+
_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').fillStyle = _constants__WEBPACK_IMPORTED_MODULE_0__.PACMAN_COLOR_POWERUP;
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').fillStyle = _constants__WEBPACK_IMPORTED_MODULE_0__.PACMAN_COLOR;
|
|
73
|
+
}
|
|
74
|
+
const mouthAngle = _store__WEBPACK_IMPORTED_MODULE_2__.Store.pacmanMouthOpen ? 0.35 * Math.PI : 0.1 * Math.PI;
|
|
75
|
+
let startAngle, endAngle;
|
|
76
|
+
switch (_store__WEBPACK_IMPORTED_MODULE_2__.Store.pacman.direction) {
|
|
77
|
+
case 'up':
|
|
78
|
+
startAngle = 1.5 * Math.PI + mouthAngle;
|
|
79
|
+
endAngle = 1.5 * Math.PI - mouthAngle;
|
|
80
|
+
break;
|
|
81
|
+
case 'down':
|
|
82
|
+
startAngle = 0.5 * Math.PI + mouthAngle;
|
|
83
|
+
endAngle = 0.5 * Math.PI - mouthAngle;
|
|
84
|
+
break;
|
|
85
|
+
case 'left':
|
|
86
|
+
startAngle = Math.PI + mouthAngle;
|
|
87
|
+
endAngle = Math.PI - mouthAngle;
|
|
88
|
+
break;
|
|
89
|
+
case 'right':
|
|
90
|
+
default:
|
|
91
|
+
startAngle = 0 + mouthAngle;
|
|
92
|
+
endAngle = 2 * Math.PI - mouthAngle;
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').beginPath();
|
|
96
|
+
_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').arc(x, y, radius, startAngle, endAngle);
|
|
97
|
+
_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').lineTo(x, y);
|
|
98
|
+
_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').fill();
|
|
99
|
+
};
|
|
100
|
+
const drawGhosts = () => {
|
|
101
|
+
_store__WEBPACK_IMPORTED_MODULE_2__.Store.ghosts.forEach((ghost) => {
|
|
102
|
+
const x = ghost.y * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE) + _constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE / 2;
|
|
103
|
+
const y = ghost.x * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE) + _constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE / 2 + 15;
|
|
104
|
+
const radius = _constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE / 2;
|
|
105
|
+
_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').fillStyle = ghost.scared ? 'blue' : ghost.color;
|
|
106
|
+
_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').beginPath();
|
|
107
|
+
_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').arc(x, y, radius, 0, Math.PI);
|
|
108
|
+
_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').rect(x - radius, y, radius * 2, radius);
|
|
109
|
+
_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').fill();
|
|
110
|
+
_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').fillStyle = 'white';
|
|
111
|
+
_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').beginPath();
|
|
112
|
+
_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').arc(x - radius / 3, y - radius / 3, radius / 4, 0, Math.PI * 2);
|
|
113
|
+
_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').arc(x + radius / 3, y - radius / 3, radius / 4, 0, Math.PI * 2);
|
|
114
|
+
_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').fill();
|
|
115
|
+
_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').fillStyle = 'black';
|
|
116
|
+
_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').beginPath();
|
|
117
|
+
_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').arc(x - radius / 3, y - radius / 3, radius / 8, 0, Math.PI * 2);
|
|
118
|
+
_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').arc(x + radius / 3, y - radius / 3, radius / 8, 0, Math.PI * 2);
|
|
119
|
+
_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').fill();
|
|
120
|
+
});
|
|
121
|
+
};
|
|
122
|
+
const renderGameOver = () => {
|
|
123
|
+
_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').fillStyle = 'black';
|
|
124
|
+
_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').font = '20px Arial';
|
|
125
|
+
_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').textAlign = 'center';
|
|
126
|
+
_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').fillText('Game Over', _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.width / 2, _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.height / 2);
|
|
127
|
+
};
|
|
128
|
+
const drawSoundController = () => {
|
|
129
|
+
if (!_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.enableSounds) {
|
|
130
|
+
console.log('vvvv');
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
const width = 30, height = 30, left = _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.width - width - 10, top = 10;
|
|
134
|
+
_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').fillStyle = `rgba(0, 0, 0, ${_music_player__WEBPACK_IMPORTED_MODULE_1__.MusicPlayer.getInstance().isMuted ? 0.3 : 0.5})`;
|
|
135
|
+
_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').beginPath();
|
|
136
|
+
_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').moveTo(left + 10, top + 10);
|
|
137
|
+
_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').lineTo(left + 20, top + 5);
|
|
138
|
+
_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').lineTo(left + 20, top + 25);
|
|
139
|
+
_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').lineTo(left + 10, top + 20);
|
|
140
|
+
_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').closePath();
|
|
141
|
+
_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').fill();
|
|
142
|
+
if (!_music_player__WEBPACK_IMPORTED_MODULE_1__.MusicPlayer.getInstance().isMuted) {
|
|
143
|
+
_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').strokeStyle = `rgba(0, 0, 0, 0.4)`;
|
|
144
|
+
_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').lineWidth = 2;
|
|
145
|
+
// First wave
|
|
146
|
+
_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').beginPath();
|
|
147
|
+
_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').arc(left + 25, top + 15, 5, 0, Math.PI * 2);
|
|
148
|
+
_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').stroke();
|
|
149
|
+
// Second wave
|
|
150
|
+
_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').beginPath();
|
|
151
|
+
_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').arc(left + 25, top + 15, 8, 0, Math.PI * 2);
|
|
152
|
+
_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').stroke();
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
// Mute line
|
|
156
|
+
_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').strokeStyle = 'rgba(255, 0, 0, 0.6)';
|
|
157
|
+
_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').lineWidth = 3;
|
|
158
|
+
_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').beginPath();
|
|
159
|
+
_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').moveTo(left + 25, top + 5);
|
|
160
|
+
_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').lineTo(left + 5, top + 25);
|
|
161
|
+
_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').stroke();
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
const listenToSoundController = () => {
|
|
165
|
+
if (!_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.enableSounds) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.addEventListener('click', function (event) {
|
|
169
|
+
const rect = _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getBoundingClientRect();
|
|
170
|
+
const x = event.clientX - rect.left, y = event.clientY - rect.top;
|
|
171
|
+
const width = 30, height = 30, left = _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.width - width - 10, top = 10;
|
|
172
|
+
if (x >= left && x <= left + this.width && y >= top && y <= top + this.height) {
|
|
173
|
+
if (_music_player__WEBPACK_IMPORTED_MODULE_1__.MusicPlayer.getInstance().isMuted) {
|
|
174
|
+
_music_player__WEBPACK_IMPORTED_MODULE_1__.MusicPlayer.getInstance().unmute();
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
_music_player__WEBPACK_IMPORTED_MODULE_1__.MusicPlayer.getInstance().mute();
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
};
|
|
182
|
+
const Canvas = {
|
|
183
|
+
resizeCanvas,
|
|
184
|
+
drawGrid,
|
|
185
|
+
drawPacman,
|
|
186
|
+
drawGhosts,
|
|
187
|
+
renderGameOver,
|
|
188
|
+
drawSoundController,
|
|
189
|
+
listenToSoundController
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
/***/ }),
|
|
194
|
+
|
|
195
|
+
/***/ "./src/constants.ts":
|
|
196
|
+
/*!**************************!*\
|
|
197
|
+
!*** ./src/constants.ts ***!
|
|
198
|
+
\**************************/
|
|
199
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
200
|
+
|
|
201
|
+
__webpack_require__.r(__webpack_exports__);
|
|
202
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
203
|
+
/* harmony export */ CELL_SIZE: () => (/* binding */ CELL_SIZE),
|
|
204
|
+
/* harmony export */ DELTA_TIME: () => (/* binding */ DELTA_TIME),
|
|
205
|
+
/* harmony export */ GAME_THEMES: () => (/* binding */ GAME_THEMES),
|
|
206
|
+
/* harmony export */ GAP_SIZE: () => (/* binding */ GAP_SIZE),
|
|
207
|
+
/* harmony export */ GHOST_COLORS: () => (/* binding */ GHOST_COLORS),
|
|
208
|
+
/* harmony export */ GRID_HEIGHT: () => (/* binding */ GRID_HEIGHT),
|
|
209
|
+
/* harmony export */ GRID_WIDTH: () => (/* binding */ GRID_WIDTH),
|
|
210
|
+
/* harmony export */ MONTHS: () => (/* binding */ MONTHS),
|
|
211
|
+
/* harmony export */ PACMAN_COLOR: () => (/* binding */ PACMAN_COLOR),
|
|
212
|
+
/* harmony export */ PACMAN_COLOR_DEAD: () => (/* binding */ PACMAN_COLOR_DEAD),
|
|
213
|
+
/* harmony export */ PACMAN_COLOR_POWERUP: () => (/* binding */ PACMAN_COLOR_POWERUP),
|
|
214
|
+
/* harmony export */ PACMAN_DEATH_DURATION: () => (/* binding */ PACMAN_DEATH_DURATION),
|
|
215
|
+
/* harmony export */ PACMAN_POWERUP_DURATION: () => (/* binding */ PACMAN_POWERUP_DURATION)
|
|
216
|
+
/* harmony export */ });
|
|
217
|
+
const CELL_SIZE = 20;
|
|
218
|
+
const GAP_SIZE = 2;
|
|
219
|
+
const GRID_WIDTH = 52;
|
|
220
|
+
const GRID_HEIGHT = 7;
|
|
221
|
+
const PACMAN_COLOR = 'yellow';
|
|
222
|
+
const PACMAN_COLOR_POWERUP = 'red';
|
|
223
|
+
const PACMAN_COLOR_DEAD = '#80808064';
|
|
224
|
+
const GHOST_COLORS = ['red', 'pink', 'cyan', 'orange'];
|
|
225
|
+
const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
226
|
+
const DELTA_TIME = 250;
|
|
227
|
+
const PACMAN_DEATH_DURATION = 10;
|
|
228
|
+
const PACMAN_POWERUP_DURATION = 15;
|
|
229
|
+
const GAME_THEMES = {
|
|
230
|
+
github: {
|
|
231
|
+
textColor: '#586069',
|
|
232
|
+
gridBackground: '#ffffff',
|
|
233
|
+
contributionBoxColor: '#9be9a8',
|
|
234
|
+
emptyContributionBoxColor: '#ebedf0'
|
|
235
|
+
},
|
|
236
|
+
'github-dark': {
|
|
237
|
+
textColor: '#8b949e',
|
|
238
|
+
gridBackground: '#0d1117',
|
|
239
|
+
contributionBoxColor: '#26a641',
|
|
240
|
+
emptyContributionBoxColor: '#161b22'
|
|
241
|
+
},
|
|
242
|
+
gitlab: {
|
|
243
|
+
textColor: '#626167',
|
|
244
|
+
gridBackground: '#ffffff',
|
|
245
|
+
contributionBoxColor: '#7992f5',
|
|
246
|
+
emptyContributionBoxColor: '#ececef'
|
|
247
|
+
},
|
|
248
|
+
'gitlab-dark': {
|
|
249
|
+
textColor: '#999999',
|
|
250
|
+
gridBackground: '#1f1f1f',
|
|
251
|
+
contributionBoxColor: '#2e7db1',
|
|
252
|
+
emptyContributionBoxColor: '#2d2d2d'
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
/***/ }),
|
|
258
|
+
|
|
259
|
+
/***/ "./src/game.ts":
|
|
260
|
+
/*!*********************!*\
|
|
261
|
+
!*** ./src/game.ts ***!
|
|
262
|
+
\*********************/
|
|
263
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
264
|
+
|
|
265
|
+
__webpack_require__.r(__webpack_exports__);
|
|
266
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
267
|
+
/* harmony export */ Game: () => (/* binding */ Game)
|
|
268
|
+
/* harmony export */ });
|
|
269
|
+
/* harmony import */ var _canvas__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./canvas */ "./src/canvas.ts");
|
|
270
|
+
/* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./constants */ "./src/constants.ts");
|
|
271
|
+
/* harmony import */ var _music_player__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./music-player */ "./src/music-player.ts");
|
|
272
|
+
/* harmony import */ var _store__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./store */ "./src/store.ts");
|
|
273
|
+
/* harmony import */ var _svg__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./svg */ "./src/svg.ts");
|
|
274
|
+
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
275
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
276
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
277
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
278
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
279
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
280
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
281
|
+
});
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
const initializeGrid = () => {
|
|
289
|
+
_store__WEBPACK_IMPORTED_MODULE_3__.Store.grid = Array.from({ length: _constants__WEBPACK_IMPORTED_MODULE_1__.GRID_HEIGHT }, () => Array.from({ length: _constants__WEBPACK_IMPORTED_MODULE_1__.GRID_WIDTH }, () => 0));
|
|
290
|
+
_store__WEBPACK_IMPORTED_MODULE_3__.Store.monthLabels = Array(_constants__WEBPACK_IMPORTED_MODULE_1__.GRID_WIDTH).fill('');
|
|
291
|
+
let maxCommits = 1;
|
|
292
|
+
const now = new Date();
|
|
293
|
+
const startOfCurrentWeek = new Date(now);
|
|
294
|
+
startOfCurrentWeek.setDate(now.getDate() - now.getDay());
|
|
295
|
+
_store__WEBPACK_IMPORTED_MODULE_3__.Store.contributions.forEach((contribution) => {
|
|
296
|
+
const contributionDate = new Date(contribution.date);
|
|
297
|
+
const dayOfWeek = contributionDate.getDay();
|
|
298
|
+
const weeksAgo = Math.floor((+startOfCurrentWeek - +contributionDate) / (1000 * 60 * 60 * 24 * 7));
|
|
299
|
+
if (weeksAgo >= 0 && weeksAgo < _constants__WEBPACK_IMPORTED_MODULE_1__.GRID_WIDTH && dayOfWeek >= 0 && dayOfWeek < _constants__WEBPACK_IMPORTED_MODULE_1__.GRID_HEIGHT) {
|
|
300
|
+
_store__WEBPACK_IMPORTED_MODULE_3__.Store.grid[dayOfWeek][_constants__WEBPACK_IMPORTED_MODULE_1__.GRID_WIDTH - 1 - weeksAgo] = contribution.count;
|
|
301
|
+
if (contribution.count > maxCommits)
|
|
302
|
+
maxCommits = contribution.count;
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
for (let x = 0; x < _constants__WEBPACK_IMPORTED_MODULE_1__.GRID_HEIGHT; x++) {
|
|
306
|
+
for (let y = 0; y < _constants__WEBPACK_IMPORTED_MODULE_1__.GRID_WIDTH; y++) {
|
|
307
|
+
if (_store__WEBPACK_IMPORTED_MODULE_3__.Store.grid[x][y] > 0) {
|
|
308
|
+
_store__WEBPACK_IMPORTED_MODULE_3__.Store.grid[x][y] = _store__WEBPACK_IMPORTED_MODULE_3__.Store.grid[x][y] / maxCommits;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
for (let y = 0; y < _constants__WEBPACK_IMPORTED_MODULE_1__.GRID_WIDTH; y++) {
|
|
313
|
+
const weeksAgo = _constants__WEBPACK_IMPORTED_MODULE_1__.GRID_WIDTH - 1 - y;
|
|
314
|
+
const columnDate = new Date(startOfCurrentWeek);
|
|
315
|
+
columnDate.setDate(columnDate.getDate() - weeksAgo * 7);
|
|
316
|
+
_store__WEBPACK_IMPORTED_MODULE_3__.Store.monthLabels[y] = _constants__WEBPACK_IMPORTED_MODULE_1__.MONTHS[columnDate.getMonth()];
|
|
317
|
+
}
|
|
318
|
+
};
|
|
319
|
+
const placePacman = () => {
|
|
320
|
+
let validCells = [];
|
|
321
|
+
for (let x = 0; x < _constants__WEBPACK_IMPORTED_MODULE_1__.GRID_HEIGHT; x++) {
|
|
322
|
+
for (let y = 0; y < _constants__WEBPACK_IMPORTED_MODULE_1__.GRID_WIDTH; y++) {
|
|
323
|
+
if (_store__WEBPACK_IMPORTED_MODULE_3__.Store.grid[x][y] > 0)
|
|
324
|
+
validCells.push({ x, y });
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
if (validCells.length > 0) {
|
|
328
|
+
const randomCell = validCells[Math.floor(Math.random() * validCells.length)];
|
|
329
|
+
_store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman = {
|
|
330
|
+
x: randomCell.x,
|
|
331
|
+
y: randomCell.y,
|
|
332
|
+
direction: 'right',
|
|
333
|
+
points: 0,
|
|
334
|
+
deadReaminingDuration: 0,
|
|
335
|
+
powerupReaminingDuration: 0
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
if (_store__WEBPACK_IMPORTED_MODULE_3__.Store.config.outputFormat == 'canvas')
|
|
339
|
+
_canvas__WEBPACK_IMPORTED_MODULE_0__.Canvas.drawPacman();
|
|
340
|
+
};
|
|
341
|
+
const placeGhosts = () => {
|
|
342
|
+
_store__WEBPACK_IMPORTED_MODULE_3__.Store.ghosts = [];
|
|
343
|
+
_store__WEBPACK_IMPORTED_MODULE_3__.Store.scaredGhostsDestinations = [];
|
|
344
|
+
// Create 4 ghosts
|
|
345
|
+
for (let i = 0; i < 4; i++) {
|
|
346
|
+
const color = _constants__WEBPACK_IMPORTED_MODULE_1__.GHOST_COLORS[i % _constants__WEBPACK_IMPORTED_MODULE_1__.GHOST_COLORS.length];
|
|
347
|
+
let x, y;
|
|
348
|
+
do {
|
|
349
|
+
x = Math.floor(Math.random() * _constants__WEBPACK_IMPORTED_MODULE_1__.GRID_HEIGHT);
|
|
350
|
+
y = Math.floor(Math.random() * _constants__WEBPACK_IMPORTED_MODULE_1__.GRID_WIDTH);
|
|
351
|
+
} while (_store__WEBPACK_IMPORTED_MODULE_3__.Store.grid[x][y] === 0);
|
|
352
|
+
_store__WEBPACK_IMPORTED_MODULE_3__.Store.ghosts.push({ x, y, color, scared: false, target: undefined });
|
|
353
|
+
_store__WEBPACK_IMPORTED_MODULE_3__.Store.scaredGhostsDestinations.push({ x: 0, y: 0 });
|
|
354
|
+
}
|
|
355
|
+
if (_store__WEBPACK_IMPORTED_MODULE_3__.Store.config.outputFormat == 'canvas')
|
|
356
|
+
_canvas__WEBPACK_IMPORTED_MODULE_0__.Canvas.drawGhosts();
|
|
357
|
+
};
|
|
358
|
+
const startGame = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
359
|
+
if (_store__WEBPACK_IMPORTED_MODULE_3__.Store.config.outputFormat == 'canvas') {
|
|
360
|
+
_store__WEBPACK_IMPORTED_MODULE_3__.Store.config.canvas = _store__WEBPACK_IMPORTED_MODULE_3__.Store.config.canvas;
|
|
361
|
+
_canvas__WEBPACK_IMPORTED_MODULE_0__.Canvas.resizeCanvas();
|
|
362
|
+
_canvas__WEBPACK_IMPORTED_MODULE_0__.Canvas.listenToSoundController();
|
|
363
|
+
}
|
|
364
|
+
_store__WEBPACK_IMPORTED_MODULE_3__.Store.frameCount = 0;
|
|
365
|
+
_store__WEBPACK_IMPORTED_MODULE_3__.Store.ghosts.forEach((ghost) => (ghost.scared = false));
|
|
366
|
+
initializeGrid();
|
|
367
|
+
if (_store__WEBPACK_IMPORTED_MODULE_3__.Store.config.outputFormat == 'canvas')
|
|
368
|
+
_canvas__WEBPACK_IMPORTED_MODULE_0__.Canvas.drawGrid();
|
|
369
|
+
if (_store__WEBPACK_IMPORTED_MODULE_3__.Store.config.outputFormat == 'canvas') {
|
|
370
|
+
if (!_store__WEBPACK_IMPORTED_MODULE_3__.Store.config.enableSounds) {
|
|
371
|
+
_music_player__WEBPACK_IMPORTED_MODULE_2__.MusicPlayer.getInstance().mute();
|
|
372
|
+
}
|
|
373
|
+
yield _music_player__WEBPACK_IMPORTED_MODULE_2__.MusicPlayer.getInstance().preloadSounds();
|
|
374
|
+
_music_player__WEBPACK_IMPORTED_MODULE_2__.MusicPlayer.getInstance().startDefaultSound();
|
|
375
|
+
yield _music_player__WEBPACK_IMPORTED_MODULE_2__.MusicPlayer.getInstance().play(_music_player__WEBPACK_IMPORTED_MODULE_2__.Sound.BEGINNING);
|
|
376
|
+
}
|
|
377
|
+
placePacman();
|
|
378
|
+
placeGhosts();
|
|
379
|
+
if (_store__WEBPACK_IMPORTED_MODULE_3__.Store.config.outputFormat == 'svg') {
|
|
380
|
+
const remainingCells = () => _store__WEBPACK_IMPORTED_MODULE_3__.Store.grid.some((row) => row.some((cell) => cell > 0));
|
|
381
|
+
while (remainingCells()) {
|
|
382
|
+
yield updateGame();
|
|
383
|
+
}
|
|
384
|
+
// One more time to generate svg
|
|
385
|
+
yield updateGame();
|
|
386
|
+
}
|
|
387
|
+
else {
|
|
388
|
+
clearInterval(_store__WEBPACK_IMPORTED_MODULE_3__.Store.gameInterval);
|
|
389
|
+
_store__WEBPACK_IMPORTED_MODULE_3__.Store.gameInterval = setInterval(() => __awaiter(void 0, void 0, void 0, function* () { return yield updateGame(); }), _constants__WEBPACK_IMPORTED_MODULE_1__.DELTA_TIME);
|
|
390
|
+
}
|
|
391
|
+
});
|
|
392
|
+
const updateGame = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
393
|
+
_store__WEBPACK_IMPORTED_MODULE_3__.Store.frameCount++;
|
|
394
|
+
if (_store__WEBPACK_IMPORTED_MODULE_3__.Store.frameCount % _store__WEBPACK_IMPORTED_MODULE_3__.Store.config.gameSpeed !== 0) {
|
|
395
|
+
_store__WEBPACK_IMPORTED_MODULE_3__.Store.gameHistory.push({
|
|
396
|
+
pacman: Object.assign({}, _store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman),
|
|
397
|
+
ghosts: _store__WEBPACK_IMPORTED_MODULE_3__.Store.ghosts.map((ghost) => (Object.assign({}, ghost))),
|
|
398
|
+
grid: _store__WEBPACK_IMPORTED_MODULE_3__.Store.grid.map((row) => [...row])
|
|
399
|
+
});
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
if (_store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.deadReaminingDuration) {
|
|
403
|
+
_store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.deadReaminingDuration--;
|
|
404
|
+
if (!_store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.deadReaminingDuration) {
|
|
405
|
+
// IT'S ALIVE!
|
|
406
|
+
if (_store__WEBPACK_IMPORTED_MODULE_3__.Store.config.outputFormat == 'canvas')
|
|
407
|
+
_music_player__WEBPACK_IMPORTED_MODULE_2__.MusicPlayer.getInstance()
|
|
408
|
+
.play(_music_player__WEBPACK_IMPORTED_MODULE_2__.Sound.GAME_OVER)
|
|
409
|
+
.then(() => _music_player__WEBPACK_IMPORTED_MODULE_2__.MusicPlayer.getInstance().startDefaultSound());
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
if (_store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.powerupReaminingDuration) {
|
|
413
|
+
_store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.powerupReaminingDuration--;
|
|
414
|
+
if (!_store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.powerupReaminingDuration) {
|
|
415
|
+
_store__WEBPACK_IMPORTED_MODULE_3__.Store.ghosts.forEach((ghost) => (ghost.scared = false));
|
|
416
|
+
_store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.points = 0;
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
const remainingCells = _store__WEBPACK_IMPORTED_MODULE_3__.Store.grid.some((row) => row.some((cell) => cell > 0));
|
|
420
|
+
if (!remainingCells) {
|
|
421
|
+
if (_store__WEBPACK_IMPORTED_MODULE_3__.Store.config.outputFormat == 'canvas') {
|
|
422
|
+
clearInterval(_store__WEBPACK_IMPORTED_MODULE_3__.Store.gameInterval);
|
|
423
|
+
if (_store__WEBPACK_IMPORTED_MODULE_3__.Store.config.outputFormat == 'canvas') {
|
|
424
|
+
_canvas__WEBPACK_IMPORTED_MODULE_0__.Canvas.renderGameOver();
|
|
425
|
+
_music_player__WEBPACK_IMPORTED_MODULE_2__.MusicPlayer.getInstance()
|
|
426
|
+
.play(_music_player__WEBPACK_IMPORTED_MODULE_2__.Sound.BEGINNING)
|
|
427
|
+
.then(() => _music_player__WEBPACK_IMPORTED_MODULE_2__.MusicPlayer.getInstance().stopDefaultSound());
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
if (_store__WEBPACK_IMPORTED_MODULE_3__.Store.config.outputFormat == 'svg') {
|
|
431
|
+
const animatedSVG = _svg__WEBPACK_IMPORTED_MODULE_4__.SVG.generateAnimatedSVG();
|
|
432
|
+
const svgBlob = new Blob([animatedSVG], {
|
|
433
|
+
type: 'image/svg+xml;charset=utf-8'
|
|
434
|
+
});
|
|
435
|
+
const svgUrl = URL.createObjectURL(svgBlob);
|
|
436
|
+
_store__WEBPACK_IMPORTED_MODULE_3__.Store.config.svgCallback(svgUrl);
|
|
437
|
+
}
|
|
438
|
+
_store__WEBPACK_IMPORTED_MODULE_3__.Store.config.gameOverCallback();
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
movePacman();
|
|
442
|
+
moveGhosts();
|
|
443
|
+
checkCollisions();
|
|
444
|
+
_store__WEBPACK_IMPORTED_MODULE_3__.Store.pacmanMouthOpen = !_store__WEBPACK_IMPORTED_MODULE_3__.Store.pacmanMouthOpen;
|
|
445
|
+
_store__WEBPACK_IMPORTED_MODULE_3__.Store.gameHistory.push({
|
|
446
|
+
pacman: Object.assign({}, _store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman),
|
|
447
|
+
ghosts: _store__WEBPACK_IMPORTED_MODULE_3__.Store.ghosts.map((ghost) => (Object.assign({}, ghost))),
|
|
448
|
+
grid: _store__WEBPACK_IMPORTED_MODULE_3__.Store.grid.map((row) => [...row])
|
|
449
|
+
});
|
|
450
|
+
if (_store__WEBPACK_IMPORTED_MODULE_3__.Store.config.outputFormat == 'canvas')
|
|
451
|
+
_canvas__WEBPACK_IMPORTED_MODULE_0__.Canvas.drawGrid();
|
|
452
|
+
if (_store__WEBPACK_IMPORTED_MODULE_3__.Store.config.outputFormat == 'canvas')
|
|
453
|
+
_canvas__WEBPACK_IMPORTED_MODULE_0__.Canvas.drawPacman();
|
|
454
|
+
if (_store__WEBPACK_IMPORTED_MODULE_3__.Store.config.outputFormat == 'canvas')
|
|
455
|
+
_canvas__WEBPACK_IMPORTED_MODULE_0__.Canvas.drawGhosts();
|
|
456
|
+
if (_store__WEBPACK_IMPORTED_MODULE_3__.Store.config.outputFormat == 'canvas')
|
|
457
|
+
_canvas__WEBPACK_IMPORTED_MODULE_0__.Canvas.drawSoundController();
|
|
458
|
+
});
|
|
459
|
+
const movePacman = () => {
|
|
460
|
+
if (_store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.deadReaminingDuration) {
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
463
|
+
let targetCells = [];
|
|
464
|
+
if (_store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.powerupReaminingDuration) {
|
|
465
|
+
targetCells = _store__WEBPACK_IMPORTED_MODULE_3__.Store.ghosts.map((ghost) => ({
|
|
466
|
+
x: ghost.x,
|
|
467
|
+
y: ghost.y,
|
|
468
|
+
distance: Infinity
|
|
469
|
+
}));
|
|
470
|
+
}
|
|
471
|
+
else {
|
|
472
|
+
for (let x = 0; x < _constants__WEBPACK_IMPORTED_MODULE_1__.GRID_HEIGHT; x++) {
|
|
473
|
+
for (let y = 0; y < _constants__WEBPACK_IMPORTED_MODULE_1__.GRID_WIDTH; y++) {
|
|
474
|
+
if (_store__WEBPACK_IMPORTED_MODULE_3__.Store.grid[x][y] > 0)
|
|
475
|
+
targetCells.push({ x, y, distance: Infinity });
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
if (targetCells.length === 0)
|
|
480
|
+
return;
|
|
481
|
+
const closest = targetCells.reduce((closest, cell) => {
|
|
482
|
+
const distance = Math.abs(cell.x - _store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.x) + Math.abs(cell.y - _store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.y);
|
|
483
|
+
return distance < closest.distance ? Object.assign(Object.assign({}, cell), { distance }) : closest;
|
|
484
|
+
}, { x: _store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.x, y: _store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.y, distance: Infinity });
|
|
485
|
+
const dx = closest.x - _store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.x;
|
|
486
|
+
const dy = closest.y - _store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.y;
|
|
487
|
+
if (Math.abs(dx) > Math.abs(dy)) {
|
|
488
|
+
_store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.x += Math.sign(dx);
|
|
489
|
+
_store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.direction = dx > 0 ? 'down' : 'up';
|
|
490
|
+
}
|
|
491
|
+
else {
|
|
492
|
+
_store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.y += Math.sign(dy);
|
|
493
|
+
_store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.direction = dy > 0 ? 'right' : 'left';
|
|
494
|
+
}
|
|
495
|
+
if (_store__WEBPACK_IMPORTED_MODULE_3__.Store.grid[_store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.x][_store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.y] > 0) {
|
|
496
|
+
_store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.points += 1;
|
|
497
|
+
_store__WEBPACK_IMPORTED_MODULE_3__.Store.grid[_store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.x][_store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.y] = 0;
|
|
498
|
+
if (_store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.points >= 30)
|
|
499
|
+
activatePowerUp();
|
|
500
|
+
}
|
|
501
|
+
};
|
|
502
|
+
const moveGhosts = () => {
|
|
503
|
+
_store__WEBPACK_IMPORTED_MODULE_3__.Store.ghosts.forEach((ghost, index) => {
|
|
504
|
+
if (ghost.scared) {
|
|
505
|
+
if (!ghost.target) {
|
|
506
|
+
ghost.target = getRandomDestination(ghost.x, ghost.y);
|
|
507
|
+
}
|
|
508
|
+
const dx = ghost.target.x - ghost.x;
|
|
509
|
+
const dy = ghost.target.y - ghost.y;
|
|
510
|
+
const moveX = Math.abs(dx) > Math.abs(dy) ? Math.sign(dx) : 0;
|
|
511
|
+
const moveY = Math.abs(dy) >= Math.abs(dx) ? Math.sign(dy) : 0;
|
|
512
|
+
const newX = ghost.x + moveX;
|
|
513
|
+
const newY = ghost.y + moveY;
|
|
514
|
+
if (newX >= 0 && newX < _constants__WEBPACK_IMPORTED_MODULE_1__.GRID_HEIGHT && newY >= 0 && newY < _constants__WEBPACK_IMPORTED_MODULE_1__.GRID_WIDTH) {
|
|
515
|
+
ghost.x = newX;
|
|
516
|
+
ghost.y = newY;
|
|
517
|
+
}
|
|
518
|
+
if (ghost.x === ghost.target.x && ghost.y === ghost.target.y) {
|
|
519
|
+
ghost.target = getRandomDestination(ghost.x, ghost.y);
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
else {
|
|
523
|
+
const directions = [
|
|
524
|
+
[-1, 0],
|
|
525
|
+
[1, 0],
|
|
526
|
+
[0, -1],
|
|
527
|
+
[0, 1]
|
|
528
|
+
];
|
|
529
|
+
const [dx, dy] = directions[Math.floor(Math.random() * directions.length)];
|
|
530
|
+
// If Pacman has the power-up, ghosts move slower (move every other frame)
|
|
531
|
+
if (_store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.powerupReaminingDuration && Math.random() < 0.5)
|
|
532
|
+
return;
|
|
533
|
+
const newX = ghost.x + dx;
|
|
534
|
+
const newY = ghost.y + dy;
|
|
535
|
+
if (newX >= 0 && newX < _constants__WEBPACK_IMPORTED_MODULE_1__.GRID_HEIGHT && newY >= 0 && newY < _constants__WEBPACK_IMPORTED_MODULE_1__.GRID_WIDTH) {
|
|
536
|
+
ghost.x = newX;
|
|
537
|
+
ghost.y = newY;
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
});
|
|
541
|
+
};
|
|
542
|
+
const getRandomDestination = (x, y) => {
|
|
543
|
+
const maxDistance = 10;
|
|
544
|
+
const randomX = x + Math.floor(Math.random() * (2 * maxDistance + 1)) - maxDistance;
|
|
545
|
+
const randomY = y + Math.floor(Math.random() * (2 * maxDistance + 1)) - maxDistance;
|
|
546
|
+
return {
|
|
547
|
+
x: Math.max(0, Math.min(randomX, _constants__WEBPACK_IMPORTED_MODULE_1__.GRID_HEIGHT - 1)),
|
|
548
|
+
y: Math.max(0, Math.min(randomY, _constants__WEBPACK_IMPORTED_MODULE_1__.GRID_WIDTH - 1))
|
|
549
|
+
};
|
|
550
|
+
};
|
|
551
|
+
const checkCollisions = () => {
|
|
552
|
+
if (_store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.deadReaminingDuration)
|
|
553
|
+
return;
|
|
554
|
+
_store__WEBPACK_IMPORTED_MODULE_3__.Store.ghosts.forEach((ghost, index) => {
|
|
555
|
+
if (ghost.x === _store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.x && ghost.y === _store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.y) {
|
|
556
|
+
if (_store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.powerupReaminingDuration && ghost.scared) {
|
|
557
|
+
respawnGhost(index);
|
|
558
|
+
_store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.points += 10;
|
|
559
|
+
if (_store__WEBPACK_IMPORTED_MODULE_3__.Store.config.outputFormat == 'canvas') {
|
|
560
|
+
_music_player__WEBPACK_IMPORTED_MODULE_2__.MusicPlayer.getInstance().play(_music_player__WEBPACK_IMPORTED_MODULE_2__.Sound.EAT_GHOST);
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
else {
|
|
564
|
+
_store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.points = 0;
|
|
565
|
+
_store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.powerupReaminingDuration = 0;
|
|
566
|
+
_store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.deadReaminingDuration = _constants__WEBPACK_IMPORTED_MODULE_1__.PACMAN_DEATH_DURATION;
|
|
567
|
+
if (_store__WEBPACK_IMPORTED_MODULE_3__.Store.config.outputFormat == 'canvas') {
|
|
568
|
+
_music_player__WEBPACK_IMPORTED_MODULE_2__.MusicPlayer.getInstance()
|
|
569
|
+
.play(_music_player__WEBPACK_IMPORTED_MODULE_2__.Sound.GAME_OVER)
|
|
570
|
+
.then(() => _music_player__WEBPACK_IMPORTED_MODULE_2__.MusicPlayer.getInstance().stopDefaultSound());
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
});
|
|
575
|
+
};
|
|
576
|
+
const respawnGhost = (ghostIndex) => {
|
|
577
|
+
let x, y;
|
|
578
|
+
do {
|
|
579
|
+
x = Math.floor(Math.random() * _constants__WEBPACK_IMPORTED_MODULE_1__.GRID_HEIGHT);
|
|
580
|
+
y = Math.floor(Math.random() * _constants__WEBPACK_IMPORTED_MODULE_1__.GRID_WIDTH);
|
|
581
|
+
} while ((Math.abs(x - _store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.x) <= 2 && Math.abs(y - _store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.y) <= 2) || _store__WEBPACK_IMPORTED_MODULE_3__.Store.grid[x][y] === 0);
|
|
582
|
+
_store__WEBPACK_IMPORTED_MODULE_3__.Store.ghosts[ghostIndex] = {
|
|
583
|
+
x,
|
|
584
|
+
y,
|
|
585
|
+
color: _constants__WEBPACK_IMPORTED_MODULE_1__.GHOST_COLORS[ghostIndex % _constants__WEBPACK_IMPORTED_MODULE_1__.GHOST_COLORS.length],
|
|
586
|
+
scared: false,
|
|
587
|
+
target: undefined
|
|
588
|
+
};
|
|
589
|
+
};
|
|
590
|
+
const activatePowerUp = () => {
|
|
591
|
+
_store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.powerupReaminingDuration = _constants__WEBPACK_IMPORTED_MODULE_1__.PACMAN_POWERUP_DURATION;
|
|
592
|
+
_store__WEBPACK_IMPORTED_MODULE_3__.Store.ghosts.forEach((ghost) => (ghost.scared = true));
|
|
593
|
+
};
|
|
594
|
+
const Game = {
|
|
595
|
+
startGame
|
|
596
|
+
};
|
|
597
|
+
|
|
598
|
+
|
|
599
|
+
/***/ }),
|
|
600
|
+
|
|
601
|
+
/***/ "./src/music-player.ts":
|
|
602
|
+
/*!*****************************!*\
|
|
603
|
+
!*** ./src/music-player.ts ***!
|
|
604
|
+
\*****************************/
|
|
605
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
606
|
+
|
|
607
|
+
__webpack_require__.r(__webpack_exports__);
|
|
608
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
609
|
+
/* harmony export */ MusicPlayer: () => (/* binding */ MusicPlayer),
|
|
610
|
+
/* harmony export */ Sound: () => (/* binding */ Sound)
|
|
611
|
+
/* harmony export */ });
|
|
612
|
+
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
613
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
614
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
615
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
616
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
617
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
618
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
619
|
+
});
|
|
620
|
+
};
|
|
621
|
+
var Sound;
|
|
622
|
+
(function (Sound) {
|
|
623
|
+
Sound["DEFAULT"] = "/src/assets/sounds/pacman_chomp.wav";
|
|
624
|
+
Sound["BEGINNING"] = "/src/assets/sounds/pacman_beginning.wav";
|
|
625
|
+
Sound["GAME_OVER"] = "/src/assets/sounds/pacman_death.wav";
|
|
626
|
+
Sound["EAT_GHOST"] = "/src/assets/sounds/pacman_eatghost.wav";
|
|
627
|
+
})(Sound || (Sound = {}));
|
|
628
|
+
class MusicPlayer {
|
|
629
|
+
constructor() {
|
|
630
|
+
this.sounds = new Map();
|
|
631
|
+
this.currentSource = null;
|
|
632
|
+
this.defaultSource = null;
|
|
633
|
+
this.isMuted = false;
|
|
634
|
+
this.audioContext = new AudioContext();
|
|
635
|
+
}
|
|
636
|
+
static getInstance() {
|
|
637
|
+
if (!MusicPlayer.instance) {
|
|
638
|
+
MusicPlayer.instance = new MusicPlayer();
|
|
639
|
+
}
|
|
640
|
+
return MusicPlayer.instance;
|
|
641
|
+
}
|
|
642
|
+
preloadSounds() {
|
|
643
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
644
|
+
for (const sound of Object.values(Sound)) {
|
|
645
|
+
const response = yield fetch(sound);
|
|
646
|
+
const arrayBuffer = yield response.arrayBuffer();
|
|
647
|
+
const audioBuffer = yield this.audioContext.decodeAudioData(arrayBuffer);
|
|
648
|
+
this.sounds.set(sound, audioBuffer);
|
|
649
|
+
}
|
|
650
|
+
});
|
|
651
|
+
}
|
|
652
|
+
play(sound) {
|
|
653
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
654
|
+
if (this.isMuted) {
|
|
655
|
+
return;
|
|
656
|
+
}
|
|
657
|
+
if (this.currentSource) {
|
|
658
|
+
this.currentSource.stop();
|
|
659
|
+
}
|
|
660
|
+
const buffer = this.sounds.get(sound);
|
|
661
|
+
if (!buffer) {
|
|
662
|
+
console.error(`Sound ${sound} not found`);
|
|
663
|
+
return;
|
|
664
|
+
}
|
|
665
|
+
this.currentSource = this.audioContext.createBufferSource();
|
|
666
|
+
this.currentSource.buffer = buffer;
|
|
667
|
+
this.currentSource.connect(this.audioContext.destination);
|
|
668
|
+
if (!this.isMuted) {
|
|
669
|
+
this.currentSource.start();
|
|
670
|
+
}
|
|
671
|
+
return new Promise((resolve) => {
|
|
672
|
+
this.currentSource.onended = () => {
|
|
673
|
+
this.currentSource = null;
|
|
674
|
+
resolve();
|
|
675
|
+
};
|
|
676
|
+
});
|
|
677
|
+
});
|
|
678
|
+
}
|
|
679
|
+
startDefaultSound() {
|
|
680
|
+
if (this.defaultSource) {
|
|
681
|
+
this.defaultSource.stop();
|
|
682
|
+
}
|
|
683
|
+
const buffer = this.sounds.get(Sound.DEFAULT);
|
|
684
|
+
if (!buffer) {
|
|
685
|
+
console.error('Default sound not found');
|
|
686
|
+
return;
|
|
687
|
+
}
|
|
688
|
+
this.defaultSource = this.audioContext.createBufferSource();
|
|
689
|
+
this.defaultSource.buffer = buffer;
|
|
690
|
+
this.defaultSource.loop = true;
|
|
691
|
+
this.defaultSource.connect(this.audioContext.destination);
|
|
692
|
+
if (!this.isMuted) {
|
|
693
|
+
this.defaultSource.start();
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
stopDefaultSound() {
|
|
697
|
+
if (this.defaultSource) {
|
|
698
|
+
this.defaultSource.stop();
|
|
699
|
+
this.defaultSource = null;
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
mute() {
|
|
703
|
+
this.isMuted = true;
|
|
704
|
+
if (this.currentSource) {
|
|
705
|
+
this.currentSource.disconnect();
|
|
706
|
+
}
|
|
707
|
+
if (this.defaultSource) {
|
|
708
|
+
this.defaultSource.disconnect();
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
unmute() {
|
|
712
|
+
this.isMuted = false;
|
|
713
|
+
if (this.currentSource) {
|
|
714
|
+
this.currentSource.connect(this.audioContext.destination);
|
|
715
|
+
}
|
|
716
|
+
if (this.defaultSource) {
|
|
717
|
+
this.defaultSource.connect(this.audioContext.destination);
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
|
|
723
|
+
/***/ }),
|
|
724
|
+
|
|
725
|
+
/***/ "./src/store.ts":
|
|
726
|
+
/*!**********************!*\
|
|
727
|
+
!*** ./src/store.ts ***!
|
|
728
|
+
\**********************/
|
|
729
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
730
|
+
|
|
731
|
+
__webpack_require__.r(__webpack_exports__);
|
|
732
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
733
|
+
/* harmony export */ Store: () => (/* binding */ Store)
|
|
734
|
+
/* harmony export */ });
|
|
735
|
+
const Store = {
|
|
736
|
+
frameCount: 0,
|
|
737
|
+
contributions: [],
|
|
738
|
+
pacman: {
|
|
739
|
+
x: 0,
|
|
740
|
+
y: 0,
|
|
741
|
+
direction: 'right',
|
|
742
|
+
points: 0,
|
|
743
|
+
deadReaminingDuration: 0,
|
|
744
|
+
powerupReaminingDuration: 0
|
|
745
|
+
},
|
|
746
|
+
ghosts: [],
|
|
747
|
+
grid: [],
|
|
748
|
+
monthLabels: [],
|
|
749
|
+
pacmanMouthOpen: true,
|
|
750
|
+
gameInterval: 0,
|
|
751
|
+
scaredGhostsDestinations: [],
|
|
752
|
+
gameHistory: [],
|
|
753
|
+
config: undefined
|
|
754
|
+
};
|
|
755
|
+
|
|
756
|
+
|
|
757
|
+
/***/ }),
|
|
758
|
+
|
|
759
|
+
/***/ "./src/svg.ts":
|
|
760
|
+
/*!********************!*\
|
|
761
|
+
!*** ./src/svg.ts ***!
|
|
762
|
+
\********************/
|
|
763
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
764
|
+
|
|
765
|
+
__webpack_require__.r(__webpack_exports__);
|
|
766
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
767
|
+
/* harmony export */ SVG: () => (/* binding */ SVG)
|
|
768
|
+
/* harmony export */ });
|
|
769
|
+
/* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./constants */ "./src/constants.ts");
|
|
770
|
+
/* harmony import */ var _store__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./store */ "./src/store.ts");
|
|
771
|
+
/* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./utils */ "./src/utils.ts");
|
|
772
|
+
|
|
773
|
+
|
|
774
|
+
|
|
775
|
+
const generateAnimatedSVG = () => {
|
|
776
|
+
const svgWidth = _constants__WEBPACK_IMPORTED_MODULE_0__.GRID_WIDTH * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE);
|
|
777
|
+
const svgHeight = _constants__WEBPACK_IMPORTED_MODULE_0__.GRID_HEIGHT * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE) + 20;
|
|
778
|
+
let svg = `<svg width="${svgWidth}" height="${svgHeight}" xmlns="http://www.w3.org/2000/svg">`;
|
|
779
|
+
svg += `<rect width="100%" height="100%" fill="${_utils__WEBPACK_IMPORTED_MODULE_2__.Utils.getCurrentTheme().gridBackground}"/>`;
|
|
780
|
+
// Month labels
|
|
781
|
+
let lastMonth = '';
|
|
782
|
+
for (let y = 0; y < _constants__WEBPACK_IMPORTED_MODULE_0__.GRID_WIDTH; y++) {
|
|
783
|
+
if (_store__WEBPACK_IMPORTED_MODULE_1__.Store.monthLabels[y] !== lastMonth) {
|
|
784
|
+
const xPos = y * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE) + _constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE / 2;
|
|
785
|
+
svg += `<text x="${xPos}" y="10" text-anchor="middle" font-size="10" fill="${_utils__WEBPACK_IMPORTED_MODULE_2__.Utils.getCurrentTheme().textColor}">${_store__WEBPACK_IMPORTED_MODULE_1__.Store.monthLabels[y]}</text>`;
|
|
786
|
+
lastMonth = _store__WEBPACK_IMPORTED_MODULE_1__.Store.monthLabels[y];
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
// Grid
|
|
790
|
+
for (let x = 0; x < _constants__WEBPACK_IMPORTED_MODULE_0__.GRID_HEIGHT; x++) {
|
|
791
|
+
for (let y = 0; y < _constants__WEBPACK_IMPORTED_MODULE_0__.GRID_WIDTH; y++) {
|
|
792
|
+
const cellX = y * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE);
|
|
793
|
+
const cellY = x * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE) + 15;
|
|
794
|
+
const intensity = _store__WEBPACK_IMPORTED_MODULE_1__.Store.gameHistory[0].grid[x][y];
|
|
795
|
+
const color = intensity > 0 ? getContributionColor(intensity) : _utils__WEBPACK_IMPORTED_MODULE_2__.Utils.getCurrentTheme().emptyContributionBoxColor;
|
|
796
|
+
svg += `<rect id="cell-${x}-${y}" x="${cellX}" y="${cellY}" width="${_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE}" height="${_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE}" rx="5" fill="${color}">
|
|
797
|
+
<animate attributeName="fill" dur="${_store__WEBPACK_IMPORTED_MODULE_1__.Store.gameHistory.length * 300}ms" repeatCount="indefinite"
|
|
798
|
+
values="${generateCellColorValues(x, y)}"
|
|
799
|
+
keyTimes="${generateKeyTimes()}"/>
|
|
800
|
+
</rect>`;
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
// Pacman
|
|
804
|
+
svg += `<path id="pacman" d="${generatePacManPath(0.35)}"
|
|
805
|
+
transform="translate(${_store__WEBPACK_IMPORTED_MODULE_1__.Store.pacman.y * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE)}, ${_store__WEBPACK_IMPORTED_MODULE_1__.Store.pacman.x * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE) + 15})">
|
|
806
|
+
<animate attributeName="fill" dur="${_store__WEBPACK_IMPORTED_MODULE_1__.Store.gameHistory.length * 300}ms" repeatCount="indefinite"
|
|
807
|
+
keyTimes="${generateKeyTimes()}"
|
|
808
|
+
values="${generatePacManColors()}"/>
|
|
809
|
+
<animateTransform attributeName="transform" type="translate" dur="${_store__WEBPACK_IMPORTED_MODULE_1__.Store.gameHistory.length * 300}ms" repeatCount="indefinite"
|
|
810
|
+
keyTimes="${generateKeyTimes()}"
|
|
811
|
+
values="${generatePacManPositions()}"/>
|
|
812
|
+
<animate attributeName="d" dur="0.2s" repeatCount="indefinite"
|
|
813
|
+
values="${generatePacManPath(0.25)};${generatePacManPath(0.05)};${generatePacManPath(0.25)}"/>
|
|
814
|
+
</path>`;
|
|
815
|
+
// Ghosts
|
|
816
|
+
_store__WEBPACK_IMPORTED_MODULE_1__.Store.ghosts.forEach((ghost, index) => {
|
|
817
|
+
svg += `<path id="ghost${index}" d="${generateGhostPath(_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE / 2)}" fill="${ghost.color}">
|
|
818
|
+
<animate attributeName="fill" dur="${_store__WEBPACK_IMPORTED_MODULE_1__.Store.gameHistory.length * 300}ms" repeatCount="indefinite"
|
|
819
|
+
keyTimes="${generateKeyTimes()}"
|
|
820
|
+
values="${generateGhostColors(index)}"/>
|
|
821
|
+
<animateTransform attributeName="transform" type="translate" dur="${_store__WEBPACK_IMPORTED_MODULE_1__.Store.gameHistory.length * 300}ms" repeatCount="indefinite"
|
|
822
|
+
keyTimes="${generateKeyTimes()}"
|
|
823
|
+
values="${generateGhostPositions(index)}"/>
|
|
824
|
+
</path>
|
|
825
|
+
<circle cx="${_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE / 3}" cy="${_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE / 3}" r="${_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE / 8}" fill="white">
|
|
826
|
+
<animateTransform attributeName="transform" type="translate" dur="${_store__WEBPACK_IMPORTED_MODULE_1__.Store.gameHistory.length * 300}ms" repeatCount="indefinite"
|
|
827
|
+
keyTimes="${generateKeyTimes()}"
|
|
828
|
+
values="${generateGhostPositions(index)}"/>
|
|
829
|
+
</circle>
|
|
830
|
+
<circle cx="${(_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE * 2) / 3}" cy="${_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE / 3}" r="${_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE / 8}" fill="white">
|
|
831
|
+
<animateTransform attributeName="transform" type="translate" dur="${_store__WEBPACK_IMPORTED_MODULE_1__.Store.gameHistory.length * 300}ms" repeatCount="indefinite"
|
|
832
|
+
keyTimes="${generateKeyTimes()}"
|
|
833
|
+
values="${generateGhostPositions(index)}"/>
|
|
834
|
+
</circle>
|
|
835
|
+
<circle cx="${_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE / 3}" cy="${_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE / 3}" r="${_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE / 16}" fill="black">
|
|
836
|
+
<animateTransform attributeName="transform" type="translate" dur="${_store__WEBPACK_IMPORTED_MODULE_1__.Store.gameHistory.length * 300}ms" repeatCount="indefinite"
|
|
837
|
+
keyTimes="${generateKeyTimes()}"
|
|
838
|
+
values="${generateGhostPositions(index)}"/>
|
|
839
|
+
</circle>
|
|
840
|
+
<circle cx="${(_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE * 2) / 3}" cy="${_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE / 3}" r="${_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE / 16}" fill="black">
|
|
841
|
+
<animateTransform attributeName="transform" type="translate" dur="${_store__WEBPACK_IMPORTED_MODULE_1__.Store.gameHistory.length * 300}ms" repeatCount="indefinite"
|
|
842
|
+
keyTimes="${generateKeyTimes()}"
|
|
843
|
+
values="${generateGhostPositions(index)}"/>
|
|
844
|
+
</circle>`;
|
|
845
|
+
});
|
|
846
|
+
svg += '</svg>';
|
|
847
|
+
return svg;
|
|
848
|
+
};
|
|
849
|
+
const generatePacManPath = (mouthAngle) => {
|
|
850
|
+
const radius = _constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE / 2;
|
|
851
|
+
const startAngle = mouthAngle;
|
|
852
|
+
const endAngle = 2 * Math.PI - mouthAngle;
|
|
853
|
+
return `M ${radius},${radius}
|
|
854
|
+
L ${radius + radius * Math.cos(startAngle)},${radius + radius * Math.sin(startAngle)}
|
|
855
|
+
A ${radius},${radius} 0 1,1 ${radius + radius * Math.cos(endAngle)},${radius + radius * Math.sin(endAngle)}
|
|
856
|
+
Z`;
|
|
857
|
+
};
|
|
858
|
+
const generateKeyTimes = () => {
|
|
859
|
+
return _store__WEBPACK_IMPORTED_MODULE_1__.Store.gameHistory.map((_, index) => index / (_store__WEBPACK_IMPORTED_MODULE_1__.Store.gameHistory.length - 1)).join(';');
|
|
860
|
+
};
|
|
861
|
+
const generatePacManPositions = () => {
|
|
862
|
+
return _store__WEBPACK_IMPORTED_MODULE_1__.Store.gameHistory
|
|
863
|
+
.map((state) => {
|
|
864
|
+
const x = state.pacman.y * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE);
|
|
865
|
+
const y = state.pacman.x * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE) + 15;
|
|
866
|
+
return `${x},${y}`;
|
|
867
|
+
})
|
|
868
|
+
.join(';');
|
|
869
|
+
};
|
|
870
|
+
const generatePacManColors = () => {
|
|
871
|
+
return _store__WEBPACK_IMPORTED_MODULE_1__.Store.gameHistory
|
|
872
|
+
.map((state) => {
|
|
873
|
+
if (state.pacman.deadReaminingDuration) {
|
|
874
|
+
return _constants__WEBPACK_IMPORTED_MODULE_0__.PACMAN_COLOR_DEAD;
|
|
875
|
+
}
|
|
876
|
+
else if (state.pacman.powerupReaminingDuration) {
|
|
877
|
+
return _constants__WEBPACK_IMPORTED_MODULE_0__.PACMAN_COLOR_POWERUP;
|
|
878
|
+
}
|
|
879
|
+
else {
|
|
880
|
+
return _constants__WEBPACK_IMPORTED_MODULE_0__.PACMAN_COLOR;
|
|
881
|
+
}
|
|
882
|
+
})
|
|
883
|
+
.join(';');
|
|
884
|
+
};
|
|
885
|
+
const generateCellColorValues = (x, y) => {
|
|
886
|
+
return _store__WEBPACK_IMPORTED_MODULE_1__.Store.gameHistory
|
|
887
|
+
.map((state) => {
|
|
888
|
+
const intensity = state.grid[x][y];
|
|
889
|
+
return intensity > 0 ? getContributionColor(intensity) : _utils__WEBPACK_IMPORTED_MODULE_2__.Utils.getCurrentTheme().emptyContributionBoxColor;
|
|
890
|
+
})
|
|
891
|
+
.join(';');
|
|
892
|
+
};
|
|
893
|
+
const getContributionColor = (intensity) => {
|
|
894
|
+
const adjustedIntensity = intensity < 0.2 ? 0.3 : intensity;
|
|
895
|
+
return _utils__WEBPACK_IMPORTED_MODULE_2__.Utils.hexToRGBA(_utils__WEBPACK_IMPORTED_MODULE_2__.Utils.getCurrentTheme().contributionBoxColor, adjustedIntensity);
|
|
896
|
+
};
|
|
897
|
+
const generateGhostPositions = (ghostIndex) => {
|
|
898
|
+
return _store__WEBPACK_IMPORTED_MODULE_1__.Store.gameHistory
|
|
899
|
+
.map((state) => {
|
|
900
|
+
const ghost = state.ghosts[ghostIndex];
|
|
901
|
+
const x = ghost.y * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE);
|
|
902
|
+
const y = ghost.x * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE) + 15;
|
|
903
|
+
return `${x},${y}`;
|
|
904
|
+
})
|
|
905
|
+
.join(';');
|
|
906
|
+
};
|
|
907
|
+
const generateGhostPath = (radius) => {
|
|
908
|
+
return `M ${radius},${radius * 2}
|
|
909
|
+
Q ${radius * 0.8},${radius * 1.5} ${radius * 0.5},${radius * 1.3}
|
|
910
|
+
Q ${radius * 0.3},${radius * 1.1} 0,${radius}
|
|
911
|
+
L 0,0
|
|
912
|
+
L ${radius * 2},0
|
|
913
|
+
L ${radius * 2},${radius}
|
|
914
|
+
Q ${radius * 1.7},${radius * 1.1} ${radius * 1.5},${radius * 1.3}
|
|
915
|
+
Q ${radius * 1.2},${radius * 1.5} ${radius},${radius * 2}
|
|
916
|
+
Z`;
|
|
917
|
+
};
|
|
918
|
+
const generateGhostColors = (ghostIndex) => {
|
|
919
|
+
return _store__WEBPACK_IMPORTED_MODULE_1__.Store.gameHistory
|
|
920
|
+
.map((state) => {
|
|
921
|
+
const ghost = state.ghosts[ghostIndex];
|
|
922
|
+
return ghost.scared ? 'blue' : ghost.color;
|
|
923
|
+
})
|
|
924
|
+
.join(';');
|
|
925
|
+
};
|
|
926
|
+
const SVG = {
|
|
927
|
+
generateAnimatedSVG
|
|
928
|
+
};
|
|
929
|
+
|
|
930
|
+
|
|
931
|
+
/***/ }),
|
|
932
|
+
|
|
933
|
+
/***/ "./src/utils.ts":
|
|
934
|
+
/*!**********************!*\
|
|
935
|
+
!*** ./src/utils.ts ***!
|
|
936
|
+
\**********************/
|
|
937
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
938
|
+
|
|
939
|
+
__webpack_require__.r(__webpack_exports__);
|
|
940
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
941
|
+
/* harmony export */ Utils: () => (/* binding */ Utils)
|
|
942
|
+
/* harmony export */ });
|
|
943
|
+
/* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./constants */ "./src/constants.ts");
|
|
944
|
+
/* harmony import */ var _store__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./store */ "./src/store.ts");
|
|
945
|
+
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
946
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
947
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
948
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
949
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
950
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
951
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
952
|
+
});
|
|
953
|
+
};
|
|
954
|
+
|
|
955
|
+
|
|
956
|
+
const getGitlabContribution = (username) => __awaiter(void 0, void 0, void 0, function* () {
|
|
957
|
+
const response = yield fetch(`https://gitlab.com/users/${username}/calendar.json`);
|
|
958
|
+
const contributionsList = yield response.json();
|
|
959
|
+
return Object.entries(contributionsList).map(([date, count]) => ({
|
|
960
|
+
date: new Date(date),
|
|
961
|
+
count: Number(count)
|
|
962
|
+
}));
|
|
963
|
+
});
|
|
964
|
+
const getGithubContribution = (username) => __awaiter(void 0, void 0, void 0, function* () {
|
|
965
|
+
const response = yield fetch(`https://api.github.com/search/commits?q=author:${username}&sort=author-date&order=desc&page=1&per_page=1000`);
|
|
966
|
+
const contributionsList = yield response.json();
|
|
967
|
+
return Array.from(contributionsList.items
|
|
968
|
+
.reduce((map, item) => {
|
|
969
|
+
const dateString = item.commit.committer.date.split('T')[0];
|
|
970
|
+
const date = new Date(dateString);
|
|
971
|
+
const count = (map.get(dateString) || { count: 0 }).count + 1;
|
|
972
|
+
return map.set(dateString, { date, count });
|
|
973
|
+
}, new Map())
|
|
974
|
+
.values());
|
|
975
|
+
});
|
|
976
|
+
const getCurrentTheme = () => {
|
|
977
|
+
var _a;
|
|
978
|
+
return (_a = _constants__WEBPACK_IMPORTED_MODULE_0__.GAME_THEMES[_store__WEBPACK_IMPORTED_MODULE_1__.Store.config.gameTheme]) !== null && _a !== void 0 ? _a : _constants__WEBPACK_IMPORTED_MODULE_0__.GAME_THEMES['github'];
|
|
979
|
+
};
|
|
980
|
+
function hexToRGBA(hex, alpha) {
|
|
981
|
+
const r = parseInt(hex.slice(1, 3), 16);
|
|
982
|
+
const g = parseInt(hex.slice(3, 5), 16);
|
|
983
|
+
const b = parseInt(hex.slice(5, 7), 16);
|
|
984
|
+
return `rgba(${r}, ${g}, ${b}, ${alpha})`;
|
|
985
|
+
}
|
|
986
|
+
const Utils = {
|
|
987
|
+
getGitlabContribution,
|
|
988
|
+
getGithubContribution,
|
|
989
|
+
getCurrentTheme,
|
|
990
|
+
hexToRGBA
|
|
991
|
+
};
|
|
992
|
+
|
|
993
|
+
|
|
994
|
+
/***/ })
|
|
995
|
+
|
|
996
|
+
/******/ });
|
|
997
|
+
/************************************************************************/
|
|
998
|
+
/******/ // The module cache
|
|
999
|
+
/******/ var __webpack_module_cache__ = {};
|
|
1000
|
+
/******/
|
|
1001
|
+
/******/ // The require function
|
|
1002
|
+
/******/ function __webpack_require__(moduleId) {
|
|
1003
|
+
/******/ // Check if module is in cache
|
|
1004
|
+
/******/ var cachedModule = __webpack_module_cache__[moduleId];
|
|
1005
|
+
/******/ if (cachedModule !== undefined) {
|
|
1006
|
+
/******/ return cachedModule.exports;
|
|
1007
|
+
/******/ }
|
|
1008
|
+
/******/ // Create a new module (and put it into the cache)
|
|
1009
|
+
/******/ var module = __webpack_module_cache__[moduleId] = {
|
|
1010
|
+
/******/ // no module.id needed
|
|
1011
|
+
/******/ // no module.loaded needed
|
|
1012
|
+
/******/ exports: {}
|
|
1013
|
+
/******/ };
|
|
1014
|
+
/******/
|
|
1015
|
+
/******/ // Execute the module function
|
|
1016
|
+
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
1017
|
+
/******/
|
|
1018
|
+
/******/ // Return the exports of the module
|
|
1019
|
+
/******/ return module.exports;
|
|
1020
|
+
/******/ }
|
|
1021
|
+
/******/
|
|
1022
|
+
/************************************************************************/
|
|
1023
|
+
/******/ /* webpack/runtime/define property getters */
|
|
1024
|
+
/******/ (() => {
|
|
1025
|
+
/******/ // define getter functions for harmony exports
|
|
1026
|
+
/******/ __webpack_require__.d = (exports, definition) => {
|
|
1027
|
+
/******/ for(var key in definition) {
|
|
1028
|
+
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
1029
|
+
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
1030
|
+
/******/ }
|
|
1031
|
+
/******/ }
|
|
1032
|
+
/******/ };
|
|
1033
|
+
/******/ })();
|
|
1034
|
+
/******/
|
|
1035
|
+
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
|
1036
|
+
/******/ (() => {
|
|
1037
|
+
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
1038
|
+
/******/ })();
|
|
1039
|
+
/******/
|
|
1040
|
+
/******/ /* webpack/runtime/make namespace object */
|
|
1041
|
+
/******/ (() => {
|
|
1042
|
+
/******/ // define __esModule on exports
|
|
1043
|
+
/******/ __webpack_require__.r = (exports) => {
|
|
1044
|
+
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
1045
|
+
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
1046
|
+
/******/ }
|
|
1047
|
+
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
|
1048
|
+
/******/ };
|
|
1049
|
+
/******/ })();
|
|
1050
|
+
/******/
|
|
1051
|
+
/************************************************************************/
|
|
1052
|
+
var __webpack_exports__ = {};
|
|
1053
|
+
// This entry needs to be wrapped in an IIFE because it needs to be isolated against other modules in the chunk.
|
|
1054
|
+
(() => {
|
|
1055
|
+
/*!**********************!*\
|
|
1056
|
+
!*** ./src/index.ts ***!
|
|
1057
|
+
\**********************/
|
|
1058
|
+
__webpack_require__.r(__webpack_exports__);
|
|
1059
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
1060
|
+
/* harmony export */ renderContributions: () => (/* binding */ renderContributions)
|
|
1061
|
+
/* harmony export */ });
|
|
1062
|
+
/* harmony import */ var _game__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./game */ "./src/game.ts");
|
|
1063
|
+
/* harmony import */ var _store__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./store */ "./src/store.ts");
|
|
1064
|
+
/* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./utils */ "./src/utils.ts");
|
|
1065
|
+
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
1066
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
1067
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
1068
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
1069
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
1070
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
1071
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
1072
|
+
});
|
|
1073
|
+
};
|
|
1074
|
+
|
|
1075
|
+
|
|
1076
|
+
|
|
1077
|
+
const renderContributions = (conf) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1078
|
+
const defaultConfing = {
|
|
1079
|
+
platform: 'github',
|
|
1080
|
+
username: '',
|
|
1081
|
+
canvas: undefined,
|
|
1082
|
+
outputFormat: 'svg',
|
|
1083
|
+
svgCallback: (_) => { },
|
|
1084
|
+
gameOverCallback: () => () => { },
|
|
1085
|
+
gameTheme: 'github',
|
|
1086
|
+
gameSpeed: 1,
|
|
1087
|
+
enableSounds: true
|
|
1088
|
+
};
|
|
1089
|
+
_store__WEBPACK_IMPORTED_MODULE_1__.Store.config = Object.assign(Object.assign({}, defaultConfing), conf);
|
|
1090
|
+
switch (conf.platform) {
|
|
1091
|
+
case 'gitlab':
|
|
1092
|
+
_store__WEBPACK_IMPORTED_MODULE_1__.Store.contributions = yield _utils__WEBPACK_IMPORTED_MODULE_2__.Utils.getGitlabContribution(conf.username);
|
|
1093
|
+
break;
|
|
1094
|
+
case 'github':
|
|
1095
|
+
_store__WEBPACK_IMPORTED_MODULE_1__.Store.contributions = yield _utils__WEBPACK_IMPORTED_MODULE_2__.Utils.getGithubContribution(conf.username);
|
|
1096
|
+
break;
|
|
1097
|
+
}
|
|
1098
|
+
_game__WEBPACK_IMPORTED_MODULE_0__.Game.startGame();
|
|
1099
|
+
});
|
|
1100
|
+
|
|
1101
|
+
})();
|
|
1102
|
+
|
|
1103
|
+
var __webpack_exports__renderContributions = __webpack_exports__.renderContributions;
|
|
1104
|
+
export { __webpack_exports__renderContributions as renderContributions };
|
|
1105
|
+
|
|
1106
|
+
//# sourceMappingURL=pacman-contribution-graph.js.map
|