This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Minimal AJAX get request method to fetch data. Example usage: | |
get('example.com/api/products/123') | |
.then(product => console.log(product.name)) | |
*/ | |
function get(url) { | |
return new Promise(res => { | |
let xmlHttp = new XMLHttpRequest(); | |
xmlHttp.onreadystatechange = () => { | |
if(xmlHttp.readyState == 4 && xmlHttp.status == 200) res(JSON.parse(xmlHttp.responseText)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function drawImage(ctx, img, x, y, angle = 0, scale = 1){ | |
ctx.save(); | |
ctx.translate(x + img.width * scale / 2, y + img.height * scale / 2); | |
ctx.rotate(angle); | |
ctx.translate(- x - img.width * scale / 2, - y - img.height * scale / 2); | |
ctx.drawImage(img, x, y, img.width * scale, img.height * scale); | |
ctx.restore(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Input { | |
constructor(el = document) { | |
this.keys = []; | |
this.mouse = []; | |
this.mousemoveHandlers = []; | |
this.mousedownHandlers = []; | |
this.mouseupHandlers = []; | |
document.addEventListener("keydown", e => { | |
this.keys[e.key] = true; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fx = { | |
flashCounter: 0, | |
flashDamp: 10,//increase to make flash faster, decrease for longer flash | |
flashColor: "#fff", | |
shakeCounter: 0, | |
shakeAmplitude: 20, | |
shakeDamp: 5,//increse to make shake shorter, decrease to shake longer | |
shakeSpeed: 0.1, | |
shake(amount = 1) { | |
this.shakeCounter = amount; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class View { | |
constructor({ | |
canvas = document.querySelector("canvas"), | |
imageNames = [], | |
cameraAnchor = new Vector(0, 0), | |
cameraPosition = new Vector(0, 0), | |
cameraAngle = 0, | |
cameraScale = 1, | |
cameraHeight = 1000, | |
cameraZoom = 1, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DotComment { | |
constructor() { | |
this.comment = ''; | |
const lowerCaseAlphabets = 'abcdefghiklmnopqrstvxyzåäö'.split(''); | |
const specialCharacters = '_'.split(''); | |
const upperCaseAlphabets = lowerCaseAlphabets.map(char => | |
char.toUpperCase() | |
); | |
const characters = [ |