@jamesrock/rockjs 1.7.0 → 1.8.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.
Files changed (2) hide show
  1. package/index.js +55 -0
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -178,3 +178,58 @@ export class Rounder {
178
178
  return Math.round(value / this.tolerance) * this.tolerance;
179
179
  };
180
180
  };
181
+
182
+ export class DisplayObject {
183
+ appendTo(to) {
184
+
185
+ to.appendChild(this.node);
186
+ return this;
187
+
188
+ };
189
+ addEventListener(event, handler, passive = true) {
190
+
191
+ this.node.addEventListener(event, handler, {passive});
192
+ return this;
193
+
194
+ };
195
+ dispatchEvent(event) {
196
+
197
+ this.node.dispatchEvent(new Event(event));
198
+ return this;
199
+
200
+ };
201
+ };
202
+
203
+ export class GameBase extends DisplayObject {
204
+ constructor(name) {
205
+
206
+ super();
207
+
208
+ this.node = createNode('div', name);
209
+ this.gameOverNode = createNode('div', 'game-over');
210
+ this.canvas = createNode('canvas', 'game-canvas');
211
+ this.ctx = this.canvas.getContext('2d');
212
+ this.storage = new Storage(`me.jamesrock.${name}`);
213
+
214
+ };
215
+ showGameOverScreen() {
216
+
217
+ const best = this.storage.get('best') || 0;
218
+ this.storage.set('best', this.score > best ? this.score : best);
219
+
220
+ this.gameOverNode.innerHTML = `\
221
+ <div class="game-over-body">\
222
+ <h1>Game over!</h1>\
223
+ <div>\
224
+ <p class="score">${formatNumber(this.score)}</p>\
225
+ <p class="best">Best: ${formatNumber(this.storage.get('best'))}</p>\
226
+ </div>\
227
+ <p class="continue">Tap to continue</p>\
228
+ </div>`;
229
+ this.gameOver = true;
230
+ this.gameOverNode.dataset.active = true;
231
+
232
+ return this;
233
+
234
+ };
235
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jamesrock/rockjs",
3
- "version": "1.7.0",
3
+ "version": "1.8.0",
4
4
  "description": "utility bliss",
5
5
  "license": "ISC",
6
6
  "author": "James Rock",